backup Mapping Actions and remove them and try to use Enricher Service for AiConversation ...
This commit is contained in:
@@ -1,56 +0,0 @@
|
|||||||
using System;
|
|
||||||
using AutoMapper;
|
|
||||||
using xAiModels.Interfaces;
|
|
||||||
using xAiModels.Models.Dtos;
|
|
||||||
using xAiModels.Models.Entities;
|
|
||||||
using xIdentityService.Extensions;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiModels.Configurations.Entities
|
|
||||||
{
|
|
||||||
public class XAiConversationMappingAction : IMappingAction<XAiConversation, XAiConversationDto>
|
|
||||||
{
|
|
||||||
private readonly IXIdentityProvider identityProvider;
|
|
||||||
private readonly IXAiProjectTitleResourceProvider projectTitleResourceProvider;
|
|
||||||
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
|
|
||||||
private readonly IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider;
|
|
||||||
|
|
||||||
public XAiConversationMappingAction(
|
|
||||||
IXIdentityProvider identityProvider,
|
|
||||||
IXAiProjectTitleResourceProvider projectTitleResourceProvider,
|
|
||||||
IXAiConversationTitleResourceProvider conversationTitleResourceProvider,
|
|
||||||
IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider
|
|
||||||
)
|
|
||||||
{
|
|
||||||
this.identityProvider = identityProvider;
|
|
||||||
this.projectTitleResourceProvider = projectTitleResourceProvider;
|
|
||||||
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
|
|
||||||
this.projectDescriptionResourceProvider = projectDescriptionResourceProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Process(
|
|
||||||
XAiConversation source,
|
|
||||||
XAiConversationDto destination,
|
|
||||||
ResolutionContext context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Retrieve Owner ...
|
|
||||||
var device = identityProvider.GetDevice();
|
|
||||||
var ownerUserInfo = identityProvider.GetUserInfo(
|
|
||||||
device: device,
|
|
||||||
userSelectByParam: source.OwnerId
|
|
||||||
)
|
|
||||||
.GetAwaiter()
|
|
||||||
.GetResult();
|
|
||||||
var owner = ownerUserInfo.ToXPersonDto();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Setting Owner ...
|
|
||||||
destination.Owner = owner;
|
|
||||||
|
|
||||||
// Retrieve Project Info ...
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
using System;
|
|
||||||
using AutoMapper;
|
|
||||||
using xAiModels.Models.Dtos;
|
|
||||||
using xAiModels.Models.Entities;
|
|
||||||
using xIdentityService.Extensions;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiModels.Configurations.Entities
|
|
||||||
{
|
|
||||||
public class XAiMessageMappingAction : IMappingAction<XAiMessage, XAiMessageDto>
|
|
||||||
{
|
|
||||||
private readonly IXIdentityProvider identityProvider;
|
|
||||||
|
|
||||||
public XAiMessageMappingAction(
|
|
||||||
IXIdentityProvider identityProvider
|
|
||||||
)
|
|
||||||
{
|
|
||||||
this.identityProvider = identityProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Process(
|
|
||||||
XAiMessage source,
|
|
||||||
XAiMessageDto destination,
|
|
||||||
ResolutionContext context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Retrieve Owner ...
|
|
||||||
var device = identityProvider.GetDevice();
|
|
||||||
var ownerUserInfo = identityProvider.GetUserInfo(
|
|
||||||
device: device,
|
|
||||||
userSelectByParam: source.OwnerId
|
|
||||||
)
|
|
||||||
.GetAwaiter()
|
|
||||||
.GetResult();
|
|
||||||
var owner = ownerUserInfo.ToXPersonDto();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Setting Owner ...
|
|
||||||
destination.Owner = owner;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Owner ...
|
|
||||||
// Retrieve Conversation ...
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
using System;
|
|
||||||
using AutoMapper;
|
|
||||||
using xAiModels.Models.Dtos;
|
|
||||||
using xAiModels.Models.Entities;
|
|
||||||
using xIdentityService.Extensions;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiModels.Configurations.Entities
|
|
||||||
{
|
|
||||||
public class XAiProjectMappingAction : IMappingAction<XAiProject, XAiProjectDto>
|
|
||||||
{
|
|
||||||
private readonly IXIdentityProvider identityProvider;
|
|
||||||
|
|
||||||
public XAiProjectMappingAction(
|
|
||||||
IXIdentityProvider identityProvider
|
|
||||||
)
|
|
||||||
{
|
|
||||||
this.identityProvider = identityProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Process(
|
|
||||||
XAiProject source,
|
|
||||||
XAiProjectDto destination,
|
|
||||||
ResolutionContext context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Retrieve Owner ...
|
|
||||||
var device = identityProvider.GetDevice();
|
|
||||||
var ownerUserInfo = identityProvider.GetUserInfo(
|
|
||||||
device: device,
|
|
||||||
userSelectByParam: source.OwnerId
|
|
||||||
)
|
|
||||||
.GetAwaiter()
|
|
||||||
.GetResult();
|
|
||||||
var owner = ownerUserInfo.ToXPersonDto();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Setting Owner ...
|
|
||||||
destination.Owner = owner;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Owner ...
|
|
||||||
// Retrieve Title Resources ...
|
|
||||||
// Retrieve Description Resources ...
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using xAiModels.Configurations.Entities;
|
|
||||||
using xAiModels.Models.Dtos;
|
using xAiModels.Models.Dtos;
|
||||||
using xAiModels.Models.Entities;
|
using xAiModels.Models.Entities;
|
||||||
|
|
||||||
@@ -11,18 +10,15 @@ namespace xAiModels.Configurations
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
// XAiMessage ...
|
// XAiMessage ...
|
||||||
CreateMap<XAiMessage, XAiMessageDto>()
|
CreateMap<XAiMessage, XAiMessageDto>();
|
||||||
.AfterMap<XAiMessageMappingAction>();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// XAiProject ...
|
// XAiProject ...
|
||||||
CreateMap<XAiProject, XAiProjectDto>()
|
CreateMap<XAiProject, XAiProjectDto>();
|
||||||
.AfterMap<XAiProjectMappingAction>();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// XAiConversation ...
|
// XAiConversation ...
|
||||||
CreateMap<XAiConversation, XAiConversationDto>()
|
CreateMap<XAiConversation, XAiConversationDto>();
|
||||||
.AfterMap<XAiConversationMappingAction>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,8 @@ using xAiModels.Interfaces.Entities;
|
|||||||
using xAiModels.Interfaces;
|
using xAiModels.Interfaces;
|
||||||
using xAiModels.Providers;
|
using xAiModels.Providers;
|
||||||
using xAiModels.Constants;
|
using xAiModels.Constants;
|
||||||
|
using xAiModels.Interfaces.Enrichers;
|
||||||
|
using xAiModels.Providers.Enrichers;
|
||||||
|
|
||||||
namespace xAiModels.DI
|
namespace xAiModels.DI
|
||||||
{
|
{
|
||||||
@@ -420,7 +422,6 @@ namespace xAiModels.DI
|
|||||||
//
|
//
|
||||||
#region AiMessage ...
|
#region AiMessage ...
|
||||||
//
|
//
|
||||||
// Models ...
|
|
||||||
services.Add(
|
services.Add(
|
||||||
new ServiceDescriptor(typeof(IXAiMessageServiceProvider), typeof(XAiMessageServiceProvider), lifeTime)
|
new ServiceDescriptor(typeof(IXAiMessageServiceProvider), typeof(XAiMessageServiceProvider), lifeTime)
|
||||||
);
|
);
|
||||||
@@ -435,7 +436,6 @@ namespace xAiModels.DI
|
|||||||
//
|
//
|
||||||
#region AiProject ...
|
#region AiProject ...
|
||||||
//
|
//
|
||||||
// Models ...
|
|
||||||
services.Add(
|
services.Add(
|
||||||
new ServiceDescriptor(typeof(IXAiProjectServiceProvider), typeof(XAiProjectServiceProvider), lifeTime)
|
new ServiceDescriptor(typeof(IXAiProjectServiceProvider), typeof(XAiProjectServiceProvider), lifeTime)
|
||||||
);
|
);
|
||||||
@@ -459,7 +459,6 @@ namespace xAiModels.DI
|
|||||||
//
|
//
|
||||||
#region AiConversation ...
|
#region AiConversation ...
|
||||||
//
|
//
|
||||||
// Models ...
|
|
||||||
services.Add(
|
services.Add(
|
||||||
new ServiceDescriptor(typeof(IXAiConversationServiceProvider), typeof(XAiConversationServiceProvider), lifeTime)
|
new ServiceDescriptor(typeof(IXAiConversationServiceProvider), typeof(XAiConversationServiceProvider), lifeTime)
|
||||||
);
|
);
|
||||||
@@ -475,6 +474,12 @@ namespace xAiModels.DI
|
|||||||
services.Add(
|
services.Add(
|
||||||
new ServiceDescriptor(typeof(IXAiConversationTitleResourceProvider), typeof(XAiConversationTitleResourceProvider), lifeTime)
|
new ServiceDescriptor(typeof(IXAiConversationTitleResourceProvider), typeof(XAiConversationTitleResourceProvider), lifeTime)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Enrichers ...
|
||||||
|
services.Add(
|
||||||
|
new ServiceDescriptor(typeof(IXAiConversationEnricher), typeof(XAiConversationEnricher), lifeTime)
|
||||||
|
);
|
||||||
#endregion
|
#endregion
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using xAiModels.Models.Dtos;
|
||||||
|
|
||||||
|
namespace xAiModels.Interfaces.Enrichers
|
||||||
|
{
|
||||||
|
public interface IXAiConversationEnricher
|
||||||
|
{
|
||||||
|
Task EnrichAsync(
|
||||||
|
XAiConversationDto source,
|
||||||
|
XAiConversationDto destination,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
Task<IEnumerable<XAiConversationDto>> EnrichRangeAsync(
|
||||||
|
IEnumerable<XAiConversationDto> sources,
|
||||||
|
IEnumerable<XAiConversationDto> destinations,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,11 +26,21 @@ namespace xAiModels.Models.Dtos
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// All Exists Title Locale Resources ...
|
||||||
|
/// </summary>
|
||||||
|
public virtual XLocaleResourceDto[] TitleLocales { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Description of Project ...
|
/// Description of Project ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// All Exists Description Locale Resources ...
|
||||||
|
/// </summary>
|
||||||
|
public virtual XLocaleResourceDto[] DescriptionLocales { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// a Prompt for Project Start ...
|
/// a Prompt for Project Start ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,23 +1,485 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
using xAiModels.Interfaces.Dtos;
|
using xAiModels.Interfaces.Dtos;
|
||||||
|
using xAiModels.Interfaces.Enrichers;
|
||||||
using xAiModels.Interfaces.Entities;
|
using xAiModels.Interfaces.Entities;
|
||||||
using xAiModels.Models.Dtos;
|
using xAiModels.Models.Dtos;
|
||||||
using xAiModels.Models.Entities;
|
using xAiModels.Models.Entities;
|
||||||
|
using xCommons.Extensions;
|
||||||
using xDataService.Providers;
|
using xDataService.Providers;
|
||||||
|
using xModels.Dtos;
|
||||||
|
|
||||||
namespace xAiModels.Providers.Dtos
|
namespace xAiModels.Providers.Dtos
|
||||||
{
|
{
|
||||||
public class XAiConversationRepositoryService : XBaseRepositoryService<XAiConversation, XAiConversationDto, Guid>, IXAiConversationRepositoryService
|
public class XAiConversationRepositoryService : XBaseRepositoryService<XAiConversation, XAiConversationDto, Guid>, IXAiConversationRepositoryService
|
||||||
{
|
{
|
||||||
|
private readonly IXAiConversationEnricher enricher;
|
||||||
|
|
||||||
public XAiConversationRepositoryService(
|
public XAiConversationRepositoryService(
|
||||||
|
IXAiConversationEnricher enricher,
|
||||||
IXAiConversationRepository repository,
|
IXAiConversationRepository repository,
|
||||||
IEnumerable<Profile> mapperProfiles = null
|
IEnumerable<Profile> mapperProfiles = null
|
||||||
) : base(
|
) : base(
|
||||||
repository,
|
repository,
|
||||||
mapperProfiles
|
mapperProfiles
|
||||||
)
|
)
|
||||||
{ }
|
{
|
||||||
|
this.enricher = enricher;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Actions ...
|
||||||
|
//
|
||||||
|
#region Add ...
|
||||||
|
/// <summary>
|
||||||
|
/// add a new Dto ...
|
||||||
|
/// </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
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
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,
|
||||||
|
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="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override async Task<XAiConversationDto> AddOrUpdateAsync(
|
||||||
|
XAiConversationDto item,
|
||||||
|
bool saveChanges = 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,
|
||||||
|
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="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override async Task<XAiConversationDto> UpdateAsync(
|
||||||
|
Guid id,
|
||||||
|
XAiConversationDto 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())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await enricher.EnrichAsync(
|
||||||
|
source: result,
|
||||||
|
destination: result,
|
||||||
|
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<XAiConversationDto> 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<XAiConversationDto> RemoveAsync(
|
||||||
|
XAiConversationDto 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<XAiConversationDto> GetAsync(
|
||||||
|
Guid id,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, 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<XAiConversationDto>> GetAllAsync(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, 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<XAiConversationDto> GetAllAsAsyncEnumerable(
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||||
|
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, 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)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
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<XAiConversationDto> FindOneAsync(
|
||||||
|
Expression<Func<XAiConversation, bool>> predicate,
|
||||||
|
bool ignoreSoftDeleteds = true,
|
||||||
|
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, 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())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await enricher.EnrichAsync(
|
||||||
|
source: result,
|
||||||
|
destination: result,
|
||||||
|
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="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
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
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="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
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,194 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using xAiModels.Interfaces;
|
||||||
|
using xAiModels.Interfaces.Dtos;
|
||||||
|
using xAiModels.Interfaces.Enrichers;
|
||||||
|
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 IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
|
||||||
|
|
||||||
|
public XAiConversationEnricher(
|
||||||
|
IXIdentityProvider identityProvider,
|
||||||
|
IXAiProjectRepositoryService projectRepositoryService,
|
||||||
|
IXAiConversationTitleResourceProvider conversationTitleResourceProvider
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.identityProvider = identityProvider;
|
||||||
|
this.projectRepositoryService = projectRepositoryService;
|
||||||
|
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
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Run independent async operations concurrently
|
||||||
|
var ownerTask = ResolveOwnerAsync(source.OwnerId, cancellationToken);
|
||||||
|
var projectTask = ResolveProjectAsync(source.ProjectId, cancellationToken);
|
||||||
|
var titleLocalesTask = ResolveTitleLocalesAsync(source.Title, cancellationToken);
|
||||||
|
|
||||||
|
//
|
||||||
|
// wait until All Tasks Resolved ...
|
||||||
|
await Task.WhenAll(ownerTask, titleLocalesTask, projectTask);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Attached Resolved Info to Destination ...
|
||||||
|
destination.Owner = ownerTask.Result;
|
||||||
|
destination.TitleLocales = titleLocalesTask.Result;
|
||||||
|
var project = projectTask.Result;
|
||||||
|
if (!project.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
destination.ProjectTitle = project.Title;
|
||||||
|
destination.ProjectDescription = project.Description;
|
||||||
|
destination.ProjectTitleLocales = project.TitleLocales;
|
||||||
|
destination.ProjectDescriptionLocales = project.DescriptionLocales;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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<IEnumerable<XAiConversationDto>> EnrichRangeAsync(
|
||||||
|
IEnumerable<XAiConversationDto> sources,
|
||||||
|
IEnumerable<XAiConversationDto> destinations,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Make Tasks Ready ...
|
||||||
|
var tasks = sources.Zip(destinations, (src, dst) =>
|
||||||
|
EnrichAsync(src, dst, cancellationToken)
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
await Task.WhenAll(tasks);
|
||||||
|
|
||||||
|
//
|
||||||
|
return destinations;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
#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();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reading Title Locales ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="title"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task<XLocaleResourceDto[]> ResolveTitleLocalesAsync(
|
||||||
|
string title,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XLocaleResourceDto[] result = [];
|
||||||
|
if (title.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var locales = await conversationTitleResourceProvider.GetLocales(
|
||||||
|
identifier: title,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
result = [.. locales];
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve Project ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="projectId"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task<XAiProjectDto> ResolveProjectAsync(
|
||||||
|
Guid projectId,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XAiProjectDto result = null;
|
||||||
|
if (projectId.IsNull() || projectId.IsDefaultGuid())
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = await projectRepositoryService.GetAsync(
|
||||||
|
id: projectId,
|
||||||
|
includeBuilder: null,
|
||||||
|
ignoreSoftDeleteds: true,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user