apply fix on Models Enrichments ...
This commit is contained in:
@@ -1,30 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using xAiModels.Configurations;
|
||||
using xAiModels.Interfaces.Dtos;
|
||||
using xAiModels.Interfaces.Enrichers;
|
||||
using xAiModels.Interfaces.Entities;
|
||||
using xAiModels.Models.Dtos;
|
||||
using xAiModels.Models.Entities;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Providers;
|
||||
using xIdentityService.Interfaces;
|
||||
using xIdentityService.Extensions;
|
||||
using xModels.Dtos;
|
||||
using xAiModels.Interfaces;
|
||||
|
||||
namespace xAiModels.Providers.Dtos
|
||||
{
|
||||
public class XAiConversationRepositoryService : XBaseRepositoryService<XAiConversation, XAiConversationDto, Guid>, IXAiConversationRepositoryService
|
||||
{
|
||||
private readonly IXAiConversationEnricher enricher;
|
||||
private readonly IXIdentityProvider identityProvider;
|
||||
private readonly IXAiConversationRepository repository;
|
||||
private readonly IXAiProjectTitleResourceProvider projectTitleResourceProvider;
|
||||
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
|
||||
private readonly IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider;
|
||||
|
||||
public XAiConversationRepositoryService(
|
||||
IXAiConversationEnricher enricher,
|
||||
IXAiConversationRepository repository
|
||||
IXIdentityProvider identityProvider,
|
||||
IXAiConversationRepository repository,
|
||||
IXAiProjectTitleResourceProvider projectTitleResourceProvider,
|
||||
IXAiConversationTitleResourceProvider conversationTitleResourceProvider,
|
||||
IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider
|
||||
) : base(
|
||||
repository,
|
||||
mapperProfiles:
|
||||
@@ -33,771 +39,169 @@ namespace xAiModels.Providers.Dtos
|
||||
]
|
||||
)
|
||||
{
|
||||
this.enricher = enricher;
|
||||
this.repository = repository;
|
||||
this.identityProvider = identityProvider;
|
||||
this.projectTitleResourceProvider = projectTitleResourceProvider;
|
||||
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
|
||||
this.projectDescriptionResourceProvider = projectDescriptionResourceProvider;
|
||||
}
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
//
|
||||
#region Add ...
|
||||
#region Enrichers ...
|
||||
/// <summary>
|
||||
/// add a new Dto ...
|
||||
/// Enrich Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiConversationDto> AddAsync(
|
||||
XAiConversationDto item,
|
||||
bool saveChanges = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await AddAsync(
|
||||
item: item,
|
||||
fillMessages: false,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add or update a Dto (add if not exists/update if exists) ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiConversationDto> AddOrUpdateAsync(
|
||||
XAiConversationDto item,
|
||||
bool saveChanges = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await AddOrUpdateAsync(
|
||||
item: item,
|
||||
fillMessages: false,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Update ...
|
||||
/// <summary>
|
||||
/// Update an Dto values ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiConversationDto> UpdateAsync(
|
||||
Guid id,
|
||||
XAiConversationDto item,
|
||||
bool saveChanges = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await UpdateAsync(
|
||||
id: id,
|
||||
item: item,
|
||||
fillMessages: false,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
#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="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiConversationDto> RemoveAsync(
|
||||
Guid id,
|
||||
bool softDelete = true,
|
||||
bool saveChanges = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await RemoveAsync(
|
||||
id: id,
|
||||
fillMessages: false,
|
||||
softDelete: softDelete,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// remove an Dto ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiConversationDto> RemoveAsync(
|
||||
XAiConversationDto item,
|
||||
bool softDelete = true,
|
||||
bool saveChanges = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await RemoveAsync(
|
||||
item: item,
|
||||
fillMessages: false,
|
||||
softDelete: softDelete,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
#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="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiConversationDto> GetAsync(
|
||||
Guid id,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await GetAsync(
|
||||
id: id,
|
||||
fillMessages: false,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve all exists Dtos ...
|
||||
/// </summary>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<IEnumerable<XAiConversationDto>> GetAllAsync(
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await GetAllAsync(
|
||||
fillMessages: false,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve all exists Dtos
|
||||
/// as Async Enumerable ...
|
||||
/// </summary>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override IAsyncEnumerable<XAiConversationDto> GetAllAsAsyncEnumerable(
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return GetAllAsAsyncEnumerable(
|
||||
fillMessages: false,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// find an Dto by providing a Conditional Expression ...
|
||||
/// </summary>
|
||||
/// <param name="predicate"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiConversationDto> FindOneAsync(
|
||||
Expression<Func<XAiConversation, bool>> predicate,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await FindOneAsync(
|
||||
fillMessages: false,
|
||||
predicate: predicate,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
}
|
||||
|
||||
/// <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="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override 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,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await FindManyAsync(
|
||||
fillMessages: false,
|
||||
predicate: predicate,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
}
|
||||
|
||||
/// <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="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override 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,
|
||||
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="source"></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,
|
||||
public virtual async Task<XAiConversationDto> Enrich(
|
||||
XAiConversation source,
|
||||
bool fillMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.AddAsync(
|
||||
item: item,
|
||||
saveChanges: saveChanges,
|
||||
// Mapping Default ...
|
||||
var result = Mapper.Map<XAiConversationDto>(source);
|
||||
result = await Enrich(
|
||||
source: result,
|
||||
fillMessages: fillMessages,
|
||||
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) ...
|
||||
/// Enrich Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="source"></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,
|
||||
public virtual async Task<XAiConversationDto> Enrich(
|
||||
XAiConversationDto source,
|
||||
bool fillMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.AddAsync(
|
||||
item: item,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
// Handdle Owner ...
|
||||
XPersonDto owner = null;
|
||||
if (!source.OwnerId.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
fillMessages: fillMessages,
|
||||
// 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
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
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())
|
||||
// Handle Project Info ...
|
||||
XResourceDto projectTitleResource = null;
|
||||
XResourceDto projectDescriptionResource = null;
|
||||
if (!source.ProjectId.IsDefaultGuid())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
fillMessages: fillMessages,
|
||||
projectTitleResource = await projectTitleResourceProvider.GetResource(
|
||||
owner: source.OwnerId,
|
||||
identifier: source.ProjectId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
projectDescriptionResource = await projectDescriptionResourceProvider.GetResource(
|
||||
owner: source.OwnerId,
|
||||
identifier: source.ProjectId,
|
||||
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())
|
||||
// Attach Extracted Items ...
|
||||
var result = Mapper.Map<XAiConversationDto>(source, options =>
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// remove an Dto ...
|
||||
/// Enrich Specified Items ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="sources"></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,
|
||||
public virtual async Task<IEnumerable<XAiConversationDto>> EnrichRange(
|
||||
IEnumerable<XAiConversation> sources,
|
||||
bool fillMessages = false,
|
||||
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,
|
||||
var tasks = sources
|
||||
.Select(x => Enrich(
|
||||
source: x,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
));
|
||||
|
||||
//
|
||||
var result = await Task.WhenAll(tasks);
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Retrieve ...
|
||||
/// <summary>
|
||||
/// retrieve an Dto by it's Id ...
|
||||
/// Enrich Specified Items ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="sources"></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,
|
||||
public virtual async Task<IEnumerable<XAiConversationDto>> EnrichRange(
|
||||
IEnumerable<XAiConversationDto> sources,
|
||||
bool fillMessages = false,
|
||||
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,
|
||||
var tasks = sources
|
||||
.Select(x => Enrich(
|
||||
source: x,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
));
|
||||
|
||||
//
|
||||
var result = await Task.WhenAll(tasks);
|
||||
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(
|
||||
query: query,
|
||||
predicate: predicate,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichRangeAsync(
|
||||
sources: result.Items,
|
||||
destinations: result.Items,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using xAiModels.Configurations;
|
||||
using xAiModels.Interfaces.Dtos;
|
||||
using xAiModels.Interfaces.Enrichers;
|
||||
using xAiModels.Interfaces.Entities;
|
||||
using xAiModels.Models.Dtos;
|
||||
using xAiModels.Models.Entities;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Providers;
|
||||
using xIdentityService.Interfaces;
|
||||
using xModels.Dtos;
|
||||
using xIdentityService.Extensions;
|
||||
using xAiModels.Interfaces;
|
||||
using System.Linq;
|
||||
|
||||
namespace xAiModels.Providers.Dtos
|
||||
{
|
||||
public class XAiMessageRepositoryService : XBaseRepositoryService<XAiMessage, XAiMessageDto, Guid>, IXAiMessageRepositoryService
|
||||
{
|
||||
private readonly IXAiMessageEnricher enricher;
|
||||
private readonly IXIdentityProvider identityProvider;
|
||||
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
|
||||
|
||||
public XAiMessageRepositoryService(
|
||||
IXAiMessageEnricher enricher,
|
||||
IXAiMessageRepository repository
|
||||
IXAiMessageRepository repository,
|
||||
IXIdentityProvider identityProvider,
|
||||
IXAiConversationTitleResourceProvider conversationTitleResourceProvider
|
||||
) : base(
|
||||
repository,
|
||||
mapperProfiles:
|
||||
@@ -33,455 +34,132 @@ namespace xAiModels.Providers.Dtos
|
||||
]
|
||||
)
|
||||
{
|
||||
this.enricher = enricher;
|
||||
this.identityProvider = identityProvider;
|
||||
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
|
||||
}
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
//
|
||||
#region Add ...
|
||||
#region Enrichers ...
|
||||
/// <summary>
|
||||
/// add a new Dto ...
|
||||
/// Enrich Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiMessageDto> AddAsync(
|
||||
XAiMessageDto item,
|
||||
bool saveChanges = true,
|
||||
public virtual async Task<XAiMessageDto> Enrich(
|
||||
XAiMessage source,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.AddAsync(
|
||||
item: item,
|
||||
saveChanges: saveChanges,
|
||||
// Mapping Default ...
|
||||
var result = Mapper.Map<XAiMessageDto>(source);
|
||||
result = await Enrich(
|
||||
source: result,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add or update a Dto (add if not exists/update if exists) ...
|
||||
/// Enrich Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiMessageDto> AddOrUpdateAsync(
|
||||
XAiMessageDto item,
|
||||
bool saveChanges = true,
|
||||
public virtual async Task<XAiMessageDto> Enrich(
|
||||
XAiMessageDto source,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.AddAsync(
|
||||
item: item,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
// Handdle Owner ...
|
||||
XPersonDto owner = null;
|
||||
if (!source.OwnerId.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
cancellationToken: cancellationToken
|
||||
// Try to Retrieve User Info ...
|
||||
var device = identityProvider.GetDevice();
|
||||
var userInfo = await identityProvider.GetUserInfo(
|
||||
device: device,
|
||||
userSelectByParam: source.OwnerId
|
||||
);
|
||||
owner = userInfo.ToXPersonDto();
|
||||
}
|
||||
|
||||
//
|
||||
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="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiMessageDto> UpdateAsync(
|
||||
Guid id,
|
||||
XAiMessageDto item,
|
||||
bool saveChanges = 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())
|
||||
// Hanlde Conversation Title ...
|
||||
string conversationTitle = string.Empty;
|
||||
XResourceDto conversationTitleResource = null;
|
||||
if (!source.ConversationId.IsDefaultGuid())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
conversationTitleResource = await conversationTitleResourceProvider.GetResource(
|
||||
owner: source.OwnerId,
|
||||
identifier: source.ConversationId,
|
||||
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="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiMessageDto> RemoveAsync(
|
||||
Guid id,
|
||||
bool softDelete = true,
|
||||
bool saveChanges = 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,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// remove an Dto ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiMessageDto> RemoveAsync(
|
||||
XAiMessageDto item,
|
||||
bool softDelete = true,
|
||||
bool saveChanges = 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,
|
||||
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="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiMessageDto> GetAsync(
|
||||
Guid id,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiMessage>, IIncludableQueryable<XAiMessage, object>> includeBuilder = null,
|
||||
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,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve all exists Dtos ...
|
||||
/// </summary>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<IEnumerable<XAiMessageDto>> GetAllAsync(
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiMessage>, IOrderedQueryable<XAiMessage>> orderBuilder = null,
|
||||
Func<IQueryable<XAiMessage>, IIncludableQueryable<XAiMessage, object>> includeBuilder = null,
|
||||
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,
|
||||
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="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async IAsyncEnumerable<XAiMessageDto> GetAllAsAsyncEnumerable(
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiMessage>, IOrderedQueryable<XAiMessage>> orderBuilder = null,
|
||||
Func<IQueryable<XAiMessage>, IIncludableQueryable<XAiMessage, object>> includeBuilder = null,
|
||||
[EnumeratorCancellation] CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var enumerable = base.GetAllAsAsyncEnumerable(
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
await foreach (var dto in enumerable)
|
||||
{
|
||||
//
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
if (!conversationTitleResource.IsNullOrDefault())
|
||||
{
|
||||
yield break;
|
||||
conversationTitle = conversationTitleResource.Resource;
|
||||
}
|
||||
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: dto,
|
||||
destination: dto,
|
||||
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="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiMessageDto> FindOneAsync(
|
||||
Expression<Func<XAiMessage, bool>> predicate,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiMessage>, IIncludableQueryable<XAiMessage, object>> includeBuilder = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.FindOneAsync(
|
||||
predicate: predicate,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
// Attach Extracted Items ...
|
||||
var result = Mapper.Map<XAiMessageDto>(source, options =>
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
options.Items[nameof(source.Owner)] = owner;
|
||||
options.Items[nameof(source.ConversationTitle)] = conversationTitle;
|
||||
options.Items[nameof(source.ConversationTitleResouce)] = conversationTitleResource;
|
||||
});
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// find a collection of Dtos by proving a Conditional Expression ...
|
||||
/// Enrich Specified Items ...
|
||||
/// </summary>
|
||||
/// <param name="predicate"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<IEnumerable<XAiMessageDto>> FindManyAsync(
|
||||
Expression<Func<XAiMessage, bool>> predicate,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiMessage>, IOrderedQueryable<XAiMessage>> orderBuilder = null,
|
||||
Func<IQueryable<XAiMessage>, IIncludableQueryable<XAiMessage, object>> includeBuilder = null,
|
||||
public virtual async Task<IEnumerable<XAiMessageDto>> EnrichRange(
|
||||
IEnumerable<XAiMessage> sources,
|
||||
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,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
var tasks = sources
|
||||
.Select(x => Enrich(x, cancellationToken));
|
||||
|
||||
//
|
||||
var result = await Task.WhenAll(tasks);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve Dtos based on XQuery Pagination structure ...
|
||||
/// Enrich Specified Items ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="predicate"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XQueryResult<XAiMessageDto>> QueryAsync(
|
||||
XQuery query,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Expression<Func<XAiMessage, bool>> predicate = null,
|
||||
Func<IQueryable<XAiMessage>, IOrderedQueryable<XAiMessage>> orderBuilder = null,
|
||||
Func<IQueryable<XAiMessage>, IIncludableQueryable<XAiMessage, object>> includeBuilder = null,
|
||||
public virtual async Task<IEnumerable<XAiMessageDto>> EnrichRange(
|
||||
IEnumerable<XAiMessageDto> sources,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.QueryAsync(
|
||||
query: query,
|
||||
predicate: predicate,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichRangeAsync(
|
||||
sources: result.Items,
|
||||
destinations: result.Items,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
var tasks = sources
|
||||
.Select(x => Enrich(x, cancellationToken));
|
||||
|
||||
//
|
||||
var result = await Task.WhenAll(tasks);
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,215 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xAiModels.Interfaces;
|
||||
using xAiModels.Interfaces.Dtos;
|
||||
using xAiModels.Interfaces.Enrichers;
|
||||
using xAiModels.Interfaces.Entities;
|
||||
using xAiModels.Models.Dtos;
|
||||
using xAiModels.Models.Entities;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityService.Interfaces;
|
||||
using xIdentityService.Extensions;
|
||||
using xModels.Dtos;
|
||||
using System.Linq;
|
||||
|
||||
namespace xAiModels.Providers.Enrichers
|
||||
{
|
||||
public class XAiConversationEnricher : IXAiConversationEnricher
|
||||
{
|
||||
private readonly IXIdentityProvider identityProvider;
|
||||
private readonly IXAiProjectRepositoryService projectRepositoryService;
|
||||
private readonly IXAiConversationRepository repository;
|
||||
private readonly IXAiProjectTitleResourceProvider projectTitleResourceProvider;
|
||||
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
|
||||
private readonly IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider;
|
||||
|
||||
public XAiConversationEnricher(
|
||||
IXIdentityProvider identityProvider,
|
||||
IXAiProjectRepositoryService projectRepositoryService,
|
||||
IXAiConversationTitleResourceProvider conversationTitleResourceProvider
|
||||
IXAiConversationRepository repository,
|
||||
IXAiProjectTitleResourceProvider projectTitleResourceProvider,
|
||||
IXAiConversationTitleResourceProvider conversationTitleResourceProvider,
|
||||
IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider
|
||||
)
|
||||
{
|
||||
//
|
||||
this.repository = repository;
|
||||
this.identityProvider = identityProvider;
|
||||
this.projectRepositoryService = projectRepositoryService;
|
||||
this.projectTitleResourceProvider = projectTitleResourceProvider;
|
||||
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Signle Entity to Dto ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="destination"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task EnrichAsync(
|
||||
XAiConversationDto source,
|
||||
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 ...
|
||||
Task[] tasks = [
|
||||
ownerTask,
|
||||
projectTask,
|
||||
titleLocalesTask
|
||||
];
|
||||
if (fillMessages)
|
||||
{
|
||||
tasks = [.. tasks, messagesTask];
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
|
||||
//
|
||||
// Attached Resolved Info to Destination ...
|
||||
destination.Owner = ownerTask.Result;
|
||||
destination.TitleResource = titleLocalesTask.Result;
|
||||
var project = projectTask.Result;
|
||||
if (!project.IsNullOrDefault())
|
||||
{
|
||||
destination.ProjectTitle = project.Title;
|
||||
destination.ProjectDescription = project.Description;
|
||||
destination.ProjectTitleResource = project.TitleResource;
|
||||
destination.ProjectDescriptionResource = project.DescriptionResource;
|
||||
}
|
||||
if (!messagesTask.Result.IsNull())
|
||||
{
|
||||
destination.Messages = [.. messagesTask.Result];
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public async Task EnrichRangeAsync(
|
||||
IEnumerable<XAiConversationDto> sources,
|
||||
IEnumerable<XAiConversationDto> destinations,
|
||||
bool fillMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Make Tasks Ready ...
|
||||
var tasks = sources.Zip(destinations, (src, dst) =>
|
||||
EnrichAsync(src, dst, cancellationToken)
|
||||
);
|
||||
|
||||
//
|
||||
await Task.WhenAll(tasks);
|
||||
this.projectDescriptionResourceProvider = projectDescriptionResourceProvider;
|
||||
}
|
||||
|
||||
//
|
||||
#region Private ...
|
||||
#region Enrichers ...
|
||||
/// <summary>
|
||||
/// Reading Owner User Info ...
|
||||
/// Enrich Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<XPersonDto> ResolveOwnerAsync(
|
||||
string ownerId,
|
||||
public virtual async Task<XAiConversationDto> Enrich(
|
||||
XAiConversation source,
|
||||
bool fillMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
XPersonDto result = null;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (ownerId.IsNullOrEmpty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Try to Retrieve User Info ...
|
||||
var device = identityProvider.GetDevice();
|
||||
var userInfo = await identityProvider.GetUserInfo(
|
||||
device: device,
|
||||
userSelectByParam: ownerId
|
||||
);
|
||||
result = userInfo.ToXPersonDto();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reading Title Locales ...
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<XResourceDto> ResolveTitleLocalesAsync(
|
||||
string title,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
XResourceDto result = null;
|
||||
if (title.IsNullOrEmpty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = await conversationTitleResourceProvider.GetResource(
|
||||
owner: null,
|
||||
identifier: title,
|
||||
// Mapping Default ...
|
||||
var result = source.MapConvert<XAiConversationDto, XAiConversation>();
|
||||
result = await Enrich(
|
||||
source: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
@@ -218,58 +67,130 @@ namespace xAiModels.Providers.Enrichers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Project ...
|
||||
/// Enrich Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<XAiProjectDto> ResolveProjectAsync(
|
||||
Guid projectId,
|
||||
public virtual async Task<XAiConversationDto> Enrich(
|
||||
XAiConversationDto source,
|
||||
bool fillMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
XAiProjectDto result = null;
|
||||
if (projectId.IsNull() || projectId.IsDefaultGuid())
|
||||
// Handdle Owner ...
|
||||
XPersonDto owner = null;
|
||||
if (!source.OwnerId.IsNullOrEmpty())
|
||||
{
|
||||
return result;
|
||||
//
|
||||
// Try to Retrieve User Info ...
|
||||
var device = identityProvider.GetDevice();
|
||||
var userInfo = await identityProvider.GetUserInfo(
|
||||
device: device,
|
||||
userSelectByParam: source.OwnerId
|
||||
);
|
||||
owner = userInfo.ToXPersonDto();
|
||||
}
|
||||
|
||||
//
|
||||
result = await projectRepositoryService.GetAsync(
|
||||
id: projectId,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
// 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<XAiConversationDto, XAiConversationDto>();
|
||||
result.Owner = owner;
|
||||
result.TitleResource = titleResource;
|
||||
result.ProjectTitleResource = projectTitleResource;
|
||||
result.ProjectDescriptionResource = projectDescriptionResource;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Specified Conversation Messages ...
|
||||
/// Enrich Specified Items ...
|
||||
/// </summary>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<IEnumerable<XAiMessageDto>> ResolveMessagesAsync(
|
||||
Guid conversationId,
|
||||
public virtual async Task<IEnumerable<XAiConversationDto>> EnrichRange(
|
||||
IEnumerable<XAiConversation> sources,
|
||||
bool fillMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = new List<XAiMessageDto>();
|
||||
|
||||
//
|
||||
if (conversationId.IsDefaultGuid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
var tasks = sources
|
||||
.Select(x => Enrich(
|
||||
source: x,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
));
|
||||
|
||||
//
|
||||
var result = await Task.WhenAll(tasks);
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Enrich Specified Items ...
|
||||
/// </summary>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XAiConversationDto>> EnrichRange(
|
||||
IEnumerable<XAiConversationDto> 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
|
||||
}
|
||||
}
|
||||
@@ -10,135 +10,144 @@ using xIdentityService.Extensions;
|
||||
using xModels.Dtos;
|
||||
using System.Linq;
|
||||
using xAiModels.Interfaces.Dtos;
|
||||
using xAiModels.Models.Entities;
|
||||
using xAiModels.Interfaces;
|
||||
|
||||
namespace xAiModels.Providers.Enrichers
|
||||
{
|
||||
public class XAiMessageEnricher : IXAiMessageEnricher
|
||||
{
|
||||
private readonly IXIdentityProvider identityProvider;
|
||||
private readonly IXAiConversationRepositoryService conversationRepositoryService;
|
||||
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
|
||||
|
||||
public XAiMessageEnricher(
|
||||
IXIdentityProvider identityProvider,
|
||||
IXAiConversationRepositoryService conversationRepositoryService
|
||||
IXAiConversationTitleResourceProvider conversationTitleResourceProvider
|
||||
)
|
||||
{
|
||||
this.identityProvider = identityProvider;
|
||||
this.conversationRepositoryService = conversationRepositoryService;
|
||||
}
|
||||
|
||||
public async Task EnrichAsync(
|
||||
XAiMessageDto source,
|
||||
XAiMessageDto destination,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Run independent async operations concurrently
|
||||
var ownerTask = ResolveOwnerAsync(source.OwnerId, cancellationToken);
|
||||
var conversationTask = ResolveConversationAsync(source.ConversationId, cancellationToken);
|
||||
|
||||
//
|
||||
// wait until All Tasks Resolved ...
|
||||
await Task.WhenAll(ownerTask, conversationTask);
|
||||
|
||||
//
|
||||
// Attached Resolved Info to Destination ...
|
||||
destination.Owner = ownerTask.Result;
|
||||
if (!conversationTask.Result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
destination.ConversationTitle = conversationTask.Result.Title;
|
||||
destination.ConversationTitleResouce = conversationTask.Result.TitleResource;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task EnrichRangeAsync(
|
||||
IEnumerable<XAiMessageDto> sources,
|
||||
IEnumerable<XAiMessageDto> destinations,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Make Tasks Ready ...
|
||||
var tasks = sources.Zip(destinations, (src, dst) =>
|
||||
EnrichAsync(src, dst, cancellationToken)
|
||||
);
|
||||
|
||||
//
|
||||
await Task.WhenAll(tasks);
|
||||
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
|
||||
}
|
||||
|
||||
//
|
||||
#region Private ...
|
||||
#region Enrichers ...
|
||||
/// <summary>
|
||||
/// Reading Owner User Info ...
|
||||
/// Enrich Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<XPersonDto> ResolveOwnerAsync(
|
||||
string ownerId,
|
||||
public virtual async Task<XAiMessageDto> Enrich(
|
||||
XAiMessage source,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
XPersonDto result = null;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (ownerId.IsNullOrEmpty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Try to Retrieve User Info ...
|
||||
var device = identityProvider.GetDevice();
|
||||
var userInfo = await identityProvider.GetUserInfo(
|
||||
device: device,
|
||||
userSelectByParam: ownerId
|
||||
);
|
||||
result = userInfo.ToXPersonDto();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reading Conversation ...
|
||||
/// </summary>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<XAiConversationDto> ResolveConversationAsync(
|
||||
Guid conversationId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
XAiConversationDto result = null;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (conversationId.IsNull() ||
|
||||
conversationId.IsDefaultGuid()
|
||||
)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = await conversationRepositoryService.GetAsync(
|
||||
id: conversationId,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
// Mapping Default ...
|
||||
var result = source.MapConvert<XAiMessageDto, XAiMessage>();
|
||||
result = await Enrich(
|
||||
source: result,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Enrich Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiMessageDto> 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<XAiMessageDto, XAiMessageDto>();
|
||||
result.Owner = owner;
|
||||
result.ConversationTitle = conversationTitle;
|
||||
result.ConversationTitleResouce = conversationTitleResource;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enrich Specified Items ...
|
||||
/// </summary>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XAiMessageDto>> EnrichRange(
|
||||
IEnumerable<XAiMessage> sources,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var tasks = sources
|
||||
.Select(x => Enrich(x, cancellationToken));
|
||||
|
||||
//
|
||||
var result = await Task.WhenAll(tasks);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enrich Specified Items ...
|
||||
/// </summary>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XAiMessageDto>> EnrichRange(
|
||||
IEnumerable<XAiMessageDto> sources,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var tasks = sources
|
||||
.Select(x => Enrich(x, cancellationToken));
|
||||
|
||||
//
|
||||
var result = await Task.WhenAll(tasks);
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,276 +1,309 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xAiModels.Interfaces.Enrichers;
|
||||
using xAiModels.Interfaces.Entities;
|
||||
using xAiModels.Models.Dtos;
|
||||
using xAiModels.Models.Entities;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityService.Interfaces;
|
||||
using xIdentityService.Extensions;
|
||||
using xModels.Dtos;
|
||||
using xAiModels.Interfaces;
|
||||
using xAiModels.Interfaces.Dtos;
|
||||
|
||||
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 IXAiConversationRepositoryService conversationRepositoryService;
|
||||
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
|
||||
private readonly IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider;
|
||||
|
||||
public XAiProjectEnricher(
|
||||
IXIdentityProvider identityProvider,
|
||||
IXAiMessageRepository messageRepository,
|
||||
IXAiConversationRepository conversationRepository,
|
||||
IXAiProjectTitleResourceProvider projectTitleResourceProvider,
|
||||
// IXAiConversationRepositoryService conversationRepositoryService,
|
||||
IXAiConversationTitleResourceProvider conversationTitleResourceProvider,
|
||||
IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider
|
||||
)
|
||||
{
|
||||
//
|
||||
this.identityProvider = identityProvider;
|
||||
this.messageRepository = messageRepository;
|
||||
this.conversationRepository = conversationRepository;
|
||||
this.projectTitleResourceProvider = projectTitleResourceProvider;
|
||||
// this.conversationRepositoryService = conversationRepositoryService;
|
||||
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
|
||||
this.projectDescriptionResourceProvider = projectDescriptionResourceProvider;
|
||||
}
|
||||
|
||||
public async Task EnrichAsync(
|
||||
XAiProjectDto source,
|
||||
XAiProjectDto destination,
|
||||
//
|
||||
#region Enrichers ...
|
||||
/// <summary>
|
||||
/// Enrich Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiProjectDto> Enrich(
|
||||
XAiProject source,
|
||||
bool fillConversations = false,
|
||||
bool fillConversationMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
await EnrichAsync(
|
||||
source: source,
|
||||
destination: destination,
|
||||
fillConversations: false,
|
||||
cancellationToken: cancellationToken
|
||||
//
|
||||
// Mapping Default ...
|
||||
var result = source.MapConvert<XAiProjectDto, XAiProject>();
|
||||
result = await Enrich(
|
||||
source: result,
|
||||
fillConversations: fillConversations,
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task EnrichAsync(
|
||||
/// <summary>
|
||||
/// Enrich Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiProjectDto> Enrich(
|
||||
XAiProjectDto source,
|
||||
XAiProjectDto destination,
|
||||
bool fillConversations = true,
|
||||
bool fillConversationMessages = true,
|
||||
bool fillConversations = false,
|
||||
bool fillConversationMessages = false,
|
||||
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 descriptionTask = ResolveDescriptionAsync(source.Description, cancellationToken);
|
||||
// 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();
|
||||
}
|
||||
|
||||
//
|
||||
// wait until All Tasks Resolved ...
|
||||
Task[] tasks =
|
||||
// Handle Title ...
|
||||
XResourceDto titleResource = null;
|
||||
if (!source.Title.IsNullOrEmpty())
|
||||
{
|
||||
titleTask,
|
||||
ownerTask,
|
||||
descriptionTask
|
||||
};
|
||||
//
|
||||
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<XAiConversationDto> conversations = [];
|
||||
if (fillConversations)
|
||||
{
|
||||
tasks = [.. tasks, conversationsTask];
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
|
||||
//
|
||||
// Attached Resolved Info to Destination ...
|
||||
destination.Owner = ownerTask.Result;
|
||||
destination.TitleResource = titleTask.Result;
|
||||
destination.DescriptionResource = descriptionTask.Result;
|
||||
if (!conversationsTask.Result.IsNull())
|
||||
{
|
||||
destination.Conversations = [.. conversationsTask.Result];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task EnrichRangeAsync(
|
||||
IEnumerable<XAiProjectDto> sources,
|
||||
IEnumerable<XAiProjectDto> destinations,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Make Tasks Ready ...
|
||||
var tasks = sources.Zip(destinations, (src, dst) =>
|
||||
EnrichAsync(src, dst, cancellationToken)
|
||||
);
|
||||
|
||||
//
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
public async Task EnrichRangeAsync(
|
||||
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(
|
||||
source: src,
|
||||
destination: dst,
|
||||
fillConversations: 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<XAiConversationDto, XAiConversation>();
|
||||
|
||||
//
|
||||
// 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<XAiMessageDto> 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<XAiMessageDto, XAiMessage>();
|
||||
|
||||
//
|
||||
// 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 = source.MapConvert<XAiProjectDto, XAiProjectDto>();
|
||||
result.Owner = owner;
|
||||
result.TitleResource = titleResource;
|
||||
result.Conversations = [.. conversations];
|
||||
result.DescriptionResource = descriptionResource;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enrich Specified Items ...
|
||||
/// </summary>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XAiProjectDto>> EnrichRange(
|
||||
IEnumerable<XAiProject> sources,
|
||||
bool fillConversations = false,
|
||||
bool fillConversationMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var tasks = sources
|
||||
.Select(x => Enrich(
|
||||
source: x,
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversations: fillConversations,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
)
|
||||
);
|
||||
|
||||
//
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
//
|
||||
#region Private ...
|
||||
/// <summary>
|
||||
/// Reading Owner User Info ...
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<XPersonDto> ResolveOwnerAsync(
|
||||
string ownerId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
XPersonDto result = null;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (ownerId.IsNullOrEmpty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Try to Retrieve User Info ...
|
||||
var device = identityProvider.GetDevice();
|
||||
var userInfo = await identityProvider.GetUserInfo(
|
||||
device: device,
|
||||
userSelectByParam: ownerId
|
||||
);
|
||||
result = userInfo.ToXPersonDto();
|
||||
));
|
||||
|
||||
//
|
||||
var result = await Task.WhenAll(tasks);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Title Resource ...
|
||||
/// Enrich Specified Items ...
|
||||
/// </summary>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="fillConversations"></param>
|
||||
/// <param name="fillConversationMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<XResourceDto> ResolveTitleAsync(
|
||||
string identifier,
|
||||
public virtual async Task<IEnumerable<XAiProjectDto>> EnrichRange(
|
||||
IEnumerable<XAiProjectDto> sources,
|
||||
bool fillConversations = false,
|
||||
bool fillConversationMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
XResourceDto result = null;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (identifier.IsNullOrEmpty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = await projectTitleResourceProvider.GetResource(
|
||||
owner: null,
|
||||
identifier: identifier,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
var tasks = sources
|
||||
.Select(x => Enrich(
|
||||
source: x,
|
||||
cancellationToken: cancellationToken,
|
||||
fillConversations: fillConversations,
|
||||
fillConversationMessages: fillConversationMessages
|
||||
));
|
||||
|
||||
//
|
||||
var result = await Task.WhenAll(tasks);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Description Resource ...
|
||||
/// </summary>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<XResourceDto> ResolveDescriptionAsync(
|
||||
string identifier,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
XResourceDto result = null;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (identifier.IsNullOrEmpty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = await projectDescriptionResourceProvider.GetResource(
|
||||
owner: null,
|
||||
identifier: identifier,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
)
|
||||
{
|
||||
//
|
||||
List<XAiConversationDto> result = [];
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (projectId.IsNull() ||
|
||||
projectId.IsDefaultGuid()
|
||||
)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// var items = await conversationRepositoryService.FindManyAsync(
|
||||
// orderBuilder: null,
|
||||
// includeBuilder: null,
|
||||
// ignoreSoftDeleteds: true,
|
||||
// fillMessages: fillMessages,
|
||||
// predicate: x => x.Id == projectId,
|
||||
// cancellationToken: cancellationToken
|
||||
// );
|
||||
// result = [.. items];
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using MongoDB.Driver.Core.Connections;
|
||||
using xAiModels.Constants;
|
||||
using xAiModels.Extensions;
|
||||
using xAiModels.Interfaces;
|
||||
@@ -105,11 +104,11 @@ namespace xAiModels.Providers
|
||||
var result = await projectRepositoryService.FindManyAsync(
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
fillConversations: fillConversations,
|
||||
// fillConversations: fillConversations,
|
||||
predicate: x => x.OwnerId == ownerId,
|
||||
cancellationToken: cancellationToken,
|
||||
orderBuilder: x => x.OrderBy(y => y.CreatedOn),
|
||||
fillConversationMessages: fillConversationMessages
|
||||
orderBuilder: x => x.OrderBy(y => y.CreatedOn)
|
||||
// fillConversationMessages: fillConversationMessages
|
||||
);
|
||||
|
||||
//
|
||||
@@ -143,7 +142,7 @@ namespace xAiModels.Providers
|
||||
var result = await conversationRepositoryService.FindManyAsync(
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: false,
|
||||
fillMessages: fillMessages,
|
||||
// fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken,
|
||||
predicate: x => x.ProjectId == projectId,
|
||||
orderBuilder: x => x.OrderBy(y => y.CreatedOn)
|
||||
@@ -234,8 +233,8 @@ namespace xAiModels.Providers
|
||||
result = await projectRepositoryService.AddAsync(
|
||||
item: item,
|
||||
saveChanges: true,
|
||||
fillConversations: false,
|
||||
fillConversationMessages: false,
|
||||
// fillConversations: false,
|
||||
// fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
@@ -313,8 +312,8 @@ namespace xAiModels.Providers
|
||||
id: projectId,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
fillConversations: false,
|
||||
fillConversationMessages: false,
|
||||
// fillConversations: false,
|
||||
// fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (project.IsNullOrDefault())
|
||||
@@ -353,7 +352,7 @@ namespace xAiModels.Providers
|
||||
result = await conversationRepositoryService.AddAsync(
|
||||
item: item,
|
||||
saveChanges: true,
|
||||
fillMessages: false,
|
||||
// fillMessages: false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
@@ -730,8 +729,8 @@ namespace xAiModels.Providers
|
||||
id: project.Id,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
fillConversations: false,
|
||||
fillConversationMessages: false,
|
||||
// fillConversations: false,
|
||||
// fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
@@ -822,8 +821,8 @@ namespace xAiModels.Providers
|
||||
id: project.Id,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
fillConversations: false,
|
||||
fillConversationMessages: false,
|
||||
// fillConversations: false,
|
||||
// fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
@@ -944,8 +943,8 @@ namespace xAiModels.Providers
|
||||
id: project.Id,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
fillConversations: false,
|
||||
fillConversationMessages: false,
|
||||
// fillConversations: false,
|
||||
// fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user