### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Configurations\XAiApiConfiguration.cs
using xAiModels.Models;
using xAiModels.Constants;
namespace xAiModels.Configurations
{
public class XAiApiConfiguration
{
///
/// Model Providers ...
///
public XAiModelDescriptor[] Models { get; set; } = [];
///
/// Each User must Has a Default Project, this is Title Resource Identifier ...
///
public string DefaultProjectTitleResource { get; set; } = XAiModelsConstants.DefaultXAiProjectTitleResourceID;
///
/// Each User must Has a Default Project, this is Description Resource Identifier ...
///
public string DefaultProjectDescriptionResource { get; set; } = XAiModelsConstants.DefaultXAiProjectDescriptionResourceID;
///
/// Each User must Has a Default Conversation, this is Title Resource Identifier ... ...
///
public string DefaultConversationTitleResource { get; set; } = XAiModelsConstants.DefaultXAiConversationTitleResourceID;
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Configurations\XAiModelMappersProfile.cs
using AutoMapper;
using xAiModels.Models.Dtos;
using xAiModels.Models.Entities;
namespace xAiModels.Configurations
{
public class XAiModelMappersProfile : Profile
{
public XAiModelMappersProfile()
{
//
// XAiMessage ...
CreateMap();
//
// XAiProject ...
CreateMap();
//
// XAiConversation ...
CreateMap();
}
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Configurations\Entities\XAiConversationEntityConfiguration.cs
using System;
using xAiModels.Constants;
using xDataService.Providers;
using xAiModels.Models.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace xAiModels.Configurations.Entities
{
public class XAiConversationEntityConfiguration : XBaseEntityTypeConfiguration
{
public override void Configure(EntityTypeBuilder builder)
{
builder.ToTable(XAiModelsConstants.XAiConversationTable);
}
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Configurations\Entities\XAiMessageEntityConfiguration.cs
using System;
using xAiModels.Constants;
using xDataService.Providers;
using xAiModels.Models.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace xAiModels.Configurations.Entities
{
public class XAiMessageEntityConfiguration : XBaseEntityTypeConfiguration
{
public override void Configure(EntityTypeBuilder builder)
{
builder.ToTable(XAiModelsConstants.XAiMessageTable);
}
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Configurations\Entities\XAiProjectEntityConfiguration.cs
using System;
using xAiModels.Constants;
using xDataService.Providers;
using xAiModels.Models.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace xAiModels.Configurations.Entities
{
public class XAiProjectEntityConfiguration : XBaseEntityTypeConfiguration
{
public override void Configure(EntityTypeBuilder builder)
{
builder.ToTable(XAiModelsConstants.XAiProjectTable);
}
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Constants\ConfigurationNodeNames.cs
namespace xAiModels.Constants
{
public partial struct ConfigurationNodeNames
{
public const string AI_API_NODE = "AiApiConfiguration";
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Constants\XAiChatRole.cs
using xExceptions.Attributes;
namespace xAiModels.Constants
{
public struct XAiChatRoles
{
public const string None = "none";
public const string User = "user";
public const string Tool = "tool";
public const string System = "system";
public const string Assistant = "assistant";
}
public enum XAiChatRole
{
[StringValue(XAiChatRoles.None)]
None,
[StringValue(XAiChatRoles.User)]
User,
[StringValue(XAiChatRoles.Tool)]
Tool,
[StringValue(XAiChatRoles.System)]
System,
[StringValue(XAiChatRoles.Assistant)]
Assistant,
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Constants\XAiDataProviderConstants.cs
using xExceptions.Attributes;
namespace xAiModels.Constants
{
public struct XAiDataProviderConstants
{
public const string XDefaultAiProjectSuffix = "DefAiPrj";
public const string XDefaultAiConversationSuffix = "DefAiCnv";
}
public enum XAiDataProviderHubActions
{
//
// Project ...
[StringValue("ProjectCreated")]
ProjectCreated,
[StringValue("ProjectUpdated")]
ProjectUpdated,
[StringValue("ProjectRemoved")]
ProjectRemoved,
//
// Conversation ...
[StringValue("ConversationCreated")]
ConversationCreated,
[StringValue("ConversationUpdated")]
ConversationUpdated,
[StringValue("ConversationRemoved")]
ConversationRemoved,
//
// Message ...
[StringValue("MessageCreated")]
MessageCreated,
[StringValue("MessageUpdated")]
MessageUpdated,
[StringValue("MessageRemoved")]
MessageRemoved,
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Constants\XAiModelProviderType.cs
namespace xAiModels.Constants
{
///
/// Specifiy Provider Type ...
///
public enum XAiModelProviderType
{
None,
OpenAI,
Ollama,
DeepSeek,
HuggingFace
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Constants\XAiModelsConstants.cs
namespace xAiModels.Constants
{
public struct XAiModelsConstants
{
//
// Service Extensions Log Tag ...
public const string XAiModelsDILogTag = "XAiModels";
//
// Table Mapping Identifiers ...
public const string XAiMessageTable = "AiMessages";
public const string XAiProjectTable = "AiProjects";
public const string XAiConversationTable = "AiConversations";
//
// GraphQL Collection Mappings ...
public const string XAiMessageSingleName = "aiMessage";
public const string XAiProjectSingleName = "aiProject";
public const string XAiConversationSignleName = "aiConversation";
public const string XAiMessageCollectionName = "aiMessages";
public const string XAiProjectCollectionName = "AiProjectsa";
public const string XAiConversationCollectionName = "aiConversations";
//
// Hubs ...
public const string XAiMessageDtoHub = "aiMessageDto";
public const string XAiMessageEntityHub = "aiMessageEntity";
public const string XAiProjectDtoHub = "aiProjectDto";
public const string XAiProjectEntityHub = "aiProjectEntity";
public const string XAiConversationDtoHub = "aiConversationDto";
public const string XAiConversationEntityHub = "aiConversationEntity";
//
// Resource Provider Identifiers ...
public const string XAiProjectTitleIdentifier = "AiPrjT";
public const string XAiProjectDescriptionIdentifier = "AiPrjD";
public const string XAiConversationTitleIdentifier = "AiCnvrT";
//
// EF Repositories Helper Extensions ...
public const string GetXAiMessageEFRepositoryDescriptor = "GetXAiMessageEFRepositoryDescriptor";
public const string GetXAiProjectEFRepositoryDescriptor = "GetXAiProjectEFRepositoryDescriptor";
public const string GetXAiConversationEFRepositoryDescriptor = "GetXAiConversationEFRepositoryDescriptor";
//
public const string DefaultXAiProjectTitleResourceID = "XAiPrjT";
public const string DefaultXAiConversationTitleResourceID = "XAiCnvT";
public const string DefaultXAiProjectDescriptionResourceID = "XAiPrjD";
//
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\DI\XDIHelperExtension.cs
using System;
using xDataService.Db;
using xPushService.DI;
using xDataService.DI;
using xCommons.Helpers;
using xAiModels.Helpers;
using xDataService.Models;
using xAiModels.Providers;
using xAiModels.Constants;
using xCommons.Extensions;
using xPushService.Helpers;
using xAiModels.Interfaces;
using xExceptions.Constants;
using xDataService.Constants;
using xAiModels.Providers.Dtos;
using xAiModels.Interfaces.Dtos;
using Microsoft.AspNetCore.Builder;
using xAiModels.Providers.Entities;
using xAiModels.Interfaces.Entities;
using xAiModels.Providers.Enrichers;
using xAiModels.Interfaces.Enrichers;
using Microsoft.Extensions.DependencyInjection;
namespace xAiModels.DI
{
///
/// Service Registration Extensions Classes ...
///
public static class XDIHelperExtension
{
///
/// Register Service ...
///
///
///
///
public static void AddXAiDataService(
this IServiceCollection services,
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
{
AddAiDataService(
contextType: null,
services: services,
lifeTime: lifeTime,
repositoryType: repositoryType
);
}
///
/// Register Service ...
///
///
///
///
///
public static void AddXAiDataService(
this IServiceCollection services,
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
where TContext : XDbContext
{
AddAiDataService(
services: services,
lifeTime: lifeTime,
contextType: typeof(TContext),
repositoryType: repositoryType
);
}
///
/// Use XSubCategoryService Middleware ...
///
///
///
public static void UseXAiDataService(
this IApplicationBuilder app,
bool isDevelopmentEnvironment = false
)
{
//
#region Using Hubs ...
//
var pushHelper = new XPushServiceHelper();
//
// XAiMessage ...
pushHelper.AddHub(XAiModelsConstants.XAiMessageDtoHub);
pushHelper.AddHub(XAiModelsConstants.XAiMessageEntityHub);
//
// XAiProject ...
pushHelper.AddHub(XAiModelsConstants.XAiProjectDtoHub);
pushHelper.AddHub(XAiModelsConstants.XAiProjectEntityHub);
//
// XAiConversation ...
pushHelper.AddHub(XAiModelsConstants.XAiConversationDtoHub);
pushHelper.AddHub(XAiModelsConstants.XAiConversationEntityHub);
//
app.UseXPushService(pushHelper);
#endregion
//
// Using XAiConversation Repository Descriptor ...
if (!aiConversationDescriptor.IsNull())
{
//
app.UseXRepository(
descriptor: aiConversationDescriptor,
isDevelopmentEnvironment: isDevelopmentEnvironment
);
}
//
// Using XAiMessage Repository Descriptor ...
if (!aiMessageDescriptor.IsNull())
{
//
app.UseXRepository(
descriptor: aiMessageDescriptor,
isDevelopmentEnvironment: isDevelopmentEnvironment
);
}
//
// Using XAiProject Repository Descriptor ...
if (!aiProjectDescriptor.IsNull())
{
//
app.UseXRepository(
descriptor: aiProjectDescriptor,
isDevelopmentEnvironment: isDevelopmentEnvironment
);
}
//
// Create an Scope for Services Acces ...
// Handle Seeding Category/SubCategory Resources ...
// TODO: Enable Seeding if Required ...
// using (var scope = app.ApplicationServices.CreateScope())
// {
// //
// // Retrieve Configuratuions ...
// var aiMessageProvider = scope.ServiceProvider.GetService();
// var aiProjectProvider = scope.ServiceProvider.GetService();
// var aiConversationProvider = scope.ServiceProvider.GetService();
// var configuration = scope.ServiceProvider.GetService();
// if (!configuration.IsNullOrDefault() &&
// !categoryProvider.IsNullOrDefault() &&
// !subaiConversationDescriptor.IsNullOrDefault()
// )
// {
// //
// // Logging ...
// Log("Start Seeding ...");
// //
// // Count Data in Category ...
// var hasCategory = (categoryProvider.Count().GetAwaiter().GetResult()) > 0;
// var hasSubCategory = (subCategoryProvider.Count().GetAwaiter().GetResult()) > 0;
// //
// // Seed Category Resources ...
// var canSeed =
// !hasCategory &&
// configuration.Categories.HasChild();
// if (canSeed)
// {
// //
// // Loop through Provided items ...
// foreach (var cat in configuration.Categories)
// {
// //
// try
// {
// //
// Log($"Start Seeding Category: {cat.Titles.Locales.ToArray()[0].Value} ...");
// //
// categoryProvider.Refresh(
// resource: cat,
// userInfo: null,
// connectionId: null,
// cancellationToken: default
// )
// .GetAwaiter()
// .GetResult();
// //
// Log($"Seeding Category: {cat.Titles.Locales.ToArray()[0].Value} Finished Successfully ...");
// }
// catch (Exception ex)
// {
// Log($"Seeding Category: {cat.Titles.Locales.ToArray()[0].Value} Failed due: {ex.Message} ...");
// }
// }
// }
// //
// // Seed SubCategory Resources ...
// canSeed =
// !hasSubCategory &&
// configuration.SubCategories.HasChild();
// if (canSeed)
// {
// //
// // Loop through Provided items ...
// foreach (var subcat in configuration.SubCategories)
// {
// //
// try
// {
// //
// Log($"Start Seeding SubCategory: {subcat.Titles.Locales.ToArray()[0].Value} ...");
// //
// subCategoryProvider.Refresh(
// userInfo: null,
// resource: subcat,
// connectionId: null,
// cancellationToken: default
// )
// .GetAwaiter()
// .GetResult();
// //
// Log($"Seeding SubCategory: {subcat.Titles.Locales.ToArray()[0].Value} Finished Successfully ...");
// }
// catch (Exception ex)
// {
// Log($"Seeding SubCategory: {subcat.Titles.Locales.ToArray()[0].Value} Failed due: {ex.Message} ...");
// }
// }
// }
// //
// Log("Finish Seeding ...");
// }
// }
}
//
#region Private ...
private static XRepositoryDescriptor aiMessageDescriptor = null;
private static XRepositoryDescriptor aiProjectDescriptor = null;
private static XRepositoryDescriptor aiConversationDescriptor = null;
///
/// a LogTag for Service ...
///
private static string XLogTag = XAiModelsConstants.XAiModelsDILogTag;
///
/// print a log in Console ...
///
///
private static void Log(string message)
{
Console.WriteLine($"{XLogTag} => {message}");
}
///
/// Register Service ...
///
///
///
///
///
private static void AddAiDataService(
IServiceCollection services,
XRepositoryType repositoryType,
Type contextType = null,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
{
//
var exception = XException.InvalidArgs.ToException(); ;
//
// Services ...
var isServicesExists = !services.IsNull();
if (!isServicesExists)
{
//
Log("Service Registration failed, services not provided ...");
throw exception;
}
//
// Lifetime ...
var isLifetimeExists = !lifeTime.IsNull();
if (!isLifetimeExists)
{
//
Log("Service Registration failed, lifetime not provided ...");
throw exception;
}
//
// Validate Repository Type ...
var isRepositoryTypeValid =
(repositoryType == XRepositoryType.EF &&
!contextType.IsNull()) ||
((repositoryType == XRepositoryType.Mongo ||
repositoryType == XRepositoryType.InMemory) &&
contextType.IsNull());
if (!isRepositoryTypeValid)
{
//
Log("Service Registration failed, Invalid Repository Type and Context Type ...");
throw exception;
}
//
// Maske Instance of Repository Descriptor
// Based on Provided Type ...
switch (repositoryType)
{
//
case XRepositoryType.EF:
//
// XAiMessage ...
aiMessageDescriptor = typeof(XAiModelsHelper)
.InvokeGenericMethod(
args: null,
runtimeType: contextType,
methodName: XAiModelsConstants.GetXAiMessageEFRepositoryDescriptor
);
//
// XAiProject ...
aiProjectDescriptor = typeof(XAiModelsHelper)
.InvokeGenericMethod(
args: null,
runtimeType: contextType,
methodName: XAiModelsConstants.GetXAiProjectEFRepositoryDescriptor
);
//
// XAiConversation ...
aiConversationDescriptor = typeof(XAiModelsHelper)
.InvokeGenericMethod(
args: null,
runtimeType: contextType,
methodName: XAiModelsConstants.GetXAiConversationEFRepositoryDescriptor
);
break;
//
case XRepositoryType.Mongo:
//
// XAiMessage ...
aiMessageDescriptor = XAiModelsHelper.GetXAiMessageMongoRepositoryDescriptor();
//
// XAiProject ...
aiProjectDescriptor = XAiModelsHelper.GetXAiProjectMongoRepositoryDescriptor();
//
// XAiConversation ...
aiConversationDescriptor = XAiModelsHelper.GetXAiConversationMongoRepositoryDescriptor();
break;
//
case XRepositoryType.InMemory:
//
// XAiMessage ...
aiMessageDescriptor = XAiModelsHelper.GetXAiMessageInMemoryRepositoryDescriptor();
//
// XAiProject ...
aiProjectDescriptor = XAiModelsHelper.GetXAiProjectInMemoryRepositoryDescriptor();
//
// XAiConversation ...
aiConversationDescriptor = XAiModelsHelper.GetXAiConversationInMemoryRepositoryDescriptor();
break;
}
//
#region Register Repository Descriptor ...
//
// XAiMessage ...
if (!aiMessageDescriptor.IsNull())
{
//
services.AddXRepository(
lifeTime: lifeTime,
descriptor: aiMessageDescriptor
);
}
//
// XAiProject ...
if (!aiProjectDescriptor.IsNull())
{
//
services.AddXRepository(
lifeTime: lifeTime,
descriptor: aiProjectDescriptor
);
}
//
// XAiConversation ...
if (!aiConversationDescriptor.IsNull())
{
//
services.AddXRepository(
lifeTime: lifeTime,
descriptor: aiConversationDescriptor
);
}
#endregion
//
#region Register Services ...
//
#region AiMessage ...
//
services.Add(
new ServiceDescriptor(typeof(IXAiMessageServiceProvider), typeof(XAiMessageServiceProvider), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXAiMessageRepositoryService), typeof(XAiMessageRepositoryService), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXAiMessageRepositoryProvider), typeof(XAiMessageRepositoryProvider), lifeTime)
);
//
// Enrichers ...
services.Add(
new ServiceDescriptor(typeof(IXAiMessageEnricher), typeof(XAiMessageEnricher), lifeTime)
);
#endregion
//
#region AiProject ...
//
services.Add(
new ServiceDescriptor(typeof(IXAiProjectServiceProvider), typeof(XAiProjectServiceProvider), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXAiProjectRepositoryService), typeof(XAiProjectRepositoryService), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXAiProjectRepositoryProvider), typeof(XAiProjectRepositoryProvider), lifeTime)
);
//
// Resource Providers ...
services.Add(
new ServiceDescriptor(typeof(IXAiProjectTitleResourceProvider), typeof(XAiProjectTitleResourceProvider), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXAiProjectDescriptionResourceProvider), typeof(XAiProjectDescriptionResourceProvider), lifeTime)
);
//
// Enrichers ...
services.Add(
new ServiceDescriptor(typeof(IXAiProjectEnricher), typeof(XAiProjectEnricher), lifeTime)
);
#endregion
//
#region AiConversation ...
//
services.Add(
new ServiceDescriptor(typeof(IXAiConversationServiceProvider), typeof(XAiConversationServiceProvider), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXAiConversationRepositoryService), typeof(XAiConversationRepositoryService), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXAiConversationRepositoryProvider), typeof(XAiConversationRepositoryProvider), lifeTime)
);
//
// Resource Providers ...
services.Add(
new ServiceDescriptor(typeof(IXAiConversationTitleResourceProvider), typeof(XAiConversationTitleResourceProvider), lifeTime)
);
//
// Enrichers ...
services.Add(
new ServiceDescriptor(typeof(IXAiConversationEnricher), typeof(XAiConversationEnricher), lifeTime)
);
#endregion
#endregion
//
// Data Provider ...
services.Add(
new ServiceDescriptor(typeof(IXAiDataProvider), typeof(XAiDataProvider), lifeTime)
);
//
Log("Service Regitration Succeed ...");
}
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Extensions\ChatResponseExtensions.cs
using xCommons.Extensions;
using Microsoft.Extensions.AI;
namespace xAiModels.Extensions
{
public static class ChatResponseExtensions
{
///
/// Validate a Chat Response ...
///
///
///
public static bool IsValid(this ChatResponse source)
{
//
var result =
source is not null &&
!source.IsNullOrDefault() &&
!string.IsNullOrWhiteSpace(source.Text) &&
source.FinishReason == ChatFinishReason.Stop;
//
return result;
}
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Extensions\ChatRoleExtensions.cs
using xAiModels.Constants;
using xCommons.Extensions;
using Microsoft.Extensions.AI;
namespace xAiModels.Extensions
{
///
/// Extensions for ChatRole ...
///
public static class ChatRoleExtensions
{
///
/// Normalize an String to Propper Chat Role Value ...
/// >
///
///
///
public static string GetChatRoleTitle(this string source)
{
//
var result = XAiChatRoles.None;
//
if (source.ToNormalString() == XAiChatRoles.None.ToNormalString())
{
result = XAiChatRoles.None;
}
else if (source.ToNormalString() == XAiChatRoles.User.ToNormalString())
{
result = XAiChatRoles.User;
}
else if (source.ToNormalString() == XAiChatRoles.Tool.ToNormalString())
{
result = XAiChatRoles.Tool;
}
else if (source.ToNormalString() == XAiChatRoles.System.ToNormalString())
{
result = XAiChatRoles.System;
}
else if (source.ToNormalString() == XAiChatRoles.Assistant.ToNormalString())
{
result = XAiChatRoles.Assistant;
}
//
return result;
}
///
/// Get Chat Role Title from Chat Role Class ...
///
///
///
///
public static string GetRole(this ChatRole source)
{
//
var result = source.Value
.GetChatRoleTitle();
//
return result;
}
///
/// Generate Chat Role Class Based on role Title ...
///
///
///
public static ChatRole ToChatRole(this string source)
{
//
var role = source.GetChatRoleTitle();
ChatRole result = new ChatRole(role);
//
return result;
}
///
/// Generate Chat Role Class Based on role Title ...
///
///
///
public static ChatRole ToChatRole(this XAiChatRole source)
{
//
var role = source.GetStringValue();
ChatRole result = new ChatRole(role);
//
return result;
}
///
/// Extract Chat Role Enum from Chat Role ...
///
///
///
///
///
public static XAiChatRole ToChatRole(this ChatRole source)
{
//
var role = source
.GetRole()
.GetChatRoleTitle();
//
XAiChatRole result = XAiChatRole.User;
//
if (role == XAiChatRoles.User)
{
result = XAiChatRole.User;
}
else if (role == XAiChatRoles.Tool)
{
result = XAiChatRole.Tool;
}
else if (role == XAiChatRoles.System)
{
result = XAiChatRole.System;
}
else if (role == XAiChatRoles.Assistant)
{
result = XAiChatRole.Assistant;
}
//
return result;
}
///
/// Validate an String as Chat Role ...
///
///
///
public static bool IsValid(this string source)
{
//
var result =
source != XAiChatRoles.None &&
source.ToNormalString() != XAiChatRoles.None.ToNormalString();
//
return result;
}
///
/// Validate Role ...
/// >
///
///
///
public static bool IsValid(this XAiChatRole source)
{
//
var result = source != XAiChatRole.None;
return result;
}
///
/// Validate Role ...
/// >
///
///
///
public static bool IsValid(this ChatRole source)
{
//
var role = source.ToChatRole();
var result = role.IsValid();
return result;
}
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Extensions\XAiApiConfigurationExtensions.cs
using System.Linq;
using xAiModels.Models;
using xCommons.Extensions;
using xAiModels.Configurations;
namespace xAiModels.Extensions
{
public static class XAiApiConfigurationExtensions
{
///
/// Validate Api Configuration ...
///
///
///
public static bool IsValid(this XAiApiConfiguration source)
{
return
!source.IsNullOrDefault() &&
source.Models.HasChild();
}
///
/// Retrieve Default Model Descriptor ...
///
///
///
public static XAiModelDescriptor GetDefaultModel(this XAiApiConfiguration source)
{
//
XAiModelDescriptor result = null;
//
if (source.IsValid())
{
result = source.Models.First();
}
//
return result;
}
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Extensions\XAiModelsExtensions.cs
using System;
using System.Linq;
using xAiModels.Models;
using xModels.Extensions;
using xCommons.Extensions;
using xAiModels.Constants;
using xAiModels.Models.Dtos;
using xExceptions.Constants;
using Microsoft.Extensions.AI;
using xAiModels.Models.Entities;
using System.Collections.Generic;
namespace xAiModels.Extensions
{
///
/// Extensions Methods for XAiModels ...
///
public static class XAiModelsExtensions
{
///
/// Validate a Project for Add Or Update ...
///
///
///
public static bool IsValidForAddOrUpdate(this XAiProject source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.OwnerId.IsNullOrEmpty() &&
!source.Prompt.IsNullOrEmpty();
//
return result;
}
public static bool IsValidForAddOrUpdate(this XAiProjectDto source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.OwnerId.IsNullOrEmpty() &&
!source.Prompt.IsNullOrEmpty();
//
return result;
}
///
/// Validate a Conversation for Add Or Update ...
///
///
///
public static bool IsValidForAddOrUpdate(this XAiConversation source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.OwnerId.IsNullOrEmpty() &&
!source.ProjectId.IsNull() &&
!source.ProjectId.IsDefaultGuid();
//
return result;
}
public static bool IsValidForAddOrUpdate(this XAiConversationDto source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.OwnerId.IsNullOrEmpty() &&
!source.ProjectId.IsNull() &&
!source.ProjectId.IsDefaultGuid();
//
return result;
}
///
/// Validate a Message for Add Or Update ...
///
///
///
public static bool IsValidForAddOrUpdate(this XAiMessage source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.OwnerId.IsNullOrEmpty() &&
source.Role.IsValid() &&
!source.ConversationId.IsNull() &&
!source.ConversationId.IsDefaultGuid() &&
!source.Content.IsNullOrEmpty();
//
return result;
}
public static bool IsValidForAddOrUpdate(this XAiMessageDto source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.OwnerId.IsNullOrEmpty() &&
source.Role.IsValid() &&
!source.ConversationId.IsNull() &&
!source.ConversationId.IsDefaultGuid() &&
!source.Content.IsNullOrEmpty();
//
return result;
}
///
/// Validate a Model Descriptor ...
///
///
///
public static bool IsValid(this XAiModelDescriptor source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.Name.IsNullOrEmpty() &&
!source.Url.IsNullOrEmpty() &&
source.Url.IsValidUrl() &&
!source.LLM.IsNullOrEmpty() &&
source.Provider != Constants.XAiModelProviderType.None;
//
return result;
}
///
/// Validate Specified Param ...
///
///
///
public static bool IsValid(this XAiPromptParam source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.Name.IsNullOrEmpty() &&
!source.Param.IsNullOrEmpty();
//
return result;
}
///
/// Validate Specified Prompt ...
///
///
///
public static bool IsValid(this XAiPromptDescriptor source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.Name.IsNullOrEmpty() &&
!source.Template.IsNullOrEmpty();
if (!result)
{
return result;
}
//
if (source.Params.HasChild())
{
result =
result &&
source.Params.All(x => x.IsValid());
}
//
return result;
}
///
/// Validate a Request for Retrieve Response in Controllers ...
///
///
///
public static bool IsValid(this XAiResponseRequest source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.Prompt.IsNullOrEmpty();
//
return result;
}
///
/// Validate a File Extraction Result ...
///
///
///
public static bool IsValid(this XFileExtractionResult source)
{
//
var result =
!source.IsNullOrDefault() &&
(
source.Images.HasChild() ||
!source.Text.IsNullOrEmpty() ||
!source.AudioTranscript.IsNullOrEmpty()
);
return result;
}
///
/// Converts a File Extraction Result to AI Contents ...
///
///
///
public static IList ToAIContents(this XFileExtractionResult source)
{
//
var result = new List();
//
if (source.IsValid())
{
//
// Main Text ...
if (!source.Text.IsNullOrEmpty())
{
result.Add(new TextContent(source.Text));
}
//
// Images ...
if (source.Images.HasChild())
{
//
foreach (var img in source.Images)
{
result.Add(new DataContent(img.Bytes, img.MimeType));
}
}
//
// Transcripted Audio ...
if (!source.AudioTranscript.IsNullOrEmpty())
{
result.Add(new TextContent($"[Audio Transcript]\n{source.AudioTranscript}"));
}
}
//
return result;
}
///
/// Check a Collection Contains Default Project for Specified Owner or not ...
///
///
///
///
public static bool HasDefaultProject(
this IEnumerable source,
string ownerId
)
{
//
// Validate Args ...
if (source.HasChild() ||
ownerId.IsNullOrEmpty())
{
XException.InvalidArgs.Throw();
}
//
var item = source
.FirstOrDefault(x =>
x.Title
.ToNormalString()
.Contains(ownerId.ToNormalString()) &&
x.Title
.ToNormalString()
.Contains(XAiModelsConstants.DefaultXAiProjectDescriptionResourceID.ToNormalString())
);
//
var result = !item.IsNullOrDefault();
//
return result;
}
///
/// Check a Collection Contains Default Conversation for Specified Project or not ...
///
///
///
///
///
public static bool HasDefaultConversation(
this IEnumerable source,
string ownerId,
Guid projectId
)
{
//
// Validate Args ...
if (source.HasChild() ||
projectId.IsDefaultGuid())
{
XException.InvalidArgs.Throw();
}
//
var item = source
.FirstOrDefault(x =>
x.Title
.ToNormalString()
.Contains(ownerId.ToNormalString()) &&
x.Title
.ToNormalString()
.Contains(projectId.ToString().ToNormalString()) &&
x.Title
.ToNormalString()
.Contains(XAiModelsConstants.DefaultXAiConversationTitleResourceID)
);
//
var result = !item.IsNullOrDefault();
//
return result;
}
///
/// Retrieve Default Project Id from a Collection ...
///
///
///
///
public static Guid GetDafualtProject(
this IEnumerable source,
string ownerId
)
{
//
// Validate Args ...
if (!source.HasChild() ||
ownerId.IsNullOrEmpty())
{
XException.InvalidArgs.Throw();
}
//
var item = source
.FirstOrDefault(x =>
x.Title
.ToNormalString()
.Contains(ownerId.ToNormalString()) &&
x.Title
.ToNormalString()
.Contains(XAiModelsConstants.XAiProjectTitleIdentifier.ToNormalString())
);
if (item.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
return item.Id;
}
///
/// Get Default Conversation Id from a Collection Contains ...
///
///
///
///
///
public static Guid GetDefaultConversation(
this IEnumerable source,
string ownerId,
Guid projectId
)
{
//
// Validate Args ...
if (!source.HasChild() ||
ownerId.IsNullOrEmpty() ||
projectId.IsDefaultGuid())
{
XException.InvalidArgs.Throw();
}
//
var item = source
.FirstOrDefault(x =>
x.Title
.ToNormalString()
.Contains(ownerId.ToNormalString()) &&
x.Title
.ToNormalString()
.Contains(XAiModelsConstants.XAiConversationTitleIdentifier.ToNormalString())
);
if (item.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
var result = item.Id;
//
return result;
}
///
/// Converts a Message Dto to ChatMessage ...
///
///
///
///
public static ChatMessage ToChatMessages(
this XAiMessageDto source,
IList additionalContents = null
)
{
//
ChatMessage result = null;
//
if (!source.IsNullOrDefault())
{
//
var contents = new List
{
//
// Add Source Content ...
new TextContent(source.Content)
};
//
// Add Additional Content ...
if (additionalContents.HasChild())
{
contents.AddRange(additionalContents);
}
//
result = new ChatMessage
{
Contents = contents,
AuthorName =
source.Role == XAiChatRole.User &&
!source.Owner.IsNullOrDefault()
? source.Owner.GetFullname()
: string.Empty,
Role = source.Role.ToChatRole(),
MessageId = source.Id.ToString(),
};
}
//
return result;
}
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Helpers\XAiModelsHelper.cs
using System;
using GraphQL.Types;
using xDataService.Db;
using xDataService.Models;
using xDataService.Providers;
using xAiModels.Models.Entities;
using xAiModels.Providers.GraphQL;
using xAiModels.Providers.Entities;
using xAiModels.Interfaces.Entities;
namespace xAiModels.Helpers
{
public static class XAiModelsHelper
{
//
#region XAiConversation ...
//
#region EF Repository Descriptor Provider(s) ...
public static XEFRepositoryDescriptor<
XAiConversation,
Guid,
IXAiConversationKeyGenerator,
XAiConversationKeyGenerator,
IXAiConversationRepositoryEvents,
XAiConversationRepositoryEvents,
XAiConversationGraphType,
GuidGraphType,
XAiConversationGraphQuery,
IXAiConversationGraphQLTypeHelper,
XAiConversationGraphQLTypeHelper,
XAiConversationGraphSchema,
IXAiConversationRepository,
XAiConversationEFRepository,
TContext
> GetXAiConversationEFRepositoryDescriptor()
where TContext : XDbContext
{
//
var result = new XEFRepositoryDescriptor<
XAiConversation,
Guid,
IXAiConversationKeyGenerator,
XAiConversationKeyGenerator,
IXAiConversationRepositoryEvents,
XAiConversationRepositoryEvents,
XAiConversationGraphType,
GuidGraphType,
XAiConversationGraphQuery,
IXAiConversationGraphQLTypeHelper,
XAiConversationGraphQLTypeHelper,
XAiConversationGraphSchema,
IXAiConversationRepository,
XAiConversationEFRepository,
TContext
>();
//
return result;
}
public static XEFRepositoryDescriptor<
XAiConversation,
Guid,
IXAiConversationKeyGenerator,
XAiConversationKeyGenerator,
IXAiConversationRepositoryEvents,
XAiConversationRepositoryEvents,
XAiConversationGraphType,
GuidGraphType,
XAiConversationGraphQuery,
IXAiConversationGraphQLTypeHelper,
XAiConversationGraphQLTypeHelper,
XAiConversationGraphSchema,
IXAiConversationRepository,
XAiConversationEFRepository,
TContext,
IXAiConversationSeeder,
TSeederImplementation
> GetXAiConversationEFRepositoryDescriptor()
where TContext : XDbContext
where TSeederImplementation : XBaseDbSeeder
{
//
var result = new XEFRepositoryDescriptor<
XAiConversation,
Guid,
IXAiConversationKeyGenerator,
XAiConversationKeyGenerator,
IXAiConversationRepositoryEvents,
XAiConversationRepositoryEvents,
XAiConversationGraphType,
GuidGraphType,
XAiConversationGraphQuery,
IXAiConversationGraphQLTypeHelper,
XAiConversationGraphQLTypeHelper,
XAiConversationGraphSchema,
IXAiConversationRepository,
XAiConversationEFRepository,
TContext,
IXAiConversationSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region Mongo Repository Descriptor Provider(s) ...
public static XMongoRepositoryDescriptor<
XAiConversation,
Guid,
IXAiConversationKeyGenerator,
XAiConversationKeyGenerator,
IXAiConversationRepositoryEvents,
XAiConversationRepositoryEvents,
XAiConversationGraphType,
GuidGraphType,
XAiConversationGraphQuery,
IXAiConversationGraphQLTypeHelper,
XAiConversationGraphQLTypeHelper,
XAiConversationGraphSchema,
IXAiConversationRepository,
XAiConversationMongoRepository
> GetXAiConversationMongoRepositoryDescriptor()
{
//
var result = new XMongoRepositoryDescriptor<
XAiConversation,
Guid,
IXAiConversationKeyGenerator,
XAiConversationKeyGenerator,
IXAiConversationRepositoryEvents,
XAiConversationRepositoryEvents,
XAiConversationGraphType,
GuidGraphType,
XAiConversationGraphQuery,
IXAiConversationGraphQLTypeHelper,
XAiConversationGraphQLTypeHelper,
XAiConversationGraphSchema,
IXAiConversationRepository,
XAiConversationMongoRepository
>();
//
return result;
}
public static XMongoRepositoryDescriptor<
XAiConversation,
Guid,
IXAiConversationKeyGenerator,
XAiConversationKeyGenerator,
IXAiConversationRepositoryEvents,
XAiConversationRepositoryEvents,
XAiConversationGraphType,
GuidGraphType,
XAiConversationGraphQuery,
IXAiConversationGraphQLTypeHelper,
XAiConversationGraphQLTypeHelper,
XAiConversationGraphSchema,
IXAiConversationRepository,
XAiConversationMongoRepository,
IXAiConversationSeeder,
TSeederImplementation
> GetXAiConversationMongoRepositoryDescriptor()
where TSeederImplementation : XBaseDbSeeder
{
//
var result = new XMongoRepositoryDescriptor<
XAiConversation,
Guid,
IXAiConversationKeyGenerator,
XAiConversationKeyGenerator,
IXAiConversationRepositoryEvents,
XAiConversationRepositoryEvents,
XAiConversationGraphType,
GuidGraphType,
XAiConversationGraphQuery,
IXAiConversationGraphQLTypeHelper,
XAiConversationGraphQLTypeHelper,
XAiConversationGraphSchema,
IXAiConversationRepository,
XAiConversationMongoRepository,
IXAiConversationSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region InMemory Repository Descriptor Provider(s) ...
public static XInMemoryRepositoryDescriptor<
XAiConversation,
Guid,
IXAiConversationKeyGenerator,
XAiConversationKeyGenerator,
IXAiConversationRepositoryEvents,
XAiConversationRepositoryEvents,
XAiConversationGraphType,
GuidGraphType,
XAiConversationGraphQuery,
IXAiConversationGraphQLTypeHelper,
XAiConversationGraphQLTypeHelper,
XAiConversationGraphSchema,
IXAiConversationRepository,
XAiConversationInMemoryRepository
> GetXAiConversationInMemoryRepositoryDescriptor()
{
//
var result = new XInMemoryRepositoryDescriptor<
XAiConversation,
Guid,
IXAiConversationKeyGenerator,
XAiConversationKeyGenerator,
IXAiConversationRepositoryEvents,
XAiConversationRepositoryEvents,
XAiConversationGraphType,
GuidGraphType,
XAiConversationGraphQuery,
IXAiConversationGraphQLTypeHelper,
XAiConversationGraphQLTypeHelper,
XAiConversationGraphSchema,
IXAiConversationRepository,
XAiConversationInMemoryRepository
>();
//
return result;
}
public static XInMemoryRepositoryDescriptor<
XAiConversation,
Guid,
IXAiConversationKeyGenerator,
XAiConversationKeyGenerator,
IXAiConversationRepositoryEvents,
XAiConversationRepositoryEvents,
XAiConversationGraphType,
GuidGraphType,
XAiConversationGraphQuery,
IXAiConversationGraphQLTypeHelper,
XAiConversationGraphQLTypeHelper,
XAiConversationGraphSchema,
IXAiConversationRepository,
XAiConversationInMemoryRepository,
IXAiConversationSeeder,
TSeederImplementation
> GetXAiConversationInMemoryRepositoryDescriptor()
where TSeederImplementation : XBaseDbSeeder
{
//
var result = new XInMemoryRepositoryDescriptor<
XAiConversation,
Guid,
IXAiConversationKeyGenerator,
XAiConversationKeyGenerator,
IXAiConversationRepositoryEvents,
XAiConversationRepositoryEvents,
XAiConversationGraphType,
GuidGraphType,
XAiConversationGraphQuery,
IXAiConversationGraphQLTypeHelper,
XAiConversationGraphQLTypeHelper,
XAiConversationGraphSchema,
IXAiConversationRepository,
XAiConversationInMemoryRepository,
IXAiConversationSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
#endregion
//
#region XAiMessage ...
//
#region EF Repository Descriptor Provider(s) ...
public static XEFRepositoryDescriptor<
XAiMessage,
Guid,
IXAiMessageKeyGenerator,
XAiMessageKeyGenerator,
IXAiMessageRepositoryEvents,
XAiMessageRepositoryEvents,
XAiMessageGraphType,
GuidGraphType,
XAiMessageGraphQuery,
IXAiMessageGraphQLTypeHelper,
XAiMessageGraphQLTypeHelper,
XAiMessageGraphSchema,
IXAiMessageRepository,
XAiMessageEFRepository,
TContext
> GetXAiMessageEFRepositoryDescriptor()
where TContext : XDbContext
{
//
var result = new XEFRepositoryDescriptor<
XAiMessage,
Guid,
IXAiMessageKeyGenerator,
XAiMessageKeyGenerator,
IXAiMessageRepositoryEvents,
XAiMessageRepositoryEvents,
XAiMessageGraphType,
GuidGraphType,
XAiMessageGraphQuery,
IXAiMessageGraphQLTypeHelper,
XAiMessageGraphQLTypeHelper,
XAiMessageGraphSchema,
IXAiMessageRepository,
XAiMessageEFRepository,
TContext
>();
//
return result;
}
public static XEFRepositoryDescriptor<
XAiMessage,
Guid,
IXAiMessageKeyGenerator,
XAiMessageKeyGenerator,
IXAiMessageRepositoryEvents,
XAiMessageRepositoryEvents,
XAiMessageGraphType,
GuidGraphType,
XAiMessageGraphQuery,
IXAiMessageGraphQLTypeHelper,
XAiMessageGraphQLTypeHelper,
XAiMessageGraphSchema,
IXAiMessageRepository,
XAiMessageEFRepository,
TContext,
IXAiMessageSeeder,
TSeederImplementation
> GetXAiMessageEFRepositoryDescriptor()
where TContext : XDbContext
where TSeederImplementation : XBaseDbSeeder
{
//
var result = new XEFRepositoryDescriptor<
XAiMessage,
Guid,
IXAiMessageKeyGenerator,
XAiMessageKeyGenerator,
IXAiMessageRepositoryEvents,
XAiMessageRepositoryEvents,
XAiMessageGraphType,
GuidGraphType,
XAiMessageGraphQuery,
IXAiMessageGraphQLTypeHelper,
XAiMessageGraphQLTypeHelper,
XAiMessageGraphSchema,
IXAiMessageRepository,
XAiMessageEFRepository,
TContext,
IXAiMessageSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region Mongo Repository Descriptor Provider(s) ...
public static XMongoRepositoryDescriptor<
XAiMessage,
Guid,
IXAiMessageKeyGenerator,
XAiMessageKeyGenerator,
IXAiMessageRepositoryEvents,
XAiMessageRepositoryEvents,
XAiMessageGraphType,
GuidGraphType,
XAiMessageGraphQuery,
IXAiMessageGraphQLTypeHelper,
XAiMessageGraphQLTypeHelper,
XAiMessageGraphSchema,
IXAiMessageRepository,
XAiMessageMongoRepository
> GetXAiMessageMongoRepositoryDescriptor()
{
//
var result = new XMongoRepositoryDescriptor<
XAiMessage,
Guid,
IXAiMessageKeyGenerator,
XAiMessageKeyGenerator,
IXAiMessageRepositoryEvents,
XAiMessageRepositoryEvents,
XAiMessageGraphType,
GuidGraphType,
XAiMessageGraphQuery,
IXAiMessageGraphQLTypeHelper,
XAiMessageGraphQLTypeHelper,
XAiMessageGraphSchema,
IXAiMessageRepository,
XAiMessageMongoRepository
>();
//
return result;
}
public static XMongoRepositoryDescriptor<
XAiMessage,
Guid,
IXAiMessageKeyGenerator,
XAiMessageKeyGenerator,
IXAiMessageRepositoryEvents,
XAiMessageRepositoryEvents,
XAiMessageGraphType,
GuidGraphType,
XAiMessageGraphQuery,
IXAiMessageGraphQLTypeHelper,
XAiMessageGraphQLTypeHelper,
XAiMessageGraphSchema,
IXAiMessageRepository,
XAiMessageMongoRepository,
IXAiMessageSeeder,
TSeederImplementation
> GetXAiMessageMongoRepositoryDescriptor()
where TSeederImplementation : XBaseDbSeeder
{
//
var result = new XMongoRepositoryDescriptor<
XAiMessage,
Guid,
IXAiMessageKeyGenerator,
XAiMessageKeyGenerator,
IXAiMessageRepositoryEvents,
XAiMessageRepositoryEvents,
XAiMessageGraphType,
GuidGraphType,
XAiMessageGraphQuery,
IXAiMessageGraphQLTypeHelper,
XAiMessageGraphQLTypeHelper,
XAiMessageGraphSchema,
IXAiMessageRepository,
XAiMessageMongoRepository,
IXAiMessageSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region InMemory Repository Descriptor Provider(s) ...
public static XInMemoryRepositoryDescriptor<
XAiMessage,
Guid,
IXAiMessageKeyGenerator,
XAiMessageKeyGenerator,
IXAiMessageRepositoryEvents,
XAiMessageRepositoryEvents,
XAiMessageGraphType,
GuidGraphType,
XAiMessageGraphQuery,
IXAiMessageGraphQLTypeHelper,
XAiMessageGraphQLTypeHelper,
XAiMessageGraphSchema,
IXAiMessageRepository,
XAiMessageInMemoryRepository
> GetXAiMessageInMemoryRepositoryDescriptor()
{
//
var result = new XInMemoryRepositoryDescriptor<
XAiMessage,
Guid,
IXAiMessageKeyGenerator,
XAiMessageKeyGenerator,
IXAiMessageRepositoryEvents,
XAiMessageRepositoryEvents,
XAiMessageGraphType,
GuidGraphType,
XAiMessageGraphQuery,
IXAiMessageGraphQLTypeHelper,
XAiMessageGraphQLTypeHelper,
XAiMessageGraphSchema,
IXAiMessageRepository,
XAiMessageInMemoryRepository
>();
//
return result;
}
public static XInMemoryRepositoryDescriptor<
XAiMessage,
Guid,
IXAiMessageKeyGenerator,
XAiMessageKeyGenerator,
IXAiMessageRepositoryEvents,
XAiMessageRepositoryEvents,
XAiMessageGraphType,
GuidGraphType,
XAiMessageGraphQuery,
IXAiMessageGraphQLTypeHelper,
XAiMessageGraphQLTypeHelper,
XAiMessageGraphSchema,
IXAiMessageRepository,
XAiMessageInMemoryRepository,
IXAiMessageSeeder,
TSeederImplementation
> GetXAiMessageInMemoryRepositoryDescriptor()
where TSeederImplementation : XBaseDbSeeder
{
//
var result = new XInMemoryRepositoryDescriptor<
XAiMessage,
Guid,
IXAiMessageKeyGenerator,
XAiMessageKeyGenerator,
IXAiMessageRepositoryEvents,
XAiMessageRepositoryEvents,
XAiMessageGraphType,
GuidGraphType,
XAiMessageGraphQuery,
IXAiMessageGraphQLTypeHelper,
XAiMessageGraphQLTypeHelper,
XAiMessageGraphSchema,
IXAiMessageRepository,
XAiMessageInMemoryRepository,
IXAiMessageSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
#endregion
//
#region XAiProject ...
//
#region EF Repository Descriptor Provider(s) ...
public static XEFRepositoryDescriptor<
XAiProject,
Guid,
IXAiProjectKeyGenerator,
XAiProjectKeyGenerator,
IXAiProjectRepositoryEvents,
XAiProjectRepositoryEvents,
XAiProjectGraphType,
GuidGraphType,
XAiProjectGraphQuery,
IXAiProjectGraphQLTypeHelper,
XAiProjectGraphQLTypeHelper,
XAiProjectGraphSchema,
IXAiProjectRepository,
XAiProjectEFRepository,
TContext
> GetXAiProjectEFRepositoryDescriptor()
where TContext : XDbContext
{
//
var result = new XEFRepositoryDescriptor<
XAiProject,
Guid,
IXAiProjectKeyGenerator,
XAiProjectKeyGenerator,
IXAiProjectRepositoryEvents,
XAiProjectRepositoryEvents,
XAiProjectGraphType,
GuidGraphType,
XAiProjectGraphQuery,
IXAiProjectGraphQLTypeHelper,
XAiProjectGraphQLTypeHelper,
XAiProjectGraphSchema,
IXAiProjectRepository,
XAiProjectEFRepository,
TContext
>();
//
return result;
}
public static XEFRepositoryDescriptor<
XAiProject,
Guid,
IXAiProjectKeyGenerator,
XAiProjectKeyGenerator,
IXAiProjectRepositoryEvents,
XAiProjectRepositoryEvents,
XAiProjectGraphType,
GuidGraphType,
XAiProjectGraphQuery,
IXAiProjectGraphQLTypeHelper,
XAiProjectGraphQLTypeHelper,
XAiProjectGraphSchema,
IXAiProjectRepository,
XAiProjectEFRepository,
TContext,
IXAiProjectSeeder,
TSeederImplementation
> GetXAiProjectEFRepositoryDescriptor()
where TContext : XDbContext
where TSeederImplementation : XBaseDbSeeder
{
//
var result = new XEFRepositoryDescriptor<
XAiProject,
Guid,
IXAiProjectKeyGenerator,
XAiProjectKeyGenerator,
IXAiProjectRepositoryEvents,
XAiProjectRepositoryEvents,
XAiProjectGraphType,
GuidGraphType,
XAiProjectGraphQuery,
IXAiProjectGraphQLTypeHelper,
XAiProjectGraphQLTypeHelper,
XAiProjectGraphSchema,
IXAiProjectRepository,
XAiProjectEFRepository,
TContext,
IXAiProjectSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region Mongo Repository Descriptor Provider(s) ...
public static XMongoRepositoryDescriptor<
XAiProject,
Guid,
IXAiProjectKeyGenerator,
XAiProjectKeyGenerator,
IXAiProjectRepositoryEvents,
XAiProjectRepositoryEvents,
XAiProjectGraphType,
GuidGraphType,
XAiProjectGraphQuery,
IXAiProjectGraphQLTypeHelper,
XAiProjectGraphQLTypeHelper,
XAiProjectGraphSchema,
IXAiProjectRepository,
XAiProjectMongoRepository
> GetXAiProjectMongoRepositoryDescriptor()
{
//
var result = new XMongoRepositoryDescriptor<
XAiProject,
Guid,
IXAiProjectKeyGenerator,
XAiProjectKeyGenerator,
IXAiProjectRepositoryEvents,
XAiProjectRepositoryEvents,
XAiProjectGraphType,
GuidGraphType,
XAiProjectGraphQuery,
IXAiProjectGraphQLTypeHelper,
XAiProjectGraphQLTypeHelper,
XAiProjectGraphSchema,
IXAiProjectRepository,
XAiProjectMongoRepository
>();
//
return result;
}
public static XMongoRepositoryDescriptor<
XAiProject,
Guid,
IXAiProjectKeyGenerator,
XAiProjectKeyGenerator,
IXAiProjectRepositoryEvents,
XAiProjectRepositoryEvents,
XAiProjectGraphType,
GuidGraphType,
XAiProjectGraphQuery,
IXAiProjectGraphQLTypeHelper,
XAiProjectGraphQLTypeHelper,
XAiProjectGraphSchema,
IXAiProjectRepository,
XAiProjectMongoRepository,
IXAiProjectSeeder,
TSeederImplementation
> GetXAiProjectMongoRepositoryDescriptor()
where TSeederImplementation : XBaseDbSeeder
{
//
var result = new XMongoRepositoryDescriptor<
XAiProject,
Guid,
IXAiProjectKeyGenerator,
XAiProjectKeyGenerator,
IXAiProjectRepositoryEvents,
XAiProjectRepositoryEvents,
XAiProjectGraphType,
GuidGraphType,
XAiProjectGraphQuery,
IXAiProjectGraphQLTypeHelper,
XAiProjectGraphQLTypeHelper,
XAiProjectGraphSchema,
IXAiProjectRepository,
XAiProjectMongoRepository,
IXAiProjectSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region InMemory Repository Descriptor Provider(s) ...
public static XInMemoryRepositoryDescriptor<
XAiProject,
Guid,
IXAiProjectKeyGenerator,
XAiProjectKeyGenerator,
IXAiProjectRepositoryEvents,
XAiProjectRepositoryEvents,
XAiProjectGraphType,
GuidGraphType,
XAiProjectGraphQuery,
IXAiProjectGraphQLTypeHelper,
XAiProjectGraphQLTypeHelper,
XAiProjectGraphSchema,
IXAiProjectRepository,
XAiProjectInMemoryRepository
> GetXAiProjectInMemoryRepositoryDescriptor()
{
//
var result = new XInMemoryRepositoryDescriptor<
XAiProject,
Guid,
IXAiProjectKeyGenerator,
XAiProjectKeyGenerator,
IXAiProjectRepositoryEvents,
XAiProjectRepositoryEvents,
XAiProjectGraphType,
GuidGraphType,
XAiProjectGraphQuery,
IXAiProjectGraphQLTypeHelper,
XAiProjectGraphQLTypeHelper,
XAiProjectGraphSchema,
IXAiProjectRepository,
XAiProjectInMemoryRepository
>();
//
return result;
}
public static XInMemoryRepositoryDescriptor<
XAiProject,
Guid,
IXAiProjectKeyGenerator,
XAiProjectKeyGenerator,
IXAiProjectRepositoryEvents,
XAiProjectRepositoryEvents,
XAiProjectGraphType,
GuidGraphType,
XAiProjectGraphQuery,
IXAiProjectGraphQLTypeHelper,
XAiProjectGraphQLTypeHelper,
XAiProjectGraphSchema,
IXAiProjectRepository,
XAiProjectInMemoryRepository,
IXAiProjectSeeder,
TSeederImplementation
> GetXAiProjectInMemoryRepositoryDescriptor()
where TSeederImplementation : XBaseDbSeeder
{
//
var result = new XInMemoryRepositoryDescriptor<
XAiProject,
Guid,
IXAiProjectKeyGenerator,
XAiProjectKeyGenerator,
IXAiProjectRepositoryEvents,
XAiProjectRepositoryEvents,
XAiProjectGraphType,
GuidGraphType,
XAiProjectGraphQuery,
IXAiProjectGraphQLTypeHelper,
XAiProjectGraphQLTypeHelper,
XAiProjectGraphSchema,
IXAiProjectRepository,
XAiProjectInMemoryRepository,
IXAiProjectSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\IXAiConversationTitleResourceProvider.cs
using xStringService.Interfaces;
namespace xAiModels.Interfaces
{
public interface IXAiConversationTitleResourceProvider : IXOwnedItemResourceProvider
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\IXAiDataProvider.cs
using System;
using xModels.Dtos;
using System.Threading;
using xAiModels.Models.Dtos;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace xAiModels.Interfaces
{
///
/// All Data Manipulation Requirements ...
///
public interface IXAiDataProvider
{
//
#region Getters ...
///
/// Retrieve Specified Project ...
///
///
///
///
///
///
Task GetProject(
Guid id,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
);
///
/// Retrieve Specified Conversation ...
///
///
///
///
///
Task GetConversation(
Guid id,
bool fillMessages = false,
CancellationToken cancellationToken = default
);
#endregion
//
#region Loaders ...
///
/// Load Projects List of Specified Owner ...
///
///
///
///
///
///
///
Task> LoadProjects(
string ownerId,
string connectionId = null,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
);
///
/// Load List of Conversations for Specified Project ...
///
///
///
///
///
///
Task> LoadConversations(
Guid projectId,
bool fillMessages = false,
string connectionId = null,
CancellationToken cancellationToken = default
);
///
/// Load Messages of Specified Conversation ...
///
///
///
///
Task> LoadMessages(
Guid conversationId,
CancellationToken cancellationToken = default
);
#endregion
//
#region Enrichers ...
///
/// Enrich Specified Item ...
///
///
///
///
///
///
Task Enrich(
XAiProjectDto source,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Items ...
///
///
///
///
///
///
Task> EnrichRange(
IEnumerable sources,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Item ...
///
///
///
///
///
Task Enrich(
XAiConversationDto source,
bool fillMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Items ...
///
///
///
///
///
Task> EnrichRange(
IEnumerable sources,
bool fillMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Item ...
///
///
///
///
Task Enrich(
XAiMessageDto source,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Items ...
///
///
///
///
Task> EnrichRange(
IEnumerable sources,
CancellationToken cancellationToken = default
);
#endregion
//
#region Defaults ...
///
/// Retrieve Default Project of Specified Owner ...
/// Create it if not Handled ...
///
///
///
///
///
Task GetDefaultProject(
string ownerId,
string connectionId = null,
CancellationToken cancellationToken = default
);
///
/// Retrieve Default Conversation of Specified Owner ...
/// Create it if not Handled ...
///
///
///
///
///
///
Task GetDefaultConversation(
string ownerId,
Guid projectId,
string connectionId = null,
CancellationToken cancellationToken = default
);
#endregion
//
#region Creator/Adders ...
///
/// Create Project ...
///
///
///
///
///
///
Task CreateProject(
string ownerId,
XAiProjectDto item = null,
string connectionId = null,
CancellationToken cancellationToken = default
);
///
/// Create Conversation ...
///
///
///
///
///
///
///
Task CreateConversation(
string ownerId,
Guid projectId,
XAiConversationDto item = null,
string connectionId = null,
CancellationToken cancellationToken = default
);
///
/// Add Message ...
///
///
///
///
///
///
Task AddMessage(
Guid conversationId,
XAiMessageDto item,
string connectionId = null,
CancellationToken cancellationToken = default
);
#endregion
//
#region Query ...
///
/// Query Projects ...
///
///
///
///
///
Task> QueryProjects(
string ownerId,
XQuery query,
CancellationToken cancellationToken = default
);
///
/// Query Conversations ...
///
///
///
///
///
///
Task> QueryConversations(
string ownerId,
Guid projectId,
XQuery query,
CancellationToken cancellationToken = default
);
///
/// Query Messages ...
///
///
///
///
///
///
Task> QueryMessages(
string ownerId,
Guid conversationId,
XQuery query,
CancellationToken cancellationToken = default
);
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\IXAiProjectDescriptionResourceProvider.cs
using xStringService.Interfaces;
namespace xAiModels.Interfaces
{
public interface IXAiProjectDescriptionResourceProvider : IXOwnedItemResourceProvider
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\IXAiProjectTitleResourceProvider.cs
using xStringService.Interfaces;
namespace xAiModels.Interfaces
{
public interface IXAiProjectTitleResourceProvider : IXOwnedItemResourceProvider
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Dtos\IXAiConversationDtoHub.cs
using System;
using xAiModels.Models.Dtos;
using xPushService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Dtos
{
public interface IXAiConversationDtoHub : IXBaseDtoHub
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Dtos\IXAiConversationRepositoryService.cs
using System;
using System.Threading;
using xAiModels.Models.Dtos;
using System.Threading.Tasks;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
using System.Collections.Generic;
namespace xAiModels.Interfaces.Dtos
{
public interface IXAiConversationRepositoryService : IXBaseRepositoryService
{
//
#region Enrichers ...
///
/// Enrich Specified Item ...
///
///
///
///
///
Task Enrich(
XAiConversation source,
bool fillMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Item ...
///
///
///
///
///
Task Enrich(
XAiConversationDto source,
bool fillMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Items ...
///
///
///
///
///
Task> EnrichRange(
IEnumerable sources,
bool fillMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Items ...
///
///
///
///
///
Task> EnrichRange(
IEnumerable sources,
bool fillMessages = false,
CancellationToken cancellationToken = default
);
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Dtos\IXAiConversationServiceProvider.cs
using System;
using xAiModels.Models.Dtos;
using xPushService.Interfaces;
using xAiModels.Providers.Dtos;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Dtos
{
public interface IXAiConversationServiceProvider : IXBaseDtoProvider
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Dtos\IXAiMessageDtoHub.cs
using System;
using xAiModels.Models.Dtos;
using xPushService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Dtos
{
public interface IXAiMessageDtoHub : IXBaseDtoHub
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Dtos\IXAiMessageRepositoryService.cs
using System;
using System.Threading;
using xAiModels.Models.Dtos;
using System.Threading.Tasks;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
using System.Collections.Generic;
namespace xAiModels.Interfaces.Dtos
{
public interface IXAiMessageRepositoryService : IXBaseRepositoryService
{
//
#region Enrichers ...
///
/// Enrich Specified Item ...
///
///
///
///
Task Enrich(
XAiMessage source,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Item ...
///
///
///
///
Task Enrich(
XAiMessageDto source,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Items ...
///
///
///
///
Task> EnrichRange(
IEnumerable sources,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Items ...
///
///
///
///
Task> EnrichRange(
IEnumerable sources,
CancellationToken cancellationToken = default
);
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Dtos\IXAiMessageServiceProvider.cs
using System;
using xAiModels.Models.Dtos;
using xPushService.Interfaces;
using xAiModels.Providers.Dtos;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Dtos
{
public interface IXAiMessageServiceProvider : IXBaseDtoProvider
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Dtos\IXAiProjectDtoHub.cs
using System;
using xAiModels.Models.Dtos;
using xPushService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Dtos
{
public interface IXAiProjectDtoHub : IXBaseDtoHub
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Dtos\IXAiProjectRepositoryService.cs
using System;
using System.Threading;
using xAiModels.Models.Dtos;
using System.Threading.Tasks;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
using System.Collections.Generic;
namespace xAiModels.Interfaces.Dtos
{
public interface IXAiProjectRepositoryService : IXBaseRepositoryService
{
//
#region Enrichers ...
///
/// Enrich Specified Item ...
///
///
///
///
///
///
Task Enrich(
XAiProject source,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Item ...
///
///
///
///
///
///
Task Enrich(
XAiProjectDto source,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Items ...
///
///
///
///
///
///
Task> EnrichRange(
IEnumerable sources,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Items ...
///
///
///
///
///
///
Task> EnrichRange(
IEnumerable sources,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
);
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Dtos\IXAiProjectServiceProvider.cs
using System;
using xAiModels.Models.Dtos;
using xPushService.Interfaces;
using xAiModels.Providers.Dtos;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Dtos
{
public interface IXAiProjectServiceProvider : IXBaseDtoProvider
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Enrichers\IXAiConversationEnricher.cs
using System.Threading;
using xAiModels.Models.Dtos;
using System.Threading.Tasks;
using xAiModels.Models.Entities;
using System.Collections.Generic;
namespace xAiModels.Interfaces.Enrichers
{
///
/// Ai Conversation Enricher ...
///
public interface IXAiConversationEnricher
{
//
#region Enrichers ...
///
/// Enrich Specified Item ...
///
///
///
///
///
Task Enrich(
XAiConversation source,
bool fillMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Item ...
///
///
///
///
///
Task Enrich(
XAiConversationDto source,
bool fillMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Items ...
///
///
///
///
///
Task> EnrichRange(
IEnumerable sources,
bool fillMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Items ...
///
///
///
///
///
Task> EnrichRange(
IEnumerable sources,
bool fillMessages = false,
CancellationToken cancellationToken = default
);
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Enrichers\IXAiMessageEnricher.cs
using System.Threading;
using xAiModels.Models.Dtos;
using System.Threading.Tasks;
using xAiModels.Models.Entities;
using System.Collections.Generic;
namespace xAiModels.Interfaces.Enrichers
{
public interface IXAiMessageEnricher
{
//
#region Enrichers ...
///
/// Enrich Specified Item ...
///
///
///
///
Task Enrich(
XAiMessage source,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Item ...
///
///
///
///
Task Enrich(
XAiMessageDto source,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Items ...
///
///
///
///
Task> EnrichRange(
IEnumerable sources,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Items ...
///
///
///
///
Task> EnrichRange(
IEnumerable sources,
CancellationToken cancellationToken = default
);
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Enrichers\IXAiProjectEnricher.cs
using System.Threading;
using xAiModels.Models.Dtos;
using System.Threading.Tasks;
using xAiModels.Models.Entities;
using System.Collections.Generic;
namespace xAiModels.Interfaces.Enrichers
{
public interface IXAiProjectEnricher
{
//
#region Enrichers ...
///
/// Enrich Specified Item ...
///
///
///
///
///
///
Task Enrich(
XAiProject source,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Item ...
///
///
///
///
///
///
Task Enrich(
XAiProjectDto source,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Items ...
///
///
///
///
///
///
Task> EnrichRange(
IEnumerable sources,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
);
///
/// Enrich Specified Items ...
///
///
///
///
///
///
Task> EnrichRange(
IEnumerable sources,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
);
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiConversationEntityHub.cs
using System;
using xPushService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiConversationEntityHub : IXBaseEntityHub
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiConversationGraphQLTypeHelper.cs
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiConversationGraphQLTypeHelper : IXBaseGraphQLTypeHelper
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiConversationKeyGenerator.cs
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiConversationKeyGenerator : IXKeyGenerator
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiConversationRepository.cs
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiConversationRepository : IXBaseRepository
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiConversationRepositoryEvents.cs
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiConversationRepositoryEvents : IXBaseRepositoryEvents
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiConversationRepositoryProvider.cs
using System;
using xPushService.Interfaces;
using xAiModels.Models.Entities;
using xAiModels.Providers.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiConversationRepositoryProvider : IXBaseEntityProvider
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiConversationSeeder.cs
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiConversationSeeder : IXBaseDbSeeder
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiDocumentEntityHub.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiDocumentEntityHub
{
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiMessageEntityHub.cs
using System;
using xPushService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiMessageEntityHub : IXBaseEntityHub
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiMessageGraphQLTypeHelper.cs
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiMessageGraphQLTypeHelper : IXBaseGraphQLTypeHelper
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiMessageKeyGenerator.cs
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiMessageKeyGenerator : IXKeyGenerator
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiMessageRepository.cs
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiMessageRepository : IXBaseRepository
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiMessageRepositoryEvents.cs
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiMessageRepositoryEvents : IXBaseRepositoryEvents
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiMessageRepositoryProvider.cs
using System;
using xPushService.Interfaces;
using xAiModels.Models.Entities;
using xAiModels.Providers.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiMessageRepositoryProvider : IXBaseEntityProvider
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiMessageSeeder.cs
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiMessageSeeder : IXBaseDbSeeder
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiProjectEntityHub.cs
using System;
using xPushService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiProjectEntityHub : IXBaseEntityHub
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiProjectGraphQLTypeHelper.cs
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiProjectGraphQLTypeHelper : IXBaseGraphQLTypeHelper
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiProjectKeyGenerator.cs
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiProjectKeyGenerator : IXKeyGenerator
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiProjectRepository.cs
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiProjectRepository : IXBaseRepository
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiProjectRepositoryEvents.cs
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiProjectRepositoryEvents : IXBaseRepositoryEvents
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiProjectRepositoryProvider.cs
using System;
using xPushService.Interfaces;
using xAiModels.Models.Entities;
using xAiModels.Providers.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiProjectRepositoryProvider : IXBaseEntityProvider
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Interfaces\Entities\IXAiProjectSeeder.cs
using System;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
namespace xAiModels.Interfaces.Entities
{
public interface IXAiProjectSeeder : IXBaseDbSeeder
{ }
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Models\XAiModelDescriptor.cs
using xAiModels.Constants;
namespace xAiModels.Models
{
///
/// Describe a Provided Model ...
///
public class XAiModelDescriptor
{
///
/// Provider Name ...
///
public string Name { get; set; }
///
/// LLM Provider Url ...
///
public string Url { get; set; }
///
/// Model Name ...
///
public string LLM { get; set; }
///
/// Api Key for Connection ...
///
public string ApiKey { get; set; }
///
/// Specified Model Provider Type ...
///
public XAiModelProviderType Provider { get; set; } = XAiModelProviderType.Ollama;
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Models\XAiPromptDescriptor.cs
namespace xAiModels.Models
{
///
/// Describe Specified Prompt ...
///
public class XAiPromptDescriptor
{
///
/// Prompt Name ...
///
public string Name { get; set; }
///
/// Prompt Template ...
///
public string Template { get; set; }
///
/// Prompt Description ...
///
public string Description { get; set; }
///
/// Prompt Template Params ...
///
public XAiPromptParam[] Params { get; set; } = [];
}
///
/// Specified a Prompt Param ...
///
public class XAiPromptParam
{
///
/// Param Name ...
///
public string Name { get; set; }
///
/// Param Identifier ...
///
public string Param { get; set; }
///
/// Parma Description ...
///
public string Description { get; set; }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Models\XAiResonseMessage.cs
using System;
using xModels.Base;
using xAiModels.Constants;
namespace xAiModels.Models
{
public class XAiResonseMessage : XBaseDto
{
public long Sequence { get; set; }
public Guid RespondTo { get; set; }
public string OwnerId { get; set; }
public string Content { get; set; }
public XAiChatRole Role { get; set; }
public DateTime RespondedOn { get; set; }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Models\XAiResponseRequest.cs
using System;
namespace xAiModels.Models
{
///
/// /Request for a Response in Controllers ...
///
public class XAiResponseRequest
{
///
/// Prompt Text ...
///
public string Prompt { get; set; }
///
/// Specified Project Id ...
///
public Guid ProjectId { get; set; }
///
/// Specified Conversation Id ...
///
public Guid ConversationId { get; set; }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Models\XFileExtractionResult.cs
using System.Collections.Generic;
namespace xAiModels.Models
{
///
/// Holds File Extraction Result ...
///
public class XFileExtractionResult
{
///
/// Extracted String Content ...
///
public string Text { get; set; } = string.Empty;
///
/// Extracted Images for Vision Model ...
///
public IList Images { get; set; } = [];
///
/// Extracted Content from Audio File ...
///
public string AudioTranscript { get; set; } = string.Empty;
///
/// Main File Name ...
///
public string FileName { get; set; }
///
/// Main File MIME Type ...
///
public string MimeType { get; set; }
///
/// Specified Fallback done using Images or not ...
///
public bool UsedImageFallback { get; set; } = false;
///
/// Error Message ...
///
public string ErrorMessage { get; set; }
}
///
/// Extracted Image ...
///
public class XExtractedImage
{
///
/// Content as Byte ...
///
public byte[] Bytes { get; set; }
///
/// MIME Type of Image ...
///
public string MimeType { get; set; } = "image/png";
///
/// for PDF Files ...
///
public int? PageNumber { get; set; }
///
/// Describe Image ...
///
public string Description { get; set; }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Models\Dtos\XAiConversationDto.cs
using System;
using xModels.Base;
using xModels.Dtos;
using System.Collections.Generic;
namespace xAiModels.Models.Dtos
{
///
/// Conversation Describe ...
///
public class XAiConversationDto : XBaseGuidIDEntityDto
{
///
/// User Identifier ...
///
///
public string OwnerId { get; set; }
///
/// Owner Info ...
///
public virtual XPersonDto Owner { get; set; } = null;
///
/// Conversation Title Resource ID ...
///
public string Title { get; set; }
///
/// All Exists Title Locale Resources ...
///
public virtual XResourceDto TitleResource { get; set; }
///
/// Created Time ...
///
public DateTime CreatedOn { get; set; }
///
/// Updated Time ...
///
public DateTime UpdatedAt { get; set; }
///
/// Conversation Messages ...
///
public virtual IEnumerable Messages { get; set; } = [];
///
/// Project ID ...
///
public Guid ProjectId { get; set; }
///
/// Project Title Resource ID ...
///
public virtual string ProjectTitle { get; set; } = null;
///
/// Project Description Resource ID ...
///
public virtual string ProjectDescription { get; set; } = null;
///
/// Project Title Locale Resources ...
///
public virtual XResourceDto ProjectTitleResource { get; set; }
///
/// Project Description Locale Resources ...
///
public virtual XResourceDto ProjectDescriptionResource { get; set; }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Models\Dtos\XAiMessageDto.cs
using System;
using xModels.Base;
using xModels.Dtos;
using xAiModels.Constants;
using xCommons.Extensions;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace xAiModels.Models.Dtos
{
public class XAiMessageDto : XBaseGuidIDEntityDto
{
///
/// User Identifier ...
///
///
public string OwnerId { get; set; }
///
/// Owner Info ...
///
public virtual XPersonDto Owner { get; set; } = null;
///
/// Message of Chat ...
///
public string Content { get; set; }
///
/// Role of Message ...
///
public XAiChatRole Role { get; set; }
///
/// Created Time ...
///
public DateTime CreatedOn { get; set; }
///
/// Updated Time ...
///
public DateTime UpdatedAt { get; set; }
///
/// Conversation Id ...
///
public Guid ConversationId { get; set; }
///
/// Conversation Info ...
///
public virtual string ConversationTitle { get; set; } = null;
public virtual XResourceDto ConversationTitleResouce { get; set; } = null;
//
#region Meta Data Property ...
private string _metadata;
///
/// Meta Data of Message ...
///
[NotMapped]
public IDictionary Metadata { get; private set; } = null;
///
/// Meta Data of MEssage in Json ...
///
public string MetaDatas
{
//
get => _metadata;
//
set
{
//
// Converts Json String to Dictionary ...
if (!value.IsNullOrEmpty())
{
Metadata = value.FromJSON>();
}
//
_metadata = value;
}
}
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Models\Dtos\XAiProjectDto.cs
using System;
using xModels.Base;
using xModels.Dtos;
using System.Collections.Generic;
namespace xAiModels.Models.Dtos
{
///
/// Describe a Project ...
///
public class XAiProjectDto : XBaseGuidIDEntityDto
{
///
/// User Identifier ...
///
///
public string OwnerId { get; set; }
///
/// Owner Info ...
///
public virtual XPersonDto Owner { get; set; } = null;
///
/// Title of Project ...
///
public string Title { get; set; }
///
/// All Exists Title Locale Resources ...
///
public virtual XResourceDto TitleResource { get; set; }
///
/// Description of Project ...
///
public string Description { get; set; }
///
/// All Exists Description Locale Resources ...
///
public virtual XResourceDto DescriptionResource { get; set; }
///
/// a Prompt for Project Start ...
///
public string Prompt { get; set; }
///
/// Created Time ...
///
public DateTime CreatedOn { get; set; }
///
/// Updated Time ...
///
public DateTime UpdatedAt { get; set; }
///
/// Conversations ...
///
public virtual IList Conversations { get; set; } = [];
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Models\Entities\XAiConversation.cs
using System;
using xModels.Base;
using System.ComponentModel.DataAnnotations;
namespace xAiModels.Models.Entities
{
///
/// Conversation Describe ...
///
public class XAiConversation : XBaseGuidIDEntity
{
///
/// User Identifier ...
///
///
[Required]
[StringLength(255)]
public string OwnerId { get; set; }
///
/// Title of Conversation ...
///
[Required]
[StringLength(255)]
public string Title { get; set; }
///
/// Created Time ...
///
public DateTime CreatedOn { get; set; }
///
/// Updated Time ...
///
public DateTime UpdatedAt { get; set; }
///
/// Project ID ...
///
[Required]
public Guid ProjectId { get; set; }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Models\Entities\XAiDocument.cs
using System;
using System.ComponentModel.DataAnnotations;
using xModels.Base;
namespace xAiModels.Models.Entities
{
///
/// Represents an embedd document in the AI system.
///
public class XAiDocument : XBaseGuidIDEntity
{
///
/// User Identifier ...
///
///
[Required]
[StringLength(255)]
public string OwnerId { get; set; }
///
/// Title of Document ...
///
[StringLength(255)]
public string Title { get; set; }
///
/// Content of Document ...
///
public string Content { get; set; }
///
/// Hash of the Document Content ...
///
public string ContentHash { get; set; } = string.Empty;
///
/// Embedding Model Identifier ...
///
public string EmbeddingModel { get; set; } = string.Empty;
///
/// Dimensions of the Embedding ...
///
public int Dimensions { get; set; }
///
/// Vector representation of the Document ...
///
public byte[] Vector { get; set; } = [];
///
/// Created Time ...
///
public DateTime CreatedOn { get; set; }
///
/// Updated Time ...
///
public DateTime UpdatedAt { get; set; }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Models\Entities\XAiMessage.cs
using System;
using xModels.Base;
using xAiModels.Constants;
using xCommons.Extensions;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace xAiModels.Models.Entities
{
///
/// Message Model of Ai ...
///
public class XAiMessage : XBaseGuidIDEntity
{
///
/// User Identifier ...
///
///
[Required]
[StringLength(255)]
public string OwnerId { get; set; }
///
/// Message of Chat ...
///
[Required]
public string Content { get; set; }
///
/// Role of Message ...
///
public XAiChatRole Role { get; set; }
///
/// Created Time ...
///
public DateTime CreatedOn { get; set; }
///
/// Updated Time ...
///
public DateTime UpdatedAt { get; set; }
///
/// Conversation Id ...
///
[StringLength(255)]
public Guid ConversationId { get; set; }
//
#region Meta Data Property ...
private string _metadata;
///
/// Meta Data of Message ...
///
[NotMapped]
public IDictionary Metadata { get; private set; } = null;
///
/// Meta Data of MEssage in Json ...
///
public string MetaDatas
{
//
get => _metadata;
//
set
{
//
// Converts Json String to Dictionary ...
if (!value.IsNullOrEmpty())
{
Metadata = value.FromJSON>();
}
//
_metadata = value;
}
}
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Models\Entities\XAiProject.cs
using System;
using xModels.Base;
using System.ComponentModel.DataAnnotations;
namespace xAiModels.Models.Entities
{
///
/// Describe a Project ...
///
public class XAiProject : XBaseGuidIDEntity
{
///
/// User Identifier ...
///
///
[Required]
[StringLength(255)]
public string OwnerId { get; set; }
///
/// Title of Project ...
///
[Required]
[StringLength(255)]
public string Title { get; set; }
///
/// Description of Project ...
///
[StringLength(1000)]
public string Description { get; set; }
///
/// a Prompt for Project Start ...
///
public string Prompt { get; set; }
///
/// Created Time ...
///
public DateTime CreatedOn { get; set; }
///
/// Updated Time ...
///
public DateTime UpdatedAt { get; set; }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\XAiConversationEntityRegisterar.cs
using System;
using xDataService.Providers;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
using Microsoft.EntityFrameworkCore;
using xAiModels.Configurations.Entities;
namespace xAiModels.Providers
{
public class XAiConversationEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar
{
public XAiConversationEntityRegisterar()
: base(nameof(XAiConversationEntityRegisterar))
{
//
// Add Entity ...
AddEntity();
}
///
/// Configure Entities ...
///
///
public override void ConfigureEntities(ModelBuilder modelBuilder)
{
//
// Configure Entity Using Provided ...
modelBuilder
.ApplyConfigurationsFromAssembly(typeof(XAiConversationEntityConfiguration).Assembly);
//
base.ConfigureEntities(modelBuilder);
}
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\XAiConversationTitleResourceProvider.cs
using xAiModels.Constants;
using xAiModels.Interfaces;
using xCommons.Configurations;
using xStringService.Providers;
using xStringService.Interfaces.Dtos;
namespace xAiModels.Providers
{
public class XAiConversationTitleResourceProvider : XBaseOwnedItemResourceProvider, IXAiConversationTitleResourceProvider
{
public XAiConversationTitleResourceProvider(
XAppConfiguration appConfig,
IXStringServiceProvider stringProvider
) : base(
appConfig: appConfig,
stringProvider: stringProvider,
item: XAiModelsConstants.XAiConversationTitleIdentifier
)
{ }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\XAiDataProvider.cs
using System;
using System.Linq;
using xModels.Dtos;
using System.Threading;
using xAiModels.Constants;
using xCommons.Extensions;
using xAiModels.Extensions;
using xAiModels.Interfaces;
using xAiModels.Models.Dtos;
using xExceptions.Constants;
using System.Threading.Tasks;
using xCommons.Configurations;
using System.Linq.Expressions;
using xDataService.Extensions;
using xAiModels.Providers.Hubs;
using xAiModels.Interfaces.Dtos;
using xStringService.Interfaces;
using xAiModels.Models.Entities;
using System.Collections.Generic;
using Microsoft.AspNetCore.SignalR;
using xAiModels.Interfaces.Enrichers;
namespace xAiModels.Providers
{
///
/// All Data Manipulation Requirements ...
///
public class XAiDataProvider : IXAiDataProvider
{
//
#region Properties ...
private readonly IXStringProvider stringProvider;
private readonly XAppConfiguration appConfiguration;
private readonly IHubContext hub;
private readonly IXAiMessageEnricher messageEnricher;
private readonly IXAiProjectEnricher projectEnricher;
private readonly IXAiConversationEnricher conversationEnricher;
private readonly IXAiMessageRepositoryService messageRepositoryService;
private readonly IXAiProjectRepositoryService projectRepositoryService;
private readonly IXAiProjectTitleResourceProvider projectTitleResourceProvider;
private readonly IXAiConversationRepositoryService conversationRepositoryService;
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
private readonly IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider;
#endregion
public XAiDataProvider(
IXStringProvider stringProvider,
XAppConfiguration appConfiguration,
IHubContext hub,
IXAiProjectEnricher projectEnricher,
IXAiMessageEnricher messageEnricher,
IXAiConversationEnricher conversationEnricher,
IXAiMessageRepositoryService messageRepositoryService,
IXAiProjectRepositoryService projectRepositoryService,
IXAiProjectTitleResourceProvider projectTitleResourceProvider,
IXAiConversationRepositoryService conversationRepositoryService,
IXAiConversationTitleResourceProvider conversationTitleResourceProvider,
IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider
)
{
this.hub = hub;
this.stringProvider = stringProvider;
this.projectEnricher = projectEnricher;
this.messageEnricher = messageEnricher;
this.appConfiguration = appConfiguration;
this.conversationEnricher = conversationEnricher;
this.messageRepositoryService = messageRepositoryService;
this.projectRepositoryService = projectRepositoryService;
this.projectTitleResourceProvider = projectTitleResourceProvider;
this.conversationRepositoryService = conversationRepositoryService;
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
this.projectDescriptionResourceProvider = projectDescriptionResourceProvider;
}
//
#region Loaders ...
///
/// Load Projects List of Specified Owner ...
///
///
///
///
///
///
///
public async Task> LoadProjects(
string ownerId,
string connectionId = null,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
)
{
//
// Validate Args ...
if (ownerId.IsNullOrEmpty())
{
XException.InvalidArgs.Throw();
}
//
// Handle Default Project and Conversation ...
//
// Default Project ...
bool hasDefault = await HasDefaultProject(
ownerId: ownerId,
cancellationToken: cancellationToken
);
if (!hasDefault)
{
//
await CreateDefaultProject(
ownerId: ownerId,
connectionId: connectionId,
cancellationToken: cancellationToken
);
}
var defaultProject = await GetDefaultProject(
ownerId: ownerId,
connectionId: connectionId,
cancellationToken: cancellationToken
);
//
// Default Project's Default Conversation ...
hasDefault = await HasDefaultConversation(
ownerId: ownerId,
projectId: defaultProject.Id,
cancellationToken: cancellationToken
);
if (!hasDefault)
{
//
await CreateDefaultConversation(
ownerId: ownerId,
connectionId: connectionId,
projectId: defaultProject.Id,
cancellationToken: cancellationToken
);
}
//
// Retrieve Project List ...
var result = await projectRepositoryService.FindManyAsync(
includeBuilder: null,
ignoreSoftDeleteds: true,
predicate: x => x.OwnerId == ownerId,
cancellationToken: cancellationToken,
orderBuilder: x => x.OrderBy(y => y.CreatedOn)
);
//
if (result.HasChild())
{
//
result = await projectEnricher.EnrichRange(
sources: result,
cancellationToken: cancellationToken,
fillConversations: fillConversations,
fillConversationMessages: fillConversationMessages
);
}
//
return result;
}
///
/// Load List of Conversations for Specified Project ...
///
///
///
///
///
///
public async Task> LoadConversations(
Guid projectId,
bool fillMessages = false,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Validate Args ...
if (projectId.IsNull() ||
projectId.IsDefaultGuid()
)
{
XException.InvalidArgs.Throw();
}
//
// Retrieve Project ...
var project = await projectRepositoryService.GetAsync(
id: projectId,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
);
if (project.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
// Default Conversation ...
var hasDefault = await HasDefaultConversation(
projectId: projectId,
ownerId: project.OwnerId,
connectionId: connectionId,
cancellationToken: cancellationToken
);
if (!hasDefault)
{
//
await CreateDefaultConversation(
projectId: projectId,
ownerId: project.OwnerId,
connectionId: connectionId,
cancellationToken: cancellationToken
);
}
//
// Retrieve Conversation's List ...
var result = await conversationRepositoryService.FindManyAsync(
includeBuilder: null,
ignoreSoftDeleteds: false,
cancellationToken: cancellationToken,
predicate: x => x.ProjectId == projectId,
orderBuilder: x => x.OrderBy(y => y.CreatedOn)
);
//
if (result.HasChild())
{
//
result = await conversationEnricher.EnrichRange(
sources: result,
fillMessages: fillMessages,
cancellationToken: cancellationToken
);
}
//
return result;
}
///
/// Load Messages of Specified Conversation ...
///
///
///
///
public async Task> LoadMessages(
Guid conversationId,
CancellationToken cancellationToken = default
)
{
//
// Validate Args ...
if (conversationId.IsNull() ||
conversationId.IsDefaultGuid()
)
{
XException.InvalidArgs.Throw();
}
//
var conversation = await conversationRepositoryService.GetAsync(
id: conversationId,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
);
if (conversation.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
// Retrieve Message Lists of Specified Conversation ...
var result = await messageRepositoryService.FindManyAsync(
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken,
orderBuilder: x => x.OrderBy(y => y.CreatedOn),
predicate: x => x.ConversationId == conversationId
);
//
if (result.HasChild())
{
//
result = await messageEnricher.EnrichRange(
sources: result,
cancellationToken: cancellationToken
);
}
//
return result;
}
#endregion
//
#region Getters ...
///
/// Retrieve Specified Project ...
///
///
///
///
///
///
public async Task GetProject(
Guid id,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
)
{
//
// Validate Args ...
if (id.IsDefaultGuid())
{
XException.InvalidArgs.Throw();
}
//
var result = await projectRepositoryService.GetAsync(
id: id,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
);
if (result.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
// Handle Enrichment ...
result = await projectEnricher.Enrich(
source: result,
fillConversations: fillConversations,
cancellationToken: cancellationToken,
fillConversationMessages: fillConversationMessages
);
//
return result;
}
///
/// Retrieve Specified Conversation ...
///
///
///
///
///
public async Task GetConversation(
Guid id,
bool fillMessages = false,
CancellationToken cancellationToken = default
)
{
//
// Validate Args ...
if (id.IsDefaultGuid())
{
XException.InvalidArgs.Throw();
}
//
var result = await conversationRepositoryService.GetAsync(
id: id,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
);
if (result.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
// Handle Enrichment ...
result = await conversationEnricher.Enrich(
source: result,
fillMessages: fillMessages,
cancellationToken: cancellationToken
);
//
return result;
}
#endregion
//
#region Creator/Adders ...
///
/// Create Project ...
///
///
///
///
///
///
public async Task CreateProject(
string ownerId,
XAiProjectDto item = null,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Validate Args ...
if (ownerId.IsNullOrEmpty())
{
XException.InvalidArgs.Throw();
}
//
// Check Project Provided or not ...
var hasProject = !item.IsNullOrDefault();
//
// Normalize Provided Project ...
if (hasProject)
{
//
item.OwnerId = ownerId;
item.CreatedOn = DateTime.UtcNow;
//
// Validate Item ...
if (!item.IsValidForAddOrUpdate())
{
XException.InvalidData.Throw();
}
}
//
XAiProjectDto result = null;
var defaultLanguage = appConfiguration.DefaultLanguage;
//
// Create Provided Project ...
if (hasProject)
{
//
// Add Item for ID Gneneration ...
result = await projectRepositoryService.AddAsync(
item: item,
saveChanges: true,
cancellationToken: cancellationToken
);
//
// Checking Resources ...
//
// Titles ...
var titleResource = string.Empty;
if (!item.TitleResource.IsNullOrDefault() &&
item.TitleResource.Locales.HasChild())
{
//
// Adding Title Resource Locales ...
var isDefaultLanguageHandled = false;
foreach (var trl in item.TitleResource.Locales)
{
//
// Attaching Default Language ...
if (!isDefaultLanguageHandled &&
trl.Language.IsNullOrEmpty())
{
//
trl.Language = defaultLanguage;
isDefaultLanguageHandled = false;
}
//
// Check Value Exists ...
if (trl.Value.IsNullOrEmpty())
{
continue;
}
//
var resource = await projectTitleResourceProvider.AddOrUpdateLocale(
locale: trl,
owner: ownerId,
identifier: result.Id,
connectionId: connectionId,
cancellationToken: cancellationToken
);
if (!resource.IsNullOrDefault() &&
titleResource.IsNullOrEmpty())
{
titleResource = resource.Resource;
}
}
}
//
// Descriptions ...
var descriptionResource = string.Empty;
if (!item.DescriptionResource.IsNullOrDefault() &&
item.DescriptionResource.Locales.HasChild())
{
//
// Adding Description Resource Locales ....
var isDefaultLanguageHandled = false;
foreach (var trl in item.DescriptionResource.Locales)
{
//
// Attaching Default Language ...
if (!isDefaultLanguageHandled &&
trl.Language.IsNullOrEmpty())
{
//
trl.Language = defaultLanguage;
isDefaultLanguageHandled = false;
}
//
// Check Value Exists ...
if (trl.Value.IsNullOrEmpty())
{
continue;
}
//
var resource = await projectDescriptionResourceProvider.AddOrUpdateLocale(
locale: trl,
owner: ownerId,
identifier: result.Id,
connectionId: connectionId,
cancellationToken: cancellationToken
);
if (!resource.IsNullOrDefault() &&
descriptionResource.IsNullOrEmpty())
{
descriptionResource = resource.Resource;
}
}
}
//
// Update Data ...
result.Title = titleResource;
result.Description = descriptionResource;
result = await projectRepositoryService.UpdateAsync(
item: result,
id: result.Id,
saveChanges: true,
cancellationToken: cancellationToken
);
if (!result.IsNullOrDefault())
{
//
result = await projectEnricher.Enrich(
source: result,
fillConversations: false,
fillConversationMessages: false,
cancellationToken: cancellationToken
);
}
//
// Handling Send Push Notification ...
if (!result.IsNullOrDefault() &&
!connectionId.IsNullOrEmpty()
)
{
//
await SendPush(
connectionId: connectionId,
cancellationToken: cancellationToken,
payLoad: item.ToJSON(camelCase: true),
action: XAiDataProviderHubActions.ProjectCreated.GetStringValue()
);
}
}
//
// Check Default Project ...
else
{
//
// Check Default Project Exists or not ...
var hasDefault = await HasDefaultProject(
ownerId: ownerId,
cancellationToken: cancellationToken
);
//
// If Default Project Exists, Throw Exception ...
if (hasDefault)
{
XException.InvalidArgs.Throw();
}
//
// Create and Retrive Default Project ...
result = await GetDefaultProject(
ownerId: ownerId,
connectionId: connectionId,
cancellationToken: cancellationToken
);
}
//
// Validate ...
if (result.IsNullOrDefault())
{
XException.ActionFailed.Throw();
}
//
// Handle Enrichment ...
result = await Enrich(
source: result,
fillConversations: false,
fillConversationMessages: false,
cancellationToken: cancellationToken
);
//
return result;
}
///
/// Create an AI Conversation ...
///
///
///
///
///
///
///
public async Task CreateConversation(
string ownerId,
Guid projectId,
XAiConversationDto item = null,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Validate Args ...
if (projectId.IsNull() ||
projectId.IsDefaultGuid())
{
XException.InvalidArgs.Throw();
}
//
// Handle Proejct ...
XAiProjectDto project = await projectRepositoryService.GetAsync(
id: projectId,
includeBuilder: null,
ignoreSoftDeleteds: true,
// fillConversations: false,
// fillConversationMessages: false,
cancellationToken: cancellationToken
);
if (project.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
// Check Conversation Provided or not ...
var hasConversation = !item.IsNullOrDefault();
//
// Normalize Conversation if Provided ...
if (hasConversation)
{
//
item.OwnerId = ownerId;
item.ProjectId = project.Id;
item.CreatedOn = DateTime.UtcNow;
//
// Validate Item ...
if (!item.IsValidForAddOrUpdate())
{
XException.InvalidData.Throw();
}
}
//
XAiConversationDto result = null;
var defaultLanguage = appConfiguration.DefaultLanguage;
//
// Create Provided Conversation ...
if (hasConversation)
{
//
// Add Item for ID Gneneration ...
result = await conversationRepositoryService.AddAsync(
item: item,
saveChanges: true,
// fillMessages: false,
cancellationToken: cancellationToken
);
//
// Checking Resources ...
//
// Titles ...
var titleResource = string.Empty;
if (!item.TitleResource.IsNullOrDefault() &&
item.TitleResource.Locales.HasChild())
{
//
// Adding Title Resource Locales ...
var isDefaultLanguageHandled = false;
foreach (var trl in item.TitleResource.Locales)
{
//
// Attaching Default Language ...
if (!isDefaultLanguageHandled &&
trl.Language.IsNullOrEmpty())
{
//
trl.Language = defaultLanguage;
isDefaultLanguageHandled = false;
}
//
// Check Value Exists ...
if (trl.Value.IsNullOrEmpty())
{
continue;
}
//
var resource = await conversationTitleResourceProvider.AddOrUpdateLocale(
locale: trl,
owner: ownerId,
identifier: result.Id,
connectionId: connectionId,
cancellationToken: cancellationToken
);
if (!resource.IsNullOrDefault() &&
titleResource.IsNullOrEmpty())
{
titleResource = resource.Resource;
}
}
}
//
// Update Data ...
result.Title = titleResource;
result = await conversationRepositoryService.UpdateAsync(
item: result,
id: result.Id,
saveChanges: true,
cancellationToken: cancellationToken
);
if (!result.IsNullOrDefault())
{
//
result = await conversationEnricher.Enrich(
source: result,
fillMessages: false,
cancellationToken: cancellationToken
);
}
//
// Handling Send Push Notification ...
if (!result.IsNullOrDefault() &&
!connectionId.IsNullOrEmpty()
)
{
//
await SendPush(
connectionId: connectionId,
cancellationToken: cancellationToken,
payLoad: item.ToJSON(camelCase: true),
action: XAiDataProviderHubActions.ConversationCreated.GetStringValue()
);
}
}
//
// Check Default Conversation ...
else
{
//
// Check Default Conversation Exists or not ...
var hasDefault = await HasDefaultConversation(
projectId: project.Id,
ownerId: project.OwnerId,
cancellationToken: cancellationToken
);
//
// If Default Project Exists, Throw Exception ...
if (hasDefault)
{
XException.InvalidArgs.Throw();
}
//
// Create and Retrive Default Conversation ...
result = await GetDefaultConversation(
projectId: project.Id,
ownerId: project.OwnerId,
connectionId: connectionId,
cancellationToken: cancellationToken
);
}
//
// Validate ...
if (result.IsNullOrDefault())
{
XException.ActionFailed.Throw();
}
//
// Handle Enrichment ...
result = await Enrich(
source: result,
fillMessages: false,
cancellationToken: cancellationToken
);
//
return result;
}
///
/// Add Message ...
///
///
///
///
///
///
public async Task AddMessage(
Guid conversationId,
XAiMessageDto item,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Validate Args ...
if (item.IsNullOrDefault() ||
conversationId.IsNull() ||
conversationId.IsDefaultGuid()
)
{
XException.InvalidArgs.Throw();
}
//
// Normalize ...
item.CreatedOn = DateTime.UtcNow;
item.ConversationId = conversationId;
//
// Validate Item ...
if (!item.IsValidForAddOrUpdate())
{
XException.InvalidData.Throw();
}
//
var result = await messageRepositoryService.AddAsync(
item: item,
saveChanges: true,
cancellationToken: cancellationToken
);
//
// Handle Enrichment ...
if (!result.IsNullOrDefault())
{
//
result = await Enrich(
source: result,
cancellationToken: cancellationToken
);
}
//
// Handling Send Push Notification ...
if (!result.IsNullOrDefault() &&
!connectionId.IsNullOrEmpty()
)
{
//
await SendPush(
connectionId: connectionId,
cancellationToken: cancellationToken,
payLoad: item.ToJSON(camelCase: true),
action: XAiDataProviderHubActions.MessageCreated.GetStringValue()
);
}
//
return result;
}
#endregion
//
#region Updaters ...
#endregion
//
#region Defaults ...
///
/// Retrieve Default Project of Specified Owner ...
/// Create it if not Handled ...
///
///
///
///
///
public async Task GetDefaultProject(
string ownerId,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Check Default Project Exists or noit ...
var isExists = await HasDefaultProject(
ownerId: ownerId,
cancellationToken: cancellationToken
);
if (!isExists)
{
//
await CreateDefaultProject(
ownerId: ownerId,
connectionId: connectionId,
cancellationToken: cancellationToken
);
}
//
var resource = await stringProvider.FindOne(
cancellationToken: cancellationToken,
predicate: x =>
x.ResourceTitle
.ToNormalString()
.Contains(ownerId.ToNormalString()) &&
x.ResourceTitle
.ToNormalString()
.Contains(XAiModelsConstants.XAiProjectTitleIdentifier.ToNormalString()) &&
x.TranslatedValue
.ToNormalString()
.Contains(XAiDataProviderConstants.XDefaultAiProjectSuffix.ToNormalString())
);
if (resource.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
var result = await projectRepositoryService.FindOneAsync(
cancellationToken: cancellationToken,
predicate: x => x.Title
.Equals(
resource.ResourceTitle,
StringComparison.InvariantCultureIgnoreCase
)
);
if (result.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
return result;
}
///
/// Retrieve Default Conversation of Specified Owner ...
/// Create it if not Handled ...
///
///
///
///
///
///
public async Task GetDefaultConversation(
string ownerId,
Guid projectId,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Validate Args ...
if (ownerId.IsNullOrEmpty())
{
XException.InvalidArgs.Throw();
}
//
// Prepare Project ...
XAiProjectDto project = null;
if (projectId.IsNull() ||
projectId.IsDefaultGuid()
)
{
//
project = await GetDefaultProject(
ownerId: ownerId,
connectionId: connectionId,
cancellationToken: cancellationToken
);
}
else
{
//
project = await projectRepositoryService.GetAsync(
id: project.Id,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
);
}
if (project.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
// Check Default Conversation Exists or noit ...
var isExists = await HasDefaultConversation(
ownerId: ownerId,
projectId: project.Id,
connectionId: connectionId,
cancellationToken: cancellationToken
);
if (!isExists)
{
//
await CreateDefaultConversation(
ownerId: ownerId,
projectId: project.Id,
connectionId: connectionId,
cancellationToken: cancellationToken
);
}
//
// Detect Conversation Resource ...
var resource = await stringProvider.FindOne(
cancellationToken: cancellationToken,
predicate: x =>
x.ResourceTitle
.ToNormalString()
.Contains(ownerId.ToNormalString()) &&
x.ResourceTitle
.ToNormalString()
.Contains(XAiModelsConstants.XAiProjectTitleIdentifier
.ToNormalString()) &&
x.TranslatedValue
.ToNormalString()
.Contains(XAiDataProviderConstants.XDefaultAiProjectSuffix)
);
if (resource.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
// Find Default Conversation ...
var result = await conversationRepositoryService.FindOneAsync(
cancellationToken: cancellationToken,
predicate: x => x.Title
.Equals(
resource.ResourceTitle,
StringComparison.InvariantCultureIgnoreCase
) &&
x.ProjectId == project.Id
);
if (result.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
return result;
}
#endregion
//
#region Query ...
///
/// Query Projects ...
///
///
///
///
///
public async Task> QueryProjects(
string ownerId,
XQuery query,
CancellationToken cancellationToken = default
)
{
//
Expression> predicate = null;
if (ownerId.IsNullOrEmpty())
{
predicate = x => x.OwnerId == ownerId;
}
//
var result = await projectRepositoryService.QueryAsync(
query: query,
predicate: predicate,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken,
orderBuilder: x => x.OrderBy(y => y.CreatedOn)
);
if (!result.IsNullOrDefault() &&
result.Items.HasChild())
{
//
result.Items = [..await EnrichRange(
sources: result.Items,
fillConversations: false,
fillConversationMessages: false,
cancellationToken: cancellationToken
)];
}
//
return result;
}
///
/// Query Conversations ...
///
///
///
///
///
///
public async Task> QueryConversations(
string ownerId,
Guid projectId,
XQuery query,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
if (projectId.IsDefaultGuid())
{
XException.InvalidArgs.Throw();
}
//
// Retrieve Project ...
var project = await projectRepositoryService.GetAsync(
id: projectId,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
);
if (project.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
Expression> predicate = x =>
x.ProjectId == projectId;
if (ownerId.IsNullOrEmpty())
{
//
predicate = x =>
x.OwnerId == ownerId &&
x.ProjectId == projectId;
}
//
var result = await conversationRepositoryService.QueryAsync(
query: query,
predicate: predicate,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken,
orderBuilder: x => x.OrderBy(y => y.CreatedOn)
);
if (!result.IsNullOrDefault() &&
result.Items.HasChild())
{
//
result.Items = [..await EnrichRange(
fillMessages: false,
sources: result.Items,
cancellationToken: cancellationToken
)];
}
//
return result;
}
///
/// Query Messages ...
///
///
///
///
///
///
public async Task> QueryMessages(
string ownerId,
Guid conversationId,
XQuery query,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
if (conversationId.IsDefaultGuid())
{
XException.InvalidArgs.Throw();
}
//
// Retrieve Conversation ...
var conversation = await conversationRepositoryService.GetAsync(
id: conversationId,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
);
if (conversation.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
Expression> predicate = x =>
x.ConversationId == conversationId;
if (ownerId.IsNullOrEmpty())
{
//
predicate = x =>
x.OwnerId == ownerId &&
x.ConversationId == conversationId;
}
//
var result = await messageRepositoryService.QueryAsync(
query: query,
predicate: predicate,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken,
orderBuilder: x => x.OrderBy(y => y.CreatedOn)
);
if (!result.IsNullOrDefault() &&
result.Items.HasChild())
{
//
result.Items = [..await EnrichRange(
sources: result.Items,
cancellationToken: cancellationToken
)];
}
//
return result;
}
#endregion
//
#region Enrichers ...
///
/// Enrich Specified Item ...
///
///
///
///
///
///
public async Task Enrich(
XAiProjectDto source,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
)
{
//
var result = await projectEnricher.Enrich(
source: source,
fillConversations: fillConversations,
cancellationToken: cancellationToken,
fillConversationMessages: fillConversationMessages
);
//
return result;
}
///
/// Enrich Specified Items ...
///
///
///
///
///
///
public async Task> EnrichRange(
IEnumerable sources,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
)
{
//
var result = await projectEnricher.EnrichRange(
sources: sources,
fillConversations: fillConversations,
cancellationToken: cancellationToken,
fillConversationMessages: fillConversationMessages
);
//
return result;
}
///
/// Enrich Specified Item ...
///
///
///
///
///
public async Task Enrich(
XAiConversationDto source,
bool fillMessages = false,
CancellationToken cancellationToken = default
)
{
//
var result = await conversationEnricher.Enrich(
source: source,
fillMessages: fillMessages,
cancellationToken: cancellationToken
);
//
return result;
}
///
/// Enrich Specified Items ...
///
///
///
///
///
public async Task> EnrichRange(
IEnumerable sources,
bool fillMessages = false,
CancellationToken cancellationToken = default
)
{
//
var result = await conversationEnricher.EnrichRange(
sources: sources,
fillMessages: fillMessages,
cancellationToken: cancellationToken
);
//
return result;
}
///
/// Enrich Specified Item ...
///
///
///
///
public async Task Enrich(
XAiMessageDto source,
CancellationToken cancellationToken = default
)
{
//
var result = await messageEnricher.Enrich(
source: source,
cancellationToken: cancellationToken
);
//
return result;
}
///
/// Enrich Specified Items ...
///
///
///
///
public async Task> EnrichRange(
IEnumerable sources,
CancellationToken cancellationToken = default
)
{
//
var result = await messageEnricher.EnrichRange(
sources: sources,
cancellationToken: cancellationToken
);
//
return result;
}
#endregion
//
#region Private ...
///
/// Check Default Project Exists or not ...
///
///
///
///
private async Task HasDefaultProject(
string ownerId,
CancellationToken cancellationToken = default
)
{
//
// Validate Args ...
var result = !ownerId.IsNullOrEmpty();
if (!result)
{
return result;
}
//
// Check Default Owner Exists or not ...
var defaultProjectResource = await stringProvider.FindOne(
cancellationToken: cancellationToken,
predicate: x =>
x.ResourceTitle
.ToNormalString()
.Contains(ownerId.ToNormalString()) &&
x.ResourceTitle
.ToNormalString()
.Contains(XAiModelsConstants.XAiProjectTitleIdentifier.ToNormalString()) &&
x.TranslatedValue
.ToNormalString()
.Contains(XAiDataProviderConstants.XDefaultAiProjectSuffix.ToNormalString())
);
result = !defaultProjectResource.IsNullOrDefault();
//
return result;
}
///
/// Create Default Project for Specified Owner ...
///
///
///
///
///
private async Task CreateDefaultProject(
string ownerId,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
if (ownerId.IsNullOrEmpty())
{
return;
}
//
var defaultLang = appConfiguration.DefaultLanguage;
//
// Check Default Owner Exists or not ...
var isExists = await HasDefaultProject(
ownerId: ownerId,
cancellationToken: cancellationToken
);
if (isExists)
{
return;
}
//
// Create Default ...
var item = new XAiProjectDto()
{
OwnerId = ownerId,
CreatedOn = DateTime.UtcNow,
Title = Guid.NewGuid().ToString(),
Description = Guid.NewGuid().ToString(),
};
item = await projectRepositoryService.AddAsync(
item: item,
saveChanges: true,
cancellationToken: cancellationToken
);
//
// Prepare Tile and Description Resource Ids ...
var titleResource = await projectTitleResourceProvider.AddOrUpdateLocale(
owner: ownerId,
identifier: item.Id,
locale: new XLocaleResourceDto
{
Language = defaultLang,
Value = XAiDataProviderConstants.XDefaultAiProjectSuffix
},
cancellationToken: cancellationToken
);
var descriptionResource = await projectDescriptionResourceProvider.AddOrUpdateLocale(
owner: ownerId,
identifier: item.Id,
new XLocaleResourceDto
{
Language = defaultLang,
Value = XAiDataProviderConstants.XDefaultAiProjectSuffix
},
cancellationToken: cancellationToken
);
if (titleResource.IsNullOrDefault() ||
descriptionResource.IsNullOrDefault()
)
{
return;
}
//
// Update Project Resources ...
item.Title = titleResource.Resource;
item.Description = descriptionResource.Resource;
item = await projectRepositoryService.UpdateAsync(
id: item.Id,
item: item,
saveChanges: true,
cancellationToken: cancellationToken
);
//
// Sending Push ...
if (!connectionId.IsNullOrEmpty())
{
//
await SendPush(
connectionId: connectionId,
cancellationToken: cancellationToken,
payLoad: item.ToJSON(camelCase: true),
action: XAiDataProviderHubActions.ProjectCreated.GetStringValue()
);
}
}
///
/// Check Default Conversation Exists or not ...
///
///
///
///
///
///
private async Task HasDefaultConversation(
string ownerId,
Guid projectId,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Validate Args ...
var result = !ownerId.IsNullOrEmpty();
if (!result)
{
return result;
}
//
// Prepare Project ...
XAiProjectDto project = null;
if (projectId.IsNull() ||
projectId.IsDefaultGuid()
)
{
//
project = await GetDefaultProject(
ownerId: ownerId,
connectionId: connectionId,
cancellationToken: cancellationToken
);
}
else
{
//
project = await projectRepositoryService.GetAsync(
id: projectId,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
);
}
if (project.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
// Check Default Owner Exists or not ...
var resource = await stringProvider.FindOne(
cancellationToken: cancellationToken,
predicate: x =>
x.ResourceTitle
.ToNormalString()
.Contains(ownerId.ToString().ToNormalString()) &&
x.ResourceTitle
.ToNormalString()
.Contains(XAiModelsConstants.XAiConversationTitleIdentifier.ToNormalString()) &&
x.TranslatedValue
.ToNormalString()
.Contains(XAiDataProviderConstants.XDefaultAiConversationSuffix.ToNormalString())
);
result = !resource.IsNullOrDefault();
if (!result)
{
return result;
}
//
var defaultConversation = await conversationRepositoryService.FindOneAsync(
cancellationToken: cancellationToken,
predicate: x =>
x.ProjectId == projectId &&
x.Title == resource.ResourceTitle
);
result = !defaultConversation.IsNullOrDefault();
//
return result;
}
///
/// Check Default Conversation Exists or not ...
///
///
///
///
///
///
private async Task CreateDefaultConversation(
string ownerId,
Guid projectId,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Validate Args ...
var isValid = !ownerId.IsNullOrEmpty();
if (!isValid)
{
return;
}
//
var defaultLang = appConfiguration.DefaultLanguage;
//
// Prepare Project ...
XAiProjectDto project = null;
if (projectId.IsNull() ||
projectId.IsDefaultGuid()
)
{
//
project = await GetDefaultProject(
ownerId: ownerId,
connectionId: connectionId,
cancellationToken: cancellationToken
);
}
else
{
//
project = await projectRepositoryService.GetAsync(
id: projectId,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
);
}
if (project.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
// Check Default Owner Exists or not ...
isValid = await HasDefaultConversation(
ownerId: ownerId,
projectId: project.Id,
cancellationToken: cancellationToken
);
if (isValid)
{
return;
}
//
// Create Default Conversation ...
var item = new XAiConversationDto
{
OwnerId = ownerId,
ProjectId = project.Id,
CreatedOn = DateTime.UtcNow,
Title = Guid.NewGuid().ToString()
};
item = await conversationRepositoryService.AddAsync(
item: item,
saveChanges: true,
cancellationToken: cancellationToken
);
//
// Prepare Title Resource Ids ...
var titleResource = await conversationTitleResourceProvider.AddOrUpdateLocale(
owner: ownerId,
identifier: item.Id,
locale: new XLocaleResourceDto
{
Language = defaultLang,
Value = XAiDataProviderConstants.XDefaultAiConversationSuffix
},
cancellationToken: cancellationToken
);
if (titleResource.IsNullOrDefault())
{
return;
}
//
// Update Conversation Resources ...
item.Title = titleResource.Resource;
item = await conversationRepositoryService.UpdateAsync(
item: item,
id: item.Id,
saveChanges: true,
cancellationToken: cancellationToken
);
//
// Sending Push ...
if (!connectionId.IsNullOrEmpty())
{
//
await SendPush(
connectionId: connectionId,
cancellationToken: cancellationToken,
payLoad: item.ToJSON(camelCase: true),
action: XAiDataProviderHubActions.ConversationCreated.GetStringValue()
);
}
}
///
/// Send Custom Push Message ...
///
///
///
///
///
///
public async Task SendPush(
string action,
string payLoad,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
try
{
//
// Collect Allowed Actions ...
var actions = new List
{
XAiDataProviderHubActions.ProjectCreated.GetStringValue(),
XAiDataProviderHubActions.ProjectUpdated.GetStringValue(),
XAiDataProviderHubActions.ProjectRemoved.GetStringValue(),
XAiDataProviderHubActions.MessageCreated.GetStringValue(),
XAiDataProviderHubActions.MessageUpdated.GetStringValue(),
XAiDataProviderHubActions.MessageRemoved.GetStringValue(),
XAiDataProviderHubActions.ConversationCreated.GetStringValue(),
XAiDataProviderHubActions.ConversationUpdated.GetStringValue(),
XAiDataProviderHubActions.ConversationRemoved.GetStringValue(),
};
//
// Validate Args ...
var isValid =
!action.IsNullOrEmpty() &&
actions.Contains(action);
if (!isValid)
{
return;
}
//
// Retrieve Connection Id ...
var clients = hub.Clients.All;
if (!connectionId.IsNullOrEmpty())
{
clients = hub.Clients.AllExcept(connectionId);
}
//
await clients.SendAsync(
action,
payLoad,
connectionId,
cancellationToken
);
}
catch { }
}
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\XAiMessageEntityRegisterar.cs
using System;
using xDataService.Providers;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
using Microsoft.EntityFrameworkCore;
using xAiModels.Configurations.Entities;
namespace xAiModels.Providers
{
public class XAiMessageEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar
{
public XAiMessageEntityRegisterar()
: base(nameof(XAiMessageEntityRegisterar))
{
//
// Add Entity ...
AddEntity();
}
///
/// Configure Entities ...
///
///
public override void ConfigureEntities(ModelBuilder modelBuilder)
{
//
// Configure Entity Using Provided ...
modelBuilder
.ApplyConfigurationsFromAssembly(typeof(XAiMessageEntityConfiguration).Assembly);
//
base.ConfigureEntities(modelBuilder);
}
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\XAiProjectDescriptionResourceProvider.cs
using xAiModels.Constants;
using xAiModels.Interfaces;
using xCommons.Configurations;
using xStringService.Providers;
using xStringService.Interfaces.Dtos;
namespace xAiModels.Providers
{
public class XAiProjectDescriptionResourceProvider : XBaseOwnedItemResourceProvider, IXAiProjectDescriptionResourceProvider
{
public XAiProjectDescriptionResourceProvider(
XAppConfiguration appConfig,
IXStringServiceProvider stringProvider
) : base(
appConfig: appConfig,
stringProvider: stringProvider,
item: XAiModelsConstants.XAiProjectDescriptionIdentifier
)
{ }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\XAiProjectEntityRegisterar.cs
using System;
using xDataService.Providers;
using xDataService.Interfaces;
using xAiModels.Models.Entities;
using Microsoft.EntityFrameworkCore;
using xAiModels.Configurations.Entities;
namespace xAiModels.Providers
{
public class XAiProjectEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar
{
public XAiProjectEntityRegisterar()
: base(nameof(XAiProjectEntityRegisterar))
{
//
// Add Entity ...
AddEntity();
}
///
/// Configure Entities ...
///
///
public override void ConfigureEntities(ModelBuilder modelBuilder)
{
//
// Configure Entity Using Provided ...
modelBuilder
.ApplyConfigurationsFromAssembly(typeof(XAiProjectEntityConfiguration).Assembly);
//
base.ConfigureEntities(modelBuilder);
}
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\XAiProjectTitleResourceProvider.cs
using xAiModels.Constants;
using xAiModels.Interfaces;
using xCommons.Configurations;
using xStringService.Providers;
using xStringService.Interfaces.Dtos;
namespace xAiModels.Providers
{
public class XAiProjectTitleResourceProvider : XBaseOwnedItemResourceProvider, IXAiProjectTitleResourceProvider
{
public XAiProjectTitleResourceProvider(
XAppConfiguration appConfig,
IXStringServiceProvider stringProvider
) : base(
appConfig: appConfig,
stringProvider: stringProvider,
item: XAiModelsConstants.XAiProjectTitleIdentifier
)
{ }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\Dtos\XAiConversationDtoHub.cs
using System;
using xPushService.Base;
using xAiModels.Models.Dtos;
using xAiModels.Interfaces.Dtos;
using xAiModels.Models.Entities;
using Microsoft.Extensions.Logging;
namespace xAiModels.Providers.Dtos
{
public class XAiConversationDtoHub : XBaseDtoHub, IXAiConversationDtoHub
{
public XAiConversationDtoHub(
ILogger logger
) : base(logger)
{ }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\Dtos\XAiConversationRepositoryService.cs
using System;
using System.Linq;
using xModels.Dtos;
using System.Threading;
using xCommons.Extensions;
using xAiModels.Interfaces;
using xAiModels.Models.Dtos;
using System.Threading.Tasks;
using xDataService.Providers;
using xAiModels.Configurations;
using xAiModels.Interfaces.Dtos;
using xAiModels.Models.Entities;
using System.Collections.Generic;
using xIdentityService.Interfaces;
using xIdentityService.Extensions;
using xAiModels.Interfaces.Entities;
namespace xAiModels.Providers.Dtos
{
public class XAiConversationRepositoryService : XBaseRepositoryService, IXAiConversationRepositoryService
{
private readonly IXIdentityProvider identityProvider;
private readonly IXAiConversationRepository repository;
private readonly IXAiProjectTitleResourceProvider projectTitleResourceProvider;
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
private readonly IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider;
public XAiConversationRepositoryService(
IXIdentityProvider identityProvider,
IXAiConversationRepository repository,
IXAiProjectTitleResourceProvider projectTitleResourceProvider,
IXAiConversationTitleResourceProvider conversationTitleResourceProvider,
IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider
) : base(
repository,
mapperProfiles:
[
new XAiModelMappersProfile()
]
)
{
this.repository = repository;
this.identityProvider = identityProvider;
this.projectTitleResourceProvider = projectTitleResourceProvider;
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
this.projectDescriptionResourceProvider = projectDescriptionResourceProvider;
}
//
#region Enrichers ...
///
/// Enrich Specified Item ...
///
///
///
///
///
public virtual async Task Enrich(
XAiConversation source,
bool fillMessages = false,
CancellationToken cancellationToken = default
)
{
//
// Mapping Default ...
var result = Mapper.Map(source);
result = await Enrich(
source: result,
fillMessages: fillMessages,
cancellationToken: cancellationToken
);
//
return result;
}
///
/// Enrich Specified Item ...
///
///
///
///
///
public virtual async Task Enrich(
XAiConversationDto source,
bool fillMessages = false,
CancellationToken cancellationToken = default
)
{
//
// Handdle Owner ...
XPersonDto owner = null;
if (!source.OwnerId.IsNullOrEmpty())
{
//
// Try to Retrieve User Info ...
var device = identityProvider.GetDevice();
var userInfo = await identityProvider.GetUserInfo(
device: device,
userSelectByParam: source.OwnerId
);
owner = userInfo.ToXPersonDto();
}
//
// Handle Title Resource ...
XResourceDto titleResource = null;
if (!source.Title.IsNullOrEmpty())
{
//
titleResource = await conversationTitleResourceProvider.GetResource(
owner: source.OwnerId,
identifier: source.Id,
cancellationToken: cancellationToken
);
}
//
// Handle Project Info ...
XResourceDto projectTitleResource = null;
XResourceDto projectDescriptionResource = null;
if (!source.ProjectId.IsDefaultGuid())
{
//
projectTitleResource = await projectTitleResourceProvider.GetResource(
owner: source.OwnerId,
identifier: source.ProjectId,
cancellationToken: cancellationToken
);
//
projectDescriptionResource = await projectDescriptionResourceProvider.GetResource(
owner: source.OwnerId,
identifier: source.ProjectId,
cancellationToken: cancellationToken
);
}
//
// Attach Extracted Items ...
var result = Mapper.Map(source, options =>
{
//
options.Items[nameof(source.Owner)] = owner;
options.Items[nameof(source.TitleResource)] = titleResource;
options.Items[nameof(source.ProjectTitleResource)] = projectTitleResource;
options.Items[nameof(source.ProjectDescriptionResource)] = projectDescriptionResource;
});
//
return result;
}
///
/// Enrich Specified Items ...
///
///
///
///
///
public virtual async Task> EnrichRange(
IEnumerable sources,
bool fillMessages = false,
CancellationToken cancellationToken = default
)
{
//
var tasks = sources
.Select(x => Enrich(
source: x,
fillMessages: fillMessages,
cancellationToken: cancellationToken
));
//
var result = await Task.WhenAll(tasks);
return result;
}
///
/// Enrich Specified Items ...
///
///
///
///
///
public virtual async Task> EnrichRange(
IEnumerable sources,
bool fillMessages = false,
CancellationToken cancellationToken = default
)
{
//
var tasks = sources
.Select(x => Enrich(
source: x,
fillMessages: fillMessages,
cancellationToken: cancellationToken
));
//
var result = await Task.WhenAll(tasks);
return result;
}
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\Dtos\XAiConversationServiceProvider.cs
using System;
using xPushService.Base;
using xAiModels.Models.Dtos;
using xAiModels.Interfaces.Dtos;
using xAiModels.Models.Entities;
using xDataService.Configuration;
using xIdentityService.Interfaces;
using Microsoft.AspNetCore.SignalR;
namespace xAiModels.Providers.Dtos
{
public class XAiConversationServiceProvider : XBaseDtoProvider, IXAiConversationServiceProvider
{
public XAiConversationServiceProvider(
IHubContext hub,
XDataServiceConfiguration dataConfiguration,
IXAiConversationRepositoryService service,
IXIdentityProvider identityProvider = null
) : base(
hub,
dataConfiguration,
service,
identityProvider
)
{ }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\Dtos\XAiMessageDtoHub.cs
using System;
using xPushService.Base;
using xAiModels.Models.Dtos;
using xAiModels.Interfaces.Dtos;
using xAiModels.Models.Entities;
using Microsoft.Extensions.Logging;
namespace xAiModels.Providers.Dtos
{
public class XAiMessageDtoHub : XBaseDtoHub, IXAiMessageDtoHub
{
public XAiMessageDtoHub(
ILogger logger
) : base(logger)
{ }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\Dtos\XAiMessageRepositoryService.cs
using System;
using System.Linq;
using xModels.Dtos;
using System.Threading;
using xCommons.Extensions;
using xAiModels.Interfaces;
using xAiModels.Models.Dtos;
using System.Threading.Tasks;
using xDataService.Providers;
using xAiModels.Configurations;
using xAiModels.Interfaces.Dtos;
using xAiModels.Models.Entities;
using System.Collections.Generic;
using xIdentityService.Interfaces;
using xIdentityService.Extensions;
using xAiModels.Interfaces.Entities;
namespace xAiModels.Providers.Dtos
{
public class XAiMessageRepositoryService : XBaseRepositoryService, IXAiMessageRepositoryService
{
private readonly IXIdentityProvider identityProvider;
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
public XAiMessageRepositoryService(
IXAiMessageRepository repository,
IXIdentityProvider identityProvider,
IXAiConversationTitleResourceProvider conversationTitleResourceProvider
) : base(
repository,
mapperProfiles:
[
new XAiModelMappersProfile()
]
)
{
this.identityProvider = identityProvider;
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
}
//
#region Enrichers ...
///
/// Enrich Specified Item ...
///
///
///
///
public virtual async Task Enrich(
XAiMessage source,
CancellationToken cancellationToken = default
)
{
//
// Mapping Default ...
var result = Mapper.Map(source);
result = await Enrich(
source: result,
cancellationToken: cancellationToken
);
//
return result;
}
///
/// Enrich Specified Item ...
///
///
///
///
public virtual async Task Enrich(
XAiMessageDto source,
CancellationToken cancellationToken = default
)
{
//
// Handdle Owner ...
XPersonDto owner = null;
if (!source.OwnerId.IsNullOrEmpty())
{
//
// Try to Retrieve User Info ...
var device = identityProvider.GetDevice();
var userInfo = await identityProvider.GetUserInfo(
device: device,
userSelectByParam: source.OwnerId
);
owner = userInfo.ToXPersonDto();
}
//
// Hanlde Conversation Title ...
string conversationTitle = string.Empty;
XResourceDto conversationTitleResource = null;
if (!source.ConversationId.IsDefaultGuid())
{
//
conversationTitleResource = await conversationTitleResourceProvider.GetResource(
owner: source.OwnerId,
identifier: source.ConversationId,
cancellationToken: cancellationToken
);
if (!conversationTitleResource.IsNullOrDefault())
{
conversationTitle = conversationTitleResource.Resource;
}
}
//
// Attach Extracted Items ...
var result = Mapper.Map(source, options =>
{
//
options.Items[nameof(source.Owner)] = owner;
options.Items[nameof(source.ConversationTitle)] = conversationTitle;
options.Items[nameof(source.ConversationTitleResouce)] = conversationTitleResource;
});
//
return result;
}
///
/// Enrich Specified Items ...
///
///
///
///
public virtual async Task> EnrichRange(
IEnumerable sources,
CancellationToken cancellationToken = default
)
{
//
var tasks = sources
.Select(x => Enrich(x, cancellationToken));
//
var result = await Task.WhenAll(tasks);
return result;
}
///
/// Enrich Specified Items ...
///
///
///
///
public virtual async Task> EnrichRange(
IEnumerable sources,
CancellationToken cancellationToken = default
)
{
//
var tasks = sources
.Select(x => Enrich(x, cancellationToken));
//
var result = await Task.WhenAll(tasks);
return result;
}
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\Dtos\XAiMessageServiceProvider.cs
using System;
using xPushService.Base;
using xAiModels.Models.Dtos;
using xAiModels.Interfaces.Dtos;
using xAiModels.Models.Entities;
using xDataService.Configuration;
using xIdentityService.Interfaces;
using Microsoft.AspNetCore.SignalR;
namespace xAiModels.Providers.Dtos
{
public class XAiMessageServiceProvider : XBaseDtoProvider, IXAiMessageServiceProvider
{
public XAiMessageServiceProvider(
IHubContext hub,
XDataServiceConfiguration dataConfiguration,
IXAiMessageRepositoryService service,
IXIdentityProvider identityProvider = null
) : base(
hub,
dataConfiguration,
service,
identityProvider
)
{ }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\Dtos\XAiProjectDtoHub.cs
using System;
using xPushService.Base;
using xAiModels.Models.Dtos;
using xAiModels.Interfaces.Dtos;
using xAiModels.Models.Entities;
using Microsoft.Extensions.Logging;
namespace xAiModels.Providers.Dtos
{
public class XAiProjectDtoHub : XBaseDtoHub, IXAiProjectDtoHub
{
public XAiProjectDtoHub(
ILogger logger
) : base(logger)
{ }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\Dtos\XAiProjectRepositoryService.cs
using System;
using System.Linq;
using xModels.Dtos;
using System.Threading;
using xCommons.Extensions;
using xAiModels.Interfaces;
using xAiModels.Models.Dtos;
using System.Threading.Tasks;
using xDataService.Providers;
using xAiModels.Configurations;
using xAiModels.Interfaces.Dtos;
using xAiModels.Models.Entities;
using System.Collections.Generic;
using xIdentityService.Interfaces;
using xIdentityService.Extensions;
using xAiModels.Interfaces.Entities;
namespace xAiModels.Providers.Dtos
{
public class XAiProjectRepositoryService : XBaseRepositoryService, IXAiProjectRepositoryService
{
private readonly IXIdentityProvider identityProvider;
private readonly IXAiMessageRepository messageRepository;
private readonly IXAiConversationRepository conversationRepository;
private readonly IXAiProjectTitleResourceProvider projectTitleResourceProvider;
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
private readonly IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider;
public XAiProjectRepositoryService(
IXAiProjectRepository repository,
IXIdentityProvider identityProvider,
IXAiMessageRepository messageRepository,
IXAiConversationRepository conversationRepository,
IXAiProjectTitleResourceProvider projectTitleResourceProvider,
IXAiConversationTitleResourceProvider conversationTitleResourceProvider,
IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider
) : base(
repository,
mapperProfiles:
[
new XAiModelMappersProfile()
]
)
{
//
this.identityProvider = identityProvider;
this.messageRepository = messageRepository;
this.conversationRepository = conversationRepository;
this.projectTitleResourceProvider = projectTitleResourceProvider;
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
this.projectDescriptionResourceProvider = projectDescriptionResourceProvider;
}
//
#region Enrichers ...
///
/// Enrich Specified Item ...
///
///
///
///
///
///
public virtual async Task Enrich(
XAiProject source,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
)
{
//
// Mapping Default ...
var result = Mapper.Map(source);
result = await Enrich(
source: result,
fillConversations: fillConversations,
cancellationToken: cancellationToken,
fillConversationMessages: fillConversationMessages
);
//
return result;
}
///
/// Enrich Specified Item ...
///
///
///
///
///
///
public virtual async Task Enrich(
XAiProjectDto source,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
)
{
//
// Handle Owner ...
XPersonDto owner = null;
if (!source.OwnerId.IsNullOrEmpty())
{
//
// Try to Retrieve User Info ...
var device = identityProvider.GetDevice();
var userInfo = await identityProvider.GetUserInfo(
device: device,
userSelectByParam: source.OwnerId
);
owner = userInfo.ToXPersonDto();
}
//
// Handle Title ...
XResourceDto titleResource = null;
if (!source.Title.IsNullOrEmpty())
{
//
titleResource = await projectTitleResourceProvider.GetResource(
owner: source.OwnerId,
identifier: source.Id,
cancellationToken: cancellationToken
);
}
//
// Handle Description ...
XResourceDto descriptionResource = null;
if (!source.Description.IsNullOrEmpty())
{
//
descriptionResource = await projectDescriptionResourceProvider.GetResource(
owner: source.OwnerId,
identifier: source.Id,
cancellationToken: cancellationToken
);
}
//
// Handle Conversations ...
IEnumerable conversations = [];
if (fillConversations)
{
//
// Reading Entities ...
var entitiies = await conversationRepository.FindManyAsync(
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken,
predicate: x => x.ProjectId == source.Id,
orderBuilder: x => x.OrderBy(y => y.CreatedOn)
);
//
// Converts to Dto Enumerable ...
conversations = entitiies
.MapConvert();
//
// Handle Conversation Enrichment ...
foreach (var conversation in conversations)
{
//
// Handle Owner ...
if (!conversation.OwnerId.IsNullOrEmpty())
{
conversation.Owner = owner;
}
//
// Handle Title Resource ...
if (!conversation.Title.IsNullOrEmpty())
{
//
conversation.TitleResource = await conversationTitleResourceProvider.GetResource(
owner: source.OwnerId,
identifier: conversation.Id,
cancellationToken: cancellationToken
);
}
//
// Handle Project Info ...
if (!conversation.ProjectId.IsDefaultGuid())
{
conversation.ProjectTitle = source.Title;
conversation.ProjectTitleResource = titleResource;
conversation.ProjectDescription = source.Description;
conversation.ProjectDescriptionResource = descriptionResource;
}
}
//
// Handle Fill Messages ...
if (fillConversationMessages)
{
//
foreach (var conversation in conversations)
{
//
IEnumerable messages = [];
//
// Retrieve Message Entities ...
var messageEntities = await messageRepository.FindManyAsync(
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken,
orderBuilder: x => x.OrderBy(y => y.CreatedOn),
predicate: x => x.ConversationId == conversation.Id
);
if (messageEntities.HasChild())
{
//
// Converts to Message ...
messages = messageEntities
.MapConvert();
//
// Ennrich Messages ...
foreach (var message in messages)
{
//
// Handle Owner ...
if (!message.OwnerId.IsNullOrEmpty())
{
message.Owner = owner;
}
//
// Handle Conversation ...
if (!message.ConversationId.IsDefaultGuid())
{
message.ConversationTitle = conversation.Title;
message.ConversationTitleResouce = conversation.TitleResource;
}
}
}
//
conversation.Messages = [.. messages];
}
}
}
//
// Attach Extracted Items ...
var result = Mapper.Map(source, options =>
{
//
options.Items[nameof(source.Owner)] = owner;
options.Items[nameof(source.Conversations)] = conversations;
options.Items[nameof(source.TitleResource)] = titleResource;
options.Items[nameof(source.DescriptionResource)] = descriptionResource;
});
//
return result;
}
///
/// Enrich Specified Items ...
///
///
///
///
///
///
public virtual async Task> EnrichRange(
IEnumerable sources,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
)
{
//
var tasks = sources
.Select(x => Enrich(
source: x,
cancellationToken: cancellationToken,
fillConversations: fillConversations,
fillConversationMessages: fillConversationMessages
));
//
var result = await Task.WhenAll(tasks);
return result;
}
///
/// Enrich Specified Items ...
///
///
///
///
///
///
public virtual async Task> EnrichRange(
IEnumerable sources,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
)
{
//
var tasks = sources
.Select(x => Enrich(
source: x,
cancellationToken: cancellationToken,
fillConversations: fillConversations,
fillConversationMessages: fillConversationMessages
));
//
var result = await Task.WhenAll(tasks);
return result;
}
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\Dtos\XAiProjectServiceProvider.cs
using System;
using xPushService.Base;
using xAiModels.Models.Dtos;
using xAiModels.Interfaces.Dtos;
using xAiModels.Models.Entities;
using xDataService.Configuration;
using xIdentityService.Interfaces;
using Microsoft.AspNetCore.SignalR;
namespace xAiModels.Providers.Dtos
{
public class XAiProjectServiceProvider : XBaseDtoProvider, IXAiProjectServiceProvider
{
public XAiProjectServiceProvider(
IHubContext hub,
XDataServiceConfiguration dataConfiguration,
IXAiProjectRepositoryService service,
IXIdentityProvider identityProvider = null
) : base(
hub,
dataConfiguration,
service,
identityProvider
)
{ }
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\Enrichers\XAiConversationEnricher.cs
using System.Linq;
using xModels.Dtos;
using System.Threading;
using xCommons.Extensions;
using xAiModels.Interfaces;
using xAiModels.Models.Dtos;
using System.Threading.Tasks;
using xAiModels.Models.Entities;
using System.Collections.Generic;
using xIdentityService.Interfaces;
using xIdentityService.Extensions;
using xAiModels.Interfaces.Entities;
using xAiModels.Interfaces.Enrichers;
namespace xAiModels.Providers.Enrichers
{
public class XAiConversationEnricher : IXAiConversationEnricher
{
private readonly IXIdentityProvider identityProvider;
private readonly IXAiConversationRepository repository;
private readonly IXAiProjectTitleResourceProvider projectTitleResourceProvider;
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
private readonly IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider;
public XAiConversationEnricher(
IXIdentityProvider identityProvider,
IXAiConversationRepository repository,
IXAiProjectTitleResourceProvider projectTitleResourceProvider,
IXAiConversationTitleResourceProvider conversationTitleResourceProvider,
IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider
)
{
//
this.repository = repository;
this.identityProvider = identityProvider;
this.projectTitleResourceProvider = projectTitleResourceProvider;
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
this.projectDescriptionResourceProvider = projectDescriptionResourceProvider;
}
//
#region Enrichers ...
///
/// Enrich Specified Item ...
///
///
///
///
///
public virtual async Task Enrich(
XAiConversation source,
bool fillMessages = false,
CancellationToken cancellationToken = default
)
{
//
// Mapping Default ...
var result = source.MapConvert();
result = await Enrich(
source: result,
fillMessages: fillMessages,
cancellationToken: cancellationToken
);
//
return result;
}
///
/// Enrich Specified Item ...
///
///
///
///
///
public virtual async Task Enrich(
XAiConversationDto source,
bool fillMessages = false,
CancellationToken cancellationToken = default
)
{
//
// Handdle Owner ...
XPersonDto owner = null;
if (!source.OwnerId.IsNullOrEmpty())
{
//
// Try to Retrieve User Info ...
var device = identityProvider.GetDevice();
var userInfo = await identityProvider.GetUserInfo(
device: device,
userSelectByParam: source.OwnerId
);
owner = userInfo.ToXPersonDto();
}
//
// Handle Title Resource ...
XResourceDto titleResource = null;
if (!source.Title.IsNullOrEmpty())
{
//
titleResource = await conversationTitleResourceProvider.GetResource(
owner: source.OwnerId,
identifier: source.Id,
cancellationToken: cancellationToken
);
}
//
// Handle Project Info ...
XResourceDto projectTitleResource = null;
XResourceDto projectDescriptionResource = null;
if (!source.ProjectId.IsDefaultGuid())
{
//
projectTitleResource = await projectTitleResourceProvider.GetResource(
owner: source.OwnerId,
identifier: source.ProjectId,
cancellationToken: cancellationToken
);
//
projectDescriptionResource = await projectDescriptionResourceProvider.GetResource(
owner: source.OwnerId,
identifier: source.ProjectId,
cancellationToken: cancellationToken
);
}
//
// Attach Extracted Items ...
var result = source.MapConvert();
result.Owner = owner;
result.TitleResource = titleResource;
result.ProjectTitleResource = projectTitleResource;
result.ProjectTitle = projectTitleResource.Resource;
result.ProjectDescriptionResource = projectDescriptionResource;
result.ProjectDescription = projectDescriptionResource.Resource;
//
return result;
}
///
/// Enrich Specified Items ...
///
///
///
///
///
public virtual async Task> EnrichRange(
IEnumerable sources,
bool fillMessages = false,
CancellationToken cancellationToken = default
)
{
//
var tasks = sources
.Select(x => Enrich(
source: x,
fillMessages: fillMessages,
cancellationToken: cancellationToken
));
//
var result = await Task.WhenAll(tasks);
return result;
}
///
/// Enrich Specified Items ...
///
///
///
///
///
public virtual async Task> EnrichRange(
IEnumerable sources,
bool fillMessages = false,
CancellationToken cancellationToken = default
)
{
//
var tasks = sources
.Select(x => Enrich(
source: x,
fillMessages: fillMessages,
cancellationToken: cancellationToken
));
//
var result = await Task.WhenAll(tasks);
return result;
}
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\Enrichers\XAiMessageEnricher.cs
using System.Linq;
using xModels.Dtos;
using System.Threading;
using xCommons.Extensions;
using xAiModels.Interfaces;
using xAiModels.Models.Dtos;
using System.Threading.Tasks;
using xAiModels.Models.Entities;
using System.Collections.Generic;
using xIdentityService.Interfaces;
using xIdentityService.Extensions;
using xAiModels.Interfaces.Enrichers;
namespace xAiModels.Providers.Enrichers
{
public class XAiMessageEnricher : IXAiMessageEnricher
{
private readonly IXIdentityProvider identityProvider;
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
public XAiMessageEnricher(
IXIdentityProvider identityProvider,
IXAiConversationTitleResourceProvider conversationTitleResourceProvider
)
{
this.identityProvider = identityProvider;
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
}
//
#region Enrichers ...
///
/// Enrich Specified Item ...
///
///
///
///
public virtual async Task Enrich(
XAiMessage source,
CancellationToken cancellationToken = default
)
{
//
// Mapping Default ...
var result = source.MapConvert();
result = await Enrich(
source: result,
cancellationToken: cancellationToken
);
//
return result;
}
///
/// Enrich Specified Item ...
///
///
///
///
public virtual async Task Enrich(
XAiMessageDto source,
CancellationToken cancellationToken = default
)
{
//
// Handdle Owner ...
XPersonDto owner = null;
if (!source.OwnerId.IsNullOrEmpty())
{
//
// Try to Retrieve User Info ...
var device = identityProvider.GetDevice();
var userInfo = await identityProvider.GetUserInfo(
device: device,
userSelectByParam: source.OwnerId
);
owner = userInfo.ToXPersonDto();
}
//
// Hanlde Conversation Title ...
string conversationTitle = string.Empty;
XResourceDto conversationTitleResource = null;
if (!source.ConversationId.IsDefaultGuid())
{
//
conversationTitleResource = await conversationTitleResourceProvider.GetResource(
owner: source.OwnerId,
identifier: source.ConversationId,
cancellationToken: cancellationToken
);
if (!conversationTitleResource.IsNullOrDefault())
{
conversationTitle = conversationTitleResource.Resource;
}
}
//
// Attach Extracted Items ...
var result = source.MapConvert();
result.Owner = owner;
result.ConversationTitle = conversationTitle;
result.ConversationTitleResouce = conversationTitleResource;
//
return result;
}
///
/// Enrich Specified Items ...
///
///
///
///
public virtual async Task> EnrichRange(
IEnumerable sources,
CancellationToken cancellationToken = default
)
{
//
var tasks = sources
.Select(x => Enrich(x, cancellationToken));
//
var result = await Task.WhenAll(tasks);
return result;
}
///
/// Enrich Specified Items ...
///
///
///
///
public virtual async Task> EnrichRange(
IEnumerable sources,
CancellationToken cancellationToken = default
)
{
//
var tasks = sources
.Select(x => Enrich(x, cancellationToken));
//
var result = await Task.WhenAll(tasks);
return result;
}
#endregion
}
}
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiModels\Providers\Enrichers\XAiProjectEnricher.cs
using System.Linq;
using xModels.Dtos;
using System.Threading;
using xCommons.Extensions;
using xAiModels.Interfaces;
using xAiModels.Models.Dtos;
using System.Threading.Tasks;
using xAiModels.Models.Entities;
using System.Collections.Generic;
using xIdentityService.Interfaces;
using xIdentityService.Extensions;
using xAiModels.Interfaces.Entities;
using xAiModels.Interfaces.Enrichers;
namespace xAiModels.Providers.Enrichers
{
public class XAiProjectEnricher : IXAiProjectEnricher
{
private readonly IXIdentityProvider identityProvider;
private readonly IXAiMessageRepository messageRepository;
private readonly IXAiConversationRepository conversationRepository;
private readonly IXAiProjectTitleResourceProvider projectTitleResourceProvider;
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
private readonly IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider;
public XAiProjectEnricher(
IXIdentityProvider identityProvider,
IXAiMessageRepository messageRepository,
IXAiConversationRepository conversationRepository,
IXAiProjectTitleResourceProvider projectTitleResourceProvider,
IXAiConversationTitleResourceProvider conversationTitleResourceProvider,
IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider
)
{
//
this.identityProvider = identityProvider;
this.messageRepository = messageRepository;
this.conversationRepository = conversationRepository;
this.projectTitleResourceProvider = projectTitleResourceProvider;
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
this.projectDescriptionResourceProvider = projectDescriptionResourceProvider;
}
//
#region Enrichers ...
///
/// Enrich Specified Item ...
///
///
///
///
///
///
public virtual async Task Enrich(
XAiProject source,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
)
{
//
// Mapping Default ...
var result = source.MapConvert();
result = await Enrich(
source: result,
fillConversations: fillConversations,
cancellationToken: cancellationToken,
fillConversationMessages: fillConversationMessages
);
//
return result;
}
///
/// Enrich Specified Item ...
///
///
///
///
///
///
public virtual async Task Enrich(
XAiProjectDto source,
bool fillConversations = false,
bool fillConversationMessages = false,
CancellationToken cancellationToken = default
)
{
//
// Handle Owner ...
XPersonDto owner = null;
if (!source.OwnerId.IsNullOrEmpty())
{
//
// Try to Retrieve User Info ...
var device = identityProvider.GetDevice();
var userInfo = await identityProvider.GetUserInfo(
device: device,
userSelectByParam: source.OwnerId
);
owner = userInfo.ToXPersonDto();
}
//
// Handle Title ...
XResourceDto titleResource = null;
if (!source.Title.IsNullOrEmpty())
{
//
titleResource = await projectTitleResourceProvider.GetResource(
owner: source.OwnerId,
identifier: source.Id,
cancellationToken: cancellationToken
);
}
//
// Handle Description ...
XResourceDto descriptionResource = null;
if (!source.Description.IsNullOrEmpty())
{
//
descriptionResource = await projectDescriptionResourceProvider.GetResource(
owner: source.OwnerId,
identifier: source.Id,
cancellationToken: cancellationToken
);
}
//
// Handle Conversations ...
IEnumerable