last works ...
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,222 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using xAiModels.Models.Dtos;
|
||||
using xAiModels.Models.Entities;
|
||||
using xDataService.Interfaces;
|
||||
using xModels.Dtos;
|
||||
|
||||
namespace xAiModels.Interfaces.Dtos
|
||||
{
|
||||
public interface IXAiConversationRepositoryService : IXBaseRepositoryService<XAiConversation, XAiConversationDto, Guid>
|
||||
{ }
|
||||
{
|
||||
//
|
||||
#region Actions ...
|
||||
//
|
||||
#region Add ...
|
||||
/// <summary>
|
||||
/// add a new Dto ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XAiConversationDto> AddAsync(
|
||||
XAiConversationDto item,
|
||||
bool saveChanges = true,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// add or update a Dto (add if not exists/update if exists) ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XAiConversationDto> AddOrUpdateAsync(
|
||||
XAiConversationDto item,
|
||||
bool saveChanges = true,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Update ...
|
||||
/// <summary>
|
||||
/// Update an Dto values ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XAiConversationDto> UpdateAsync(
|
||||
Guid id,
|
||||
XAiConversationDto item,
|
||||
bool saveChanges = true,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Remove ...
|
||||
/// <summary>
|
||||
/// remove an Dto by it's Id ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XAiConversationDto> RemoveAsync(
|
||||
Guid id,
|
||||
bool softDelete = false,
|
||||
bool saveChanges = true,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// remove an Dto ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XAiConversationDto> RemoveAsync(
|
||||
XAiConversationDto item,
|
||||
bool softDelete = false,
|
||||
bool saveChanges = true,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Retrieve ...
|
||||
/// <summary>
|
||||
/// retrieve an Dto by it's Id ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XAiConversationDto> GetAsync(
|
||||
Guid id,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// retrieve all exists Dtos ...
|
||||
/// </summary>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XAiConversationDto>> GetAllAsync(
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// retrieve all exists Dtos
|
||||
/// as Async Enumerable ...
|
||||
/// </summary>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
IAsyncEnumerable<XAiConversationDto> GetAllAsAsyncEnumerable(
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// find an Dto by providing a Conditional Expression ...
|
||||
/// </summary>
|
||||
/// <param name="predicate"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XAiConversationDto> FindOneAsync(
|
||||
Expression<Func<XAiConversation, bool>> predicate,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// find a collection of Dtos by proving a Conditional Expression ...
|
||||
/// </summary>
|
||||
/// <param name="predicate"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XAiConversationDto>> FindManyAsync(
|
||||
Expression<Func<XAiConversation, bool>> predicate,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// retrieve Dtos based on XQuery Pagination structure ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="predicate"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XQueryResult<XAiConversationDto>> QueryAsync(
|
||||
XQuery query,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Expression<Func<XAiConversation, bool>> predicate = null,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ namespace xAiModels.Interfaces.Dtos
|
||||
{
|
||||
public interface IXAiProjectRepositoryService : IXBaseRepositoryService<XAiProject, XAiProjectDto, Guid>
|
||||
{
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
//
|
||||
@@ -25,12 +24,14 @@ namespace xAiModels.Interfaces.Dtos
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XAiProjectDto> AddAsync(
|
||||
XAiProjectDto item,
|
||||
bool saveChanges = true,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
@@ -40,12 +41,14 @@ namespace xAiModels.Interfaces.Dtos
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XAiProjectDto> AddOrUpdateAsync(
|
||||
XAiProjectDto item,
|
||||
bool saveChanges = true,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
@@ -59,6 +62,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XAiProjectDto> UpdateAsync(
|
||||
@@ -66,6 +70,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
XAiProjectDto item,
|
||||
bool saveChanges = true,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
@@ -79,6 +84,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XAiProjectDto> RemoveAsync(
|
||||
@@ -86,6 +92,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
bool softDelete = false,
|
||||
bool saveChanges = true,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
@@ -96,6 +103,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XAiProjectDto> RemoveAsync(
|
||||
@@ -103,6 +111,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
bool softDelete = false,
|
||||
bool saveChanges = true,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
@@ -116,6 +125,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XAiProjectDto> GetAsync(
|
||||
@@ -123,6 +133,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiProject>, IIncludableQueryable<XAiProject, object>> includeBuilder = null,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
@@ -133,6 +144,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XAiProjectDto>> GetAllAsync(
|
||||
@@ -140,6 +152,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
Func<IQueryable<XAiProject>, IOrderedQueryable<XAiProject>> orderBuilder = null,
|
||||
Func<IQueryable<XAiProject>, IIncludableQueryable<XAiProject, object>> includeBuilder = null,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
@@ -151,6 +164,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
IAsyncEnumerable<XAiProjectDto> GetAllAsAsyncEnumerable(
|
||||
@@ -158,6 +172,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
Func<IQueryable<XAiProject>, IOrderedQueryable<XAiProject>> orderBuilder = null,
|
||||
Func<IQueryable<XAiProject>, IIncludableQueryable<XAiProject, object>> includeBuilder = null,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
@@ -168,6 +183,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XAiProjectDto> FindOneAsync(
|
||||
@@ -175,6 +191,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiProject>, IIncludableQueryable<XAiProject, object>> includeBuilder = null,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
@@ -186,6 +203,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XAiProjectDto>> FindManyAsync(
|
||||
@@ -194,6 +212,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
Func<IQueryable<XAiProject>, IOrderedQueryable<XAiProject>> orderBuilder = null,
|
||||
Func<IQueryable<XAiProject>, IIncludableQueryable<XAiProject, object>> includeBuilder = null,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
@@ -206,6 +225,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XQueryResult<XAiProjectDto>> QueryAsync(
|
||||
@@ -215,6 +235,7 @@ namespace xAiModels.Interfaces.Dtos
|
||||
Func<IQueryable<XAiProject>, IOrderedQueryable<XAiProject>> orderBuilder = null,
|
||||
Func<IQueryable<XAiProject>, IIncludableQueryable<XAiProject, object>> includeBuilder = null,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xAiModels.Models.Dtos;
|
||||
using xDataService.Interfaces;
|
||||
|
||||
@@ -7,5 +10,35 @@ namespace xAiModels.Interfaces.Enrichers
|
||||
/// Ai Conversation Enricher ...
|
||||
/// </summary>
|
||||
public interface IXAiConversationEnricher : IXBaseEnricher<XAiConversationDto, XAiConversationDto>
|
||||
{ }
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a Signle Entity to Dto ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="destination"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task EnrichAsync(
|
||||
XAiConversationDto source,
|
||||
XAiConversationDto destination,
|
||||
bool fillMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Collection of Entities to Dtos ...
|
||||
/// </summary>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="destinations"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task EnrichRangeAsync(
|
||||
IEnumerable<XAiConversationDto> sources,
|
||||
IEnumerable<XAiConversationDto> destinations,
|
||||
bool fillMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ namespace xAiModels.Interfaces.Enrichers
|
||||
XAiProjectDto source,
|
||||
XAiProjectDto destination,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
@@ -20,6 +21,7 @@ namespace xAiModels.Interfaces.Enrichers
|
||||
IEnumerable<XAiProjectDto> sources,
|
||||
IEnumerable<XAiProjectDto> destinations,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using xModels.Base;
|
||||
using xModels.Dtos;
|
||||
|
||||
@@ -40,6 +41,11 @@ namespace xAiModels.Models.Dtos
|
||||
/// </summary>
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Conversation Messages ...
|
||||
/// </summary>
|
||||
public virtual IEnumerable<XAiMessageDto> Messages { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Project ID ...
|
||||
/// </summary>
|
||||
|
||||
@@ -53,27 +53,12 @@ namespace xAiModels.Providers.Dtos
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.AddAsync(
|
||||
return await AddAsync(
|
||||
item: item,
|
||||
fillMessages: false,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -89,27 +74,12 @@ namespace xAiModels.Providers.Dtos
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.AddAsync(
|
||||
return await AddOrUpdateAsync(
|
||||
item: item,
|
||||
fillMessages: false,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -130,28 +100,13 @@ namespace xAiModels.Providers.Dtos
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.UpdateAsync(
|
||||
return await UpdateAsync(
|
||||
id: id,
|
||||
item: item,
|
||||
fillMessages: false,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -172,28 +127,13 @@ namespace xAiModels.Providers.Dtos
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.RemoveAsync(
|
||||
return await RemoveAsync(
|
||||
id: id,
|
||||
fillMessages: false,
|
||||
softDelete: softDelete,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -211,28 +151,13 @@ namespace xAiModels.Providers.Dtos
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.RemoveAsync(
|
||||
return await RemoveAsync(
|
||||
item: item,
|
||||
fillMessages: false,
|
||||
softDelete: softDelete,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -253,28 +178,13 @@ namespace xAiModels.Providers.Dtos
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.GetAsync(
|
||||
return await GetAsync(
|
||||
id: id,
|
||||
fillMessages: false,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -292,28 +202,13 @@ namespace xAiModels.Providers.Dtos
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.GetAllAsync(
|
||||
return await GetAllAsync(
|
||||
fillMessages: false,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichRangeAsync(
|
||||
sources: result,
|
||||
destinations: result,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -325,35 +220,20 @@ namespace xAiModels.Providers.Dtos
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async IAsyncEnumerable<XAiConversationDto> GetAllAsAsyncEnumerable(
|
||||
public override IAsyncEnumerable<XAiConversationDto> GetAllAsAsyncEnumerable(
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
[EnumeratorCancellation] CancellationToken cancellationToken = default
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var enumerable = base.GetAllAsAsyncEnumerable(
|
||||
return GetAllAsAsyncEnumerable(
|
||||
fillMessages: false,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
await foreach (var dto in enumerable)
|
||||
{
|
||||
//
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: dto,
|
||||
destination: dto,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
yield return dto;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -371,28 +251,13 @@ namespace xAiModels.Providers.Dtos
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.FindOneAsync(
|
||||
return await FindOneAsync(
|
||||
fillMessages: false,
|
||||
predicate: predicate,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -412,29 +277,14 @@ namespace xAiModels.Providers.Dtos
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.FindManyAsync(
|
||||
return await FindManyAsync(
|
||||
fillMessages: false,
|
||||
predicate: predicate,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichRangeAsync(
|
||||
sources: result,
|
||||
destinations: result,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -455,6 +305,471 @@ namespace xAiModels.Providers.Dtos
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await QueryAsync(
|
||||
query: query,
|
||||
fillMessages: false,
|
||||
predicate: predicate,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
//
|
||||
#region Add ...
|
||||
/// <summary>
|
||||
/// add a new Dto ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiConversationDto> AddAsync(
|
||||
XAiConversationDto item,
|
||||
bool saveChanges = true,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.AddAsync(
|
||||
item: item,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add or update a Dto (add if not exists/update if exists) ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiConversationDto> AddOrUpdateAsync(
|
||||
XAiConversationDto item,
|
||||
bool saveChanges = true,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.AddAsync(
|
||||
item: item,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Update ...
|
||||
/// <summary>
|
||||
/// Update an Dto values ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiConversationDto> UpdateAsync(
|
||||
Guid id,
|
||||
XAiConversationDto item,
|
||||
bool saveChanges = true,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.UpdateAsync(
|
||||
id: id,
|
||||
item: item,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Remove ...
|
||||
/// <summary>
|
||||
/// remove an Dto by it's Id ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiConversationDto> RemoveAsync(
|
||||
Guid id,
|
||||
bool softDelete = true,
|
||||
bool saveChanges = true,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.RemoveAsync(
|
||||
id: id,
|
||||
softDelete: softDelete,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// remove an Dto ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiConversationDto> RemoveAsync(
|
||||
XAiConversationDto item,
|
||||
bool softDelete = true,
|
||||
bool saveChanges = true,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.RemoveAsync(
|
||||
item: item,
|
||||
softDelete: softDelete,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Retrieve ...
|
||||
/// <summary>
|
||||
/// retrieve an Dto by it's Id ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiConversationDto> GetAsync(
|
||||
Guid id,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.GetAsync(
|
||||
id: id,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve all exists Dtos ...
|
||||
/// </summary>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XAiConversationDto>> GetAllAsync(
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.GetAllAsync(
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichRangeAsync(
|
||||
sources: result,
|
||||
destinations: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve all exists Dtos
|
||||
/// as Async Enumerable ...
|
||||
/// </summary>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async IAsyncEnumerable<XAiConversationDto> GetAllAsAsyncEnumerable(
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
[EnumeratorCancellation] CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var enumerable = base.GetAllAsAsyncEnumerable(
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
await foreach (var dto in enumerable)
|
||||
{
|
||||
//
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: dto,
|
||||
destination: dto,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
yield return dto;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// find an Dto by providing a Conditional Expression ...
|
||||
/// </summary>
|
||||
/// <param name="predicate"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiConversationDto> FindOneAsync(
|
||||
Expression<Func<XAiConversation, bool>> predicate,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.FindOneAsync(
|
||||
predicate: predicate,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// find a collection of Dtos by proving a Conditional Expression ...
|
||||
/// </summary>
|
||||
/// <param name="predicate"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XAiConversationDto>> FindManyAsync(
|
||||
Expression<Func<XAiConversation, bool>> predicate,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.FindManyAsync(
|
||||
predicate: predicate,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichRangeAsync(
|
||||
sources: result,
|
||||
destinations: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve Dtos based on XQuery Pagination structure ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="predicate"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XQueryResult<XAiConversationDto>> QueryAsync(
|
||||
XQuery query,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Expression<Func<XAiConversation, bool>> predicate = null,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.QueryAsync(
|
||||
@@ -474,6 +789,7 @@ namespace xAiModels.Providers.Dtos
|
||||
await enricher.EnrichRangeAsync(
|
||||
sources: result.Items,
|
||||
destinations: result.Items,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ namespace xAiModels.Providers.Dtos
|
||||
item: item,
|
||||
saveChanges: saveChanges,
|
||||
fillConversations: false,
|
||||
fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
@@ -79,6 +80,7 @@ namespace xAiModels.Providers.Dtos
|
||||
item: item,
|
||||
saveChanges: saveChanges,
|
||||
fillConversations: false,
|
||||
fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
@@ -106,6 +108,7 @@ namespace xAiModels.Providers.Dtos
|
||||
item: item,
|
||||
saveChanges: saveChanges,
|
||||
fillConversations: false,
|
||||
fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
@@ -133,6 +136,7 @@ namespace xAiModels.Providers.Dtos
|
||||
softDelete: softDelete,
|
||||
saveChanges: saveChanges,
|
||||
fillConversations: false,
|
||||
fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
@@ -157,6 +161,7 @@ namespace xAiModels.Providers.Dtos
|
||||
softDelete: softDelete,
|
||||
saveChanges: saveChanges,
|
||||
fillConversations: false,
|
||||
fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
@@ -183,6 +188,7 @@ namespace xAiModels.Providers.Dtos
|
||||
id: id,
|
||||
fillConversations: false,
|
||||
includeBuilder: includeBuilder,
|
||||
fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
@@ -207,6 +213,7 @@ namespace xAiModels.Providers.Dtos
|
||||
fillConversations: false,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
@@ -232,6 +239,7 @@ namespace xAiModels.Providers.Dtos
|
||||
fillConversations: false,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
@@ -256,6 +264,7 @@ namespace xAiModels.Providers.Dtos
|
||||
predicate: predicate,
|
||||
fillConversations: false,
|
||||
includeBuilder: includeBuilder,
|
||||
fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
@@ -283,6 +292,7 @@ namespace xAiModels.Providers.Dtos
|
||||
fillConversations: false,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
@@ -310,8 +320,10 @@ namespace xAiModels.Providers.Dtos
|
||||
return await QueryAsync(
|
||||
query: query,
|
||||
predicate: predicate,
|
||||
fillConversations: false,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
@@ -329,12 +341,14 @@ namespace xAiModels.Providers.Dtos
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiProjectDto> AddAsync(
|
||||
XAiProjectDto item,
|
||||
bool saveChanges = true,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -354,7 +368,8 @@ namespace xAiModels.Providers.Dtos
|
||||
source: result,
|
||||
destination: result,
|
||||
fillConversations: fillConversations,
|
||||
cancellationToken: cancellationToken
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
);
|
||||
}
|
||||
|
||||
@@ -368,12 +383,14 @@ namespace xAiModels.Providers.Dtos
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiProjectDto> AddOrUpdateAsync(
|
||||
XAiProjectDto item,
|
||||
bool saveChanges = true,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -393,7 +410,8 @@ namespace xAiModels.Providers.Dtos
|
||||
source: result,
|
||||
destination: result,
|
||||
fillConversations: fillConversations,
|
||||
cancellationToken: cancellationToken
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
);
|
||||
}
|
||||
|
||||
@@ -411,6 +429,7 @@ namespace xAiModels.Providers.Dtos
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiProjectDto> UpdateAsync(
|
||||
@@ -418,6 +437,7 @@ namespace xAiModels.Providers.Dtos
|
||||
XAiProjectDto item,
|
||||
bool saveChanges = true,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -438,7 +458,8 @@ namespace xAiModels.Providers.Dtos
|
||||
source: result,
|
||||
destination: result,
|
||||
fillConversations: fillConversations,
|
||||
cancellationToken: cancellationToken
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
);
|
||||
}
|
||||
|
||||
@@ -456,6 +477,7 @@ namespace xAiModels.Providers.Dtos
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiProjectDto> RemoveAsync(
|
||||
@@ -463,6 +485,7 @@ namespace xAiModels.Providers.Dtos
|
||||
bool softDelete = false,
|
||||
bool saveChanges = true,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -483,7 +506,8 @@ namespace xAiModels.Providers.Dtos
|
||||
source: result,
|
||||
destination: result,
|
||||
fillConversations: fillConversations,
|
||||
cancellationToken: cancellationToken
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
);
|
||||
}
|
||||
|
||||
@@ -498,6 +522,7 @@ namespace xAiModels.Providers.Dtos
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiProjectDto> RemoveAsync(
|
||||
@@ -505,6 +530,7 @@ namespace xAiModels.Providers.Dtos
|
||||
bool softDelete = false,
|
||||
bool saveChanges = true,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -525,7 +551,8 @@ namespace xAiModels.Providers.Dtos
|
||||
source: result,
|
||||
destination: result,
|
||||
fillConversations: fillConversations,
|
||||
cancellationToken: cancellationToken
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
);
|
||||
}
|
||||
|
||||
@@ -543,6 +570,7 @@ namespace xAiModels.Providers.Dtos
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiProjectDto> GetAsync(
|
||||
@@ -550,6 +578,7 @@ namespace xAiModels.Providers.Dtos
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiProject>, IIncludableQueryable<XAiProject, object>> includeBuilder = null,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -570,7 +599,8 @@ namespace xAiModels.Providers.Dtos
|
||||
source: result,
|
||||
destination: result,
|
||||
fillConversations: fillConversations,
|
||||
cancellationToken: cancellationToken
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
);
|
||||
}
|
||||
|
||||
@@ -585,6 +615,7 @@ namespace xAiModels.Providers.Dtos
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XAiProjectDto>> GetAllAsync(
|
||||
@@ -592,6 +623,7 @@ namespace xAiModels.Providers.Dtos
|
||||
Func<IQueryable<XAiProject>, IOrderedQueryable<XAiProject>> orderBuilder = null,
|
||||
Func<IQueryable<XAiProject>, IIncludableQueryable<XAiProject, object>> includeBuilder = null,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -612,7 +644,8 @@ namespace xAiModels.Providers.Dtos
|
||||
sources: result,
|
||||
destinations: result,
|
||||
fillConversations: fillConversations,
|
||||
cancellationToken: cancellationToken
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
);
|
||||
}
|
||||
|
||||
@@ -628,6 +661,7 @@ namespace xAiModels.Providers.Dtos
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async IAsyncEnumerable<XAiProjectDto> GetAllAsAsyncEnumerable(
|
||||
@@ -635,6 +669,7 @@ namespace xAiModels.Providers.Dtos
|
||||
Func<IQueryable<XAiProject>, IOrderedQueryable<XAiProject>> orderBuilder = null,
|
||||
Func<IQueryable<XAiProject>, IIncludableQueryable<XAiProject, object>> includeBuilder = null,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
[EnumeratorCancellation] CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -657,7 +692,8 @@ namespace xAiModels.Providers.Dtos
|
||||
source: dto,
|
||||
destination: dto,
|
||||
fillConversations: fillConversations,
|
||||
cancellationToken: cancellationToken
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
);
|
||||
yield return dto;
|
||||
}
|
||||
@@ -670,6 +706,7 @@ namespace xAiModels.Providers.Dtos
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiProjectDto> FindOneAsync(
|
||||
@@ -677,6 +714,7 @@ namespace xAiModels.Providers.Dtos
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiProject>, IIncludableQueryable<XAiProject, object>> includeBuilder = null,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -697,7 +735,8 @@ namespace xAiModels.Providers.Dtos
|
||||
source: result,
|
||||
destination: result,
|
||||
fillConversations: fillConversations,
|
||||
cancellationToken: cancellationToken
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
);
|
||||
}
|
||||
|
||||
@@ -713,6 +752,7 @@ namespace xAiModels.Providers.Dtos
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XAiProjectDto>> FindManyAsync(
|
||||
@@ -721,6 +761,7 @@ namespace xAiModels.Providers.Dtos
|
||||
Func<IQueryable<XAiProject>, IOrderedQueryable<XAiProject>> orderBuilder = null,
|
||||
Func<IQueryable<XAiProject>, IIncludableQueryable<XAiProject, object>> includeBuilder = null,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -742,7 +783,8 @@ namespace xAiModels.Providers.Dtos
|
||||
sources: result,
|
||||
destinations: result,
|
||||
fillConversations: fillConversations,
|
||||
cancellationToken: cancellationToken
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
);
|
||||
}
|
||||
|
||||
@@ -759,6 +801,7 @@ namespace xAiModels.Providers.Dtos
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XQueryResult<XAiProjectDto>> QueryAsync(
|
||||
@@ -768,6 +811,7 @@ namespace xAiModels.Providers.Dtos
|
||||
Func<IQueryable<XAiProject>, IOrderedQueryable<XAiProject>> orderBuilder = null,
|
||||
Func<IQueryable<XAiProject>, IIncludableQueryable<XAiProject, object>> includeBuilder = null,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -790,7 +834,8 @@ namespace xAiModels.Providers.Dtos
|
||||
sources: result.Items,
|
||||
destinations: result.Items,
|
||||
fillConversations: fillConversations,
|
||||
cancellationToken: cancellationToken
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,16 +17,19 @@ namespace xAiModels.Providers.Enrichers
|
||||
public class XAiConversationEnricher : IXAiConversationEnricher
|
||||
{
|
||||
private readonly IXIdentityProvider identityProvider;
|
||||
private readonly IXAiMessageRepositoryService messageRepositoryService;
|
||||
private readonly IXAiProjectRepositoryService projectRepositoryService;
|
||||
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
|
||||
|
||||
public XAiConversationEnricher(
|
||||
IXIdentityProvider identityProvider,
|
||||
IXAiMessageRepositoryService messageRepositoryService,
|
||||
IXAiProjectRepositoryService projectRepositoryService,
|
||||
IXAiConversationTitleResourceProvider conversationTitleResourceProvider
|
||||
)
|
||||
{
|
||||
this.identityProvider = identityProvider;
|
||||
this.messageRepositoryService = messageRepositoryService;
|
||||
this.projectRepositoryService = projectRepositoryService;
|
||||
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
|
||||
}
|
||||
@@ -43,16 +46,70 @@ namespace xAiModels.Providers.Enrichers
|
||||
XAiConversationDto destination,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
await EnrichAsync(
|
||||
source: source,
|
||||
fillMessages: false,
|
||||
destination: destination,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Collection of Entities to Dtos ...
|
||||
/// </summary>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="destinations"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task EnrichRangeAsync(
|
||||
IEnumerable<XAiConversationDto> sources,
|
||||
IEnumerable<XAiConversationDto> destinations,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
await EnrichRangeAsync(
|
||||
sources: sources,
|
||||
fillMessages: false,
|
||||
destinations: destinations,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Signle Entity to Dto ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="destination"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task EnrichAsync(
|
||||
XAiConversationDto source,
|
||||
XAiConversationDto destination,
|
||||
bool fillMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Run independent async operations concurrently
|
||||
var ownerTask = ResolveOwnerAsync(source.OwnerId, cancellationToken);
|
||||
var projectTask = ResolveProjectAsync(source.ProjectId, cancellationToken);
|
||||
var titleLocalesTask = ResolveTitleLocalesAsync(source.Title, cancellationToken);
|
||||
var messagesTask = ResolveMessagesAsync(source.Id, cancellationToken);
|
||||
|
||||
//
|
||||
// wait until All Tasks Resolved ...
|
||||
await Task.WhenAll(ownerTask, titleLocalesTask, projectTask);
|
||||
Task[] tasks = [
|
||||
ownerTask,
|
||||
projectTask,
|
||||
titleLocalesTask
|
||||
];
|
||||
if (fillMessages)
|
||||
{
|
||||
tasks = [.. tasks, messagesTask];
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
|
||||
//
|
||||
// Attached Resolved Info to Destination ...
|
||||
@@ -66,6 +123,10 @@ namespace xAiModels.Providers.Enrichers
|
||||
destination.ProjectTitleResource = project.TitleResource;
|
||||
destination.ProjectDescriptionResource = project.DescriptionResource;
|
||||
}
|
||||
if (!messagesTask.Result.IsNull())
|
||||
{
|
||||
destination.Messages = [.. messagesTask.Result];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -73,11 +134,13 @@ namespace xAiModels.Providers.Enrichers
|
||||
/// </summary>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="destinations"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task EnrichRangeAsync(
|
||||
IEnumerable<XAiConversationDto> sources,
|
||||
IEnumerable<XAiConversationDto> destinations,
|
||||
bool fillMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -185,6 +248,37 @@ namespace xAiModels.Providers.Enrichers
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Specified Conversation Messages ...
|
||||
/// </summary>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<IEnumerable<XAiMessageDto>> ResolveMessagesAsync(
|
||||
Guid conversationId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = new List<XAiMessageDto>();
|
||||
|
||||
//
|
||||
if (conversationId.IsDefaultGuid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = [.. await messageRepositoryService.FindManyAsync(
|
||||
cancellationToken: cancellationToken,
|
||||
orderBuilder: x => x.OrderBy(y => y.CreatedOn),
|
||||
predicate: x => x.ConversationId == conversationId
|
||||
)];
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -52,14 +52,19 @@ namespace xAiModels.Providers.Enrichers
|
||||
XAiProjectDto source,
|
||||
XAiProjectDto destination,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Run independent async operations concurrently
|
||||
var conversationsTask = ResolveConversationsAsync(
|
||||
source.Id,
|
||||
fillConversationMessages,
|
||||
cancellationToken
|
||||
);
|
||||
var titleTask = ResolveTitleAsync(source.Title, cancellationToken);
|
||||
var ownerTask = ResolveOwnerAsync(source.OwnerId, cancellationToken);
|
||||
var conversationsTask = ResolveConversationsAsync(source.Id, cancellationToken);
|
||||
var descriptionTask = ResolveDescriptionAsync(source.Description, cancellationToken);
|
||||
|
||||
//
|
||||
@@ -107,13 +112,20 @@ namespace xAiModels.Providers.Enrichers
|
||||
IEnumerable<XAiProjectDto> sources,
|
||||
IEnumerable<XAiProjectDto> destinations,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Make Tasks Ready ...
|
||||
var tasks = sources.Zip(destinations, (src, dst) =>
|
||||
EnrichAsync(src, dst, fillConversations, cancellationToken)
|
||||
EnrichAsync(
|
||||
source: src,
|
||||
destination: dst,
|
||||
fillConversations: fillConversations,
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
)
|
||||
);
|
||||
|
||||
//
|
||||
@@ -224,10 +236,12 @@ namespace xAiModels.Providers.Enrichers
|
||||
/// Retrieve Project Conversations ...
|
||||
/// </summary>
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<List<XAiConversationDto>> ResolveConversationsAsync(
|
||||
Guid projectId,
|
||||
bool fillMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -248,6 +262,7 @@ namespace xAiModels.Providers.Enrichers
|
||||
orderBuilder: null,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
fillMessages: fillMessages,
|
||||
predicate: x => x.Id == projectId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
@@ -0,0 +1,271 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xAiModels.Constants;
|
||||
using xAiModels.Models.Dtos;
|
||||
using xCommons.Extensions;
|
||||
using xPushService.Base;
|
||||
|
||||
namespace xAiModels.Providers.Hubs
|
||||
{
|
||||
public class XAiDataProviderHub : XBaseHub
|
||||
{
|
||||
public XAiDataProviderHub(
|
||||
ILogger<XBaseHub> logger
|
||||
) : base(logger)
|
||||
{ }
|
||||
|
||||
//
|
||||
#region XAiProject ...
|
||||
/// <summary>
|
||||
/// Notify a New Item Created ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task ProjectCreated(
|
||||
XAiProjectDto item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
await Clients
|
||||
.AllExcept(connectionId)
|
||||
.SendAsync(
|
||||
XAiDataProviderHubActions.ProjectCreated.GetStringValue(),
|
||||
item.ToJSON(camelCase: true),
|
||||
connectionId,
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notify an Item Removed ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task ProjectRemoved(
|
||||
XAiProjectDto item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
await Clients
|
||||
.AllExcept(connectionId)
|
||||
.SendAsync(
|
||||
XAiDataProviderHubActions.ProjectRemoved.GetStringValue(),
|
||||
item.ToJSON(camelCase: true),
|
||||
connectionId,
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notify an Item Updated ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task ProjectUpdated(
|
||||
XAiProjectDto item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
await Clients
|
||||
.AllExcept(connectionId)
|
||||
.SendAsync(
|
||||
XAiDataProviderHubActions.ProjectUpdated.GetStringValue(),
|
||||
item.ToJSON(camelCase: true),
|
||||
connectionId,
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region XAiConversation ...
|
||||
/// <summary>
|
||||
/// Notify a New Item Created ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task ConversationCreated(
|
||||
XAiProjectDto item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
await Clients
|
||||
.AllExcept(connectionId)
|
||||
.SendAsync(
|
||||
XAiDataProviderHubActions.ConversationCreated.GetStringValue(),
|
||||
item.ToJSON(camelCase: true),
|
||||
connectionId,
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notify an Item Removed ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task ConversationRemoved(
|
||||
XAiProjectDto item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
await Clients
|
||||
.AllExcept(connectionId)
|
||||
.SendAsync(
|
||||
XAiDataProviderHubActions.ConversationRemoved.GetStringValue(),
|
||||
item.ToJSON(camelCase: true),
|
||||
connectionId,
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notify an Item Updated ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task ConversationUpdated(
|
||||
XAiProjectDto item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
await Clients
|
||||
.AllExcept(connectionId)
|
||||
.SendAsync(
|
||||
XAiDataProviderHubActions.ConversationUpdated.GetStringValue(),
|
||||
item.ToJSON(camelCase: true),
|
||||
connectionId,
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region XAiMessage ...
|
||||
/// <summary>
|
||||
/// Notify a New Item Created ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task MessageCreated(
|
||||
XAiProjectDto item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
await Clients
|
||||
.AllExcept(connectionId)
|
||||
.SendAsync(
|
||||
XAiDataProviderHubActions.MessageCreated.GetStringValue(),
|
||||
item.ToJSON(camelCase: true),
|
||||
connectionId,
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notify an Item Removed ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task MessageRemoved(
|
||||
XAiProjectDto item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
await Clients
|
||||
.AllExcept(connectionId)
|
||||
.SendAsync(
|
||||
XAiDataProviderHubActions.MessageRemoved.GetStringValue(),
|
||||
item.ToJSON(camelCase: true),
|
||||
connectionId,
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notify an Item Updated ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task MessageUpdated(
|
||||
XAiProjectDto item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
await Clients
|
||||
.AllExcept(connectionId)
|
||||
.SendAsync(
|
||||
XAiDataProviderHubActions.MessageUpdated.GetStringValue(),
|
||||
item.ToJSON(camelCase: true),
|
||||
connectionId,
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+495
-32
@@ -1,9 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using xAiModels.Constants;
|
||||
using xAiModels.Interfaces;
|
||||
using xAiModels.Interfaces.Entities;
|
||||
using xAiModels.Providers.Dtos;
|
||||
using xAiModels.Providers.Entities;
|
||||
using xAiModels.Interfaces.Dtos;
|
||||
using xAiModels.Models.Dtos;
|
||||
using xAiModels.Providers.Hubs;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xModels.Dtos;
|
||||
using xStringService.Interfaces;
|
||||
|
||||
namespace xAiModels.Providers
|
||||
{
|
||||
@@ -12,44 +21,35 @@ namespace xAiModels.Providers
|
||||
/// </summary>
|
||||
public class XAiDataProvider : IXAiDataProvider
|
||||
{
|
||||
private readonly IHubContext<XAiMessageDtoHub> messageDtoHub;
|
||||
private readonly IHubContext<XAiProjectDtoHub> projectDtoHub;
|
||||
private readonly IXAiMessageRepository messageRepositoryService;
|
||||
private readonly IXAiProjectRepository projectRepositoryService;
|
||||
private readonly IHubContext<XAiMessageEntityHub> messageEntityHub;
|
||||
private readonly IHubContext<XAiProjectEntityHub> projectEntityHub;
|
||||
private readonly IXAiConversationRepository conversationRepository;
|
||||
private readonly IHubContext<XAiConversationDtoHub> conversationDtoHub;
|
||||
private readonly IHubContext<XAiConversationEntityHub> conversationEntityHub;
|
||||
private readonly IXStringProvider stringProvider;
|
||||
private readonly XAppConfiguration appConfiguration;
|
||||
private readonly IHubContext<XAiDataProviderHub> hub;
|
||||
private readonly IXAiMessageRepositoryService messageRepositoryService;
|
||||
private readonly IXAiProjectRepositoryService projectRepositoryService;
|
||||
private readonly IXAiProjectTitleResourceProvider projectTitleResourceProvider;
|
||||
private readonly IXAiConversationRepositoryService conversationRepositoryService;
|
||||
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
|
||||
private readonly IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider;
|
||||
|
||||
public XAiDataProvider(
|
||||
IHubContext<XAiMessageDtoHub> messageDtoHub,
|
||||
IHubContext<XAiProjectDtoHub> projectDtoHub,
|
||||
IXAiMessageRepository messageRepositoryService,
|
||||
IXAiProjectRepository projectRepositoryService,
|
||||
IHubContext<XAiMessageEntityHub> messageEntityHub,
|
||||
IHubContext<XAiProjectEntityHub> projectEntityHub,
|
||||
IXAiConversationRepository conversationRepository,
|
||||
IHubContext<XAiConversationDtoHub> conversationDtoHub,
|
||||
IHubContext<XAiConversationEntityHub> conversationEntityHub,
|
||||
IXStringProvider stringProvider,
|
||||
XAppConfiguration appConfiguration,
|
||||
IHubContext<XAiDataProviderHub> hub,
|
||||
IXAiMessageRepositoryService messageRepositoryService,
|
||||
IXAiProjectRepositoryService projectRepositoryService,
|
||||
IXAiProjectTitleResourceProvider projectTitleResourceProvider,
|
||||
IXAiConversationRepositoryService conversationRepositoryService,
|
||||
IXAiConversationTitleResourceProvider conversationTitleResourceProvider,
|
||||
IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider
|
||||
)
|
||||
{
|
||||
this.messageDtoHub = messageDtoHub;
|
||||
this.projectDtoHub = projectDtoHub;
|
||||
this.projectEntityHub = projectEntityHub;
|
||||
this.messageEntityHub = messageEntityHub;
|
||||
this.conversationDtoHub = conversationDtoHub;
|
||||
this.conversationEntityHub = conversationEntityHub;
|
||||
this.conversationRepository = conversationRepository;
|
||||
this.hub = hub;
|
||||
this.stringProvider = stringProvider;
|
||||
this.appConfiguration = appConfiguration;
|
||||
this.messageRepositoryService = messageRepositoryService;
|
||||
this.projectRepositoryService = projectRepositoryService;
|
||||
this.projectTitleResourceProvider = projectTitleResourceProvider;
|
||||
this.conversationRepositoryService = conversationRepositoryService;
|
||||
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
|
||||
this.projectDescriptionResourceProvider = projectDescriptionResourceProvider;
|
||||
}
|
||||
@@ -61,18 +61,481 @@ namespace xAiModels.Providers
|
||||
//
|
||||
#region Private ...
|
||||
/// <summary>
|
||||
/// Handle Default Project for Specified Owner ...
|
||||
/// Check Default Project Exists or not ...
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task HandleDefaultProject(string ownerId) { }
|
||||
private async Task<bool> HasDefaultProject(
|
||||
string ownerId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
var result = !ownerId.IsNullOrEmpty();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Default Owner Exists or not ...
|
||||
result = !(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)
|
||||
))
|
||||
.IsNullOrDefault();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle Default Project's Default Conversation for Specified Owner ...
|
||||
/// Retrieve Default Project of Specified Owner ...
|
||||
/// Create it if not Handled ...
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task HandleDefaultConversation(string ownerId) { }
|
||||
private async Task<XAiProjectDto> 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)
|
||||
);
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create Default Project for Specified Owner ...
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check Default Conversation Exists or not ...
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> HasDefaultConversation(
|
||||
string ownerId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
var result = !ownerId.IsNullOrEmpty();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Default Owner Exists or not ...
|
||||
result = !(await stringProvider.FindOne(
|
||||
cancellationToken: cancellationToken,
|
||||
predicate: x =>
|
||||
x.ResourceTitle
|
||||
.ToNormalString()
|
||||
.Contains(ownerId.ToNormalString()) &&
|
||||
x.ResourceTitle
|
||||
.ToNormalString()
|
||||
.Contains(XAiModelsConstants.XAiConversationTitleIdentifier
|
||||
.ToNormalString()) &&
|
||||
x.TranslatedValue
|
||||
.ToNormalString()
|
||||
.Contains(XAiDataProviderConstants.XDefaultAiConversationSuffix)
|
||||
))
|
||||
.IsNullOrDefault();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check Default Conversation Exists or not ...
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task CreateDefaultConversation(
|
||||
string ownerId,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
var isValid = !ownerId.IsNullOrEmpty();
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
var defaultLang = appConfiguration.DefaultLanguage;
|
||||
|
||||
//
|
||||
// Handle Default Project ...
|
||||
var project = await GetDefaultProject(
|
||||
ownerId: ownerId,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Check Default Owner Exists or not ...
|
||||
isValid = await HasDefaultConversation(
|
||||
ownerId: ownerId,
|
||||
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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Default Conversation of Specified Owner ...
|
||||
/// Create it if not Handled ...
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<XAiConversationDto> GetDefaultConversation(
|
||||
string ownerId,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Check Default Conversation Exists or noit ...
|
||||
var isExists = await HasDefaultConversation(
|
||||
ownerId: ownerId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!isExists)
|
||||
{
|
||||
//
|
||||
await CreateDefaultConversation(
|
||||
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)
|
||||
);
|
||||
if (resource.IsNullOrDefault())
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await conversationRepositoryService.FindOneAsync(
|
||||
cancellationToken: cancellationToken,
|
||||
predicate: x => x.Title
|
||||
.Equals(
|
||||
resource.ResourceTitle,
|
||||
StringComparison.InvariantCultureIgnoreCase
|
||||
)
|
||||
);
|
||||
if (result.IsNullOrDefault())
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send Custom Push Message ...
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="payLoad"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task SendPush(
|
||||
string action,
|
||||
string payLoad,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Collect Allowed Actions ...
|
||||
var actions = new List<string>
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user