794 lines
24 KiB
C#
794 lines
24 KiB
C#
using System;
|
|
using AutoMapper;
|
|
using System.Linq;
|
|
using xModels.Dtos;
|
|
using xIds.DbContext;
|
|
using System.Threading;
|
|
using xCommons.Extensions;
|
|
using xIds.Configurations;
|
|
using xIdentityModels.Dtos;
|
|
using xExceptions.Constants;
|
|
using System.Threading.Tasks;
|
|
using xIdentityModels.Models;
|
|
using xDataService.Extensions;
|
|
using System.Linq.Expressions;
|
|
using xIdentityModels.Extensions;
|
|
using System.Collections.Generic;
|
|
using xIdentityService.Interfaces;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
|
|
|
namespace xIds.Providers
|
|
{
|
|
public class XScopeProvider : IXScopeProvider
|
|
{
|
|
//
|
|
private readonly string permittedRole;
|
|
private readonly XIdentityDbContext dbContext;
|
|
private readonly XDataServiceConfiguration configuration;
|
|
private readonly Action<IMapperConfigurationExpression> mapperConfigurationExp;
|
|
|
|
public XScopeProvider(
|
|
XIdentityDbContext dbContext,
|
|
XDataServiceConfiguration configuration,
|
|
string permittedRole = "admin"
|
|
)
|
|
{
|
|
//
|
|
this.dbContext = dbContext;
|
|
this.permittedRole = permittedRole;
|
|
this.configuration = configuration;
|
|
|
|
//
|
|
// Configure Mapper Options ...
|
|
mapperConfigurationExp = cfg =>
|
|
{
|
|
//
|
|
cfg.CreateMap<XRoleDefinition, XRoleDefinitionDto>()
|
|
.ReverseMap();
|
|
|
|
//
|
|
cfg.CreateMap<XScopeDefinition, XScopeDefinitionDto>()
|
|
.ReverseMap();
|
|
|
|
//
|
|
cfg.CreateMap<XPolicyDefinition, XPolicyDefinitionDto>()
|
|
.ReverseMap();
|
|
};
|
|
}
|
|
|
|
//
|
|
#region Permission ...
|
|
private bool HasPermission(
|
|
XUserClaimsInfoDto userInfo = null
|
|
)
|
|
{
|
|
//
|
|
var result = permittedRole.IsNullOrEmpty();
|
|
if (result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result =
|
|
!userInfo.IsNullOrDefault() &&
|
|
userInfo.Roles
|
|
.Any(ur => ur.Equals(
|
|
permittedRole,
|
|
StringComparison.InvariantCultureIgnoreCase));
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Readers ...
|
|
/// <summary>
|
|
/// retrieve whole items as queryable ...
|
|
/// </summary>
|
|
/// <param name="asNoTracking">a flag for Tracking behaviour</param>
|
|
/// <param name="predicate">an Expression for Filter Items ...</param>
|
|
/// <param name="orderBuilder">an Order Builder expression for Ordering Query ...</param>
|
|
/// <returns></returns>
|
|
public virtual IQueryable<XScopeDefinition> AsQueryable(
|
|
bool asNoTracking = true,
|
|
Expression<Func<XScopeDefinition, bool>> predicate = null,
|
|
Func<IQueryable<XScopeDefinition>, IOrderedQueryable<XScopeDefinition>> orderBuilder = null
|
|
)
|
|
{
|
|
//
|
|
var result = dbContext.ScopeDefinitions
|
|
.Where(predicate)
|
|
.AsQueryable();
|
|
if (asNoTracking)
|
|
{
|
|
result = result.AsNoTracking();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// retrieve an Entity by it's Id ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="ignoreSoftDeleteds"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XScopeDefinitionDto> GetAsync(
|
|
int id,
|
|
bool ignoreSoftDeleteds = true,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (!id.IsValidIntId())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
var result = await FindOneAsync(x => x.Id.Equals(id));
|
|
if (result.IsNullOrDefault())
|
|
{
|
|
XException.NotFound.Throw();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// retrieve all exists Entities ...
|
|
/// </summary>
|
|
/// <param name="ignoreSoftDeleteds"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<IEnumerable<XScopeDefinitionDto>> GetAllAsync(
|
|
bool ignoreSoftDeleteds = true,
|
|
Func<IQueryable<XScopeDefinition>, IOrderedQueryable<XScopeDefinition>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
// Prepare Predicate ...
|
|
Expression<Func<XScopeDefinition, bool>> predicator = null;
|
|
if (ignoreSoftDeleteds)
|
|
{
|
|
predicator = x => !x.Deleted;
|
|
}
|
|
|
|
//
|
|
var queryable = AsQueryable(
|
|
asNoTracking: true,
|
|
predicate: predicator,
|
|
orderBuilder: orderBuilder
|
|
);
|
|
|
|
//
|
|
var items = await queryable
|
|
.ToListAsync(cancellationToken);
|
|
var result = await EnrichRangeAsync(
|
|
sources: items,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// find an Entity by providing a Conditional Expression ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="ignoreSoftDeleteds"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XScopeDefinitionDto> FindOneAsync(
|
|
Expression<Func<XScopeDefinition, bool>> predicate,
|
|
bool ignoreSoftDeleteds = true,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
// Prepare Predicate ...
|
|
Expression<Func<XScopeDefinition, bool>> predicator = null;
|
|
if (ignoreSoftDeleteds)
|
|
{
|
|
predicator = x => !x.Deleted;
|
|
}
|
|
|
|
//
|
|
var queryable = AsQueryable(
|
|
asNoTracking: true,
|
|
orderBuilder: null,
|
|
predicate: predicator
|
|
);
|
|
|
|
//
|
|
var item = await queryable
|
|
.FirstOrDefaultAsync(cancellationToken);
|
|
var result = await EnrichAsync(
|
|
source: item,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// find a collection of Entities by proving a Conditional Expression ...
|
|
/// </summary>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="ignoreSoftDeleteds"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<IEnumerable<XScopeDefinitionDto>> FindManyAsync(
|
|
Expression<Func<XScopeDefinition, bool>> predicate,
|
|
bool ignoreSoftDeleteds = true,
|
|
Func<IQueryable<XScopeDefinition>, IOrderedQueryable<XScopeDefinition>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
// Prepare Predicate ...
|
|
Expression<Func<XScopeDefinition, bool>> predicator = null;
|
|
if (ignoreSoftDeleteds)
|
|
{
|
|
predicator = x => !x.Deleted;
|
|
}
|
|
|
|
//
|
|
var queryable = AsQueryable(
|
|
asNoTracking: true,
|
|
predicate: predicator,
|
|
orderBuilder: orderBuilder
|
|
);
|
|
|
|
//
|
|
var items = await queryable
|
|
.ToListAsync(cancellationToken);
|
|
var result = await EnrichRangeAsync(
|
|
sources: items,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// count all exists Entities ...
|
|
/// </summary>
|
|
/// <param name="ignoreSoftDeleteds"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<int> CountAsync(
|
|
bool ignoreSoftDeleteds = true,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
// Prepare Predicate ...
|
|
Expression<Func<XScopeDefinition, bool>> predicator = null;
|
|
if (ignoreSoftDeleteds)
|
|
{
|
|
predicator = x => !x.Deleted;
|
|
}
|
|
|
|
//
|
|
var queryable = AsQueryable(
|
|
asNoTracking: true,
|
|
orderBuilder: null,
|
|
predicate: predicator
|
|
);
|
|
|
|
//
|
|
var result = await queryable.CountAsync();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// count all exists Entities Pages by providing page size ...
|
|
/// </summary>
|
|
/// <param name="pageSize"></param>
|
|
/// <param name="totalItems"></param>
|
|
/// <param name="ignoreSoftDeleteds"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<int> PagesCountAsync(
|
|
int pageSize,
|
|
int? totalItems = null,
|
|
bool ignoreSoftDeleteds = true,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
int count = totalItems.HasValue ? totalItems.Value : await CountAsync(
|
|
cancellationToken: cancellationToken,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
int pagesCount = count / pageSize;
|
|
|
|
//
|
|
if (count % pageSize > 0)
|
|
{
|
|
pagesCount++;
|
|
}
|
|
|
|
//
|
|
return pagesCount;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check an Entity exists or not ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="ignoreSoftDeleteds"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<bool> IsExistsAsync(
|
|
int id,
|
|
bool ignoreSoftDeleteds = true,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = false;
|
|
|
|
//
|
|
try
|
|
{
|
|
//
|
|
var exists = await GetAsync(
|
|
id: id,
|
|
cancellationToken: cancellationToken,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
|
|
//
|
|
result = !exists.IsNullOrDefault();
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Query ...
|
|
/// <summary>
|
|
/// retrieve Entities based on XQuery Pagination structure ...
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <param name="ignoreSoftDeleteds"></param>
|
|
/// <param name="predicate"></param>
|
|
/// <param name="orderBuilder"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XQueryResult<XScopeDefinitionDto>> QueryAsync(
|
|
XQuery query,
|
|
bool ignoreSoftDeleteds = true,
|
|
Expression<Func<XScopeDefinition, bool>> predicate = null,
|
|
Func<IQueryable<XScopeDefinition>, IOrderedQueryable<XScopeDefinition>> orderBuilder = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
// Normalize Query ...
|
|
query = NormalizeQuery(
|
|
source: query,
|
|
configuration: configuration
|
|
);
|
|
|
|
//
|
|
var items = await GetAllAsync(
|
|
orderBuilder: orderBuilder,
|
|
cancellationToken: cancellationToken,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
var totalItemsCount = items.Count();
|
|
|
|
//
|
|
// Apply Filter ...
|
|
if (!query.Filter.IsNullOrEmpty())
|
|
{
|
|
//
|
|
items = items
|
|
.ApplyFilter(query.Filter);
|
|
}
|
|
int filteredItemsCount = items.Count();
|
|
|
|
//
|
|
// Count Pages ...
|
|
var totalPagesCount = query.CountPages(totalItemsCount);
|
|
var filteredPagesCount = query.CountPages(filteredItemsCount);
|
|
|
|
//
|
|
// Apply Paging and Sorting ...
|
|
if (totalItemsCount > 0 &&
|
|
filteredItemsCount > 0)
|
|
{
|
|
//
|
|
// Apply Sorting ...
|
|
items = items
|
|
.ToList()
|
|
.ApplySorting(
|
|
query.SortBy,
|
|
query.IsAscending
|
|
);
|
|
|
|
//
|
|
// Apply Paging ...
|
|
items = items
|
|
.ToList()
|
|
.ApplyPaging(
|
|
query.Page,
|
|
query.PageSize
|
|
);
|
|
}
|
|
|
|
//
|
|
var resultItems = await EnrichRangeAsync(
|
|
sources: items,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
// Prepare Result ...
|
|
var result = new XQueryResult<XScopeDefinitionDto>
|
|
{
|
|
Page = query.Page,
|
|
Items = [.. resultItems],
|
|
PageSize = query.PageSize,
|
|
TotalPages = totalPagesCount,
|
|
TotalItems = totalItemsCount,
|
|
TotalFilteredPages = filteredPagesCount,
|
|
TotalFilteredItems = filteredItemsCount
|
|
};
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Add/Update/Remove ...
|
|
/// <summary>
|
|
/// add a new Entity ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="saveChanges"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XScopeDefinitionDto> AddAsync(
|
|
XScopeDefinitionDto item,
|
|
bool saveChanges = true,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (!item.IsValidForAdd())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
// Permission ...
|
|
var hasPermission = HasPermission(userInfo);
|
|
if (!hasPermission)
|
|
{
|
|
XException.NotAuthorized.Throw();
|
|
}
|
|
|
|
//
|
|
var entity = item.MapConvert<XScopeDefinition, XScopeDefinitionDto>();
|
|
var entry = await dbContext.ScopeDefinitions.AddAsync(
|
|
entity: entity,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
var changes = await dbContext.SaveChangesAsync(cancellationToken);
|
|
var isChanged =
|
|
changes > 0 &&
|
|
!entry.IsNull() &&
|
|
!entry.Entity.IsNullOrDefault();
|
|
if (!isChanged)
|
|
{
|
|
XException.ActionFailed.Throw();
|
|
}
|
|
|
|
//
|
|
var result = await EnrichAsync(
|
|
source: entry.Entity,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update an Entity values ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="item"></param>
|
|
/// <param name="saveChanges"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XScopeDefinitionDto> UpdateAsync(
|
|
int id,
|
|
XScopeDefinitionDto item,
|
|
bool saveChanges = true,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (id != item.Id ||
|
|
!id.IsValidIntId() ||
|
|
!item.IsValidForAdd())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
// Permission ...
|
|
var hasPermission = HasPermission(userInfo);
|
|
if (!hasPermission)
|
|
{
|
|
XException.NotAuthorized.Throw();
|
|
}
|
|
|
|
//
|
|
// Retrieve Exists Entity ...
|
|
var exists = await dbContext.ScopeDefinitions
|
|
.FirstOrDefaultAsync(x => x.Id == id && !x.Deleted);
|
|
if (exists.IsNullOrDefault())
|
|
{
|
|
XException.NotFound.Throw();
|
|
}
|
|
|
|
//
|
|
// Update Data on Exists Entity ...
|
|
exists = exists.UpdateData(
|
|
updateWith: item,
|
|
propertyWhiteList: [],
|
|
propertyBlackList: [
|
|
nameof(XPolicyDefinition.Id),
|
|
]
|
|
);
|
|
|
|
//
|
|
var entry = dbContext.ScopeDefinitions.Attach(exists);
|
|
entry.State = EntityState.Modified;
|
|
|
|
//
|
|
var changes = await dbContext.SaveChangesAsync(cancellationToken);
|
|
var isChanged =
|
|
changes > 0 &&
|
|
!entry.IsNull() &&
|
|
!entry.Entity.IsNullOrDefault();
|
|
if (!isChanged)
|
|
{
|
|
XException.ActionFailed.Throw();
|
|
}
|
|
|
|
//
|
|
var result = await EnrichAsync(
|
|
source: entry.Entity,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// remove an Entity by it's Id ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="softDelete"></param>
|
|
/// <param name="saveChanges"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XScopeDefinitionDto> RemoveAsync(
|
|
int id,
|
|
bool softDelete = true,
|
|
bool saveChanges = true,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (!id.IsValidIntId())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
// Permission ...
|
|
var hasPermission = HasPermission(userInfo);
|
|
if (!hasPermission)
|
|
{
|
|
XException.NotAuthorized.Throw();
|
|
}
|
|
|
|
//
|
|
// Retrieve Exists Entity ...
|
|
var exists = await dbContext.ScopeDefinitions
|
|
.FirstOrDefaultAsync(x => x.Id == id && !x.Deleted);
|
|
if (exists.IsNullOrDefault())
|
|
{
|
|
XException.NotFound.Throw();
|
|
}
|
|
|
|
//
|
|
EntityEntry<XScopeDefinition> entry = null;
|
|
if (softDelete)
|
|
{
|
|
//
|
|
exists.Deleted = true;
|
|
entry = dbContext.ScopeDefinitions.Update(exists);
|
|
}
|
|
else
|
|
{
|
|
entry = dbContext.ScopeDefinitions.Remove(exists);
|
|
}
|
|
|
|
//
|
|
var changes = await dbContext.SaveChangesAsync(cancellationToken);
|
|
var isChanged =
|
|
changes > 0 &&
|
|
!entry.IsNull() &&
|
|
!entry.Entity.IsNullOrDefault();
|
|
if (!isChanged)
|
|
{
|
|
XException.ActionFailed.Throw();
|
|
}
|
|
|
|
//
|
|
var result = await EnrichAsync(
|
|
source: entry.Entity,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Custom ...
|
|
/// <summary>
|
|
/// Normalize an XQuery based on Data Service Configurations ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="configuration"></param>
|
|
/// <returns></returns>
|
|
public XQuery NormalizeQuery(
|
|
XQuery source,
|
|
XDataServiceConfiguration configuration //
|
|
)
|
|
{
|
|
//
|
|
if (source.IsNull())
|
|
{
|
|
source = new XQuery();
|
|
}
|
|
|
|
//
|
|
// Page Size Normalization ...
|
|
if (source.PageSize < configuration.PagingConfiguration.MinAvailablePageSize)
|
|
{
|
|
source.PageSize = configuration.PagingConfiguration.MinAvailablePageSize;
|
|
}
|
|
if (source.PageSize > configuration.PagingConfiguration.MaxAvailablePageSize)
|
|
{
|
|
source.PageSize = configuration.PagingConfiguration.MaxAvailablePageSize;
|
|
}
|
|
|
|
//
|
|
return source;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Enrichers ...
|
|
/// <summary>
|
|
/// Enrich Item ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XScopeDefinitionDto> EnrichAsync(
|
|
XScopeDefinition source,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = source.MapConvert<XScopeDefinitionDto, XScopeDefinition>();
|
|
result = await EnrichAsync(
|
|
source: result,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Enrich Item ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<XScopeDefinitionDto> EnrichAsync(
|
|
XScopeDefinitionDto source,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await Task.FromResult(source);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Enrich a Collection of Items(s) ...
|
|
/// </summary>
|
|
/// <param name="sources"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<IEnumerable<XScopeDefinitionDto>> EnrichRangeAsync(
|
|
IEnumerable<XScopeDefinition> sources,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var tasks = sources
|
|
.Select(s => EnrichAsync(s, cancellationToken));
|
|
|
|
//
|
|
var result = await Task.WhenAll(tasks);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Enrich a Collection of Items(s) ...
|
|
/// </summary>
|
|
/// <param name="sources"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task<IEnumerable<XScopeDefinitionDto>> EnrichRangeAsync(
|
|
IEnumerable<XScopeDefinitionDto> sources,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var tasks = sources
|
|
.Select(s => EnrichAsync(s, cancellationToken));
|
|
|
|
//
|
|
var result = await Task.WhenAll(tasks);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
}
|
|
} |