last ...
This commit is contained in:
@@ -0,0 +1,189 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xStringService.Interfaces;
|
||||
using xStringService.Interfaces.Dtos;
|
||||
using xStringService.Models.Dtos;
|
||||
|
||||
namespace xStringService.Providers
|
||||
{
|
||||
public abstract class XBaseItemResourceProvider : IXItemResourceProvider
|
||||
{
|
||||
/// <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;
|
||||
|
||||
//
|
||||
#region Constructor ...
|
||||
protected XBaseItemResourceProvider(
|
||||
string item,
|
||||
IXStringServiceProvider stringProvider
|
||||
)
|
||||
{
|
||||
//
|
||||
this.item = item;
|
||||
this.stringProvider = stringProvider;
|
||||
provider = new XBaseResourceProvider(
|
||||
item,
|
||||
stringProvider
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region All Item Actions ...
|
||||
/// <summary>
|
||||
/// Retrieve a List of Exists Languages for Current Item ...
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<string>> GetLanguages(
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result =
|
||||
(await GetResourceLocales(cancellationToken))
|
||||
.Select(x => x.Language)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all Exists Items of type ...
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XStringDto>> GetResourceLocales(
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var identifier = GetResourceTitle();
|
||||
var result = await stringProvider
|
||||
.FindManyAsync(
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken,
|
||||
orderBuilder:
|
||||
x => x
|
||||
.OrderBy(y => y.Language)
|
||||
.ThenBy(y => y.ResourceTitle),
|
||||
predicate: x =>
|
||||
x.ResourceTitle.StartsWith(identifier, StringComparison.InvariantCultureIgnoreCase)
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Single Item Actions ...
|
||||
/// <summary>
|
||||
/// Retrieve a List of Exists Languages for Current Item ...
|
||||
/// </summary>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<string>> GetLanguages(
|
||||
object identifier,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid = !identifier.IsNull();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Set Identifier ...
|
||||
SetResourceTitle(identifier);
|
||||
|
||||
//
|
||||
var result =
|
||||
await provider.GetLanguages(cancellationToken);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all Exists Items of type ...
|
||||
/// </summary>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XStringDto>> GetResourceLocales(
|
||||
object identifier,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid = !identifier.IsNull();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Set Identifier ...
|
||||
SetResourceTitle(identifier);
|
||||
|
||||
//
|
||||
var result =
|
||||
await provider.GetResourceLocales(cancellationToken);
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Private ...
|
||||
private string GetResourceTitle(object identifier = null)
|
||||
{
|
||||
//
|
||||
var result = item;
|
||||
|
||||
//
|
||||
if (!identifier.IsNull())
|
||||
{
|
||||
result = $"{item}_{identifier}";
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
private void SetResourceTitle(object identifier = null)
|
||||
{
|
||||
//
|
||||
var itemIdentifier = GetResourceTitle(identifier);
|
||||
provider.SetField(
|
||||
field: "resource",
|
||||
value: $"{itemIdentifier}"
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user