diff --git a/Interfaces/IXItemResourceProvider.cs b/Interfaces/IXItemResourceProvider.cs
index 863a171..2125454 100644
--- a/Interfaces/IXItemResourceProvider.cs
+++ b/Interfaces/IXItemResourceProvider.cs
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
-using xIdentityModels.Models;
+using xModels.Dtos;
using xStringService.Models.Dtos;
namespace xStringService.Interfaces
@@ -9,7 +9,7 @@ namespace xStringService.Interfaces
public interface IXItemResourceProvider
{
//
- #region All Item Actions ...
+ #region Group Actions ...
///
/// Retrieve a List of Exists Languages for Current Item ...
///
@@ -27,23 +27,23 @@ namespace xStringService.Interfaces
Task> GetResourceLocales(
CancellationToken cancellationToken = default
);
+
+ ///
+ /// Remove all Exists Locales which Related to this Provider ...
+ ///
+ ///
+ ///
+ ///
+ Task RemoveResourceLocales(
+ string connectionId = null,
+ CancellationToken cancellationToken = default
+ );
#endregion
//
- #region Single Item Actions ...
+ #region Item Actions ...
///
- /// Retrieve a List of Exists Languages for Current Item ...
- ///
- ///
- ///
- ///
- Task> GetLanguages(
- object identifier,
- CancellationToken cancellationToken = default
- );
-
- ///
- /// Retrieve all Exists Items of type ...
+ /// Get all Exists Items for Specified identitifer ...
///
///
///
@@ -53,12 +53,108 @@ namespace xStringService.Interfaces
CancellationToken cancellationToken = default
);
- Task AddOrUpdateItemResourcer(
+ ///
+ /// Get all Exists Items for Specified identitifer ...
+ ///
+ ///
+ ///
+ ///
+ Task> GetLocales(
+ object identifier,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Get all Exists Locales Representaion based on Specified Identitifer
+ /// as XResourceDto ...
+ ///
+ ///
+ ///
+ ///
+ Task GetResource(
+ object identifier,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Add Or Update Locale for Specified Identitifer ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task AddOrUpdateLocale(
+ object identifier,
+ XLocaleResourceDto locale,
+ string connectionId = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Update a Resource State ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task AddOrUpdateResource(
+ object identifier,
+ XResourceDto resource,
+ string connectionId = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Remove Specified Language Locale of Specified Identifier ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task RemoveLocale(
object identifier,
string language,
- string translation,
string connectionId = null,
- XUserClaimsInfoDto userInfo = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Remove all Exists Locales for Specified Identifier ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task RemoveLocales(
+ object identifier,
+ string connectionId = null,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Check Specified ocale Exists for Specified Identifier ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task HasLocale(
+ object identifier,
+ string language,
+ CancellationToken cancellationToken = default
+ );
+
+ ///
+ /// Get all Exists Languages for Specified Identifier ...
+ ///
+ ///
+ ///
+ ///
+ Task> GetLanguages(
+ object identifier,
CancellationToken cancellationToken = default
);
#endregion
diff --git a/Interfaces/IXResourceProvider.cs b/Interfaces/IXResourceProvider.cs
index b0d8529..a6a6795 100644
--- a/Interfaces/IXResourceProvider.cs
+++ b/Interfaces/IXResourceProvider.cs
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
-using xIdentityModels.Models;
using xModels.Dtos;
using xStringService.Models.Dtos;
@@ -21,7 +20,6 @@ namespace xStringService.Interfaces
///
/// Retrieve all Exists Items ...
///
- /// Specified Resource Title
///
///
Task> GetResourceLocales(
@@ -83,13 +81,11 @@ namespace xStringService.Interfaces
/// Add or Update a Resource Model ...
///
/// a XResourceDto Model ...
- /// Actor User for Permissions ...
///
///
///
Task AddOrUpdateResource(
XResourceDto resource,
- XUserClaimsInfoDto userInfo = null,
string connectionId = null,
CancellationToken cancellationToken = default
);
@@ -98,13 +94,11 @@ namespace xStringService.Interfaces
/// Add Or Update Locale ...
///
///
- /// Actor User for Permissions ...
///
///
///
Task AddOrUpdateLocale(
XLocaleResourceDto locale,
- XUserClaimsInfoDto userInfo = null,
string connectionId = null,
CancellationToken cancellationToken = default
);
@@ -113,13 +107,11 @@ namespace xStringService.Interfaces
/// Remove Locale ...
///
///
- /// Actor User for Permissions ...
///
///
///
Task RemoveLocale(
XLocaleResourceDto locale,
- XUserClaimsInfoDto userInfo = null,
string connectionId = null,
CancellationToken cancellationToken = default
);
@@ -128,13 +120,11 @@ namespace xStringService.Interfaces
/// Remove Specified Resource Model ...
///
/// a XResourceDto Model ...
- /// Actor User for Permissions ...
///
///
///
Task RemoveResource(
XResourceDto resource,
- XUserClaimsInfoDto userInfo = null,
string connectionId = null,
CancellationToken cancellationToken = default
);
diff --git a/Providers/XBaseItemResourceProvider.cs b/Providers/XBaseItemResourceProvider.cs
index e14c53d..8ed225f 100644
--- a/Providers/XBaseItemResourceProvider.cs
+++ b/Providers/XBaseItemResourceProvider.cs
@@ -5,7 +5,6 @@ using System.Threading;
using System.Threading.Tasks;
using xCommons.Extensions;
using xExceptions.Constants;
-using xIdentityModels.Models;
using xModels.Dtos;
using xStringService.Interfaces;
using xStringService.Interfaces.Dtos;
@@ -15,6 +14,8 @@ namespace xStringService.Providers
{
public abstract class XBaseItemResourceProvider : IXItemResourceProvider
{
+ //
+ #region Props ...
///
/// Item Name for Resource Providing ...
///
@@ -30,6 +31,7 @@ namespace xStringService.Providers
/// String Provider Service ...
///
private readonly IXStringServiceProvider stringProvider;
+ #endregion
//
#region Constructor ...
@@ -49,22 +51,20 @@ namespace xStringService.Providers
#endregion
//
- #region All Item Actions ...
+ #region Group Actions ...
///
/// Retrieve a List of Exists Languages for Current Item ...
///
///
///
- public async Task> GetLanguages(
+ public virtual async Task> GetLanguages(
CancellationToken cancellationToken = default
)
{
//
- var result =
- (await GetResourceLocales(cancellationToken))
+ var result = (await ExtractItems(cancellationToken))
.Select(x => x.Language)
- .Distinct()
- .ToList();
+ .Distinct();
//
return result;
@@ -75,145 +75,439 @@ namespace xStringService.Providers
///
///
///
- public async Task> GetResourceLocales(
+ public virtual async Task> GetResourceLocales(
CancellationToken cancellationToken = default
)
{
//
- var identifier = GetResourceTitle();
- var result = await stringProvider
- .FindManyAsync(
- includeBuilder: null,
- ignoreSoftDeleteds: true,
- cancellationToken: cancellationToken,
- orderBuilder:
- x => x
- .OrderBy(y => y.Language)
- .ThenBy(y => y.ResourceTitle),
- predicate: x =>
- x.ResourceTitle.StartsWith(identifier, StringComparison.InvariantCultureIgnoreCase)
+ var result = await ExtractItems(cancellationToken);
+
+ //
+ return result;
+ }
+
+ ///
+ /// Remove all Exists Locales which Related to this Provider ...
+ ///
+ ///
+ ///
+ ///
+ 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 ...
+ ///
+ /// Get all Exists Items for Specified identitifer ...
+ ///
+ ///
+ ///
+ ///
+ public virtual async Task> 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;
+ }
+
+ ///
+ /// Get all Exists Items for Specified identitifer ...
+ ///
+ ///
+ ///
+ ///
+ public virtual async Task> 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;
+ }
+
+ ///
+ /// Get all Exists Locales Representaion based on Specified Identitifer
+ /// as XResourceDto ...
+ ///
+ ///
+ ///
+ ///
+ public virtual async Task 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;
+ }
+
+ ///
+ /// Add Or Update Locale for Specified Identitifer ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual async Task 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;
}
- #endregion
- //
- #region Single Item Actions ...
///
- /// Retrieve a List of Exists Languages for Current Item ...
+ /// Update a Resource State ...
///
///
+ ///
+ ///
///
///
- public async Task> GetLanguages(
+ public virtual async Task AddOrUpdateResource(
object identifier,
+ XResourceDto resource,
+ string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
- var isValid = !identifier.IsNull();
+ var isValid =
+ !identifier.IsNull();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
- // Set Identifier ...
- SetResourceTitle(identifier);
-
- //
- var result =
- await provider.GetLanguages(cancellationToken);
- return result;
- }
-
- ///
- /// Retrieve all Exists Items of type ...
- ///
- ///
- ///
- ///
- public async Task> GetResourceLocales(
- object identifier,
- CancellationToken cancellationToken = default
- )
- {
- //
- // Validate ...
- var isValid = !identifier.IsNull();
+ // Retrieve Identified Resource Title ...
+ var identifiedResource = GetResourceTitle(identifier);
+ isValid =
+ !resource.IsNullOrDefault() &&
+ (resource.Resource.IsNullOrEmpty() ||
+ resource.Resource == identifiedResource);
if (!isValid)
{
XException.InvalidArgs.Throw();
}
+ if (resource.Resource.IsNullOrEmpty())
+ {
+ resource.Resource = identifiedResource;
+ }
//
- // Set Identifier ...
+ // Setting Resource Title ...
SetResourceTitle(identifier);
//
- var result =
- await provider.GetResourceLocales(cancellationToken);
+ // Retrieve Resource List ...
+ var result = await provider
+ .AddOrUpdateResource(
+ resource: resource,
+ connectionId: connectionId,
+ cancellationToken: cancellationToken
+ );
+
+ //
return result;
}
- public async Task AddOrUpdateItemResourcer(
+ ///
+ /// Remove Specified Language Locale of Specified Identifier ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual async Task RemoveLocale(
object identifier,
string language,
- string translation,
string connectionId = null,
- XUserClaimsInfoDto userInfo = null,
CancellationToken cancellationToken = default
)
{
//
- var result = string.Empty;
-
- //
- // Validate Args ...
+ // Validate ...
var isValid =
!identifier.IsNull() &&
- !language.IsNullOrEmpty() &&
- !translation.IsNullOrEmpty();
+ !language.IsNullOrEmpty();
if (!isValid)
{
- return result;
+ XException.InvalidArgs.Throw();
+ }
+
+ //
+ // Check Locale Exists ...
+ isValid = await HasLocale(
+ language: language,
+ identifier: identifier,
+ cancellationToken: cancellationToken
+ );
+ if (!isValid)
+ {
+ XException.NotFound.Throw();
}
//
- // Prepare Identifier ...
- var resourceTitle = GetResourceTitle(identifier);
+ var locale = (await GetLocales(
+ identifier: identifier,
+ cancellationToken: cancellationToken
+ ))
+ .FirstOrDefault(x =>
+ x.Language.Equals(language, StringComparison.InvariantCultureIgnoreCase));
+ isValid = !locale.IsNullOrDefault();
+ if (!isValid)
+ {
+ XException.NotFound.Throw();
+ }
//
- // Set Resource Title ...
- SetResourceTitle(resourceTitle);
+ // Setting Resource Title ...
+ SetResourceTitle(identifier);
//
- // Try to Add Or Update ...
- var resource = await provider.AddOrUpdateLocale(
- userInfo: userInfo,
+ var result = await provider.RemoveLocale(
+ locale: locale,
connectionId: connectionId,
- locale: new XLocaleResourceDto
- {
- Language = language,
- Value = translation
- },
cancellationToken: cancellationToken
);
//
- // Validate Result ...
- isValid = !resource.IsNullOrDefault();
- if (isValid)
+ return result;
+ }
+
+ ///
+ /// Remove all Exists Locales for Specified Identifier ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ 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
+ );
+ }
+
+ ///
+ /// Check Specified ocale Exists for Specified Identifier ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual async Task 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;
}
+
+ ///
+ /// Get all Exists Languages for Specified Identifier ...
+ ///
+ ///
+ ///
+ ///
+ public virtual async Task> 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;
+ }
#endregion
//
@@ -251,6 +545,29 @@ namespace xStringService.Providers
value: $"{itemIdentifier}"
);
}
+
+ ///
+ /// xtract all Items which Belongs to Provider ...
+ ///
+ ///
+ ///
+ private async Task> 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
}
}
\ No newline at end of file
diff --git a/Providers/XBaseResourceProvider.cs b/Providers/XBaseResourceProvider.cs
index 23303ff..6035cdd 100644
--- a/Providers/XBaseResourceProvider.cs
+++ b/Providers/XBaseResourceProvider.cs
@@ -5,7 +5,6 @@ using System.Threading;
using System.Threading.Tasks;
using xCommons.Extensions;
using xExceptions.Constants;
-using xIdentityModels.Models;
using xModels.Dtos;
using xStringService.Extensions;
using xStringService.Interfaces;
@@ -181,13 +180,11 @@ namespace xStringService.Providers
/// Add or Update a Resource Model ...
///
/// a XResourceDto Model ...
- /// Actor User for Permissions ...
///
///
///
public virtual async Task AddOrUpdateResource(
XResourceDto resource,
- XUserClaimsInfoDto userInfo = null,
string connectionId = null,
CancellationToken cancellationToken = default
)
@@ -209,7 +206,6 @@ namespace xStringService.Providers
{
await RemoveResource(
resource: result,
- userInfo: userInfo,
connectionId: connectionId,
cancellationToken: cancellationToken
);
@@ -248,7 +244,6 @@ namespace xStringService.Providers
///
public virtual async Task AddOrUpdateLocale(
XLocaleResourceDto locale,
- XUserClaimsInfoDto userInfo = null,
string connectionId = null,
CancellationToken cancellationToken = default
)
@@ -297,11 +292,11 @@ namespace xStringService.Providers
/// Remove Locale ...
///
///
+ ///
///
///
public virtual async Task RemoveLocale(
XLocaleResourceDto locale,
- XUserClaimsInfoDto userInfo = null,
string connectionId = null,
CancellationToken cancellationToken = default
)
@@ -334,17 +329,26 @@ namespace xStringService.Providers
/// Remove Specified Resource Model ...
///
/// a XResourceDto Model ...
- /// Actor User for Permissions ...
///
///
///
public virtual async Task RemoveResource(
XResourceDto resource,
- XUserClaimsInfoDto userInfo = null,
string connectionId = null,
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);