last works on XString Service for Entities and Dtos ...
This commit is contained in:
@@ -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
@@ -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
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using xDataService.Configuration;
|
||||
using xDataService.GraphQL;
|
||||
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 "strings";
|
||||
}
|
||||
|
||||
public override string GetInQuerySingleName()
|
||||
{
|
||||
return "string";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
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
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user