last ...
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using xIdentityModels.Models;
|
using xModels.Dtos;
|
||||||
using xStringService.Models.Dtos;
|
using xStringService.Models.Dtos;
|
||||||
|
|
||||||
namespace xStringService.Interfaces
|
namespace xStringService.Interfaces
|
||||||
@@ -9,7 +9,7 @@ namespace xStringService.Interfaces
|
|||||||
public interface IXItemResourceProvider
|
public interface IXItemResourceProvider
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
#region All Item Actions ...
|
#region Group Actions ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve a List of Exists Languages for Current Item ...
|
/// Retrieve a List of Exists Languages for Current Item ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -27,23 +27,23 @@ namespace xStringService.Interfaces
|
|||||||
Task<IEnumerable<XStringDto>> GetResourceLocales(
|
Task<IEnumerable<XStringDto>> GetResourceLocales(
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove all Exists Locales which Related to this Provider ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task RemoveResourceLocales(
|
||||||
|
string connectionId = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
#region Single Item Actions ...
|
#region Item Actions ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve a List of Exists Languages for Current Item ...
|
/// Get all Exists Items for Specified identitifer ...
|
||||||
/// </summary>
|
|
||||||
/// <param name="identifier"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<IEnumerable<string>> GetLanguages(
|
|
||||||
object identifier,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieve all Exists Items of type ...
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="identifier"></param>
|
/// <param name="identifier"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
@@ -53,12 +53,108 @@ namespace xStringService.Interfaces
|
|||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|
||||||
Task<string> AddOrUpdateItemResourcer(
|
/// <summary>
|
||||||
|
/// Get all Exists Items for Specified identitifer ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XLocaleResourceDto>> GetLocales(
|
||||||
|
object identifier,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get all Exists Locales Representaion based on Specified Identitifer
|
||||||
|
/// as XResourceDto ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XResourceDto> GetResource(
|
||||||
|
object identifier,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add Or Update Locale for Specified Identitifer ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="locale"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XResourceDto> AddOrUpdateLocale(
|
||||||
|
object identifier,
|
||||||
|
XLocaleResourceDto locale,
|
||||||
|
string connectionId = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update a Resource State ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="resource"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XResourceDto> AddOrUpdateResource(
|
||||||
|
object identifier,
|
||||||
|
XResourceDto resource,
|
||||||
|
string connectionId = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove Specified Language Locale of Specified Identifier ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="language"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XResourceDto> RemoveLocale(
|
||||||
object identifier,
|
object identifier,
|
||||||
string language,
|
string language,
|
||||||
string translation,
|
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove all Exists Locales for Specified Identifier ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task RemoveLocales(
|
||||||
|
object identifier,
|
||||||
|
string connectionId = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check Specified ocale Exists for Specified Identifier ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="language"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> HasLocale(
|
||||||
|
object identifier,
|
||||||
|
string language,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get all Exists Languages for Specified Identifier ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<string>> GetLanguages(
|
||||||
|
object identifier,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using xIdentityModels.Models;
|
|
||||||
using xModels.Dtos;
|
using xModels.Dtos;
|
||||||
using xStringService.Models.Dtos;
|
using xStringService.Models.Dtos;
|
||||||
|
|
||||||
@@ -21,7 +20,6 @@ namespace xStringService.Interfaces
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve all Exists Items ...
|
/// Retrieve all Exists Items ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="resource">Specified Resource Title</param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<XStringDto>> GetResourceLocales(
|
Task<IEnumerable<XStringDto>> GetResourceLocales(
|
||||||
@@ -83,13 +81,11 @@ namespace xStringService.Interfaces
|
|||||||
/// Add or Update a Resource Model ...
|
/// Add or Update a Resource Model ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="resource">a XResourceDto Model ...</param>
|
/// <param name="resource">a XResourceDto Model ...</param>
|
||||||
/// <param name="userInfo">Actor User for Permissions ...</param>
|
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XResourceDto> AddOrUpdateResource(
|
Task<XResourceDto> AddOrUpdateResource(
|
||||||
XResourceDto resource,
|
XResourceDto resource,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
@@ -98,13 +94,11 @@ namespace xStringService.Interfaces
|
|||||||
/// Add Or Update Locale ...
|
/// Add Or Update Locale ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <param name="userInfo">Actor User for Permissions ...</param>
|
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XResourceDto> AddOrUpdateLocale(
|
Task<XResourceDto> AddOrUpdateLocale(
|
||||||
XLocaleResourceDto locale,
|
XLocaleResourceDto locale,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
@@ -113,13 +107,11 @@ namespace xStringService.Interfaces
|
|||||||
/// Remove Locale ...
|
/// Remove Locale ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <param name="userInfo">Actor User for Permissions ...</param>
|
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XResourceDto> RemoveLocale(
|
Task<XResourceDto> RemoveLocale(
|
||||||
XLocaleResourceDto locale,
|
XLocaleResourceDto locale,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
@@ -128,13 +120,11 @@ namespace xStringService.Interfaces
|
|||||||
/// Remove Specified Resource Model ...
|
/// Remove Specified Resource Model ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="resource">a XResourceDto Model ...</param>
|
/// <param name="resource">a XResourceDto Model ...</param>
|
||||||
/// <param name="userInfo">Actor User for Permissions ...</param>
|
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task RemoveResource(
|
Task RemoveResource(
|
||||||
XResourceDto resource,
|
XResourceDto resource,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
using xIdentityModels.Models;
|
|
||||||
using xModels.Dtos;
|
using xModels.Dtos;
|
||||||
using xStringService.Interfaces;
|
using xStringService.Interfaces;
|
||||||
using xStringService.Interfaces.Dtos;
|
using xStringService.Interfaces.Dtos;
|
||||||
@@ -15,6 +14,8 @@ namespace xStringService.Providers
|
|||||||
{
|
{
|
||||||
public abstract class XBaseItemResourceProvider : IXItemResourceProvider
|
public abstract class XBaseItemResourceProvider : IXItemResourceProvider
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
#region Props ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Item Name for Resource Providing ...
|
/// Item Name for Resource Providing ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -30,6 +31,7 @@ namespace xStringService.Providers
|
|||||||
/// String Provider Service ...
|
/// String Provider Service ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IXStringServiceProvider stringProvider;
|
private readonly IXStringServiceProvider stringProvider;
|
||||||
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
#region Constructor ...
|
#region Constructor ...
|
||||||
@@ -49,22 +51,20 @@ namespace xStringService.Providers
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
#region All Item Actions ...
|
#region Group Actions ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve a List of Exists Languages for Current Item ...
|
/// Retrieve a List of Exists Languages for Current Item ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<IEnumerable<string>> GetLanguages(
|
public virtual async Task<IEnumerable<string>> GetLanguages(
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
var result =
|
var result = (await ExtractItems(cancellationToken))
|
||||||
(await GetResourceLocales(cancellationToken))
|
|
||||||
.Select(x => x.Language)
|
.Select(x => x.Language)
|
||||||
.Distinct()
|
.Distinct();
|
||||||
.ToList();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
@@ -75,142 +75,436 @@ namespace xStringService.Providers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<IEnumerable<XStringDto>> GetResourceLocales(
|
public virtual async Task<IEnumerable<XStringDto>> GetResourceLocales(
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
var identifier = GetResourceTitle();
|
var result = await ExtractItems(cancellationToken);
|
||||||
var result = await stringProvider
|
|
||||||
.FindManyAsync(
|
//
|
||||||
includeBuilder: null,
|
return result;
|
||||||
ignoreSoftDeleteds: true,
|
}
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
orderBuilder:
|
/// <summary>
|
||||||
x => x
|
/// Remove all Exists Locales which Related to this Provider ...
|
||||||
.OrderBy(y => y.Language)
|
/// </summary>
|
||||||
.ThenBy(y => y.ResourceTitle),
|
/// <param name="connectionId"></param>
|
||||||
predicate: x =>
|
/// <param name="cancellationToken"></param>
|
||||||
x.ResourceTitle.StartsWith(identifier, StringComparison.InvariantCultureIgnoreCase)
|
/// <returns></returns>
|
||||||
|
public virtual async Task RemoveResourceLocales(
|
||||||
|
string connectionId = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var isDelete = false;
|
||||||
|
XStringDto deleted = null;
|
||||||
|
var items = await ExtractItems(cancellationToken);
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Cancellation ...
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Remove Item ...
|
||||||
|
deleted = await stringProvider.RemoveAsync(
|
||||||
|
id: item.Id,
|
||||||
|
softDelete: false,
|
||||||
|
saveChanges: true,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Removation Succeed ...
|
||||||
|
isDelete = !deleted.IsNullOrDefault();
|
||||||
|
if (!isDelete)
|
||||||
|
{
|
||||||
|
XException.ActionFailed.Throw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Item Actions ...
|
||||||
|
/// <summary>
|
||||||
|
/// Get all Exists Items for Specified identitifer ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual async Task<IEnumerable<XStringDto>> GetResourceLocales(
|
||||||
|
object identifier,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
var isValid = !identifier.IsNull();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Setting Resource Title ...
|
||||||
|
SetResourceTitle(identifier);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Resource List ...
|
||||||
|
var result = await provider
|
||||||
|
.GetResourceLocales(cancellationToken);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get all Exists Items for Specified identitifer ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual async Task<IEnumerable<XLocaleResourceDto>> GetLocales(
|
||||||
|
object identifier,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
var isValid = !identifier.IsNull();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Setting Resource Title ...
|
||||||
|
SetResourceTitle(identifier);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Resource List ...
|
||||||
|
var result = await provider
|
||||||
|
.GetLocales(cancellationToken);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get all Exists Locales Representaion based on Specified Identitifer
|
||||||
|
/// as XResourceDto ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual async Task<XResourceDto> GetResource(
|
||||||
|
object identifier,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
var isValid = !identifier.IsNull();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Setting Resource Title ...
|
||||||
|
SetResourceTitle(identifier);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Resource List ...
|
||||||
|
var result = await provider
|
||||||
|
.GetResource(cancellationToken);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add Or Update Locale for Specified Identitifer ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="locale"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual async Task<XResourceDto> AddOrUpdateLocale(
|
||||||
|
object identifier,
|
||||||
|
XLocaleResourceDto locale,
|
||||||
|
string connectionId = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
var isValid =
|
||||||
|
!identifier.IsNull() &&
|
||||||
|
!locale.IsNullOrDefault() &&
|
||||||
|
!locale.Value.IsNullOrEmpty() &&
|
||||||
|
!locale.Language.IsNullOrEmpty();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Setting Resource Title ...
|
||||||
|
SetResourceTitle(identifier);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Resource List ...
|
||||||
|
var result = await provider
|
||||||
|
.AddOrUpdateLocale(
|
||||||
|
locale: locale,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Single Item Actions ...
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve a List of Exists Languages for Current Item ...
|
/// Update a Resource State ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="identifier"></param>
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="resource"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<IEnumerable<string>> GetLanguages(
|
public virtual async Task<XResourceDto> AddOrUpdateResource(
|
||||||
object identifier,
|
object identifier,
|
||||||
|
XResourceDto resource,
|
||||||
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Validate ...
|
// Validate ...
|
||||||
var isValid = !identifier.IsNull();
|
var isValid =
|
||||||
|
!identifier.IsNull();
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
{
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set Identifier ...
|
// Retrieve Identified Resource Title ...
|
||||||
SetResourceTitle(identifier);
|
var identifiedResource = GetResourceTitle(identifier);
|
||||||
|
isValid =
|
||||||
//
|
!resource.IsNullOrDefault() &&
|
||||||
var result =
|
(resource.Resource.IsNullOrEmpty() ||
|
||||||
await provider.GetLanguages(cancellationToken);
|
resource.Resource == identifiedResource);
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieve all Exists Items of type ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="identifier"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<IEnumerable<XStringDto>> GetResourceLocales(
|
|
||||||
object identifier,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate ...
|
|
||||||
var isValid = !identifier.IsNull();
|
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
{
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
|
if (resource.Resource.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
resource.Resource = identifiedResource;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set Identifier ...
|
// Setting Resource Title ...
|
||||||
SetResourceTitle(identifier);
|
SetResourceTitle(identifier);
|
||||||
|
|
||||||
//
|
//
|
||||||
var result =
|
// Retrieve Resource List ...
|
||||||
await provider.GetResourceLocales(cancellationToken);
|
var result = await provider
|
||||||
|
.AddOrUpdateResource(
|
||||||
|
resource: resource,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> AddOrUpdateItemResourcer(
|
/// <summary>
|
||||||
|
/// Remove Specified Language Locale of Specified Identifier ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="language"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual async Task<XResourceDto> RemoveLocale(
|
||||||
object identifier,
|
object identifier,
|
||||||
string language,
|
string language,
|
||||||
string translation,
|
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
var result = string.Empty;
|
// Validate ...
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Args ...
|
|
||||||
var isValid =
|
var isValid =
|
||||||
!identifier.IsNull() &&
|
!identifier.IsNull() &&
|
||||||
!language.IsNullOrEmpty() &&
|
!language.IsNullOrEmpty();
|
||||||
!translation.IsNullOrEmpty();
|
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
{
|
{
|
||||||
return result;
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Prepare Identifier ...
|
// Check Locale Exists ...
|
||||||
var resourceTitle = GetResourceTitle(identifier);
|
isValid = await HasLocale(
|
||||||
|
language: language,
|
||||||
|
identifier: identifier,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set Resource Title ...
|
var locale = (await GetLocales(
|
||||||
SetResourceTitle(resourceTitle);
|
identifier: identifier,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
))
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
x.Language.Equals(language, StringComparison.InvariantCultureIgnoreCase));
|
||||||
|
isValid = !locale.IsNullOrDefault();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Try to Add Or Update ...
|
// Setting Resource Title ...
|
||||||
var resource = await provider.AddOrUpdateLocale(
|
SetResourceTitle(identifier);
|
||||||
userInfo: userInfo,
|
|
||||||
|
//
|
||||||
|
var result = await provider.RemoveLocale(
|
||||||
|
locale: locale,
|
||||||
connectionId: connectionId,
|
connectionId: connectionId,
|
||||||
locale: new XLocaleResourceDto
|
|
||||||
{
|
|
||||||
Language = language,
|
|
||||||
Value = translation
|
|
||||||
},
|
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Validate Result ...
|
return result;
|
||||||
isValid = !resource.IsNullOrDefault();
|
}
|
||||||
if (isValid)
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove all Exists Locales for Specified Identifier ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual async Task RemoveLocales(
|
||||||
|
object identifier,
|
||||||
|
string connectionId = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
var isValid =
|
||||||
|
!identifier.IsNull();
|
||||||
|
if (!isValid)
|
||||||
{
|
{
|
||||||
result = resourceTitle;
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var resource = await GetResource(
|
||||||
|
identifier: identifier,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
isValid = !resource.IsNullOrDefault();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Setting Resource Title ...
|
||||||
|
SetResourceTitle(identifier);
|
||||||
|
|
||||||
|
//
|
||||||
|
await provider.RemoveResource(
|
||||||
|
resource: resource,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check Specified ocale Exists for Specified Identifier ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="language"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual async Task<bool> HasLocale(
|
||||||
|
object identifier,
|
||||||
|
string language,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
var isValid =
|
||||||
|
!identifier.IsNull() &&
|
||||||
|
!language.IsNullOrEmpty();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Setting Resource Title ...
|
||||||
|
SetResourceTitle(identifier);
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.HasLocale(
|
||||||
|
language: language,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get all Exists Languages for Specified Identifier ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual async Task<IEnumerable<string>> GetLanguages(
|
||||||
|
object identifier,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
var isValid = !identifier.IsNull();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Setting Resource Title ...
|
||||||
|
SetResourceTitle(identifier);
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider
|
||||||
|
.GetLanguages(cancellationToken);
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -251,6 +545,29 @@ namespace xStringService.Providers
|
|||||||
value: $"{itemIdentifier}"
|
value: $"{itemIdentifier}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// xtract all Items which Belongs to Provider ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task<IEnumerable<XStringDto>> ExtractItems(
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = await stringProvider
|
||||||
|
.FindManyAsync(
|
||||||
|
includeBuilder: null,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
orderBuilder: x => x.OrderBy(y => y.Id),
|
||||||
|
predicate: x =>
|
||||||
|
x.ResourceTitle.StartsWith(
|
||||||
|
item,
|
||||||
|
StringComparison.InvariantCultureIgnoreCase)
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,6 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
using xIdentityModels.Models;
|
|
||||||
using xModels.Dtos;
|
using xModels.Dtos;
|
||||||
using xStringService.Extensions;
|
using xStringService.Extensions;
|
||||||
using xStringService.Interfaces;
|
using xStringService.Interfaces;
|
||||||
@@ -181,13 +180,11 @@ namespace xStringService.Providers
|
|||||||
/// Add or Update a Resource Model ...
|
/// Add or Update a Resource Model ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="resource">a XResourceDto Model ...</param>
|
/// <param name="resource">a XResourceDto Model ...</param>
|
||||||
/// <param name="userInfo">Actor User for Permissions ...</param>
|
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual async Task<XResourceDto> AddOrUpdateResource(
|
public virtual async Task<XResourceDto> AddOrUpdateResource(
|
||||||
XResourceDto resource,
|
XResourceDto resource,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
@@ -209,7 +206,6 @@ namespace xStringService.Providers
|
|||||||
{
|
{
|
||||||
await RemoveResource(
|
await RemoveResource(
|
||||||
resource: result,
|
resource: result,
|
||||||
userInfo: userInfo,
|
|
||||||
connectionId: connectionId,
|
connectionId: connectionId,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
@@ -248,7 +244,6 @@ namespace xStringService.Providers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual async Task<XResourceDto> AddOrUpdateLocale(
|
public virtual async Task<XResourceDto> AddOrUpdateLocale(
|
||||||
XLocaleResourceDto locale,
|
XLocaleResourceDto locale,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
@@ -297,11 +292,11 @@ namespace xStringService.Providers
|
|||||||
/// Remove Locale ...
|
/// Remove Locale ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual async Task<XResourceDto> RemoveLocale(
|
public virtual async Task<XResourceDto> RemoveLocale(
|
||||||
XLocaleResourceDto locale,
|
XLocaleResourceDto locale,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
@@ -334,17 +329,26 @@ namespace xStringService.Providers
|
|||||||
/// Remove Specified Resource Model ...
|
/// Remove Specified Resource Model ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="resource">a XResourceDto Model ...</param>
|
/// <param name="resource">a XResourceDto Model ...</param>
|
||||||
/// <param name="userInfo">Actor User for Permissions ...</param>
|
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual async Task RemoveResource(
|
public virtual async Task RemoveResource(
|
||||||
XResourceDto resource,
|
XResourceDto resource,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
// Validate Resource ...
|
||||||
|
var isValid =
|
||||||
|
!resource.IsNullOrDefault() &&
|
||||||
|
!resource.Resource.IsNullOrEmpty() &&
|
||||||
|
resource.Resource == this.resource;
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var items = await ExtractItems(cancellationToken);
|
var items = await ExtractItems(cancellationToken);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user