79 lines
2.2 KiB
C#
79 lines
2.2 KiB
C#
using System.Linq;
|
|
using xModels.Dtos;
|
|
using System.Threading;
|
|
using xCommons.Extensions;
|
|
using xAiModels.Models.Dtos;
|
|
using System.Threading.Tasks;
|
|
using xAiModels.Models.Entities;
|
|
using System.Collections.Generic;
|
|
using xIdentityService.Interfaces;
|
|
using xAiModels.Interfaces.Enrichers;
|
|
|
|
namespace xAiModels.Providers.Enrichers
|
|
{
|
|
public class XAiMcpServerEnricher : IXAiMcpServerEnricher
|
|
{
|
|
private readonly IXPersonService personService;
|
|
|
|
public XAiMcpServerEnricher(
|
|
IXPersonService personService
|
|
)
|
|
{
|
|
this.personService = personService;
|
|
}
|
|
|
|
public virtual async Task<XAiMcpServerDto> Enrich(
|
|
XAiMcpServer source,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = source.MapConvert<XAiMcpServerDto, XAiMcpServer>();
|
|
result = await Enrich(
|
|
source: result,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
public virtual async Task<XAiMcpServerDto> Enrich(
|
|
XAiMcpServerDto source,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
XPersonDto owner = null;
|
|
if (!source.OwnerId.IsNullOrEmpty())
|
|
{
|
|
owner = await personService.GetPerson(source.OwnerId);
|
|
}
|
|
|
|
//
|
|
var result = source.MapConvert<XAiMcpServerDto, XAiMcpServerDto>();
|
|
result.Owner = owner;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
public virtual async Task<IEnumerable<XAiMcpServerDto>> EnrichRange(
|
|
IEnumerable<XAiMcpServer> sources,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
var tasks = sources.Select(x => Enrich(x, cancellationToken));
|
|
return await Task.WhenAll(tasks);
|
|
}
|
|
|
|
public virtual async Task<IEnumerable<XAiMcpServerDto>> EnrichRange(
|
|
IEnumerable<XAiMcpServerDto> sources,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
var tasks = sources.Select(x => Enrich(x, cancellationToken));
|
|
return await Task.WhenAll(tasks);
|
|
}
|
|
}
|
|
} |