From fe88855e6976c2b3ddbda87d4325f64d4c457cbd Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sat, 8 Aug 2026 11:34:02 +0330 Subject: [PATCH] last ... --- Interfaces/IXOwnedItemResourceProvider.cs | 200 ++++++++++++ Providers/XBaseOwnedItemResourceProvider.cs | 331 ++++++++++++++++++++ 2 files changed, 531 insertions(+) create mode 100644 Interfaces/IXOwnedItemResourceProvider.cs create mode 100644 Providers/XBaseOwnedItemResourceProvider.cs diff --git a/Interfaces/IXOwnedItemResourceProvider.cs b/Interfaces/IXOwnedItemResourceProvider.cs new file mode 100644 index 0000000..6794ec0 --- /dev/null +++ b/Interfaces/IXOwnedItemResourceProvider.cs @@ -0,0 +1,200 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using xModels.Dtos; +using xStringService.Models.Dtos; + +namespace xStringService.Interfaces +{ + public interface IXOwnedItemResourceProvider + { + // + #region Group Actions ... + /// + /// Retrieve a List of Exists Languages for Current Item ... + /// + /// + /// + /// + Task> GetLanguages( + object owner, + CancellationToken cancellationToken = default + ); + + /// + /// Retrieve all Exists Items of type ... + /// + /// + /// + /// + Task> GetResourceLocales( + object owner, + CancellationToken cancellationToken = default + ); + + /// + /// Remove all Exists Locales which Related to this Provider ... + /// + /// + /// + /// + /// + Task RemoveResourceLocales( + object owner, + string connectionId = null, + CancellationToken cancellationToken = default + ); + #endregion + + // + #region Item Actions ... + /// + /// Get all Exists Items for Specified identitifer ... + /// + /// + /// + /// + /// + Task> GetResourceLocales( + object owner, + object identifier, + CancellationToken cancellationToken = default + ); + + /// + /// Get all Exists Items for Specified identitifer ... + /// + /// + /// + /// + /// + Task> GetLocales( + object owner, + object identifier, + CancellationToken cancellationToken = default + ); + + /// + /// Get all Exists Locales Representaion based on Specified Identitifer + /// as XResourceDto ... + /// + /// + /// + /// + /// + Task GetResource( + object owner, + object identifier, + CancellationToken cancellationToken = default + ); + + /// + /// Add Or Update Locale for Specified Identitifer ... + /// + /// + /// + /// + /// + /// + /// + Task AddOrUpdateLocale( + object owner, + object identifier, + XLocaleResourceDto locale, + string connectionId = null, + CancellationToken cancellationToken = default + ); + + /// + /// Update a Resource State ... + /// + /// + /// + /// + /// + /// + /// + Task AddOrUpdateResource( + object owner, + object identifier, + XResourceDto resource, + string connectionId = null, + CancellationToken cancellationToken = default + ); + + /// + /// Remove Specified Language Locale of Specified Identifier ... + /// + /// + /// + /// + /// + /// + /// + Task RemoveLocale( + object owner, + object identifier, + string language, + string connectionId = null, + CancellationToken cancellationToken = default + ); + + /// + /// Remove all Exists Locales for Specified Identifier ... + /// + /// + /// + /// + /// + /// + Task RemoveLocales( + object owner, + object identifier, + string connectionId = null, + CancellationToken cancellationToken = default + ); + + /// + /// Check Specified ocale Exists for Specified Identifier ... + /// + /// + /// + /// + /// + /// + Task HasLocale( + object owner, + object identifier, + string language, + CancellationToken cancellationToken = default + ); + + /// + /// Get all Exists Languages for Specified Identifier ... + /// + /// + /// + /// + /// + Task> GetLanguages( + object owner, + object identifier = null, + CancellationToken cancellationToken = default + ); + #endregion + + // + #region Resource Title Action ... + /// + /// Retrieve Resource Title ... + /// + /// + /// + /// + string GetResourceTitle( + object owner = null, + object identifier = null + ); + #endregion + } +} \ No newline at end of file diff --git a/Providers/XBaseOwnedItemResourceProvider.cs b/Providers/XBaseOwnedItemResourceProvider.cs new file mode 100644 index 0000000..29dfc76 --- /dev/null +++ b/Providers/XBaseOwnedItemResourceProvider.cs @@ -0,0 +1,331 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using xCommons.Extensions; +using xModels.Dtos; +using xStringService.Interfaces; +using xStringService.Interfaces.Dtos; +using xStringService.Models.Dtos; + +namespace xStringService.Providers +{ + public abstract class XBaseOwnedItemResourceProvider : IXOwnedItemResourceProvider + { + // + #region Props ... + /// + /// Item Name for Resource Providing ... + /// + private readonly string item; + + /// + /// String Provider Service ... + /// + private readonly IXStringServiceProvider stringProvider; + #endregion + + // + #region Constructor ... + protected XBaseOwnedItemResourceProvider( + string item, + IXStringServiceProvider stringProvider + ) + { + // + this.item = item; + this.stringProvider = stringProvider; + } + #endregion + + // + #region Group Actions ... + /// + /// Retrieve a List of Exists Languages for Current Item ... + /// + /// + /// + /// + public virtual async Task> GetLanguages( + object owner, + CancellationToken cancellationToken = default + ) + { + throw new NotImplementedException(); + } + + /// + /// Retrieve all Exists Items of type ... + /// + /// + /// + /// + public virtual async Task> GetResourceLocales( + object owner, + CancellationToken cancellationToken = default + ) + { + throw new NotImplementedException(); + } + + /// + /// Remove all Exists Locales which Related to this Provider ... + /// + /// + /// + /// + /// + public virtual async Task RemoveResourceLocales( + object owner, + string connectionId = null, + CancellationToken cancellationToken = default + ) + { + throw new NotImplementedException(); + } + #endregion + + // + #region Item Actions ... + /// + /// Get all Exists Items for Specified identitifer ... + /// + /// + /// + /// + /// + public virtual async Task> GetResourceLocales( + object owner, + object identifier, + CancellationToken cancellationToken = default + ) + { + throw new NotImplementedException(); + } + + /// + /// Get all Exists Items for Specified identitifer ... + /// + /// + /// + /// + /// + public virtual async Task> GetLocales( + object owner, + object identifier, + CancellationToken cancellationToken = default + ) + { + throw new NotImplementedException(); + } + + /// + /// Get all Exists Locales Representaion based on Specified Identitifer + /// as XResourceDto ... + /// + /// + /// + /// + /// + public virtual async Task GetResource( + object owner, + object identifier, + CancellationToken cancellationToken = default + ) + { + throw new NotImplementedException(); + } + + /// + /// Add Or Update Locale for Specified Identitifer ... + /// + /// + /// + /// + /// + /// + /// + public virtual async Task AddOrUpdateLocale( + object owner, + object identifier, + XLocaleResourceDto locale, + string connectionId = null, + CancellationToken cancellationToken = default + ) + { + throw new NotImplementedException(); + } + + /// + /// Update a Resource State ... + /// + /// + /// + /// + /// + /// + /// + public virtual async Task AddOrUpdateResource( + object owner, + object identifier, + XResourceDto resource, + string connectionId = null, + CancellationToken cancellationToken = default + ) + { + throw new NotImplementedException(); + } + + /// + /// Remove Specified Language Locale of Specified Identifier ... + /// + /// + /// + /// + /// + /// + /// + public virtual async Task RemoveLocale( + object owner, + object identifier, + string language, + string connectionId = null, + CancellationToken cancellationToken = default + ) + { + throw new NotImplementedException(); + } + + /// + /// Remove all Exists Locales for Specified Identifier ... + /// + /// + /// + /// + /// + /// + public virtual async Task RemoveLocales( + object owner, + object identifier, + string connectionId = null, + CancellationToken cancellationToken = default + ) + { + throw new NotImplementedException(); + } + + /// + /// Check Specified ocale Exists for Specified Identifier ... + /// + /// + /// + /// + /// + /// + public virtual async Task HasLocale( + object owner, + object identifier, + string language, + CancellationToken cancellationToken = default + ) + { + throw new NotImplementedException(); + } + + /// + /// Get all Exists Languages for Specified Identifier ... + /// + /// + /// + /// + /// + public virtual async Task> GetLanguages( + object owner, + object identifier = null, + CancellationToken cancellationToken = default + ) + { + throw new NotImplementedException(); + } + #endregion + + // + #region Resource Title Action ... + /// + /// Retrieve Resource Title ... + /// + /// + /// + /// + public virtual string GetResourceTitle( + object owner = null, + object identifier = null + ) + { + // + var result = item; + + // + // Normalization ... + var ownerStr = + !owner.IsNull() + ? $"{owner}" + : string.Empty; + var identifierStr = + !identifier.IsNull() + ? $"{identifier}" + : string.Empty; + + // + // Handle Owner Attach ... + if (!ownerStr.IsNullOrEmpty()) + { + result = $"{result}_{ownerStr}"; + } + + // + // Handle Identifier Attach ... + if (!identifierStr.IsNullOrEmpty()) + { + result = $"{result}_{identifierStr}"; + } + + // + return result; + } + #endregion + + // + #region Private ... + private async Task> ExtractStrings( + string resourceTitle, + CancellationToken cancellationToken = default + ) + { + // + IEnumerable result = []; + + // + if (resourceTitle.IsNullOrEmpty()) + { + return result; + } + + // + result = await stringProvider.FindManyAsync( + includeBuilder: null, + ignoreSoftDeleteds: true, + cancellationToken: cancellationToken, + predicate: x => x.ResourceTitle + .ToNormalString() + .Contains(resourceTitle), + orderBuilder: x => x.OrderBy(y => y.Id) + ); + + // + return result; + } + #endregion + } +} \ No newline at end of file