Files
xSaherelmWorkspace/Documents/GeneratedContext/xDashboard-xStringService-20260807_230501.txt
2026-08-08 00:31:18 +03:30

6127 lines
191 KiB
Plaintext

### 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<XString, int>
{
public override void Configure(EntityTypeBuilder<XString> 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<XBaseItemResourceProviderControllerBase> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXItemResourceProvider provider
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider
)
{
this.provider = provider;
}
//
#region Actions ...
/// <summary>
/// Retrieve a List of Exists Languages ...
/// </summary>
/// <param name="identifier">if null or empty, check all languages in Item Side</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Languages")]
public virtual async Task<ActionResult<IEnumerable<string>>> GetLanguages(
[FromQuery] object identifier,
CancellationToken cancellationToken = default
)
{
//
try
{
//
var result = Enumerable.Empty<string>();
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;
}
}
/// <summary>
/// Retrieve all Exists Items ...
/// </summary>
/// <param name="resource">Specified Resource Title</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("ResourceLocales")]
public virtual async Task<ActionResult<IEnumerable<XStringDto>>> GetResourceLocales(
[FromQuery] object identifier,
CancellationToken cancellationToken = default
)
{
//
try
{
//
var result = Enumerable.Empty<XStringDto>();
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;
}
}
/// <summary>
/// Get all Exists Items for Specified identitifer ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Locales/{identifier}")]
public virtual async Task<ActionResult<IEnumerable<XLocaleResourceDto>>> GetLocales(
[FromRoute] object identifier,
CancellationToken cancellationToken = default
)
{
//
try
{
//
//
return Ok();
}
catch (Exception ex)
{
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Remove Specified Language Locale of Specified Identifier ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="language">if null or empty Remove all Locales</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpDelete("Locales/{identifier}")]
public virtual async Task<ActionResult<XResourceDto>> 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;
}
}
/// <summary>
/// Check Specified ocale Exists for Specified Identifier ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Locales/{identifier}/{language}/Has")]
public virtual async Task<ActionResult<bool>> 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;
}
}
/// <summary>
/// Get all Exists Locales Representaion based on Specified Identitifer
/// as XResourceDto ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Resource/{identifier}")]
public virtual async Task<ActionResult<XResourceDto>> 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;
}
}
/// <summary>
/// Add Or Update Locale for Specified Identitifer ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="locale"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Locales/{identifier}")]
public virtual async Task<ActionResult<XResourceDto>> 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;
}
}
/// <summary>
/// Update a Resource State ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="resource"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Resource/{identifier}")]
public virtual async Task<ActionResult<XResourceDto>> 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<TResourceProvider> : XBaseIdentityApiV1Controller, IXBaseResourceProviderController
where TResourceProvider : IXResourceProvider
{
private readonly TResourceProvider provider;
protected XBaseResourceProviderControllerBase(
ILogger<XBaseResourceProviderControllerBase<TResourceProvider>> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
TResourceProvider provider
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider
)
{
this.provider = provider;
}
#region Actions ...
/// <summary>
/// Retrieve a List of Exists Languages ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Languages")]
public virtual async Task<ActionResult<IEnumerable<string>>> GetLanguages(
CancellationToken cancellationToken = default
)
{
//
try
{
//
var result = await provider
.GetLanguages(cancellationToken);
//
return Ok(result.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Retrieve all Exists Items ...
/// </summary>
/// <param name="resource">Specified Resource Title</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("LocalesResource")]
public virtual async Task<ActionResult<IEnumerable<XStringDto>>> GetResourceLocales(
CancellationToken cancellationToken = default
)
{
//
try
{
//
var result = await provider
.GetResourceLocales(cancellationToken);
//
return Ok(result.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Extract Translation of in Specified Language ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("{language}/Translation")]
public virtual async Task<ActionResult<string>> 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;
}
}
/// <summary>
/// Check Has Specified Translation or not ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("{language}/Has")]
public virtual async Task<ActionResult<bool>> 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;
}
}
/// <summary>
/// Retrieve as Locale Model ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("{language}/Locale")]
public virtual async Task<ActionResult<XLocaleResourceDto>> 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;
}
}
/// <summary>
/// Retrieve all Exists Locale Models ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Locales")]
public virtual async Task<ActionResult<IEnumerable<XLocaleResourceDto>>> GetLocales(
CancellationToken cancellationToken = default
)
{
//
try
{
//
var result = await provider
.GetLocales(cancellationToken);
//
return Ok(result.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Retrieve as XResourceDto ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Resource")]
public virtual async Task<ActionResult<XResourceDto>> GetResource(
CancellationToken cancellationToken = default
)
{
//
try
{
//
var result = await provider
.GetResource(cancellationToken);
//
return Ok(result.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Add or Update a Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("")]
public virtual async Task<ActionResult<XResourceDto>> 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;
}
}
/// <summary>
/// Add Or Update Locale ...
/// </summary>
/// <param name="locale"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Locales")]
public virtual async Task<ActionResult<XResourceDto>> 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;
}
}
/// <summary>
/// Remove Locale ...
/// </summary>
/// <param name="locale"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Locale/Remove")]
public virtual async Task<ActionResult<XResourceDto>> 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;
}
}
/// <summary>
/// Remove Specified Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Resource/Remove")]
public virtual async Task<ActionResult> 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<XString, XStringDto, int, XStringDtoHub>, IXStringProviderController
{
private readonly IXStringProvider provider;
protected XStringProviderControllerBase(
ILogger<XStringProviderControllerBase> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXStringProvider provider,
Func<IQueryable<XString>, IOrderedQueryable<XString>> defaultOrderBuilder = null,
Func<IQueryable<XString>, IIncludableQueryable<XString, object>> defaultIncludeBuilder = null
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider,
provider,
defaultOrderBuilder,
defaultIncludeBuilder
)
{
this.provider = provider;
}
//
#region Tools ...
/// <summary>
/// Retrieve a List of Exists Languages ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Languages")]
public virtual async Task<ActionResult<IEnumerable<string>>> GetLanguages(
CancellationToken cancellationToken = default
)
{
//
try
{
//
var result = await provider
.GetLanguages(cancellationToken);
//
return Ok(result.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Retrieve a List of Resource Titles ...
/// </summary>
/// <param name="language">if provided, returns all language Specified resource titles, if not, all Resource Titles</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("ResourceTitles")]
public virtual async Task<ActionResult<IEnumerable<string>>> 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;
}
}
/// <summary>
/// Retrieve all Exists Items which belongs to Specified Resource Title ...
/// </summary>
/// <param name="resource">Specified Resource Title</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("ResourceLocales")]
public virtual async Task<ActionResult<IEnumerable<XStringDto>>> 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;
}
}
/// <summary>
/// Extract Translation of a Resource in Specified Language ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="resource">Specified Resource Title ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Translation")]
public virtual async Task<ActionResult<string>> 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;
}
}
/// <summary>
/// Retrieve a Resource as Locale Model ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="resource">Specified Resource Title ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Locale")]
public virtual async Task<ActionResult<XLocaleResourceDto>> 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;
}
}
/// <summary>
/// Retrieve all Exists Resource Instances as Locale Models ...
/// </summary>
/// <param name="resource"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Locales")]
public virtual async Task<ActionResult<IEnumerable<XLocaleResourceDto>>> 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;
}
}
/// <summary>
/// Retrieve all Locales of Specified Resource and Represent as XResourceDto ...
/// </summary>
/// <param name="resource"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("GetResource")]
public virtual async Task<ActionResult<XResourceDto>> 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;
}
}
/// <summary>
/// Add or Update a Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("AddOrUpdateResource")]
public virtual async Task<ActionResult<XResourceDto>> 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;
}
}
/// <summary>
/// Remove Specified Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("RemoveResource")]
public virtual async Task<ActionResult> 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<XString, int>, IXBaseRepositoryController<XString, int>
{
protected XStringRepositoryControllerBase(
ILogger<XStringRepositoryControllerBase> logger,
XAppConfiguration appConfiguration,
XValidationProvider validationProvider,
IXStringRepository repository,
Func<IQueryable<XString>, IOrderedQueryable<XString>> defaultOrderBuilder = null,
Func<IQueryable<XString>, IIncludableQueryable<XString, object>> 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<XString, int, XStringEntityHub>, IXBaseRepositoryProviderController<XString, int, XStringEntityHub>
{
protected XStringRepositoryProviderControllerBase(
ILogger<XStringRepositoryProviderControllerBase> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXStringRepositoryProvider provider,
Func<IQueryable<XString>, IOrderedQueryable<XString>> defaultOrderBuilder = null,
Func<IQueryable<XString>, IIncludableQueryable<XString, object>> 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<XString, XStringDto, int>, IXBaseServiceController<XString, XStringDto, int>
{
protected XStringServiceControllerBase(
ILogger<XStringServiceControllerBase> logger,
XAppConfiguration appConfiguration,
XValidationProvider validationProvider,
IXStringRepositoryService repositoryService,
Func<IQueryable<XString>, IOrderedQueryable<XString>> defaultOrderBuilder = null,
Func<IQueryable<XString>, IIncludableQueryable<XString, object>> 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<XString, XStringDto, int, XStringDtoHub>, IXBaseServiceProviderController<XString, XStringDto, int, XStringDtoHub>
{
protected XStringServiceProviderControllerBase(
ILogger<XStringServiceProviderControllerBase> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXStringServiceProvider provider,
Func<IQueryable<XString>, IOrderedQueryable<XString>> defaultOrderBuilder = null,
Func<IQueryable<XString>, IIncludableQueryable<XString, object>> 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
{
/// <summary>
/// Register Service ...
/// </summary>
/// <param name="services"></param>
/// <param name="repositoryType"></param>
/// <param name="lifeTime"></param>
public static void AddXStringService(
this IServiceCollection services,
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
{
AddStringService(
contextType: null,
services: services,
lifeTime: lifeTime,
repositoryType: repositoryType
);
}
/// <summary>
/// Register Service ...
/// </summary>
/// <typeparam name="TContext"></typeparam>
/// <param name="services"></param>
/// <param name="repositoryType"></param>
/// <param name="lifeTime"></param>
public static void AddXStringService<TContext>(
this IServiceCollection services,
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
where TContext : XDbContext
{
AddStringService(
services: services,
lifeTime: lifeTime,
contextType: typeof(TContext),
repositoryType: repositoryType
);
}
/// <summary>
/// Use XStringService Middleware ...
/// </summary>
/// <param name="app"></param>
/// <param name="isDevelopmentEnvironment"></param>
public static void UseXStringService(
this IApplicationBuilder app,
bool isDevelopmentEnvironment = false
)
{
//
#region Using XString Hubs ...
//
var pushHelper = new XPushServiceHelper();
//
pushHelper.AddHub<XStringDtoHub>(XStringServiceConstants.XStringDtoHub);
pushHelper.AddHub<XStringEntityHub>(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;
/// <summary>
/// a LogTag for Service ...
/// </summary>
private static string XLogTag = XStringServiceConstants.XStringServiceDILogTag;
/// <summary>
/// print a log in Console ...
/// </summary>
/// <param name="message"></param>
private static void Log(string message)
{
Console.WriteLine($"{XLogTag} => {message}");
}
/// <summary>
/// Register Service ...
/// </summary>
/// <param name="services"></param>
/// <param name="repositoryType"></param>
/// <param name="contextType"></param>
/// <param name="lifeTime"></param>
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<XRepositoryDescriptor>(
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
{
/// <summary>
/// Converts an Entity to LocaleResource Dto ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XLocaleResourceDto ToXLocaleResourceDto(this XString source)
{
//
var result = new XLocaleResourceDto
{
Language = source.IsNull() ? "" : source.Language,
Value = source.IsNull() ? "" : source.TranslatedValue,
};
//
return result;
}
/// <summary>
/// Converts an Dto to LocaleResource Dto ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XLocaleResourceDto ToXLocaleResourceDto(this XStringDto source)
{
//
var result = new XLocaleResourceDto
{
Language = source.IsNull() ? "" : source.Language,
Value = source.IsNull() ? "" : source.TranslatedValue,
};
//
return result;
}
/// <summary>
/// Converts a Collection of Entities to Locale Resource Presentation ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static IEnumerable<XLocaleResourceDto> ToXLocaleResourceDtos(this IEnumerable<XString> source)
{
//
var result = source.Select(e => ToXLocaleResourceDto(e));
return result;
}
/// <summary>
/// Converts a Collection of Dtos to Locale Resource Presentation ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static IEnumerable<XLocaleResourceDto> ToXLocaleResourceDtos(this IEnumerable<XStringDto> 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>,
TContext
> GetXStringEFRepositoryDescriptor<TContext>()
where TContext : XDbContext
{
//
var result = new XEFRepositoryDescriptor<
XString,
int,
IXStringKeyGenerator,
XStringKeyGenerator,
IXStringRepositoryEvents,
XStringRepositoryEvents,
XStringGraphType,
IntGraphType,
XStringGraphQuery,
IXStringGraphQLTypeHelper,
XStringGraphQLTypeHelper,
XStringGraphSchema,
IXStringRepository,
XStringEFRepository<TContext>,
TContext
>();
//
return result;
}
public static XEFRepositoryDescriptor<
XString,
int,
IXStringKeyGenerator,
XStringKeyGenerator,
IXStringRepositoryEvents,
XStringRepositoryEvents,
XStringGraphType,
IntGraphType,
XStringGraphQuery,
IXStringGraphQLTypeHelper,
XStringGraphQLTypeHelper,
XStringGraphSchema,
IXStringRepository,
XStringEFRepository<TContext>,
TContext,
IXStringSeeder,
TSeederImplementation
> GetXStringEFRepositoryDescriptor<TContext, TSeederImplementation>()
where TContext : XDbContext
where TSeederImplementation : XBaseDbSeeder<XString, int>
{
//
var result = new XEFRepositoryDescriptor<
XString,
int,
IXStringKeyGenerator,
XStringKeyGenerator,
IXStringRepositoryEvents,
XStringRepositoryEvents,
XStringGraphType,
IntGraphType,
XStringGraphQuery,
IXStringGraphQLTypeHelper,
XStringGraphQLTypeHelper,
XStringGraphSchema,
IXStringRepository,
XStringEFRepository<TContext>,
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<TSeederImplementation>()
where TSeederImplementation : XBaseDbSeeder<XString, int>
{
//
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<TSeederImplementation>()
where TSeederImplementation : XBaseDbSeeder<XString, int>
{
//
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
{
/// <summary>
/// Retrieve a List of Exists Languages ...
/// </summary>
/// <param name="identifier">if null or empty, check all languages in Item Side</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Languages")]
Task<ActionResult<IEnumerable<string>>> GetLanguages(
[FromQuery] object identifier,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve all Exists Items ...
/// </summary>
/// <param name="resource">Specified Resource Title</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("ResourceLocales")]
Task<ActionResult<IEnumerable<XStringDto>>> GetResourceLocales(
[FromQuery] object identifier,
CancellationToken cancellationToken = default
);
/// <summary>
/// Get all Exists Items for Specified identitifer ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Locales/{identifier}")]
Task<ActionResult<IEnumerable<XLocaleResourceDto>>> GetLocales(
[FromRoute] object identifier,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove Specified Language Locale of Specified Identifier ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="language">if null or empty Remove all Locales</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpDelete("Locales/{identifier}")]
Task<ActionResult<XResourceDto>> RemoveLocale(
[FromRoute] object identifier,
[FromQuery] string language,
CancellationToken cancellationToken = default
);
/// <summary>
/// Check Specified ocale Exists for Specified Identifier ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Locales/{identifier}/{language}/Has")]
Task<ActionResult<bool>> HasLocale(
[FromRoute] object identifier,
[FromRoute] string language,
CancellationToken cancellationToken = default
);
/// <summary>
/// Get all Exists Locales Representaion based on Specified Identitifer
/// as XResourceDto ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Resource/{identifier}")]
Task<ActionResult<XResourceDto>> GetResource(
[FromRoute] object identifier,
CancellationToken cancellationToken = default
);
/// <summary>
/// Add Or Update Locale for Specified Identitifer ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="locale"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Locales/{identifier}")]
Task<ActionResult<XResourceDto>> AddOrUpdateLocale(
[FromRoute] object identifier,
[FromBody] XLocaleResourceDto locale,
CancellationToken cancellationToken = default
);
/// <summary>
/// Update a Resource State ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="resource"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Resource/{identifier}")]
Task<ActionResult<XResourceDto>> 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
{
/// <summary>
/// Retrieve a List of Exists Languages ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Languages")]
Task<ActionResult<IEnumerable<string>>> GetLanguages(
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve all Exists Items ...
/// </summary>
/// <param name="resource">Specified Resource Title</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("LocalesResource")]
Task<ActionResult<IEnumerable<XStringDto>>> GetResourceLocales(
CancellationToken cancellationToken = default
);
/// <summary>
/// Extract Translation of in Specified Language ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("{language}/Translation")]
Task<ActionResult<string>> GetResourceTranslation(
[FromRoute] string language,
CancellationToken cancellationToken = default
);
/// <summary>
/// Check Has Specified Translation or not ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("{language}/Has")]
Task<ActionResult<bool>> HasLocale(
[FromRoute] string language,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve as Locale Model ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("{language}/Locale")]
Task<ActionResult<XLocaleResourceDto>> GetLocale(
[FromRoute] string language,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve all Exists Locale Models ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Locales")]
Task<ActionResult<IEnumerable<XLocaleResourceDto>>> GetLocales(
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve as XResourceDto ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Resource")]
Task<ActionResult<XResourceDto>> GetResource(
CancellationToken cancellationToken = default
);
/// <summary>
/// Add or Update a Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("")]
Task<ActionResult<XResourceDto>> AddOrUpdateResource(
[FromBody] XResourceDto resource,
CancellationToken cancellationToken = default
);
/// <summary>
/// Add Or Update Locale ...
/// </summary>
/// <param name="locale"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Locales")]
Task<ActionResult<XResourceDto>> AddOrUpdateLocale(
[FromBody] XLocaleResourceDto locale,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove Locale ...
/// </summary>
/// <param name="locale"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Locale/Remove")]
Task<ActionResult<XResourceDto>> RemoveLocale(
[FromBody] XLocaleResourceDto locale,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove Specified Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Resource/Remove")]
Task<ActionResult> 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 ...
/// <summary>
/// Retrieve a List of Exists Languages for Current Item ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<string>> GetLanguages(
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve all Exists Items of type ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<XStringDto>> GetResourceLocales(
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove all Exists Locales which Related to this Provider ...
/// </summary>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task RemoveResourceLocales(
string connectionId = null,
CancellationToken cancellationToken = default
);
#endregion
//
#region Item Actions ...
/// <summary>
/// Get all Exists Items for Specified identitifer ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<XStringDto>> GetResourceLocales(
object identifier,
CancellationToken cancellationToken = default
);
/// <summary>
/// Get all Exists Items for Specified identitifer ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<XLocaleResourceDto>> GetLocales(
object identifier,
CancellationToken cancellationToken = default
);
/// <summary>
/// Get all Exists Locales Representaion based on Specified Identitifer
/// as XResourceDto ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XResourceDto> GetResource(
object identifier,
CancellationToken cancellationToken = default
);
/// <summary>
/// Add Or Update Locale for Specified Identitifer ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="locale"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XResourceDto> AddOrUpdateLocale(
object identifier,
XLocaleResourceDto locale,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Update a Resource State ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="resource"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XResourceDto> AddOrUpdateResource(
object identifier,
XResourceDto resource,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove Specified Language Locale of Specified Identifier ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="language"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XResourceDto> RemoveLocale(
object identifier,
string language,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove all Exists Locales for Specified Identifier ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task RemoveLocales(
object identifier,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Check Specified ocale Exists for Specified Identifier ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> HasLocale(
object identifier,
string language,
CancellationToken cancellationToken = default
);
/// <summary>
/// Get all Exists Languages for Specified Identifier ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<string>> GetLanguages(
object identifier,
CancellationToken cancellationToken = default
);
#endregion
//
#region Resource Title Action ...
/// <summary>
/// Retrieve Resource Title ...
/// </summary>
/// <param name="identifier"></param>
/// <returns></returns>
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
{
/// <summary>
/// Retrieve a List of Exists Languages ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<string>> GetLanguages(
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve all Exists Items ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<XStringDto>> GetResourceLocales(
CancellationToken cancellationToken = default
);
/// <summary>
/// Extract Translation of in Specified Language ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> GetResourceTranslation(
string language,
CancellationToken cancellationToken = default
);
/// <summary>
/// Check Has Specified Translation or not ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> HasLocale(
string language,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve as Locale Model ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XLocaleResourceDto> GetLocale(
string language,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve all Exists Locale Models ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<XLocaleResourceDto>> GetLocales(
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve as XResourceDto ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XResourceDto> GetResource(
CancellationToken cancellationToken = default
);
/// <summary>
/// Add or Update a Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XResourceDto> AddOrUpdateResource(
XResourceDto resource,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Add Or Update Locale ...
/// </summary>
/// <param name="locale"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XResourceDto> AddOrUpdateLocale(
XLocaleResourceDto locale,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove Locale ...
/// </summary>
/// <param name="locale"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XResourceDto> RemoveLocale(
XLocaleResourceDto locale,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove Specified Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
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<XString, XStringDto, int, XStringDtoHub>
{
//
#region Tools ...
/// <summary>
/// Retrieve a List of Exists Languages ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<string>> GetLanguages(
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve a List of Resource Titles ...
/// </summary>
/// <param name="language">if provided, returns all language Specified resource titles, if not, all Resource Titles</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<string>> GetResourceTitles(
string language = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve all Exists Items which belongs to Specified Resource Title ...
/// </summary>
/// <param name="resource">Specified Resource Title</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<XStringDto>> GetResourceLocales(
string resource,
CancellationToken cancellationToken = default
);
/// <summary>
/// Extract Translation of a Resource in Specified Language ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="resource">Specified Resource Title ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> GetResourceTranslation(
string language,
string resource,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve a Resource as Locale Model ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="resource">Specified Resource Title ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XLocaleResourceDto> GetLocale(
string language,
string resource,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve all Exists Resource Instances as Locale Models ...
/// </summary>
/// <param name="resource"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<XLocaleResourceDto>> GetLocales(
string resource,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve all Locales of Specified Resource and Represent as XResourceDto ...
/// </summary>
/// <param name="resource"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XResourceDto> GetResource(
string resource,
CancellationToken cancellationToken = default
);
/// <summary>
/// Add or Update a Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="userInfo">Actor User for Permissions ...</param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XResourceDto> AddOrUpdateResource(
XResourceDto resource,
XUserClaimsInfoDto userInfo = null,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove Specified Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="userInfo">Actor User for Permissions ...</param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
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<XString, XStringDto, int, XStringDtoHub>
{
//
#region Tools ...
/// <summary>
/// Retrieve a List of Exists Languages ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Languages")]
Task<ActionResult<IEnumerable<string>>> GetLanguages(
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve a List of Resource Titles ...
/// </summary>
/// <param name="language">if provided, returns all language Specified resource titles, if not, all Resource Titles</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("ResourceTitles")]
Task<ActionResult<IEnumerable<string>>> GetResourceTitles(
[FromQuery] string language = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve all Exists Items which belongs to Specified Resource Title ...
/// </summary>
/// <param name="resource">Specified Resource Title</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("ResourceLocales")]
Task<ActionResult<IEnumerable<XStringDto>>> GetResourceLocales(
[FromQuery] string resource,
CancellationToken cancellationToken = default
);
/// <summary>
/// Extract Translation of a Resource in Specified Language ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="resource">Specified Resource Title ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Translation")]
Task<ActionResult<string>> GetResourceTranslation(
[FromQuery] string language,
[FromQuery] string resource,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve a Resource as Locale Model ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="resource">Specified Resource Title ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Locale")]
Task<ActionResult<XLocaleResourceDto>> GetLocale(
[FromQuery] string language,
[FromQuery] string resource,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve all Exists Resource Instances as Locale Models ...
/// </summary>
/// <param name="resource"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Locales")]
Task<ActionResult<IEnumerable<XLocaleResourceDto>>> GetLocales(
[FromQuery] string resource,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve all Locales of Specified Resource and Represent as XResourceDto ...
/// </summary>
/// <param name="resource"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("GetResource")]
Task<ActionResult<XResourceDto>> GetResource(
[FromQuery] string resource,
CancellationToken cancellationToken = default
);
/// <summary>
/// Add or Update a Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("AddOrUpdateResource")]
Task<ActionResult<XResourceDto>> AddOrUpdateResource(
[FromBody] XResourceDto resource,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove Specified Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("RemoveResource")]
Task<ActionResult> 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<XString, XStringDto, int>
{ }
}
### 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<XString, XStringDto, int>
{ }
}
### 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<XString, XStringDto, int, XStringDtoHub>
{
/// <summary>
/// Application Configuration ...
/// </summary>
XAppConfiguration AppConfiguration { get; }
//
#region Retrievers ...
/// <summary>
/// Retrieve all Exists Languages ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<string>> GetLanguages(
CancellationToken cancellationToken = default
);
/// <summary>
/// Check Specified Resource Exists or not ...
/// </summary>
/// <param name="resource"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> IsResourceExists(
string resource,
string language = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve Specified Resource ...
/// </summary>
/// <param name="resource"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XStringDto> Get(
string resource,
string language = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve Specified Translation of Specified Resource ...
/// </summary>
/// <param name="resource"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> GetResourceValue(
string resource,
string language = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve an Specified Resource Items ...
/// </summary>
/// <param name="resource"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<XStringDto>> GetResources(
string resource,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve Specified Resource Items as XResourceDto Presentation ...
/// </summary>
/// <param name="resource"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XResourceDto> GetResource(
string resource,
CancellationToken cancellationToken = default
);
#endregion
//
#region Query ...
/// <summary>
/// Query Resource IDs ...
/// </summary>
/// <param name="query"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XQueryResult<string>> QueryResourceIds(
XQuery query,
CancellationToken cancellationToken = default
);
/// <summary>
/// Query Specified Language Resources ...
/// </summary>
/// <param name="query"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XQueryResult<XStringDto>> QueryLanguageResources(
XQuery query,
string language = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Query Locale Resources ...
/// </summary>
/// <param name="query"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XQueryResult<XLocaleResourceDto>> QueryLocaleResources(
XQuery query,
string language = null,
CancellationToken cancellationToken = default
);
#endregion
//
#region Add/Update Actions ...
/// <summary>
/// Add Specified Resource ...
/// </summary>
/// <param name="resource"></param>
/// <param name="value"></param>
/// <param name="language"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> Add(
string resource,
string value,
string language = null,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Update Resource ...
/// </summary>
/// <param name="resource"></param>
/// <param name="value"></param>
/// <param name="language"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> Update(
string resource,
string value,
string language = null,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Add Or Update Resource ...
/// </summary>
/// <param name="resource"></param>
/// <param name="value"></param>
/// <param name="language"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> AddOrUpdate(
string resource,
string value,
string language = null,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Add Specified Locale Resource ...
/// </summary>
/// <param name="item"></param>
/// <param name="resource"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XStringDto> AddByLocaleResource(
XLocaleResourceDto item,
string resource,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Update Specified Locale Resource ...
/// </summary>
/// <param name="item"></param>
/// <param name="resource"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XStringDto> UpdateByLocaleResource(
XLocaleResourceDto item,
string resource,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Add Or Update Resource By Locale ...
/// </summary>
/// <param name="item"></param>
/// <param name="resource"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XStringDto> AddOrUpdateByLocaleResource(
XLocaleResourceDto item,
string resource,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Add Or Update all XResourceDto(s) Locales ...
/// </summary>
/// <param name="item"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<XStringDto>> AddByResource(
XResourceDto item,
string connectionId = null,
CancellationToken cancellationToken = default
);
#endregion
//
#region Remove Actions ...
/// <summary>
/// Remove all Specified Language's Resources ...
/// </summary>
/// <param name="language"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task RemoveLanguageResources(
string language,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove all Specified Resource Ids instances ...
/// </summary>
/// <param name="resource"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<XStringDto>> RemoveResource(
string resource,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove Specified Resource ...
/// </summary>
/// <param name="resource"></param>
/// <param name="language"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> Remove(
string resource,
string language = null,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove all Resource of Specified XResourceDto ...
/// </summary>
/// <param name="item"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
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<XString, int>
{ }
}
### 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<XString, int>
{ }
}
### 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<XString, int>
{ }
}
### 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<XString, int>
{ }
}
### 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<XString>
{ }
}
### 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<XString, int, XStringEntityHub>
{ }
}
### 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<XString, int>
{}
}
### 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 ...
/// <summary>
/// Item Name for Resource Providing ...
/// </summary>
private readonly string item;
/// <summary>
/// an Implementation of Item Resource Provider
/// </summary>
/// <value></value>
private readonly XBaseResourceProvider provider;
/// <summary>
/// String Provider Service ...
/// </summary>
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 ...
/// <summary>
/// Retrieve a List of Exists Languages for Current Item ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<IEnumerable<string>> GetLanguages(
CancellationToken cancellationToken = default
)
{
//
var result = (await ExtractItems(cancellationToken))
.Select(x => x.Language)
.Distinct();
//
return result;
}
/// <summary>
/// Retrieve all Exists Items of type ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<IEnumerable<XStringDto>> GetResourceLocales(
CancellationToken cancellationToken = default
)
{
//
var result = await ExtractItems(cancellationToken);
//
return result;
}
/// <summary>
/// Remove all Exists Locales which Related to this Provider ...
/// </summary>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task RemoveResourceLocales(
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
var isDelete = false;
XStringDto deleted = null;
var items = await ExtractItems(cancellationToken);
foreach (var item in items)
{
//
// Check Cancellation ...
if (cancellationToken.IsCancellationRequested)
{
break;
}
//
// Remove Item ...
deleted = await stringProvider.RemoveAsync(
id: item.Id,
softDelete: false,
saveChanges: true,
connectionId: connectionId,
cancellationToken: cancellationToken
);
//
// Check Removation Succeed ...
isDelete = !deleted.IsNullOrDefault();
if (!isDelete)
{
XException.ActionFailed.Throw();
}
}
}
#endregion
//
#region Item Actions ...
/// <summary>
/// Get all Exists Items for Specified identitifer ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<IEnumerable<XStringDto>> GetResourceLocales(
object identifier,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
var isValid = !identifier.IsNull();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
// Setting Resource Title ...
SetResourceTitle(identifier);
//
// Retrieve Resource List ...
var result = await provider
.GetResourceLocales(cancellationToken);
//
return result;
}
/// <summary>
/// Get all Exists Items for Specified identitifer ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<IEnumerable<XLocaleResourceDto>> GetLocales(
object identifier,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
var isValid = !identifier.IsNull();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
// Setting Resource Title ...
SetResourceTitle(identifier);
//
// Retrieve Resource List ...
var result = await provider
.GetLocales(cancellationToken);
//
return result;
}
/// <summary>
/// Get all Exists Locales Representaion based on Specified Identitifer
/// as XResourceDto ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<XResourceDto> GetResource(
object identifier,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
var isValid = !identifier.IsNull();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
// Setting Resource Title ...
SetResourceTitle(identifier);
//
// Retrieve Resource List ...
var result = await provider
.GetResource(cancellationToken);
//
return result;
}
/// <summary>
/// Add Or Update Locale for Specified Identitifer ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="locale"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<XResourceDto> AddOrUpdateLocale(
object identifier,
XLocaleResourceDto locale,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
var isValid =
!identifier.IsNull() &&
!locale.IsNullOrDefault() &&
!locale.Value.IsNullOrEmpty() &&
!locale.Language.IsNullOrEmpty();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
// Setting Resource Title ...
SetResourceTitle(identifier);
//
// Retrieve Resource List ...
var result = await provider
.AddOrUpdateLocale(
locale: locale,
connectionId: connectionId,
cancellationToken: cancellationToken
);
//
return result;
}
/// <summary>
/// Update a Resource State ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="resource"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<XResourceDto> 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;
}
/// <summary>
/// Remove Specified Language Locale of Specified Identifier ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="language"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<XResourceDto> RemoveLocale(
object identifier,
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;
}
/// <summary>
/// Remove all Exists Locales for Specified Identifier ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task RemoveLocales(
object identifier,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
var isValid =
!identifier.IsNull();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
var resource = await GetResource(
identifier: identifier,
cancellationToken: cancellationToken
);
isValid = !resource.IsNullOrDefault();
if (!isValid)
{
XException.NotFound.Throw();
}
//
// Setting Resource Title ...
SetResourceTitle(identifier);
//
await provider.RemoveResource(
resource: resource,
connectionId: connectionId,
cancellationToken: cancellationToken
);
}
/// <summary>
/// Check Specified ocale Exists for Specified Identifier ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<bool> HasLocale(
object identifier,
string language,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
var isValid =
!identifier.IsNull() &&
!language.IsNullOrEmpty();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
// Setting Resource Title ...
SetResourceTitle(identifier);
//
var result = await provider.HasLocale(
language: language,
cancellationToken: cancellationToken
);
//
return result;
}
/// <summary>
/// Get all Exists Languages for Specified Identifier ...
/// </summary>
/// <param name="identifier"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<IEnumerable<string>> GetLanguages(
object identifier,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
var isValid = !identifier.IsNull();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
// Setting Resource Title ...
SetResourceTitle(identifier);
//
var result = await provider
.GetLanguages(cancellationToken);
//
return result;
}
#endregion
//
#region Resource Title Action ...
/// <summary>
/// Retrieve Resource Title ...
/// </summary>
/// <param name="identifier"></param>
/// <returns></returns>
public string GetResourceTitle(object identifier = null)
{
//
var result = item;
//
if (!identifier.IsNull())
{
result = $"{item}_{identifier}";
}
//
return result;
}
#endregion
//
#region Private ...
/// <summary>
/// Set Resource Title ...
/// </summary>
/// <param name="identifier"></param>
private void SetResourceTitle(object identifier = null)
{
//
var itemIdentifier = GetResourceTitle(identifier);
provider.SetField(
field: "resource",
value: $"{itemIdentifier}"
);
}
/// <summary>
/// xtract all Items which Belongs to Provider ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
private async Task<IEnumerable<XStringDto>> ExtractItems(
CancellationToken cancellationToken = default
)
{
//
var result = await stringProvider
.FindManyAsync(
includeBuilder: null,
cancellationToken: cancellationToken,
orderBuilder: x => x.OrderBy(y => y.Id),
predicate: x =>
x.ResourceTitle.StartsWith(
item,
StringComparison.InvariantCultureIgnoreCase)
);
return result;
}
#endregion
}
}
### 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 ...
/// <summary>
/// Retrieve a List of Exists Languages ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<IEnumerable<string>> GetLanguages(
CancellationToken cancellationToken = default
)
{
//
var result = (await ExtractItems(cancellationToken))
.Select(x => x.Language)
.Distinct()
.ToList();
//
return result;
}
/// <summary>
/// Retrieve all Exists Items ...
/// </summary>
/// <param name="resource">Specified Resource Title</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<IEnumerable<XStringDto>> GetResourceLocales(
CancellationToken cancellationToken = default
)
{
//
var result = await ExtractItems(cancellationToken);
//
return result;
}
/// <summary>
/// Extract Translation of in Specified Language ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<string> 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;
}
/// <summary>
/// Check Has Specified Translation or not ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<bool> 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;
}
/// <summary>
/// Retrieve as Locale Model ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<XLocaleResourceDto> 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;
}
/// <summary>
/// Retrieve all Exists Locale Models ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<IEnumerable<XLocaleResourceDto>> GetLocales(
CancellationToken cancellationToken = default
)
{
//
var result = (await ExtractItems(cancellationToken))
.Select(x => x.ToXLocaleResourceDto())
.ToList();
//
return result;
}
/// <summary>
/// Retrieve as XResourceDto ...
/// </summary>
/// <param name="resource"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<XResourceDto> GetResource(
CancellationToken cancellationToken = default
)
{
//
var locales = await GetLocales();
//
var result = new XResourceDto
{
Locales = locales,
Resource = resource,
};
//
return result;
}
/// <summary>
/// Add or Update a Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<XResourceDto> 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;
}
/// <summary>
/// Add Or Update Locale ...
/// </summary>
/// <param name="locale"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<XResourceDto> 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;
}
/// <summary>
/// Remove Locale ...
/// </summary>
/// <param name="locale"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<XResourceDto> 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;
}
/// <summary>
/// Remove Specified Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
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<IEnumerable<XStringDto>> 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
{
/// <summary>
/// an Entity Registerar class for XStringService ...
/// </summary>
public class XStringEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar
{
public XStringEntityRegisterar()
: base(nameof(XStringEntityRegisterar))
{
//
// Add XString Entity ...
AddEntity<XString, int>();
}
/// <summary>
/// Configure Entities ...
/// </summary>
/// <param name="modelBuilder"></param>
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<XString, XStringDto, int, XStringDtoHub>, 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 ...
/// <summary>
/// Retrieve a List of Exists Languages ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<string>> 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;
}
/// <summary>
/// Retrieve a List of Resource Titles ...
/// </summary>
/// <param name="language">if provided, returns all language Specified resource titles, if not, all Resource Titles</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<string>> 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;
}
/// <summary>
/// Retrieve all Exists Items which belongs to Specified Resource Title ...
/// </summary>
/// <param name="resource">Specified Resource Title</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<XStringDto>> 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;
}
/// <summary>
/// Extract Translation of a Resource in Specified Language ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="resource">Specified Resource Title ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<string> 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;
}
/// <summary>
/// Retrieve a Resource as Locale Model ...
/// </summary>
/// <param name="language">Specified Language ...</param>
/// <param name="resource">Specified Resource Title ...</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XLocaleResourceDto> 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;
}
/// <summary>
/// Retrieve all Exists Resource Instances as Locale Models ...
/// </summary>
/// <param name="resource"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<XLocaleResourceDto>> GetLocales(
string resource,
CancellationToken cancellationToken = default
)
{
//
var result = (await GetResourceLocales(
resource: resource,
cancellationToken: cancellationToken
))
.ToList()
.Select(x => x.ToXLocaleResourceDto())
.ToList();
//
return result;
}
/// <summary>
/// Retrieve all Locales of Specified Resource and Represent as XResourceDto ...
/// </summary>
/// <param name="resource"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XResourceDto> 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;
}
/// <summary>
/// Add or Update a Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="userInfo">Actor User for Permissions ...</param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XResourceDto> 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;
}
/// <summary>
/// Remove Specified Resource Model ...
/// </summary>
/// <param name="resource">a XResourceDto Model ...</param>
/// <param name="userInfo">Actor User for Permissions ...</param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
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<XString, XStringDto, int>, IXStringDtoHub
{
public XStringDtoHub(
ILogger<XStringDtoHub> 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<XString, XStringDto, int>, IXStringRepositoryService
{
public XStringRepositoryService(
IXStringRepository repository,
IEnumerable<Profile> 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<XString, XStringDto, int, XStringDtoHub>, IXStringServiceProvider
{
public XAppConfiguration AppConfiguration { get; }
public XStringServiceProvider(
IHubContext<XStringDtoHub> hub,
XDataServiceConfiguration dataConfiguration,
IXStringRepositoryService service,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider = null
) : base(
hub,
dataConfiguration,
service,
identityProvider
)
{
AppConfiguration = appConfiguration;
}
//
#region Retrievers ...
/// <summary>
/// Retrieve all Exists Languages ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<string>> 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;
}
/// <summary>
/// Check Specified Resource Exists or not ...
/// </summary>
/// <param name="resource"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<bool> 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;
}
/// <summary>
/// Retrieve Specified Resource ...
/// </summary>
/// <param name="resource"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XStringDto> 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;
}
/// <summary>
/// Retrieve Specified Translation of Specified Resource ...
/// </summary>
/// <param name="resource"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<string> 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;
}
/// <summary>
/// Retrieve an Specified Resource Items ...
/// </summary>
/// <param name="resource"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<XStringDto>> 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;
}
/// <summary>
/// Retrieve Specified Resource Items as XResourceDto Presentation ...
/// </summary>
/// <param name="resource"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XResourceDto> 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 ...
/// <summary>
/// Query Resource IDs ...
/// </summary>
/// <param name="query"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XQueryResult<string>> 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<string>()
.UpdateData(
updateWith: dtoResult,
propertyBlackList: new List<string>
{
nameof(XQueryResult<string>.Items)
});
//
result.Items = dtoResult.Items.ToList().Select(dto => dto.ResourceTitle);
//
return result;
}
/// <summary>
/// Query Specified Language Resources ...
/// </summary>
/// <param name="query"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XQueryResult<XStringDto>> 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;
}
/// <summary>
/// Query Locale Resources ...
/// </summary>
/// <param name="query"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XQueryResult<XLocaleResourceDto>> QueryLocaleResources(
XQuery query,
string language = null,
CancellationToken cancellationToken = default
)
{
//
Expression<Func<XString, bool>> 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<XLocaleResourceDto>()
.UpdateData(
updateWith: dtoResult,
propertyBlackList: new List<string>
{
nameof(XQueryResult<XLocaleResourceDto>.Items)
});
//
result.Items = dtoResult.Items.ToList().ToXLocaleResourceDtos();
//
return result;
}
#endregion
//
#region Add/Update Actions ...
/// <summary>
/// Add Specified Resource ...
/// </summary>
/// <param name="resource"></param>
/// <param name="value"></param>
/// <param name="language"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<bool> 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;
}
/// <summary>
/// Update Resource ...
/// </summary>
/// <param name="resource"></param>
/// <param name="value"></param>
/// <param name="language"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<bool> 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;
}
/// <summary>
/// Add Or Update Resource ...
/// </summary>
/// <param name="resource"></param>
/// <param name="value"></param>
/// <param name="language"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<bool> 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;
}
/// <summary>
/// Add Specified Locale Resource ...
/// </summary>
/// <param name="item"></param>
/// <param name="resource"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XStringDto> 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;
}
/// <summary>
/// Update Specified Locale Resource ...
/// </summary>
/// <param name="item"></param>
/// <param name="resource"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XStringDto> 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;
}
/// <summary>
/// Add Or Update Resource By Locale ...
/// </summary>
/// <param name="item"></param>
/// <param name="resource"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XStringDto> 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;
}
/// <summary>
/// Add Or Update all XResourceDto(s) Locales ...
/// </summary>
/// <param name="item"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<XStringDto>> 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 ...
/// <summary>
/// Remove all Specified Language's Resources ...
/// </summary>
/// <param name="language"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// Remove all Specified Resource Ids instances ...
/// </summary>
/// <param name="resource"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<XStringDto>> 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;
}
/// <summary>
/// Remove Specified Resource ...
/// </summary>
/// <param name="resource"></param>
/// <param name="language"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<bool> 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;
}
/// <summary>
/// Remove all Resource of Specified XResourceDto ...
/// </summary>
/// <param name="item"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
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<TContext> : XBaseEFRepository<XString, int, TContext>, IXStringRepository
where TContext : XDbContext
{
public XStringEFRepository(
IXUnitOfWorks<TContext> 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<XString, int>, IXStringEntityHub
{
public XStringEntityHub(
ILogger<XStringEntityHub> 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<XString, int>, 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<XString>, 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<XString, int>, 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<XString>, 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<XString, int, XStringEntityHub>, IXStringRepositoryProvider
{
public XStringRepositoryProvider(
IHubContext<XStringEntityHub> 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<XString, int>, 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<XString, int>, 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<XString, int, XStringGraphType, IntGraphType>
{
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<XString, int>
{
public XStringGraphType() : base()
{
Field(x => x.Language);
Field(x => x.ResourceTitle);
Field(x => x.TranslatedValue);
}
}
}