### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Configurations\Entities\XStringEntityConfiguration.cs using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using xDataService.Providers; using xStringService.Constants; using xStringService.Models.Entities; namespace xStringService.Configurations.Entities { public class XStringEntityConfiguration : XBaseEntityTypeConfiguration { public override void Configure(EntityTypeBuilder builder) { builder.ToTable(XStringServiceConstants.XStringTable); } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Constants\XStringServiceConstants.cs namespace xStringService.Constants { public struct XStringServiceConstants { // // Service Extensions Log Tag ... public const string XStringServiceDILogTag = "XStringService"; // // Table Mapping Identifiers ... public const string XStringTable = "Strings"; // // GraphQL Collection Mappings ... public const string XStringSingleName = "string"; public const string XStringCollectionName = "strings"; // // Hubs ... public const string XStringDtoHub = "stringDto"; public const string XStringEntityHub = "stringEntity"; // // Custome Constants ... // // EF Repositories Helper Extensions ... public const string GetXStringEFRepositoryDescriptor = "GetXStringEFRepositoryDescriptor"; } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Controllers\XBaseItemResourceProviderControllerBase.cs using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using xCommons.Configurations; using xCommons.Extensions; using xCommons.Providers; using xExceptions.Constants; using xIdentityService.Controllers; using xIdentityService.Interfaces; using xModels.Dtos; using xStringService.Interfaces; using xStringService.Models.Dtos; namespace xStringService.Controllers { public abstract class XBaseItemResourceProviderControllerBase : XBaseIdentityApiV1Controller, IXBaseItemResourceProviderController { private readonly IXItemResourceProvider provider; protected XBaseItemResourceProviderControllerBase( ILogger logger, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider, XValidationProvider validationProvider, IXItemResourceProvider provider ) : base( logger, appConfiguration, identityProvider, validationProvider ) { this.provider = provider; } // #region Actions ... /// /// Retrieve a List of Exists Languages ... /// /// if null or empty, check all languages in Item Side /// /// [HttpGet("Languages")] public virtual async Task>> GetLanguages( [FromQuery] object identifier, CancellationToken cancellationToken = default ) { // try { // var result = Enumerable.Empty(); if (!identifier.IsNull()) { // result = await provider.GetLanguages( identifier: identifier, cancellationToken: cancellationToken ); } else { // result = await provider.GetLanguages( cancellationToken: cancellationToken ); } // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Retrieve all Exists Items ... /// /// Specified Resource Title /// /// [HttpGet("ResourceLocales")] public virtual async Task>> GetResourceLocales( [FromQuery] object identifier, CancellationToken cancellationToken = default ) { // try { // var result = Enumerable.Empty(); if (!identifier.IsNull()) { // result = await provider.GetResourceLocales( identifier: identifier, cancellationToken: cancellationToken ); } else { // result = await provider.GetResourceLocales( cancellationToken: cancellationToken ); } // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Get all Exists Items for Specified identitifer ... /// /// /// /// [HttpGet("Locales/{identifier}")] public virtual async Task>> GetLocales( [FromRoute] object identifier, CancellationToken cancellationToken = default ) { // try { // // return Ok(); } catch (Exception ex) { var result = GetExceptionActionResult(ex); return result; } } /// /// Remove Specified Language Locale of Specified Identifier ... /// /// /// if null or empty Remove all Locales /// /// [HttpDelete("Locales/{identifier}")] public virtual async Task> RemoveLocale( [FromRoute] object identifier, [FromQuery] string language, CancellationToken cancellationToken = default ) { // try { // // Validate ... var isValid = !identifier.IsNull(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Retrieve Connection ID ... var connectionId = GetConnectionId(); // XResourceDto result = null; if (!language.IsNullOrEmpty()) { // result = await provider.RemoveLocale( language: language, identifier: identifier, connectionId: connectionId, cancellationToken: cancellationToken ); } else { // await provider.RemoveLocales( identifier: identifier, connectionId: connectionId, cancellationToken: cancellationToken ); } // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Check Specified ocale Exists for Specified Identifier ... /// /// /// /// /// [HttpGet("Locales/{identifier}/{language}/Has")] public virtual async Task> HasLocale( [FromRoute] object identifier, [FromRoute] string language, CancellationToken cancellationToken = default ) { // try { // // Validate ... await ValidationProvider .GroupValidationBuilder() .AddNotEmpty(language) .AddNotNull(identifier) .ValidateGroupAsync(); // // Calculate Result ... var result = await provider.HasLocale( language: language, identifier: identifier, cancellationToken: cancellationToken ); // return Ok(result); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Get all Exists Locales Representaion based on Specified Identitifer /// as XResourceDto ... /// /// /// /// [HttpGet("Resource/{identifier}")] public virtual async Task> GetResource( [FromRoute] object identifier, CancellationToken cancellationToken = default ) { // try { // // Validate ... ValidationProvider.NotNull(identifier); // var result = await provider.GetResource( identifier: identifier, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Add Or Update Locale for Specified Identitifer ... /// /// /// /// /// [HttpPost("Locales/{identifier}")] public virtual async Task> AddOrUpdateLocale( [FromRoute] object identifier, [FromBody] XLocaleResourceDto locale, CancellationToken cancellationToken = default ) { // try { // // Validate ... await ValidationProvider .GroupValidationBuilder() .AddNotNull(identifier) .AddNotNull(locale) .AddNotEmpty(locale.Value) .AddNotEmpty(locale.Language) .ValidateGroupAsync(); // // Retrieve Connection ID ... var connectionId = GetConnectionId(); // var result = await provider.AddOrUpdateLocale( locale: locale, identifier: identifier, connectionId: connectionId, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { var result = GetExceptionActionResult(ex); return result; } } /// /// Update a Resource State ... /// /// /// /// /// [HttpPost("Resource/{identifier}")] public virtual async Task> AddOrUpdateResource( [FromRoute] object identifier, [FromBody] XResourceDto resource, CancellationToken cancellationToken = default ) { // try { // // Validate ... await ValidationProvider .GroupValidationBuilder() .AddNotNull(identifier) .AddNotNull(resource) .ValidateGroupAsync(); // // Retrieve Connection ID ... var connectionId = GetConnectionId(); // var result = await provider.AddOrUpdateResource( resource: resource, identifier: identifier, connectionId: connectionId, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Controllers\XBaseResourceProviderControllerBase.cs using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using xCommons.Configurations; using xCommons.Extensions; using xCommons.Providers; using xIdentityService.Controllers; using xIdentityService.Interfaces; using xModels.Dtos; using xStringService.Interfaces; using xStringService.Models.Dtos; namespace xStringService.Controllers { public abstract class XBaseResourceProviderControllerBase : XBaseIdentityApiV1Controller, IXBaseResourceProviderController where TResourceProvider : IXResourceProvider { private readonly TResourceProvider provider; protected XBaseResourceProviderControllerBase( ILogger> logger, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider, XValidationProvider validationProvider, TResourceProvider provider ) : base( logger, appConfiguration, identityProvider, validationProvider ) { this.provider = provider; } #region Actions ... /// /// Retrieve a List of Exists Languages ... /// /// /// [HttpGet("Languages")] public virtual async Task>> GetLanguages( CancellationToken cancellationToken = default ) { // try { // var result = await provider .GetLanguages(cancellationToken); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Retrieve all Exists Items ... /// /// Specified Resource Title /// /// [HttpGet("LocalesResource")] public virtual async Task>> GetResourceLocales( CancellationToken cancellationToken = default ) { // try { // var result = await provider .GetResourceLocales(cancellationToken); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Extract Translation of in Specified Language ... /// /// Specified Language ... /// /// [HttpGet("{language}/Translation")] public virtual async Task> GetResourceTranslation( [FromRoute] string language, CancellationToken cancellationToken = default ) { // try { // var result = await provider .GetResourceTranslation( language: language, cancellationToken: cancellationToken ); // return Ok(result); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Check Has Specified Translation or not ... /// /// Specified Language ... /// /// [HttpGet("{language}/Has")] public virtual async Task> HasLocale( [FromRoute] string language, CancellationToken cancellationToken = default ) { // try { // var result = await provider .HasLocale( language: language, cancellationToken: cancellationToken ); // return Ok(result); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Retrieve as Locale Model ... /// /// Specified Language ... /// /// [HttpGet("{language}/Locale")] public virtual async Task> GetLocale( [FromRoute] string language, CancellationToken cancellationToken = default ) { // try { // var result = await provider .GetLocale( language: language, cancellationToken: cancellationToken ); // return Ok(result); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Retrieve all Exists Locale Models ... /// /// /// [HttpGet("Locales")] public virtual async Task>> GetLocales( CancellationToken cancellationToken = default ) { // try { // var result = await provider .GetLocales(cancellationToken); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Retrieve as XResourceDto ... /// /// /// [HttpGet("Resource")] public virtual async Task> GetResource( CancellationToken cancellationToken = default ) { // try { // var result = await provider .GetResource(cancellationToken); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Add or Update a Resource Model ... /// /// a XResourceDto Model ... /// /// [HttpPost("")] public virtual async Task> AddOrUpdateResource( [FromBody] XResourceDto resource, CancellationToken cancellationToken = default ) { // try { // var result = await provider .AddOrUpdateResource( resource: resource, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Add Or Update Locale ... /// /// /// /// [HttpPost("Locales")] public virtual async Task> AddOrUpdateLocale( [FromBody] XLocaleResourceDto locale, CancellationToken cancellationToken = default ) { // try { // var result = await provider .AddOrUpdateLocale( locale: locale, cancellationToken: cancellationToken ); // return Ok(result); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Remove Locale ... /// /// /// /// [HttpPost("Locale/Remove")] public virtual async Task> RemoveLocale( [FromBody] XLocaleResourceDto locale, CancellationToken cancellationToken = default ) { // try { // var result = await provider .RemoveLocale( locale: locale, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Remove Specified Resource Model ... /// /// a XResourceDto Model ... /// /// [HttpPost("Resource/Remove")] public virtual async Task RemoveResource( [FromBody] XResourceDto resource, CancellationToken cancellationToken = default ) { // try { // await provider .RemoveResource( resource: resource, cancellationToken: cancellationToken ); // return Ok(); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Controllers\XStringProviderControllerBase.cs using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using xCommons.Configurations; using xCommons.Extensions; using xCommons.Providers; using xExceptions.Constants; using xIdentityService.Interfaces; using xModels.Dtos; using xPushService.Controllers; using xStringService.Interfaces; using xStringService.Models.Dtos; using xStringService.Models.Entities; using xStringService.Providers.Dtos; namespace xStringService.Controllers { public abstract class XStringProviderControllerBase : XBaseProvidedController, IXStringProviderController { private readonly IXStringProvider provider; protected XStringProviderControllerBase( ILogger logger, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider, XValidationProvider validationProvider, IXStringProvider provider, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, identityProvider, validationProvider, provider, defaultOrderBuilder, defaultIncludeBuilder ) { this.provider = provider; } // #region Tools ... /// /// Retrieve a List of Exists Languages ... /// /// /// [HttpGet("Languages")] public virtual async Task>> GetLanguages( CancellationToken cancellationToken = default ) { // try { // var result = await provider .GetLanguages(cancellationToken); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Retrieve a List of Resource Titles ... /// /// if provided, returns all language Specified resource titles, if not, all Resource Titles /// /// [HttpGet("ResourceTitles")] public virtual async Task>> GetResourceTitles( [FromQuery] string language = null, CancellationToken cancellationToken = default ) { // try { // var result = await provider .GetResourceTitles( language: language, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Retrieve all Exists Items which belongs to Specified Resource Title ... /// /// Specified Resource Title /// /// [HttpGet("ResourceLocales")] public virtual async Task>> GetResourceLocales( [FromQuery] string resource, CancellationToken cancellationToken = default ) { // try { // var result = await provider .GetResourceLocales( resource: resource, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Extract Translation of a Resource in Specified Language ... /// /// Specified Language ... /// Specified Resource Title ... /// /// [HttpGet("Translation")] public virtual async Task> GetResourceTranslation( [FromQuery] string language, [FromQuery] string resource, CancellationToken cancellationToken = default ) { // try { // var result = await provider .GetResourceTranslation( language: language, resource: resource, cancellationToken: cancellationToken ); // return Ok(result); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Retrieve a Resource as Locale Model ... /// /// Specified Language ... /// Specified Resource Title ... /// /// [HttpGet("Locale")] public virtual async Task> GetLocale( [FromQuery] string language, [FromQuery] string resource, CancellationToken cancellationToken = default ) { // try { // var result = await provider .GetLocale( language: language, resource: resource, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Retrieve all Exists Resource Instances as Locale Models ... /// /// /// /// [HttpGet("Locales")] public virtual async Task>> GetLocales( [FromQuery] string resource, CancellationToken cancellationToken = default ) { // try { // var result = await provider .GetLocales( resource: resource, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Retrieve all Locales of Specified Resource and Represent as XResourceDto ... /// /// /// /// [HttpGet("GetResource")] public virtual async Task> GetResource( [FromQuery] string resource, CancellationToken cancellationToken = default ) { // try { // var result = await provider .GetResource( resource: resource, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Add or Update a Resource Model ... /// /// a XResourceDto Model ... /// /// [HttpPost("AddOrUpdateResource")] public virtual async Task> AddOrUpdateResource( [FromBody] XResourceDto resource, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotNull(resource) .AddNotEmpty(resource.Resource) .ValidateGroupAsync(); // var userInfo = await GetUserInfo(); var connectionId = GetConnectionId(); // var result = await provider .AddOrUpdateResource( resource: resource, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); // return Ok(result.ToDynamicObject()); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } /// /// Remove Specified Resource Model ... /// /// a XResourceDto Model ... /// /// [HttpPost("RemoveResource")] public virtual async Task RemoveResource( [FromBody] XResourceDto resource, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotNull(resource) .AddNotEmpty(resource.Resource) .ValidateGroupAsync(); // var userInfo = await GetUserInfo(); var connectionId = GetConnectionId(); // await provider .RemoveResource( resource: resource, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); // return Ok(); } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Controllers\XStringRepositoryControllerBase.cs using System; using System.Linq; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using xCommons.Configurations; using xCommons.Providers; using xDataService.Controllers; using xDataService.Interfaces; using xStringService.Interfaces.Entities; using xStringService.Models.Entities; namespace xStringService.Controllers { public abstract class XStringRepositoryControllerBase : XBaseRepositoryController, IXBaseRepositoryController { protected XStringRepositoryControllerBase( ILogger logger, XAppConfiguration appConfiguration, XValidationProvider validationProvider, IXStringRepository repository, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, validationProvider, repository, defaultOrderBuilder, defaultIncludeBuilder ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Controllers\XStringRepositoryProviderControllerBase.cs using System; using System.Linq; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using xCommons.Configurations; using xCommons.Providers; using xIdentityService.Interfaces; using xPushService.Controllers; using xPushService.Interfaces; using xStringService.Interfaces.Entities; using xStringService.Models.Entities; using xStringService.Providers.Entities; namespace xStringService.Controllers { public abstract class XStringRepositoryProviderControllerBase : XBaseRepositoryProviderController, IXBaseRepositoryProviderController { protected XStringRepositoryProviderControllerBase( ILogger logger, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider, XValidationProvider validationProvider, IXStringRepositoryProvider provider, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, identityProvider, validationProvider, provider, defaultOrderBuilder, defaultIncludeBuilder ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Controllers\XStringServiceControllerBase.cs using System; using System.Linq; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using xCommons.Configurations; using xCommons.Providers; using xDataService.Controllers; using xDataService.Interfaces; using xStringService.Interfaces.Dtos; using xStringService.Models.Dtos; using xStringService.Models.Entities; namespace xStringService.Controllers { public abstract class XStringServiceControllerBase : XBaseServiceController, IXBaseServiceController { protected XStringServiceControllerBase( ILogger logger, XAppConfiguration appConfiguration, XValidationProvider validationProvider, IXStringRepositoryService repositoryService, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, validationProvider, repositoryService, defaultOrderBuilder, defaultIncludeBuilder ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Controllers\XStringServiceProviderControllerBase.cs using System; using System.Linq; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using xCommons.Configurations; using xCommons.Providers; using xIdentityService.Interfaces; using xPushService.Controllers; using xPushService.Interfaces; using xStringService.Interfaces.Dtos; using xStringService.Models.Dtos; using xStringService.Models.Entities; using xStringService.Providers.Dtos; namespace xStringService.Controllers { public abstract class XStringServiceProviderControllerBase : XBaseServiceProviderController, IXBaseServiceProviderController { protected XStringServiceProviderControllerBase( ILogger logger, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider, XValidationProvider validationProvider, IXStringServiceProvider provider, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, identityProvider, validationProvider, provider, defaultOrderBuilder, defaultIncludeBuilder ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\DI\XDIHelperExtension.cs using System; using Microsoft.Extensions.DependencyInjection; using xExceptions.Constants; using xCommons.Extensions; using xDataService.Constants; using xDataService.Db; using xDataService.DI; using xDataService.Models; using xStringService.Helpers; using xCommons.Helpers; using Microsoft.AspNetCore.Builder; using xStringService.Interfaces.Dtos; using xStringService.Providers.Dtos; using xStringService.Interfaces.Entities; using xStringService.Providers.Entities; using xPushService.Helpers; using xPushService.DI; using xStringService.Interfaces; using xStringService.Providers; using xStringService.Constants; namespace xStringService.DI { public static class XDIHelperExtension { /// /// Register Service ... /// /// /// /// public static void AddXStringService( this IServiceCollection services, XRepositoryType repositoryType, ServiceLifetime lifeTime = ServiceLifetime.Scoped ) { AddStringService( contextType: null, services: services, lifeTime: lifeTime, repositoryType: repositoryType ); } /// /// Register Service ... /// /// /// /// /// public static void AddXStringService( this IServiceCollection services, XRepositoryType repositoryType, ServiceLifetime lifeTime = ServiceLifetime.Scoped ) where TContext : XDbContext { AddStringService( services: services, lifeTime: lifeTime, contextType: typeof(TContext), repositoryType: repositoryType ); } /// /// Use XStringService Middleware ... /// /// /// public static void UseXStringService( this IApplicationBuilder app, bool isDevelopmentEnvironment = false ) { // #region Using XString Hubs ... // var pushHelper = new XPushServiceHelper(); // pushHelper.AddHub(XStringServiceConstants.XStringDtoHub); pushHelper.AddHub(XStringServiceConstants.XStringEntityHub); // app.UseXPushService(pushHelper); #endregion // // Using XString Repository Descriptor ... if (!descriptor.IsNull()) { // app.UseXRepository( descriptor: descriptor, isDevelopmentEnvironment: isDevelopmentEnvironment ); } } // #region Private ... private static XRepositoryDescriptor descriptor = null; /// /// a LogTag for Service ... /// private static string XLogTag = XStringServiceConstants.XStringServiceDILogTag; /// /// print a log in Console ... /// /// private static void Log(string message) { Console.WriteLine($"{XLogTag} => {message}"); } /// /// Register Service ... /// /// /// /// /// private static void AddStringService( IServiceCollection services, XRepositoryType repositoryType, Type contextType = null, ServiceLifetime lifeTime = ServiceLifetime.Scoped ) { // var exception = XException.InvalidArgs.ToException(); ; // // Services ... var isServicesExists = !services.IsNull(); if (!isServicesExists) { // Log("Service Registration failed, services not provided ..."); throw exception; } // // Lifetime ... var isLifetimeExists = !lifeTime.IsNull(); if (!isLifetimeExists) { // Log("Service Registration failed, lifetime not provided ..."); throw exception; } // // Validate Repository Type ... var isRepositoryTypeValid = (repositoryType == XRepositoryType.EF && !contextType.IsNull()) || ((repositoryType == XRepositoryType.Mongo || repositoryType == XRepositoryType.InMemory) && contextType.IsNull()); if (!isRepositoryTypeValid) { // Log("Service Registration failed, Invalid Repository Type and Context Type ..."); throw exception; } // // Maske Instance of Repository Descriptor // Based on Provided Type ... switch(repositoryType) { // case XRepositoryType.EF: // descriptor = typeof(XStringServiceHelper) .InvokeGenericMethod( args: null, runtimeType: contextType, methodName: XStringServiceConstants.GetXStringEFRepositoryDescriptor ); break; // case XRepositoryType.Mongo: descriptor = XStringServiceHelper.GetXStringMongoRepositoryDescriptor(); break; // case XRepositoryType.InMemory: descriptor = XStringServiceHelper.GetXStringInMemoryRepositoryDescriptor(); break; } // // Register XString Repository Descriptor ... services.AddXRepository( lifeTime: lifeTime, descriptor: descriptor ); // // Register Dto Services ... services.Add( new ServiceDescriptor(typeof(IXStringServiceProvider), typeof(XStringServiceProvider), lifeTime) ); services.Add( new ServiceDescriptor(typeof(IXStringRepositoryService), typeof(XStringRepositoryService), lifeTime) ); services.Add( new ServiceDescriptor(typeof(IXStringRepositoryProvider), typeof(XStringRepositoryProvider), lifeTime) ); // // Register XString Provider ... services.Add( new ServiceDescriptor(typeof(IXStringProvider), typeof(XStringProvider), lifeTime) ); // Log("Service Regitration Succeed ..."); } #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Extensions\XModelExtensions.cs using System.Collections.Generic; using System.Linq; using xCommons.Extensions; using xModels.Dtos; using xStringService.Models.Dtos; using xStringService.Models.Entities; namespace xStringService.Extensions { public static class XModelExtensions { /// /// Converts an Entity to LocaleResource Dto ... /// /// /// public static XLocaleResourceDto ToXLocaleResourceDto(this XString source) { // var result = new XLocaleResourceDto { Language = source.IsNull() ? "" : source.Language, Value = source.IsNull() ? "" : source.TranslatedValue, }; // return result; } /// /// Converts an Dto to LocaleResource Dto ... /// /// /// public static XLocaleResourceDto ToXLocaleResourceDto(this XStringDto source) { // var result = new XLocaleResourceDto { Language = source.IsNull() ? "" : source.Language, Value = source.IsNull() ? "" : source.TranslatedValue, }; // return result; } /// /// Converts a Collection of Entities to Locale Resource Presentation ... /// /// /// public static IEnumerable ToXLocaleResourceDtos(this IEnumerable source) { // var result = source.Select(e => ToXLocaleResourceDto(e)); return result; } /// /// Converts a Collection of Dtos to Locale Resource Presentation ... /// /// /// public static IEnumerable ToXLocaleResourceDtos(this IEnumerable source) { // var result = source.Select(e => ToXLocaleResourceDto(e)); return result; } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Helpers\XStringServiceHelper.cs using GraphQL.Types; using xDataHelper.Providers.GraphQL; using xDataService.Db; using xDataService.Models; using xDataService.Providers; using xStringService.Interfaces; using xStringService.Interfaces.Entities; using xStringService.Models.Entities; using xStringService.Providers.Entities; using xStringService.Providers.GraphQL; namespace xStringService.Helpers { public static class XStringServiceHelper { // #region EF Repository Descriptor Provider(s) ... public static XEFRepositoryDescriptor< XString, int, IXStringKeyGenerator, XStringKeyGenerator, IXStringRepositoryEvents, XStringRepositoryEvents, XStringGraphType, IntGraphType, XStringGraphQuery, IXStringGraphQLTypeHelper, XStringGraphQLTypeHelper, XStringGraphSchema, IXStringRepository, XStringEFRepository, TContext > GetXStringEFRepositoryDescriptor() where TContext : XDbContext { // var result = new XEFRepositoryDescriptor< XString, int, IXStringKeyGenerator, XStringKeyGenerator, IXStringRepositoryEvents, XStringRepositoryEvents, XStringGraphType, IntGraphType, XStringGraphQuery, IXStringGraphQLTypeHelper, XStringGraphQLTypeHelper, XStringGraphSchema, IXStringRepository, XStringEFRepository, TContext >(); // return result; } public static XEFRepositoryDescriptor< XString, int, IXStringKeyGenerator, XStringKeyGenerator, IXStringRepositoryEvents, XStringRepositoryEvents, XStringGraphType, IntGraphType, XStringGraphQuery, IXStringGraphQLTypeHelper, XStringGraphQLTypeHelper, XStringGraphSchema, IXStringRepository, XStringEFRepository, TContext, IXStringSeeder, TSeederImplementation > GetXStringEFRepositoryDescriptor() where TContext : XDbContext where TSeederImplementation : XBaseDbSeeder { // var result = new XEFRepositoryDescriptor< XString, int, IXStringKeyGenerator, XStringKeyGenerator, IXStringRepositoryEvents, XStringRepositoryEvents, XStringGraphType, IntGraphType, XStringGraphQuery, IXStringGraphQLTypeHelper, XStringGraphQLTypeHelper, XStringGraphSchema, IXStringRepository, XStringEFRepository, TContext, IXStringSeeder, TSeederImplementation >(); // return result; } #endregion // #region Mongo Repository Descriptor Provider(s) ... public static XMongoRepositoryDescriptor< XString, int, IXStringKeyGenerator, XStringKeyGenerator, IXStringRepositoryEvents, XStringRepositoryEvents, XStringGraphType, IntGraphType, XStringGraphQuery, IXStringGraphQLTypeHelper, XStringGraphQLTypeHelper, XStringGraphSchema, IXStringRepository, XStringMongoRepository > GetXStringMongoRepositoryDescriptor() { // var result = new XMongoRepositoryDescriptor< XString, int, IXStringKeyGenerator, XStringKeyGenerator, IXStringRepositoryEvents, XStringRepositoryEvents, XStringGraphType, IntGraphType, XStringGraphQuery, IXStringGraphQLTypeHelper, XStringGraphQLTypeHelper, XStringGraphSchema, IXStringRepository, XStringMongoRepository >(); // return result; } public static XMongoRepositoryDescriptor< XString, int, IXStringKeyGenerator, XStringKeyGenerator, IXStringRepositoryEvents, XStringRepositoryEvents, XStringGraphType, IntGraphType, XStringGraphQuery, IXStringGraphQLTypeHelper, XStringGraphQLTypeHelper, XStringGraphSchema, IXStringRepository, XStringMongoRepository, IXStringSeeder, TSeederImplementation > GetXStringMongoRepositoryDescriptor() where TSeederImplementation : XBaseDbSeeder { // var result = new XMongoRepositoryDescriptor< XString, int, IXStringKeyGenerator, XStringKeyGenerator, IXStringRepositoryEvents, XStringRepositoryEvents, XStringGraphType, IntGraphType, XStringGraphQuery, IXStringGraphQLTypeHelper, XStringGraphQLTypeHelper, XStringGraphSchema, IXStringRepository, XStringMongoRepository, IXStringSeeder, TSeederImplementation >(); // return result; } #endregion // #region InMemory Repository Descriptor Provider(s) ... public static XInMemoryRepositoryDescriptor< XString, int, IXStringKeyGenerator, XStringKeyGenerator, IXStringRepositoryEvents, XStringRepositoryEvents, XStringGraphType, IntGraphType, XStringGraphQuery, IXStringGraphQLTypeHelper, XStringGraphQLTypeHelper, XStringGraphSchema, IXStringRepository, XStringInMemoryRepository > GetXStringInMemoryRepositoryDescriptor() { // var result = new XInMemoryRepositoryDescriptor< XString, int, IXStringKeyGenerator, XStringKeyGenerator, IXStringRepositoryEvents, XStringRepositoryEvents, XStringGraphType, IntGraphType, XStringGraphQuery, IXStringGraphQLTypeHelper, XStringGraphQLTypeHelper, XStringGraphSchema, IXStringRepository, XStringInMemoryRepository >(); // return result; } public static XInMemoryRepositoryDescriptor< XString, int, IXStringKeyGenerator, XStringKeyGenerator, IXStringRepositoryEvents, XStringRepositoryEvents, XStringGraphType, IntGraphType, XStringGraphQuery, IXStringGraphQLTypeHelper, XStringGraphQLTypeHelper, XStringGraphSchema, IXStringRepository, XStringInMemoryRepository, IXStringSeeder, TSeederImplementation > GetXStringInMemoryRepositoryDescriptor() where TSeederImplementation : XBaseDbSeeder { // var result = new XInMemoryRepositoryDescriptor< XString, int, IXStringKeyGenerator, XStringKeyGenerator, IXStringRepositoryEvents, XStringRepositoryEvents, XStringGraphType, IntGraphType, XStringGraphQuery, IXStringGraphQLTypeHelper, XStringGraphQLTypeHelper, XStringGraphSchema, IXStringRepository, XStringInMemoryRepository, IXStringSeeder, TSeederImplementation >(); // return result; } #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\IXBaseItemResourceProviderController.cs using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using xModels.Dtos; using xStringService.Models.Dtos; namespace xStringService.Interfaces { public interface IXBaseItemResourceProviderController { /// /// Retrieve a List of Exists Languages ... /// /// if null or empty, check all languages in Item Side /// /// [HttpGet("Languages")] Task>> GetLanguages( [FromQuery] object identifier, CancellationToken cancellationToken = default ); /// /// Retrieve all Exists Items ... /// /// Specified Resource Title /// /// [HttpGet("ResourceLocales")] Task>> GetResourceLocales( [FromQuery] object identifier, CancellationToken cancellationToken = default ); /// /// Get all Exists Items for Specified identitifer ... /// /// /// /// [HttpGet("Locales/{identifier}")] Task>> GetLocales( [FromRoute] object identifier, CancellationToken cancellationToken = default ); /// /// Remove Specified Language Locale of Specified Identifier ... /// /// /// if null or empty Remove all Locales /// /// [HttpDelete("Locales/{identifier}")] Task> RemoveLocale( [FromRoute] object identifier, [FromQuery] string language, CancellationToken cancellationToken = default ); /// /// Check Specified ocale Exists for Specified Identifier ... /// /// /// /// /// [HttpGet("Locales/{identifier}/{language}/Has")] Task> HasLocale( [FromRoute] object identifier, [FromRoute] string language, CancellationToken cancellationToken = default ); /// /// Get all Exists Locales Representaion based on Specified Identitifer /// as XResourceDto ... /// /// /// /// [HttpGet("Resource/{identifier}")] Task> GetResource( [FromRoute] object identifier, CancellationToken cancellationToken = default ); /// /// Add Or Update Locale for Specified Identitifer ... /// /// /// /// /// [HttpPost("Locales/{identifier}")] Task> AddOrUpdateLocale( [FromRoute] object identifier, [FromBody] XLocaleResourceDto locale, CancellationToken cancellationToken = default ); /// /// Update a Resource State ... /// /// /// /// /// [HttpPost("Resource/{identifier}")] Task> AddOrUpdateResource( [FromRoute] object identifier, [FromBody] XResourceDto resource, CancellationToken cancellationToken = default ); } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\IXBaseResourceProviderController.cs using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using xModels.Dtos; using xStringService.Models.Dtos; namespace xStringService.Interfaces { public interface IXBaseResourceProviderController { /// /// Retrieve a List of Exists Languages ... /// /// /// [HttpGet("Languages")] Task>> GetLanguages( CancellationToken cancellationToken = default ); /// /// Retrieve all Exists Items ... /// /// Specified Resource Title /// /// [HttpGet("LocalesResource")] Task>> GetResourceLocales( CancellationToken cancellationToken = default ); /// /// Extract Translation of in Specified Language ... /// /// Specified Language ... /// /// [HttpGet("{language}/Translation")] Task> GetResourceTranslation( [FromRoute] string language, CancellationToken cancellationToken = default ); /// /// Check Has Specified Translation or not ... /// /// Specified Language ... /// /// [HttpGet("{language}/Has")] Task> HasLocale( [FromRoute] string language, CancellationToken cancellationToken = default ); /// /// Retrieve as Locale Model ... /// /// Specified Language ... /// /// [HttpGet("{language}/Locale")] Task> GetLocale( [FromRoute] string language, CancellationToken cancellationToken = default ); /// /// Retrieve all Exists Locale Models ... /// /// /// [HttpGet("Locales")] Task>> GetLocales( CancellationToken cancellationToken = default ); /// /// Retrieve as XResourceDto ... /// /// /// [HttpGet("Resource")] Task> GetResource( CancellationToken cancellationToken = default ); /// /// Add or Update a Resource Model ... /// /// a XResourceDto Model ... /// /// [HttpPost("")] Task> AddOrUpdateResource( [FromBody] XResourceDto resource, CancellationToken cancellationToken = default ); /// /// Add Or Update Locale ... /// /// /// /// [HttpPost("Locales")] Task> AddOrUpdateLocale( [FromBody] XLocaleResourceDto locale, CancellationToken cancellationToken = default ); /// /// Remove Locale ... /// /// /// /// [HttpPost("Locale/Remove")] Task> RemoveLocale( [FromBody] XLocaleResourceDto locale, CancellationToken cancellationToken = default ); /// /// Remove Specified Resource Model ... /// /// a XResourceDto Model ... /// /// [HttpPost("Resource/Remove")] Task RemoveResource( [FromBody] XResourceDto resource, CancellationToken cancellationToken = default ); } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\IXItemResourceProvider.cs using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using xModels.Dtos; using xStringService.Models.Dtos; namespace xStringService.Interfaces { public interface IXItemResourceProvider { // #region Group Actions ... /// /// Retrieve a List of Exists Languages for Current Item ... /// /// /// Task> GetLanguages( CancellationToken cancellationToken = default ); /// /// Retrieve all Exists Items of type ... /// /// /// Task> GetResourceLocales( CancellationToken cancellationToken = default ); /// /// Remove all Exists Locales which Related to this Provider ... /// /// /// /// Task RemoveResourceLocales( string connectionId = null, CancellationToken cancellationToken = default ); #endregion // #region Item Actions ... /// /// Get all Exists Items for Specified identitifer ... /// /// /// /// Task> GetResourceLocales( object identifier, CancellationToken cancellationToken = default ); /// /// 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 connectionId = 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 // #region Resource Title Action ... /// /// Retrieve Resource Title ... /// /// /// string GetResourceTitle(object identifier = null); #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\IXResourceProvider.cs using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using xModels.Dtos; using xStringService.Models.Dtos; namespace xStringService.Interfaces { public interface IXResourceProvider { /// /// Retrieve a List of Exists Languages ... /// /// /// Task> GetLanguages( CancellationToken cancellationToken = default ); /// /// Retrieve all Exists Items ... /// /// /// Task> GetResourceLocales( CancellationToken cancellationToken = default ); /// /// Extract Translation of in Specified Language ... /// /// Specified Language ... /// /// Task GetResourceTranslation( string language, CancellationToken cancellationToken = default ); /// /// Check Has Specified Translation or not ... /// /// Specified Language ... /// /// Task HasLocale( string language, CancellationToken cancellationToken = default ); /// /// Retrieve as Locale Model ... /// /// Specified Language ... /// /// Task GetLocale( string language, CancellationToken cancellationToken = default ); /// /// Retrieve all Exists Locale Models ... /// /// /// Task> GetLocales( CancellationToken cancellationToken = default ); /// /// Retrieve as XResourceDto ... /// /// /// Task GetResource( CancellationToken cancellationToken = default ); /// /// Add or Update a Resource Model ... /// /// a XResourceDto Model ... /// /// /// Task AddOrUpdateResource( XResourceDto resource, string connectionId = null, CancellationToken cancellationToken = default ); /// /// Add Or Update Locale ... /// /// /// /// /// Task AddOrUpdateLocale( XLocaleResourceDto locale, string connectionId = null, CancellationToken cancellationToken = default ); /// /// Remove Locale ... /// /// /// /// /// Task RemoveLocale( XLocaleResourceDto locale, string connectionId = null, CancellationToken cancellationToken = default ); /// /// Remove Specified Resource Model ... /// /// a XResourceDto Model ... /// /// /// Task RemoveResource( XResourceDto resource, string connectionId = null, CancellationToken cancellationToken = default ); } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\IXStringProvider.cs using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using xIdentityModels.Models; using xModels.Dtos; using xPushService.Interfaces; using xStringService.Models.Dtos; using xStringService.Models.Entities; using xStringService.Providers.Dtos; namespace xStringService.Interfaces { public interface IXStringProvider : IXBaseProvided { // #region Tools ... /// /// Retrieve a List of Exists Languages ... /// /// /// Task> GetLanguages( CancellationToken cancellationToken = default ); /// /// Retrieve a List of Resource Titles ... /// /// if provided, returns all language Specified resource titles, if not, all Resource Titles /// /// Task> GetResourceTitles( string language = null, CancellationToken cancellationToken = default ); /// /// Retrieve all Exists Items which belongs to Specified Resource Title ... /// /// Specified Resource Title /// /// Task> GetResourceLocales( string resource, CancellationToken cancellationToken = default ); /// /// Extract Translation of a Resource in Specified Language ... /// /// Specified Language ... /// Specified Resource Title ... /// /// Task GetResourceTranslation( string language, string resource, CancellationToken cancellationToken = default ); /// /// Retrieve a Resource as Locale Model ... /// /// Specified Language ... /// Specified Resource Title ... /// /// Task GetLocale( string language, string resource, CancellationToken cancellationToken = default ); /// /// Retrieve all Exists Resource Instances as Locale Models ... /// /// /// /// Task> GetLocales( string resource, CancellationToken cancellationToken = default ); /// /// Retrieve all Locales of Specified Resource and Represent as XResourceDto ... /// /// /// /// Task GetResource( string resource, CancellationToken cancellationToken = default ); /// /// 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 ); /// /// Remove Specified Resource Model ... /// /// a XResourceDto Model ... /// Actor User for Permissions ... /// /// /// Task RemoveResource( XResourceDto resource, XUserClaimsInfoDto userInfo = null, string connectionId = null, CancellationToken cancellationToken = default ); #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\IXStringProviderController.cs using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using xModels.Dtos; using xPushService.Interfaces; using xStringService.Models.Dtos; using xStringService.Models.Entities; using xStringService.Providers.Dtos; namespace xStringService.Interfaces { public interface IXStringProviderController : IXBaseProvidedController { // #region Tools ... /// /// Retrieve a List of Exists Languages ... /// /// /// [HttpGet("Languages")] Task>> GetLanguages( CancellationToken cancellationToken = default ); /// /// Retrieve a List of Resource Titles ... /// /// if provided, returns all language Specified resource titles, if not, all Resource Titles /// /// [HttpGet("ResourceTitles")] Task>> GetResourceTitles( [FromQuery] string language = null, CancellationToken cancellationToken = default ); /// /// Retrieve all Exists Items which belongs to Specified Resource Title ... /// /// Specified Resource Title /// /// [HttpGet("ResourceLocales")] Task>> GetResourceLocales( [FromQuery] string resource, CancellationToken cancellationToken = default ); /// /// Extract Translation of a Resource in Specified Language ... /// /// Specified Language ... /// Specified Resource Title ... /// /// [HttpGet("Translation")] Task> GetResourceTranslation( [FromQuery] string language, [FromQuery] string resource, CancellationToken cancellationToken = default ); /// /// Retrieve a Resource as Locale Model ... /// /// Specified Language ... /// Specified Resource Title ... /// /// [HttpGet("Locale")] Task> GetLocale( [FromQuery] string language, [FromQuery] string resource, CancellationToken cancellationToken = default ); /// /// Retrieve all Exists Resource Instances as Locale Models ... /// /// /// /// [HttpGet("Locales")] Task>> GetLocales( [FromQuery] string resource, CancellationToken cancellationToken = default ); /// /// Retrieve all Locales of Specified Resource and Represent as XResourceDto ... /// /// /// /// [HttpGet("GetResource")] Task> GetResource( [FromQuery] string resource, CancellationToken cancellationToken = default ); /// /// Add or Update a Resource Model ... /// /// a XResourceDto Model ... /// /// [HttpPost("AddOrUpdateResource")] Task> AddOrUpdateResource( [FromBody] XResourceDto resource, CancellationToken cancellationToken = default ); /// /// Remove Specified Resource Model ... /// /// a XResourceDto Model ... /// /// [HttpPost("RemoveResource")] Task RemoveResource( [FromBody] XResourceDto resource, CancellationToken cancellationToken = default ); #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\Dtos\IXStringDtoHub.cs using xPushService.Interfaces; using xStringService.Models.Dtos; using xStringService.Models.Entities; namespace xStringService.Interfaces.Dtos { public interface IXStringDtoHub : IXBaseDtoHub { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\Dtos\IXStringRepositoryService.cs using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; using xDataService.Interfaces; using xModels.Dtos; using xStringService.Models.Dtos; using xStringService.Models.Entities; namespace xStringService.Interfaces.Dtos { public interface IXStringRepositoryService : IXBaseRepositoryService { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\Dtos\IXStringServiceProvider.cs using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using xCommons.Configurations; using xModels.Dtos; using xPushService.Interfaces; using xStringService.Models.Dtos; using xStringService.Models.Entities; using xStringService.Providers.Dtos; namespace xStringService.Interfaces.Dtos { public interface IXStringServiceProvider : IXBaseDtoProvider { /// /// Application Configuration ... /// XAppConfiguration AppConfiguration { get; } // #region Retrievers ... /// /// Retrieve all Exists Languages ... /// /// /// Task> GetLanguages( CancellationToken cancellationToken = default ); /// /// Check Specified Resource Exists or not ... /// /// /// /// /// Task IsResourceExists( string resource, string language = null, CancellationToken cancellationToken = default ); /// /// Retrieve Specified Resource ... /// /// /// /// /// Task Get( string resource, string language = null, CancellationToken cancellationToken = default ); /// /// Retrieve Specified Translation of Specified Resource ... /// /// /// /// /// Task GetResourceValue( string resource, string language = null, CancellationToken cancellationToken = default ); /// /// Retrieve an Specified Resource Items ... /// /// /// /// Task> GetResources( string resource, CancellationToken cancellationToken = default ); /// /// Retrieve Specified Resource Items as XResourceDto Presentation ... /// /// /// /// Task GetResource( string resource, CancellationToken cancellationToken = default ); #endregion // #region Query ... /// /// Query Resource IDs ... /// /// /// /// Task> QueryResourceIds( XQuery query, CancellationToken cancellationToken = default ); /// /// Query Specified Language Resources ... /// /// /// /// /// Task> QueryLanguageResources( XQuery query, string language = null, CancellationToken cancellationToken = default ); /// /// Query Locale Resources ... /// /// /// /// /// Task> QueryLocaleResources( XQuery query, string language = null, CancellationToken cancellationToken = default ); #endregion // #region Add/Update Actions ... /// /// Add Specified Resource ... /// /// /// /// /// /// /// Task Add( string resource, string value, string language = null, string connectionId = null, CancellationToken cancellationToken = default ); /// /// Update Resource ... /// /// /// /// /// /// /// Task Update( string resource, string value, string language = null, string connectionId = null, CancellationToken cancellationToken = default ); /// /// Add Or Update Resource ... /// /// /// /// /// /// /// Task AddOrUpdate( string resource, string value, string language = null, string connectionId = null, CancellationToken cancellationToken = default ); /// /// Add Specified Locale Resource ... /// /// /// /// /// /// Task AddByLocaleResource( XLocaleResourceDto item, string resource, string connectionId = null, CancellationToken cancellationToken = default ); /// /// Update Specified Locale Resource ... /// /// /// /// /// /// Task UpdateByLocaleResource( XLocaleResourceDto item, string resource, string connectionId = null, CancellationToken cancellationToken = default ); /// /// Add Or Update Resource By Locale ... /// /// /// /// /// /// Task AddOrUpdateByLocaleResource( XLocaleResourceDto item, string resource, string connectionId = null, CancellationToken cancellationToken = default ); /// /// Add Or Update all XResourceDto(s) Locales ... /// /// /// /// /// Task> AddByResource( XResourceDto item, string connectionId = null, CancellationToken cancellationToken = default ); #endregion // #region Remove Actions ... /// /// Remove all Specified Language's Resources ... /// /// /// /// /// Task RemoveLanguageResources( string language, string connectionId = null, CancellationToken cancellationToken = default ); /// /// Remove all Specified Resource Ids instances ... /// /// /// /// /// Task> RemoveResource( string resource, string connectionId = null, CancellationToken cancellationToken = default ); /// /// Remove Specified Resource ... /// /// /// /// /// /// Task Remove( string resource, string language = null, string connectionId = null, CancellationToken cancellationToken = default ); /// /// Remove all Resource of Specified XResourceDto ... /// /// /// /// /// Task RemoveByResource( XResourceDto item, string connectionId = null, CancellationToken cancellationToken = default ); #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\Entities\IXStringEntityHub.cs using xPushService.Interfaces; using xStringService.Models.Entities; namespace xStringService.Interfaces.Entities { public interface IXStringEntityHub : IXBaseEntityHub { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\Entities\IXStringGraphQLTypeHelper.cs using xDataService.Interfaces; using xStringService.Models.Entities; namespace xStringService.Interfaces.Entities { public interface IXStringGraphQLTypeHelper : IXBaseGraphQLTypeHelper { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\Entities\IXStringKeyGenerator.cs using xDataService.Interfaces; using xStringService.Models.Entities; namespace xStringService.Interfaces.Entities { public interface IXStringKeyGenerator : IXKeyGenerator { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\Entities\IXStringRepository.cs using xDataService.Interfaces; using xStringService.Models.Entities; namespace xStringService.Interfaces.Entities { public interface IXStringRepository : IXBaseRepository { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\Entities\IXStringRepositoryEvents.cs using xDataService.Interfaces; using xStringService.Models.Entities; namespace xStringService.Interfaces.Entities { public interface IXStringRepositoryEvents : IXBaseRepositoryEvents { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\Entities\IXStringRepositoryProvider.cs using xPushService.Interfaces; using xStringService.Models.Entities; using xStringService.Providers.Entities; namespace xStringService.Interfaces.Entities { public interface IXStringRepositoryProvider : IXBaseEntityProvider { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Interfaces\Entities\IXStringSeeder.cs using xDataService.Interfaces; using xStringService.Models.Entities; namespace xStringService.Interfaces.Entities { public interface IXStringSeeder : IXBaseDbSeeder {} } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Models\Dtos\XStringDto.cs using xModels.Base; namespace xStringService.Models.Dtos { public class XStringDto : XBaseIntIDEntityDto { public string Language { get; set; } public string ResourceTitle { get; set; } public string TranslatedValue { get; set; } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Models\Entities\XString.cs using System.ComponentModel.DataAnnotations; using xModels.Base; namespace xStringService.Models.Entities { public class XString : XBaseIntIDEntity { [Required] [StringLength (10)] public string Language { get; set; } [Required] [StringLength (255)] public string ResourceTitle { get; set; } [Required] public string TranslatedValue { get; set; } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\XBaseItemResourceProvider.cs using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using xCommons.Extensions; using xExceptions.Constants; using xModels.Dtos; using xStringService.Interfaces; using xStringService.Interfaces.Dtos; using xStringService.Models.Dtos; namespace xStringService.Providers { public abstract class XBaseItemResourceProvider : IXItemResourceProvider { // #region Props ... /// /// Item Name for Resource Providing ... /// private readonly string item; /// /// an Implementation of Item Resource Provider /// /// private readonly XBaseResourceProvider provider; /// /// String Provider Service ... /// private readonly IXStringServiceProvider stringProvider; #endregion // #region Constructor ... protected XBaseItemResourceProvider( string item, IXStringServiceProvider stringProvider ) { // this.item = item; this.stringProvider = stringProvider; provider = new XBaseResourceProvider( item, stringProvider ); } #endregion // #region Group Actions ... /// /// Retrieve a List of Exists Languages for Current Item ... /// /// /// public virtual async Task> GetLanguages( CancellationToken cancellationToken = default ) { // var result = (await ExtractItems(cancellationToken)) .Select(x => x.Language) .Distinct(); // return result; } /// /// Retrieve all Exists Items of type ... /// /// /// public virtual async Task> GetResourceLocales( CancellationToken cancellationToken = default ) { // 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; } /// /// Update a Resource State ... /// /// /// /// /// /// public virtual async Task AddOrUpdateResource( object identifier, XResourceDto resource, string connectionId = null, CancellationToken cancellationToken = default ) { // // Validate ... var isValid = !identifier.IsNull(); if (!isValid) { XException.InvalidArgs.Throw(); } // // 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; } // // Setting Resource Title ... SetResourceTitle(identifier); // // Retrieve Resource List ... var result = await provider .AddOrUpdateResource( resource: resource, connectionId: connectionId, cancellationToken: cancellationToken ); // return result; } /// /// Remove Specified Language Locale of Specified Identifier ... /// /// /// /// /// /// public virtual async Task RemoveLocale( object identifier, string language, string connectionId = null, CancellationToken cancellationToken = default ) { // // Validate ... var isValid = !identifier.IsNull() && !language.IsNullOrEmpty(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Check Locale Exists ... isValid = await HasLocale( language: language, identifier: identifier, cancellationToken: cancellationToken ); if (!isValid) { XException.NotFound.Throw(); } // var locale = (await GetLocales( identifier: identifier, cancellationToken: cancellationToken )) .FirstOrDefault(x => x.Language.Equals(language, StringComparison.InvariantCultureIgnoreCase)); isValid = !locale.IsNullOrDefault(); if (!isValid) { XException.NotFound.Throw(); } // // Setting Resource Title ... SetResourceTitle(identifier); // var result = await provider.RemoveLocale( locale: locale, connectionId: connectionId, cancellationToken: cancellationToken ); // 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) { 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 // #region Resource Title Action ... /// /// Retrieve Resource Title ... /// /// /// public string GetResourceTitle(object identifier = null) { // var result = item; // if (!identifier.IsNull()) { result = $"{item}_{identifier}"; } // return result; } #endregion // #region Private ... /// /// Set Resource Title ... /// /// private void SetResourceTitle(object identifier = null) { // var itemIdentifier = GetResourceTitle(identifier); provider.SetField( field: "resource", 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 } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\XBaseResourceProvider.cs using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using xCommons.Extensions; using xExceptions.Constants; using xModels.Dtos; using xStringService.Extensions; using xStringService.Interfaces; using xStringService.Interfaces.Dtos; using xStringService.Models.Dtos; namespace xStringService.Providers { public class XBaseResourceProvider : IXResourceProvider { protected string resource; private readonly IXStringServiceProvider provider; public XBaseResourceProvider( string resource, IXStringServiceProvider provider ) { this.resource = resource; this.provider = provider; } // #region Actions ... /// /// Retrieve a List of Exists Languages ... /// /// /// public virtual async Task> GetLanguages( CancellationToken cancellationToken = default ) { // var result = (await ExtractItems(cancellationToken)) .Select(x => x.Language) .Distinct() .ToList(); // return result; } /// /// Retrieve all Exists Items ... /// /// Specified Resource Title /// /// public virtual async Task> GetResourceLocales( CancellationToken cancellationToken = default ) { // var result = await ExtractItems(cancellationToken); // return result; } /// /// Extract Translation of in Specified Language ... /// /// Specified Language ... /// /// public virtual async Task GetResourceTranslation( string language, CancellationToken cancellationToken = default ) { // var item = (await ExtractItems(cancellationToken)) .FirstOrDefault(x => x.Language.Equals(language, StringComparison.InvariantCultureIgnoreCase)); // var result = item?.TranslatedValue ?? string.Empty; // return result; } /// /// Check Has Specified Translation or not ... /// /// Specified Language ... /// /// public virtual async Task HasLocale( string language, CancellationToken cancellationToken = default ) { // var item = (await ExtractItems(cancellationToken)) .FirstOrDefault(x => x.Language.Equals(language, StringComparison.InvariantCultureIgnoreCase)); // var result = !item.IsNullOrDefault(); // return result; } /// /// Retrieve as Locale Model ... /// /// Specified Language ... /// /// public virtual async Task GetLocale( string language, CancellationToken cancellationToken = default ) { // var item = (await ExtractItems(cancellationToken)) .FirstOrDefault(x => x.Language.Equals(language, StringComparison.InvariantCultureIgnoreCase)); // var result = !item.IsNullOrDefault() ? item.ToXLocaleResourceDto() : null; // return result; } /// /// Retrieve all Exists Locale Models ... /// /// /// public virtual async Task> GetLocales( CancellationToken cancellationToken = default ) { // var result = (await ExtractItems(cancellationToken)) .Select(x => x.ToXLocaleResourceDto()) .ToList(); // return result; } /// /// Retrieve as XResourceDto ... /// /// /// /// public virtual async Task GetResource( CancellationToken cancellationToken = default ) { // var locales = await GetLocales(); // var result = new XResourceDto { Locales = locales, Resource = resource, }; // return result; } /// /// Add or Update a Resource Model ... /// /// a XResourceDto Model ... /// /// /// public virtual async Task AddOrUpdateResource( XResourceDto resource, string connectionId = null, CancellationToken cancellationToken = default ) { // var isValid = !resource.IsNullOrDefault() && resource.Resource == this.resource; if (!isValid) { XException.InvalidArgs.Throw(); } // // Retrieve Exists Resource ... var result = await GetResource(cancellationToken); isValid = !result.IsNullOrDefault() && result.Locales.HasChild(); if (isValid) { await RemoveResource( resource: result, connectionId: connectionId, cancellationToken: cancellationToken ); } // foreach (var locale in resource.Locales) { // var item = new XStringDto { Language = locale.Language, ResourceTitle = this.resource, TranslatedValue = locale.Value, }; // await provider.AddAsync( item: item, saveChanges: true, connectionId: connectionId, cancellationToken: cancellationToken ); } // result = await GetResource(cancellationToken); return result; } /// /// Add Or Update Locale ... /// /// /// /// public virtual async Task AddOrUpdateLocale( XLocaleResourceDto locale, string connectionId = null, CancellationToken cancellationToken = default ) { // var item = (await ExtractItems(cancellationToken)) .FirstOrDefault(x => x.ResourceTitle == resource && x.Language == locale.Language); var isExists = !item.IsNullOrDefault(); if (isExists) { item.TranslatedValue = locale.Value; item = await provider.UpdateAsync( item: item, id: item.Id, saveChanges: true, connectionId: connectionId, cancellationToken: cancellationToken ); } else { item = new XStringDto { ResourceTitle = resource, Language = locale.Language, TranslatedValue = locale.Value }; item = await provider.AddAsync( item: item, saveChanges: true, connectionId: connectionId, cancellationToken: cancellationToken ); } // var result = await GetResource(cancellationToken); // return result; } /// /// Remove Locale ... /// /// /// /// /// public virtual async Task RemoveLocale( XLocaleResourceDto locale, string connectionId = null, CancellationToken cancellationToken = default ) { // var item = (await ExtractItems(cancellationToken)) .FirstOrDefault(x => x.ResourceTitle == resource && x.Language == locale.Language); var isExists = !item.IsNullOrDefault(); if (isExists) { await provider.RemoveAsync( id: item.Id, softDelete: false, saveChanges: true, connectionId: connectionId, cancellationToken: cancellationToken ); } // var result = await GetResource(cancellationToken); // return result; } /// /// Remove Specified Resource Model ... /// /// a XResourceDto Model ... /// /// /// public virtual async Task RemoveResource( XResourceDto resource, 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); // foreach (var item in items) { // await provider.RemoveAsync( id: item.Id, softDelete: false, saveChanges: true, connectionId: connectionId, cancellationToken: cancellationToken ); } } #endregion // #region Private ... private async Task> ExtractItems( CancellationToken cancellationToken = default ) { // var result = await provider.FindManyAsync( includeBuilder: null, ignoreSoftDeleteds: true, orderBuilder: x => x .OrderBy(y => y.Language) .ThenBy(y => y.ResourceTitle), cancellationToken: cancellationToken, predicate: x => x.ResourceTitle.Equals(resource, StringComparison.InvariantCultureIgnoreCase) ); // return result; } #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\XStringEntityRegisterar.cs using Microsoft.EntityFrameworkCore; using xDataService.Interfaces; using xDataService.Providers; using xStringService.Configurations.Entities; using xStringService.Models.Entities; namespace xStringService.Providers { /// /// an Entity Registerar class for XStringService ... /// public class XStringEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar { public XStringEntityRegisterar() : base(nameof(XStringEntityRegisterar)) { // // Add XString Entity ... AddEntity(); } /// /// Configure Entities ... /// /// public override void ConfigureEntities(ModelBuilder modelBuilder) { // // Configure Entity Using Provided ... modelBuilder .ApplyConfigurationsFromAssembly(typeof(XStringEntityConfiguration).Assembly); // base.ConfigureEntities(modelBuilder); } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\XStringProvider.cs using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using xCommons.Extensions; using xExceptions.Constants; using xIdentityModels.Models; using xModels.Dtos; using xPushService.Providers; using xStringService.Extensions; using xStringService.Interfaces; using xStringService.Interfaces.Dtos; using xStringService.Models.Dtos; using xStringService.Models.Entities; using xStringService.Providers.Dtos; namespace xStringService.Providers { public class XStringProvider : XBaseProvided, IXStringProvider { public XStringProvider( IXStringServiceProvider provider ) : base( provider, permittedRoles: new string[] { } ) { } public override bool IsOwned( XStringDto item, XUserClaimsInfoDto userInfo ) { return !item.IsNullOrDefault(); } public override bool IsOwned( XString item, XUserClaimsInfoDto userInfo ) { return !item.IsNullOrDefault(); } // #region Tools ... /// /// Retrieve a List of Exists Languages ... /// /// /// public async Task> GetLanguages( CancellationToken cancellationToken = default ) { // var result = (await GetAll( includeBuilder: null, cancellationToken: cancellationToken, orderBuilder: x => x.OrderBy(y => y.Language) )) .Select(x => x.Language) .Distinct() .ToList(); // return result; } /// /// Retrieve a List of Resource Titles ... /// /// if provided, returns all language Specified resource titles, if not, all Resource Titles /// /// public async Task> GetResourceTitles( string language = null, CancellationToken cancellationToken = default ) { // var result = (await FindMany( includeBuilder: null, cancellationToken: cancellationToken, orderBuilder: x => x.OrderBy(y => y.ResourceTitle), predicate: x => string.IsNullOrWhiteSpace(language) || x.Language.Equals(language, System.StringComparison.InvariantCultureIgnoreCase) )) .Select(x => x.ResourceTitle) .Distinct() .ToList(); // return result; } /// /// Retrieve all Exists Items which belongs to Specified Resource Title ... /// /// Specified Resource Title /// /// public async Task> GetResourceLocales( string resource, CancellationToken cancellationToken = default ) { // var result = await FindMany( includeBuilder: null, cancellationToken: cancellationToken, orderBuilder: x => x.OrderBy(y => y.Language), predicate: x => !string.IsNullOrWhiteSpace(resource) && resource.Equals(x.ResourceTitle, System.StringComparison.InvariantCultureIgnoreCase) ); // return result; } /// /// Extract Translation of a Resource in Specified Language ... /// /// Specified Language ... /// Specified Resource Title ... /// /// public async Task GetResourceTranslation( string language, string resource, CancellationToken cancellationToken = default ) { // var result = (await FindOne( includeBuilder: null, cancellationToken: cancellationToken, predicate: x => !string.IsNullOrWhiteSpace(language) && !string.IsNullOrWhiteSpace(resource) && x.Language.Equals(language, System.StringComparison.InvariantCultureIgnoreCase) && x.ResourceTitle.Equals(resource, System.StringComparison.InvariantCultureIgnoreCase) ))? .TranslatedValue ?? ""; // return result; } /// /// Retrieve a Resource as Locale Model ... /// /// Specified Language ... /// Specified Resource Title ... /// /// public async Task GetLocale( string language, string resource, CancellationToken cancellationToken = default ) { // var result = (await FindOne( includeBuilder: null, cancellationToken: cancellationToken, predicate: x => !string.IsNullOrWhiteSpace(language) && !string.IsNullOrWhiteSpace(resource) && x.Language.Equals(language, System.StringComparison.InvariantCultureIgnoreCase) && x.ResourceTitle.Equals(resource, System.StringComparison.InvariantCultureIgnoreCase) ))? .ToXLocaleResourceDto() ?? null; // return result; } /// /// Retrieve all Exists Resource Instances as Locale Models ... /// /// /// /// public async Task> GetLocales( string resource, CancellationToken cancellationToken = default ) { // var result = (await GetResourceLocales( resource: resource, cancellationToken: cancellationToken )) .ToList() .Select(x => x.ToXLocaleResourceDto()) .ToList(); // return result; } /// /// Retrieve all Locales of Specified Resource and Represent as XResourceDto ... /// /// /// /// public async Task GetResource( string resource, CancellationToken cancellationToken = default ) { // XResourceDto result = null; // // Validate Resource ... if (resource.IsNullOrEmpty()) { return result; } // // Extract Locales of Resource ... var locales = await GetLocales( resource: resource, cancellationToken: cancellationToken ); // // Prepare Result ... result = new XResourceDto { Locales = locales, Resource = resource, }; // return result; } /// /// Add or Update a Resource Model ... /// /// a XResourceDto Model ... /// Actor User for Permissions ... /// /// /// public async Task AddOrUpdateResource( XResourceDto resource, XUserClaimsInfoDto userInfo = null, string connectionId = null, CancellationToken cancellationToken = default ) { // XResourceDto result = null; // // Validate Args ... var isValid = !resource.IsNullOrDefault() && !resource.Resource.IsNullOrEmpty(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Check Permissions ... isValid = userInfo.IsNullOrDefault() || HasPermision(userInfo); if (!isValid) { XException.NotAllowed.Throw(); } // // Remove all Resources if Exists ... result = await GetResource( resource: resource.Resource, cancellationToken: cancellationToken ); var isExists = !result.IsNullOrDefault(); if (isExists) { // await RemoveResource( resource: result, userInfo: userInfo, cancellationToken: cancellationToken ); } // // Loop through all Exists Locales and Add them ... foreach (var locale in resource.Locales) { // if (cancellationToken.IsCancellationRequested) { break; } // var item = new XStringDto { Language = locale.Language, TranslatedValue = locale.Value, ResourceTitle = resource.Resource, }; await Add( item: item, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); } // // Reload Result after Updates ... result = await GetResource( resource: resource.Resource, cancellationToken: cancellationToken ); // return result; } /// /// Remove Specified Resource Model ... /// /// a XResourceDto Model ... /// Actor User for Permissions ... /// /// /// public async Task RemoveResource( XResourceDto resource, XUserClaimsInfoDto userInfo = null, string connectionId = null, CancellationToken cancellationToken = default ) { // // Validate ... var isValid = !resource.IsNullOrDefault(); if (!isValid) { return; } // var items = await GetResourceLocales( resource: resource.Resource, cancellationToken: cancellationToken ); isValid = !items.IsNullOrDefault() && items.HasChild(); if (!isValid) { return; } // foreach (var item in items) { // if (cancellationToken.IsCancellationRequested) { break; } // await Remove( id: item.Id, userInfo: userInfo, connectionId: connectionId, cancellationToken: cancellationToken ); } } #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\Dtos\XStringDtoHub.cs using Microsoft.Extensions.Logging; using xPushService.Base; using xStringService.Interfaces.Dtos; using xStringService.Models.Dtos; using xStringService.Models.Entities; namespace xStringService.Providers.Dtos { public class XStringDtoHub : XBaseDtoHub, IXStringDtoHub { public XStringDtoHub( ILogger logger ) : base(logger) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\Dtos\XStringRepositoryService.cs using System.Collections.Generic; using AutoMapper; using xDataService.Providers; using xStringService.Interfaces.Dtos; using xStringService.Interfaces.Entities; using xStringService.Models.Dtos; using xStringService.Models.Entities; namespace xStringService.Providers.Dtos { public class XStringRepositoryService : XBaseRepositoryService, IXStringRepositoryService { public XStringRepositoryService( IXStringRepository repository, IEnumerable mapperProfiles = null ) : base( repository, mapperProfiles ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\Dtos\XStringServiceProvider.cs using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.SignalR; using xCommons.Configurations; using xCommons.Extensions; using xDataService.Configuration; using xExceptions.Constants; using xIdentityService.Interfaces; using xModels.Dtos; using xPushService.Base; using xPushService.Constants; using xStringService.Extensions; using xStringService.Interfaces.Dtos; using xStringService.Models.Dtos; using xStringService.Models.Entities; namespace xStringService.Providers.Dtos { public class XStringServiceProvider : XBaseDtoProvider, IXStringServiceProvider { public XAppConfiguration AppConfiguration { get; } public XStringServiceProvider( IHubContext hub, XDataServiceConfiguration dataConfiguration, IXStringRepositoryService service, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider = null ) : base( hub, dataConfiguration, service, identityProvider ) { AppConfiguration = appConfiguration; } // #region Retrievers ... /// /// Retrieve all Exists Languages ... /// /// /// public async Task> GetLanguages( CancellationToken cancellationToken = default ) { // var result = (await Service.GetAllAsync( includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken, orderBuilder: x => x.OrderBy(y => y.Language) )) .AsQueryable() .Select(e => e.Language) .Distinct() .ToList(); // // Check Configuration Default Language Exists ... var hasDefaultLanguage = !AppConfiguration.DefaultLanguage.IsNullOrEmpty(); if (hasDefaultLanguage) { // // Find Default Language on Result ... hasDefaultLanguage = result.Any(e => e.ToNormalString() == AppConfiguration.DefaultLanguage.ToNormalString()); if (!hasDefaultLanguage) { result.Add(AppConfiguration.DefaultLanguage); } } // result = result .Distinct() .ToList(); // return result; } /// /// Check Specified Resource Exists or not ... /// /// /// /// /// public async Task IsResourceExists( string resource, string language = null, CancellationToken cancellationToken = default ) { // var result = false; // // Validate ... result = !resource.IsNullOrEmpty(); if (!result) { return result; } // XStringDto dto = null; if (language.IsNullOrEmpty()) { // dto = await Service .FindOneAsync( includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken, predicate: e => e.ResourceTitle == resource ); } else { // dto = await Service .FindOneAsync( includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken, predicate: e => e.ResourceTitle == resource && e.Language.ToNormalString() == language.ToNormalString() ); } // result = !dto.IsNullOrDefault(); // return result; } /// /// Retrieve Specified Resource ... /// /// /// /// /// public async Task Get( string resource, string language = null, CancellationToken cancellationToken = default ) { // // Normalize ... if (language.IsNullOrEmpty()) { language = AppConfiguration.DefaultLanguage; } // // Validate ... if (resource.IsNullOrEmpty() || language.IsNullOrEmpty()) { XException.InvalidArgs.Throw(); } // // Check Resource Exists ... var isExists = await IsResourceExists( resource: resource, language: language ); if (!isExists) { XException.NotFound.Throw(); } // var result = await Service .FindOneAsync( includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken, predicate: e => e.ResourceTitle == resource && e.Language.ToNormalString() == language.ToNormalString() ); if (result.IsNullOrDefault()) { XException.ActionFailed.Throw(); } // return result; } /// /// Retrieve Specified Translation of Specified Resource ... /// /// /// /// /// public async Task GetResourceValue( string resource, string language = null, CancellationToken cancellationToken = default ) { // var result = ""; // // Normalize ... if (language.IsNullOrEmpty()) { language = AppConfiguration.DefaultLanguage; } // // Validate ... var isValid = !resource.IsNullOrEmpty() && !language.IsNullOrEmpty(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Check Langauage Exists ... var languages = await GetLanguages(cancellationToken); isValid = languages.Any(l => l.ToNormalString() == language.ToNormalString()); if (!isValid) { XException.NotFound.Throw(); } // // Check Resource Exists ... isValid = await IsResourceExists( resource: resource, language: language, cancellationToken: cancellationToken ); if (!isValid) { XException.NotFound.Throw(); } // var dto = await Service.FindOneAsync( includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken, predicate: e => e.ResourceTitle == resource && e.Language.ToNormalString() == language.ToNormalString() ); isValid = !dto.IsNullOrDefault(); if (!isValid) { XException.ActionFailed.Throw(); } // result = dto.TranslatedValue; // return result; } /// /// Retrieve an Specified Resource Items ... /// /// /// /// public async Task> GetResources( string resource, CancellationToken cancellationToken = default ) { // // Validate ... var isValid = await IsResourceExists(resource); if (!isValid) { XException.NotFound.Throw(); } // var result = await Service .FindManyAsync( includeBuilder: null, ignoreSoftDeleteds: true, predicate: e => e.ResourceTitle == resource, orderBuilder: x => x.OrderBy(y => y.ResourceTitle), cancellationToken: cancellationToken ); // return result; } /// /// Retrieve Specified Resource Items as XResourceDto Presentation ... /// /// /// /// public async Task GetResource( string resource, CancellationToken cancellationToken = default ) { // // Validate ... bool isExists = await IsResourceExists( language: null, resource: resource, cancellationToken: cancellationToken ); if (!isExists) { XException.NotFound.Throw(); } // // Retrieve String Dto (s) ... var resources = await GetResources( resource: resource, cancellationToken: cancellationToken ); if (!resource.HasChild()) { XException.NotFound.Throw(); } // var result = new XResourceDto { Resource = resource, Locales = resources.ToXLocaleResourceDtos() }; // return result; } #endregion // #region Query ... /// /// Query Resource IDs ... /// /// /// /// public async Task> QueryResourceIds( XQuery query, CancellationToken cancellationToken = default ) { // var dtoResult = await Service.QueryAsync( query: query, predicate: null, includeBuilder: null, ignoreSoftDeleteds: true, orderBuilder: x => x.OrderBy(y => y.ResourceTitle), cancellationToken: cancellationToken ); // var result = new XQueryResult() .UpdateData( updateWith: dtoResult, propertyBlackList: new List { nameof(XQueryResult.Items) }); // result.Items = dtoResult.Items.ToList().Select(dto => dto.ResourceTitle); // return result; } /// /// Query Specified Language Resources ... /// /// /// /// /// public async Task> QueryLanguageResources( XQuery query, string language = null, CancellationToken cancellationToken = default ) { // var result = await Service.QueryAsync( query: query, includeBuilder: null, ignoreSoftDeleteds: true, orderBuilder: x => x .OrderBy(y => y.Language) .ThenBy(y => y.ResourceTitle), cancellationToken: cancellationToken, predicate: x => x.Language.ToNormalString() == language.ToNormalString() ); // return result; } /// /// Query Locale Resources ... /// /// /// /// /// public async Task> QueryLocaleResources( XQuery query, string language = null, CancellationToken cancellationToken = default ) { // Expression> predicate = null; if (!language.IsNullOrEmpty()) { // predicate = x => x.Language.ToNormalString() == language.ToNormalString(); } // var dtoResult = await Service.QueryAsync( query: query, includeBuilder: null, predicate: predicate, ignoreSoftDeleteds: true, orderBuilder: x => x .OrderBy(y => y.Language) .ThenBy(y => y.ResourceTitle), cancellationToken: cancellationToken ); // var result = new XQueryResult() .UpdateData( updateWith: dtoResult, propertyBlackList: new List { nameof(XQueryResult.Items) }); // result.Items = dtoResult.Items.ToList().ToXLocaleResourceDtos(); // return result; } #endregion // #region Add/Update Actions ... /// /// Add Specified Resource ... /// /// /// /// /// /// /// public async Task Add( string resource, string value, string language = null, string connectionId = null, CancellationToken cancellationToken = default ) { // bool result = false; // // Normalize ... if (language.IsNullOrEmpty()) { language = AppConfiguration.DefaultLanguage; } // // Validate ... result = !value.IsNullOrEmpty() && !resource.IsNullOrEmpty() && !language.IsNullOrEmpty(); if (!result) { return result; } // // Check Exists ... bool isExists = await IsResourceExists( resource: resource, language: language, cancellationToken: cancellationToken ); result = !isExists; if (!result) { XException.Duplicate.Throw(); } // // Prepare Entity to Add ... XStringDto item = new XStringDto { Language = language, TranslatedValue = value, ResourceTitle = resource, }; item = await AddAsync( item: item, saveChanges: true, connectionId: connectionId, cancellationToken: cancellationToken ); result = !item.IsNullOrDefault(); // return result; } /// /// Update Resource ... /// /// /// /// /// /// /// public async Task Update( string resource, string value, string language = null, string connectionId = null, CancellationToken cancellationToken = default ) { // bool result = false; // // Normalize ... if (language.IsNullOrEmpty()) { language = AppConfiguration.DefaultLanguage; } // // Validate ... result = !value.IsNullOrEmpty() && !language.IsNullOrEmpty() && !resource.IsNullOrEmpty(); if (!result) { return result; } // // Check Value Must Exists ... result = await IsResourceExists( resource: resource, language: language, cancellationToken: cancellationToken ); if (!result) { XException.NotFound.Throw(); } // var item = await Get( language: language, resource: resource, cancellationToken: cancellationToken ); item.TranslatedValue = value; item = await UpdateAsync( item: item, id: item.Id, saveChanges: true, connectionId: connectionId, cancellationToken: cancellationToken ); result = !item.IsNullOrDefault(); // return result; } /// /// Add Or Update Resource ... /// /// /// /// /// /// /// public async Task AddOrUpdate( string resource, string value, string language = null, string connectionId = null, CancellationToken cancellationToken = default ) { // var result = false; // // Normalize ... if (language.IsNullOrEmpty()) { language = AppConfiguration.DefaultLanguage; } // // Check Existsance ... bool isExists = await IsResourceExists( resource: resource, language: language ); // // Act Based on Existance ... if (isExists) { // result = await Update( value: value, resource: resource, language: language, connectionId: connectionId, cancellationToken: cancellationToken ); } else { // result = await Add( value: value, resource: resource, language: language, connectionId: connectionId, cancellationToken: cancellationToken ); } // return result; } /// /// Add Specified Locale Resource ... /// /// /// /// /// /// public async Task AddByLocaleResource( XLocaleResourceDto item, string resource, string connectionId = null, CancellationToken cancellationToken = default ) { // // Validate ... bool isValid = !item.IsNull() && !resource.IsNullOrEmpty() && !item.Value.IsNullOrEmpty() && !item.Language.IsNullOrEmpty(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Check Specified Resource / Language Exists ... isValid = await IsResourceExists( resource: resource, language: item.Language, cancellationToken: cancellationToken ); if (isValid) { XException.Duplicate.Throw(); } // // Prepare Item to Add ... var result = new XStringDto { Language = item.Language, ResourceTitle = resource, TranslatedValue = item.Value }; result = await AddAsync( item: result, saveChanges: true, connectionId: connectionId, cancellationToken: cancellationToken ); // return result; } /// /// Update Specified Locale Resource ... /// /// /// /// /// /// public async Task UpdateByLocaleResource( XLocaleResourceDto item, string resource, string connectionId = null, CancellationToken cancellationToken = default ) { // // Validate ... bool isValid = !item.IsNull() && !resource.IsNullOrEmpty() && !item.Value.IsNullOrEmpty() && !item.Language.IsNullOrEmpty(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Check Specified Resource / Language Exists ... isValid = await IsResourceExists( resource: resource, language: item.Language, cancellationToken: cancellationToken ); if (!isValid) { XException.NotFound.Throw(); } // var result = await Get( resource: resource, language: item.Language, cancellationToken: cancellationToken ); isValid = !result.IsNullOrDefault(); if (!isValid) { XException.NotFound.Throw(); } // // Update ... result.TranslatedValue = item.Value; result = await UpdateAsync( item: result, id: result.Id, saveChanges: true, connectionId: connectionId, cancellationToken: cancellationToken ); isValid = !result.IsNullOrDefault(); if (!isValid) { XException.ActionFailed.Throw(); } // return result; } /// /// Add Or Update Resource By Locale ... /// /// /// /// /// /// public async Task AddOrUpdateByLocaleResource( XLocaleResourceDto item, string resource, string connectionId = null, CancellationToken cancellationToken = default ) { // // Validate ... bool isValid = !item.IsNull() && !resource.IsNullOrEmpty() && !item.Value.IsNullOrEmpty() && !item.Language.IsNullOrEmpty(); if (!isValid) { XException.InvalidArgs.Throw(); } // // Check Specified Resource / Language Exists ... isValid = await IsResourceExists( resource: resource, language: item.Language, cancellationToken: cancellationToken ); // XStringDto result = null; if (!isValid) { // result = await AddByLocaleResource( item: item, resource: resource, connectionId: connectionId, cancellationToken: cancellationToken ); } else { // result = await UpdateByLocaleResource( item: item, resource: resource, connectionId: connectionId, cancellationToken: cancellationToken ); } if (result.IsNullOrDefault()) { XException.ActionFailed.Throw(); } // return result; } /// /// Add Or Update all XResourceDto(s) Locales ... /// /// /// /// /// public async Task> AddByResource( XResourceDto item, string connectionId = null, CancellationToken cancellationToken = default ) { // // Validate ... bool isValid = !item.IsNull() && item.Locales.HasChild() && !item.Resource.IsNullOrEmpty(); if (!isValid) { XException.InvalidArgs.Throw(); } // var result = await Task .WhenAll(item.Locales .Select(async e => await AddOrUpdateByLocaleResource( item: e, resource: item.Resource, connectionId: connectionId, cancellationToken: cancellationToken))); // return result; } #endregion // #region Remove Actions ... /// /// Remove all Specified Language's Resources ... /// /// /// /// /// public async Task RemoveLanguageResources( string language, string connectionId = null, CancellationToken cancellationToken = default ) { // // Validate ... bool isValid = !language.IsNullOrEmpty(); if (!isValid) { return; } // var dtos = await Service .FindManyAsync( orderBuilder: null, includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken, predicate: e => e.Language.ToNormalString() == language.ToNormalString()); // try { // await Service.RemoveRangeAsync( items: dtos, softDelete: false, saveChanges: true, cancellationToken: cancellationToken ); // var ids = dtos.Select(e => e.Id); await SendPush( connectionId: connectionId, payLoad: ids.ToJSON(camelCase: true), cancellationToken: cancellationToken, action: XBaseEntityHubAction.DeleteMany.GetStringValue() ); } catch (Exception ex) { throw ex; } } /// /// Remove all Specified Resource Ids instances ... /// /// /// /// /// public async Task> RemoveResource( string resource, string connectionId = null, CancellationToken cancellationToken = default ) { // // Validate ... bool isValid = !resource.IsNullOrEmpty(); if (!isValid) { XException.InvalidArgs.Throw(); } // var result = await Service .FindManyAsync( orderBuilder: null, includeBuilder: null, ignoreSoftDeleteds: true, cancellationToken: cancellationToken, predicate: e => e.ResourceTitle.ToNormalString() == resource.ToNormalString()); // try { // await Service.RemoveRangeAsync( items: result, softDelete: false, saveChanges: true, cancellationToken: cancellationToken ); // var ids = result.Select(e => e.Id); await SendPush( connectionId: connectionId, payLoad: ids.ToJSON(camelCase: true), cancellationToken: cancellationToken, action: XBaseEntityHubAction.DeleteMany.GetStringValue() ); } catch (Exception ex) { throw ex; } // return result; } /// /// Remove Specified Resource ... /// /// /// /// /// /// public async Task Remove( string resource, string language = null, string connectionId = null, CancellationToken cancellationToken = default ) { // bool result = false; // // Normalize ... if (language.IsNullOrEmpty()) { language = AppConfiguration.DefaultLanguage; } // // Validate ... result = !language.IsNullOrEmpty() && !resource.IsNullOrEmpty(); if (!result) { return result; } // // Check Resource Exists ... result = await IsResourceExists( language: language, resource: resource, cancellationToken: cancellationToken ); if (!result) { return result; } // var dto = await Get( language: language, resource: resource, cancellationToken: cancellationToken ); result = !dto.IsNullOrDefault(); if (!result) { return result; } // dto = await RemoveAsync( id: dto.Id, softDelete: false, saveChanges: true, connectionId: connectionId, cancellationToken: cancellationToken ); result = !dto.IsNullOrDefault(); // return result; } /// /// Remove all Resource of Specified XResourceDto ... /// /// /// /// /// public async Task RemoveByResource( XResourceDto item, string connectionId = null, CancellationToken cancellationToken = default ) { // bool isValid = !item.IsNullOrDefault() && item.Locales.HasChild() && !item.Resource.IsNullOrEmpty(); if (!isValid) { XException.InvalidArgs.Throw(); } // foreach (var locale in item.Locales) { // await Remove( resource: item.Resource, language: locale.Language, connectionId: connectionId, cancellationToken: cancellationToken ); } } #endregion } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\Entities\XStringEFRepository.cs using xDataService.Configuration; using xDataService.Db; using xDataService.Interfaces; using xDataService.Providers; using xStringService.Interfaces.Entities; using xStringService.Models.Entities; namespace xStringService.Providers.Entities { public class XStringEFRepository : XBaseEFRepository, IXStringRepository where TContext : XDbContext { public XStringEFRepository( IXUnitOfWorks unitOfWorks, XDataServiceConfiguration configuration, IXStringKeyGenerator keyGenerator = null, IXStringRepositoryEvents baseRepositoryEvents = null ) : base( unitOfWorks, configuration, keyGenerator, baseRepositoryEvents ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\Entities\XStringEntityHub.cs using Microsoft.Extensions.Logging; using xPushService.Base; using xStringService.Interfaces.Entities; using xStringService.Models.Entities; namespace xStringService.Providers.Entities { public class XStringEntityHub : XBaseEntityHub, IXStringEntityHub { public XStringEntityHub( ILogger logger ) : base(logger) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\Entities\XStringInMemoryRepository.cs using xDataService.Configuration; using xDataService.Providers; using xStringService.Interfaces.Entities; using xStringService.Models.Entities; namespace xStringService.Providers.Entities { public class XStringInMemoryRepository : XBaseInMemoryRepository, IXStringRepository { public XStringInMemoryRepository( XDataServiceConfiguration configuration, IXStringKeyGenerator keyGenerator = null, IXStringRepositoryEvents baseRepositoryEvents = null ) : base( configuration, keyGenerator, baseRepositoryEvents ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\Entities\XStringKeyGenerator.cs using xDataService.Providers; using xStringService.Interfaces.Entities; using xStringService.Models.Entities; namespace xStringService.Providers.Entities { public class XStringKeyGenerator : XIntKeyGenerator, IXStringKeyGenerator { } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\Entities\XStringMongoRepository.cs using xDataService.Configuration; using xDataService.Providers; using xStringService.Interfaces.Entities; using xStringService.Models.Entities; namespace xStringService.Providers.Entities { public class XStringMongoRepository : XBaseMongoRepository, IXStringRepository { public XStringMongoRepository( XDataBaseConfiguration dbConfiguration, XDataServiceConfiguration configuration, string collectionName = null, IXStringKeyGenerator keyGenerator = null, IXStringRepositoryEvents baseRepositoryEvents = null ) : base( dbConfiguration, configuration, collectionName, keyGenerator, baseRepositoryEvents ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\Entities\XStringRepositoryEvents.cs using xDataService.Providers; using xStringService.Interfaces.Entities; using xStringService.Models.Entities; namespace xStringService.Providers.Entities { public class XStringRepositoryEvents : XBaseRepositoryEvents, IXStringRepositoryEvents {} } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\Entities\XStringRepositoryProvider.cs using Microsoft.AspNetCore.SignalR; using xDataService.Configuration; using xIdentityService.Interfaces; using xPushService.Base; using xStringService.Interfaces.Entities; using xStringService.Models.Entities; namespace xStringService.Providers.Entities { public class XStringRepositoryProvider : XBaseEntityProvider, IXStringRepositoryProvider { public XStringRepositoryProvider( IHubContext hub, IXStringRepository repository, XDataServiceConfiguration dataConfiguration, IXIdentityProvider identityProvider = null ) : base( hub, repository, dataConfiguration, identityProvider ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\Entities\XStringSeederBase.cs using xDataService.Configuration; using xDataService.Providers; using xStringService.Interfaces.Entities; using xStringService.Models.Entities; namespace xStringService.Providers.Entities { public abstract class XStringSeederBase : XBaseDbSeeder, IXStringSeeder { protected XStringSeederBase( string entity, string database, IXStringRepository repository, XDataServiceConfiguration dataServiceConfiguration ) : base( entity, database, repository, dataServiceConfiguration ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\GraphQL\XStringGraphQLTypeHelper.cs using xDataService.Configuration; using xDataService.GraphQL; using xStringService.Constants; using xStringService.Interfaces.Entities; using xStringService.Models.Entities; namespace xStringService.Providers.GraphQL { public class XStringGraphQLTypeHelper : XBaseGraphQLTypeHelper, IXStringGraphQLTypeHelper { public XStringGraphQLTypeHelper( XDataServiceConfiguration configuration ) : base(configuration) { } public override string GetInQueryCollectionName() { return XStringServiceConstants.XStringCollectionName; } public override string GetInQuerySingleName() { return XStringServiceConstants.XStringSingleName; } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\GraphQL\XStringGraphQuery.cs using GraphQL.Types; using xDataService.Configuration; using xDataService.GraphQL; using xStringService.Interfaces.Entities; using xStringService.Models.Entities; namespace xDataHelper.Providers.GraphQL { public class XStringGraphQuery : XBaseGraphQLQuery { public XStringGraphQuery( XDataServiceConfiguration configuration, IXStringRepository repository, IXStringGraphQLTypeHelper helper ) : base( configuration, repository, helper ) { } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\GraphQL\XStringGraphSchema.cs using System; using GraphQL.Types; namespace xDataHelper.Providers.GraphQL { public class XStringGraphSchema : Schema { public XStringGraphSchema(IServiceProvider services) : base(services) { Query = (XStringGraphQuery)services.GetService(typeof(XStringGraphQuery)); } } } ### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xStringService\Providers\GraphQL\XStringGraphType.cs using xDataService.GraphQL; using xStringService.Models.Entities; namespace xDataHelper.Providers.GraphQL { public class XStringGraphType : XBaseGraphObjectType { public XStringGraphType() : base() { Field(x => x.Language); Field(x => x.ResourceTitle); Field(x => x.TranslatedValue); } } }