last works on XString Service for Entities and Dtos ...

This commit is contained in:
2026-05-23 03:14:14 +03:30
parent e6e9e1b93d
commit b44c014de8
28 changed files with 2228 additions and 32 deletions
@@ -0,0 +1,12 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using xDataService.Providers;
using xStringService.Models.Entities;
namespace xStringService.Configurations.Entities
{
public class XStringEntityConfiguration : XBaseEntityTypeConfiguration<XString, int>
{
public override void Configure(EntityTypeBuilder<XString> builder)
{ }
}
}
-9
View File
@@ -1,9 +0,0 @@
using xDataService.Providers;
using xStringService.Interfaces.Entities;
using xStringService.Models.Entities;
namespace xStringService.DataHelper.Events
{
public class XStringEvents : XBaseRepositoryEvents<XString>, IXStringEvents
{}
}
-1
View File
@@ -1,4 +1,3 @@
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using xCommons.Extensions; using xCommons.Extensions;
-15
View File
@@ -1,15 +0,0 @@
using Microsoft.Extensions.Logging;
using xPushService.Base;
using xStringService.Models.Entities;
namespace xStringService.Hubs
{
public class XStringEntityHub : XBaseEntityHub<XString, int>
{
//
#region Constructor ...
public XStringEntityHub(ILogger<XBaseHub> logger) : base(logger)
{ }
#endregion
}
}
+9
View File
@@ -0,0 +1,9 @@
using xPushService.Interfaces;
using xStringService.Models.Dtos;
using xStringService.Models.Entities;
namespace xStringService.Interfaces.Dtos
{
public interface IXStringDtoHub : IXBaseDtoHub<XString, XStringDto, int>
{ }
}
@@ -0,0 +1,15 @@
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>
{ }
}
+302
View File
@@ -0,0 +1,302 @@
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
}
}
+8
View File
@@ -0,0 +1,8 @@
using xPushService.Interfaces;
using xStringService.Models.Entities;
namespace xStringService.Interfaces.Entities
{
public interface IXStringEntityHub : IXBaseEntityHub<XString, int>
{ }
}
@@ -3,6 +3,6 @@ using xStringService.Models.Entities;
namespace xStringService.Interfaces.Entities namespace xStringService.Interfaces.Entities
{ {
public interface IXStringEvents : IXBaseRepositoryEvents<XString> public interface IXStringKeyGenerator : IXKeyGenerator<XString, int>
{ } { }
} }
@@ -0,0 +1,8 @@
using xDataService.Interfaces;
using xStringService.Models.Entities;
namespace xStringService.Interfaces.Entities
{
public interface IXStringRepositoryEvents : IXBaseRepositoryEvents<XString>
{ }
}
@@ -0,0 +1,9 @@
using xPushService.Interfaces;
using xStringService.Models.Entities;
using xStringService.Providers.Entities;
namespace xStringService.Interfaces.Entities
{
public interface IXStringRepositoryProvider : IXBaseEntityProviderr<XString, int, XStringEntityHub>
{ }
}
+136
View File
@@ -0,0 +1,136 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using xCommons.Configurations;
using xModels.Dtos;
using xStringService.Interfaces.Dtos;
using xStringService.Models.Dtos;
namespace xStringService.Interfaces
{
/// <summary>
/// a Base Class for Handling Resources Based on Specified Types on
/// String Resources Use ...
/// such as:
/// - Terms and Conditions;
/// - Contents;
/// - News;
/// - etc ...
/// </summary>
public interface IXBaseStringResourceProvider
{
//
#region Props ...
string Prefix { get; }
IXStringServiceProvider Provider { get; }
XAppConfiguration AppConfiguration { get; }
#endregion
//
#region Actions ...
/// <summary>
/// Prepare Resource Title by Given Data ...
/// </summary>
/// <param name="suffix"></param>
/// <returns></returns>
string GetResourceTitle(string suffix);
/// <summary>
/// Add Specified Locales ...
/// </summary>
/// <param name="suffix"></param>
/// <param name="locales"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<XStringDto>> Add(
string suffix,
IEnumerable<XLocaleResourceDto> locales,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Add Or Update Specified Locals ...
/// </summary>
/// <param name="resource"></param>
/// <param name="locales"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<XStringDto>> AddOrUpdate(
string resource,
IEnumerable<XLocaleResourceDto> locales,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Get Specified Locale ...
/// </summary>
/// <param name="suffix"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XLocaleResourceDto> GetLocale(
string suffix,
string language = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Add Specified Resource ...
/// </summary>
/// <param name="suffix"></param>
/// <param name="item"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XResourceDto> AddResource(
string suffix,
XResourceDto item,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Get Resources of Specified Resource ...
/// </summary>
/// <param name="suffix"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XResourceDto> GetResource(
string suffix,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove Specified Suffix Resources ...
/// </summary>
/// <param name="suffix"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task Remove(
string suffix,
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 Remove(
string resource,
string language,
string connectionId = null,
CancellationToken cancellationToken = default
);
#endregion
}
}
+1 -2
View File
@@ -2,9 +2,8 @@ using xModels.Base;
namespace xStringService.Models.Dtos namespace xStringService.Models.Dtos
{ {
public class XStringDto : XBaseDto public class XStringDto : XBaseIntIDEntityDto
{ {
public int Id { get; set; }
public string Language { get; set; } public string Language { get; set; }
public string ResourceTitle { get; set; } public string ResourceTitle { get; set; }
public string TranslatedValue { get; set; } public string TranslatedValue { get; set; }
+16
View File
@@ -0,0 +1,16 @@
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)
{ }
}
}
@@ -0,0 +1,22 @@
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 diff suppressed because it is too large Load Diff
+26
View File
@@ -0,0 +1,26 @@
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>
where TContext : XDbContext
{
protected XStringEFRepository(
IXUnitOfWorks<TContext> unitOfWorks,
XDataServiceConfiguration configuration,
IXStringKeyGenerator keyGenerator = null,
IXStringRepositoryEvents baseRepositoryEvents = null
) : base(
unitOfWorks,
configuration,
keyGenerator,
baseRepositoryEvents
)
{ }
}
}
+15
View File
@@ -0,0 +1,15 @@
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)
{ }
}
}
+9
View File
@@ -0,0 +1,9 @@
using xDataService.Providers;
using xStringService.Interfaces.Entities;
using xStringService.Models.Entities;
namespace xStringService.Providers.Entities
{
public class XStringRepositoryEvents : XBaseRepositoryEvents<XString>, IXStringRepositoryEvents
{}
}
@@ -0,0 +1,21 @@
using xDataService.Configuration;
using xDataService.Providers;
using xStringService.Interfaces.Entities;
using xStringService.Models.Entities;
namespace xStringService.Providers.Entities
{
public class XStringInMemoeryRepository : XBaseInMemoryRepository<XString, int>, IXStringRepository
{
public XStringInMemoeryRepository(
XDataServiceConfiguration configuration,
IXStringKeyGenerator keyGenerator = null,
IXStringRepositoryEvents baseRepositoryEvents = null
) : base(
configuration,
keyGenerator,
baseRepositoryEvents
)
{ }
}
}
@@ -0,0 +1,9 @@
using xDataService.Providers;
using xStringService.Interfaces.Entities;
using xStringService.Models.Entities;
namespace xStringService.Providers.Entities
{
public class XStringKeyGenerator : XIntKeyGenerator<XString>, IXStringKeyGenerator
{ }
}
@@ -0,0 +1,25 @@
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
)
{ }
}
}
@@ -0,0 +1,25 @@
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
)
{ }
}
}
@@ -3,7 +3,7 @@ using xDataService.GraphQL;
using xStringService.Interfaces.Entities; using xStringService.Interfaces.Entities;
using xStringService.Models.Entities; using xStringService.Models.Entities;
namespace xStringService.DataHelper.GraphQL namespace xStringService.Providers.GraphQL
{ {
public class XStringGraphQLTypeHelper : XBaseGraphQLTypeHelper<XString, int>, IXStringGraphQLTypeHelper public class XStringGraphQLTypeHelper : XBaseGraphQLTypeHelper<XString, int>, IXStringGraphQLTypeHelper
{ {
@@ -4,7 +4,7 @@ using xDataService.GraphQL;
using xStringService.Interfaces.Entities; using xStringService.Interfaces.Entities;
using xStringService.Models.Entities; using xStringService.Models.Entities;
namespace xDataHelper.GraphQL namespace xDataHelper.Providers.GraphQL
{ {
public class XStringGraphQuery : XBaseGraphQLQuery<XString, int, XStringGraphType, IntGraphType> public class XStringGraphQuery : XBaseGraphQLQuery<XString, int, XStringGraphType, IntGraphType>
{ {
@@ -1,7 +1,7 @@
using System; using System;
using GraphQL.Types; using GraphQL.Types;
namespace xDataHelper.GraphQL namespace xDataHelper.Providers.GraphQL
{ {
public class XStringGraphSchema : Schema public class XStringGraphSchema : Schema
{ {
@@ -1,7 +1,7 @@
using xDataService.GraphQL; using xDataService.GraphQL;
using xStringService.Models.Entities; using xStringService.Models.Entities;
namespace xDataHelper.GraphQL namespace xDataHelper.Providers.GraphQL
{ {
public class XStringGraphType : XBaseGraphObjectType<XString, int> public class XStringGraphType : XBaseGraphObjectType<XString, int>
{ {
+405
View File
@@ -0,0 +1,405 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using xCommons.Configurations;
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
{
/// <summary>
/// a Base Class for Handling Resources Based on Specified Types on
/// String Resources Use ...
/// such as:
/// - Terms and Conditions;
/// - Contents;
/// - News;
/// - etc ...
/// </summary>
public abstract class XBaseStringResourceProvider : IXBaseStringResourceProvider
{
//
#region Props ...
public string Prefix { get; }
public IXStringServiceProvider Provider { get; }
public XAppConfiguration AppConfiguration { get; }
#endregion
//
#region Constructor ...
public XBaseStringResourceProvider(
string prefix,
IXStringServiceProvider provider,
XAppConfiguration appConfiguration
)
{
//
Prefix = prefix;
Provider = provider;
AppConfiguration = appConfiguration;
}
#endregion
//
#region Actions ...
/// <summary>
/// Prepare Resource Title by Given Data ...
/// </summary>
/// <param name="suffix"></param>
/// <returns></returns>
public string GetResourceTitle(string suffix)
{
//
string result = "";
//
if (suffix.IsNullOrEmpty())
{
return result;
}
//
result = $"{Prefix}_${suffix}";
//
return result;
}
/// <summary>
/// Add Specified Locales ...
/// </summary>
/// <param name="suffix"></param>
/// <param name="locales"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<XStringDto>> Add(
string suffix,
IEnumerable<XLocaleResourceDto> locales,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
var has =
locales.HasChild() &&
!suffix.IsNullOrEmpty();
if (!has)
{
XException.InvalidArgs.Throw();
}
//
// Prepare Resource ID ...
string resourceID = GetResourceTitle(suffix);
var result = await locales.SelectAsync(async l =>
{
//
// Normalize Language ...
if (l.Language.IsNullOrEmpty())
{
l.Language = AppConfiguration.DefaultLanguage;
}
//
// Prepare Model for Add ...
var model = new XStringDto
{
Language = l.Language,
TranslatedValue = l.Value,
ResourceTitle = resourceID,
};
model = await Provider.AddAsync(
item: model,
saveChanges: true,
connectionId: connectionId,
cancellationToken: cancellationToken
);
return model;
});
//
return result;
}
/// <summary>
/// Add Or Update Specified Locals ...
/// </summary>
/// <param name="resource"></param>
/// <param name="locales"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<XStringDto>> AddOrUpdate(
string resource,
IEnumerable<XLocaleResourceDto> locales,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
bool isValid =
locales.HasChild() &&
!resource.IsNullOrEmpty() &&
locales.All(l => !l.Value.IsNullOrEmpty() && !l.Language.IsNullOrEmpty());
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
// Check Resource ...
isValid = resource.Contains(Prefix);
if (!isValid)
{
XException.NotAllowed.Throw();
}
//
var result = await locales.SelectAsync(async l =>
await Provider.AddOrUpdateByLocaleResource(
item: l,
resource: resource,
connectionId: connectionId,
cancellationToken: cancellationToken
)
);
//
return result;
}
/// <summary>
/// Get Specified Locale ...
/// </summary>
/// <param name="suffix"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XLocaleResourceDto> GetLocale(
string suffix,
string language = null,
CancellationToken cancellationToken = default
)
{
//
// Normalize ...
if (language.IsNullOrEmpty())
{
language = AppConfiguration.DefaultLanguage;
}
//
// Validate ...
if (suffix.IsNullOrEmpty() || language.IsNullOrEmpty())
{
XException.InvalidArgs.Throw();
}
//
// Prepare Resource Title ...
string resource = GetResourceTitle(suffix);
//
// Check Resource Exists ...
var isExists = await Provider.IsResourceExists(
resource: resource,
language: language,
cancellationToken: cancellationToken
);
if (!isExists)
{
XException.NotFound.Throw();
}
//
// Retrieve and Validate Dto Model ...
var model = await Provider.Get(
resource: resource,
language: language,
cancellationToken: cancellationToken
);
if (model.IsNullOrDefault())
{
XException.ActionFailed.Throw();
}
//
// Prepare Result ...
var result = model
.ToXLocaleResourceDto();
return result;
}
/// <summary>
/// Add Specified Resource ...
/// </summary>
/// <param name="suffix"></param>
/// <param name="item"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XResourceDto> AddResource(
string suffix,
XResourceDto item,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
if (suffix.IsNullOrEmpty() ||
item.IsNull() ||
!item.Locales.HasChild() ||
!item.Locales.All(l => !l.Value.IsNullOrEmpty()))
{
XException.InvalidArgs.Throw();
}
//
// Prepare Resource ID ...
var addedLocals = await Add(
suffix: suffix,
locales: item.Locales,
connectionId: connectionId,
cancellationToken: cancellationToken
);
if (!addedLocals.HasChild())
{
XException.ActionFailed.Throw();
}
//
var result = await GetResource(
suffix: suffix,
cancellationToken: cancellationToken
);
return result;
}
/// <summary>
/// Get Resources of Specified Resource ...
/// </summary>
/// <param name="suffix"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XResourceDto> GetResource(
string suffix,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
if (suffix.IsNullOrEmpty())
{
XException.InvalidArgs.Throw();
}
//
// Prepare Resource ID ...
string resourceID = GetResourceTitle(suffix);
//
// Prepare ...
var result = await Provider.GetResource(
resource: resourceID,
cancellationToken: cancellationToken
);
return result;
}
/// <summary>
/// Remove Specified Suffix Resources ...
/// </summary>
/// <param name="suffix"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task Remove(
string suffix,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
if (suffix.IsNullOrEmpty())
{
XException.InvalidArgs.Throw();
}
//
var resourceID = GetResourceTitle(suffix);
await Provider.RemoveResource(
resource: resourceID,
connectionId: connectionId,
cancellationToken: cancellationToken
);
}
/// <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 Remove(
string resource,
string language,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
bool isValid =
!resource.IsNullOrEmpty() &&
!language.IsNullOrEmpty();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
// Check resource ID Contains Prefix ...
isValid = resource.Contains(Prefix);
if (!isValid)
{
XException.NotAllowed.Throw();
}
//
// Check Exists ...
var isExists = await Provider.IsResourceExists(
resource: resource,
language: language,
cancellationToken: cancellationToken
);
if (!isExists)
{
XException.NotFound.Throw();
}
//
// Remove Resource ...
await Provider.Remove(
resource: resource,
language: language,
connectionId: connectionId,
cancellationToken: cancellationToken
);
}
#endregion
}
}