Compare commits
1
Commits
0d6ace247e
...
fe88855e69
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe88855e69 |
@@ -0,0 +1,200 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xModels.Dtos;
|
||||
using xStringService.Models.Dtos;
|
||||
|
||||
namespace xStringService.Interfaces
|
||||
{
|
||||
public interface IXOwnedItemResourceProvider
|
||||
{
|
||||
//
|
||||
#region Group Actions ...
|
||||
/// <summary>
|
||||
/// Retrieve a List of Exists Languages for Current Item ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<string>> GetLanguages(
|
||||
object owner,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all Exists Items of type ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XStringDto>> GetResourceLocales(
|
||||
object owner,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Remove all Exists Locales which Related to this Provider ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task RemoveResourceLocales(
|
||||
object owner,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Item Actions ...
|
||||
/// <summary>
|
||||
/// Get all Exists Items for Specified identitifer ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XStringDto>> GetResourceLocales(
|
||||
object owner,
|
||||
object identifier,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Get all Exists Items for Specified identitifer ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XLocaleResourceDto>> GetLocales(
|
||||
object owner,
|
||||
object identifier,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Get all Exists Locales Representaion based on Specified Identitifer
|
||||
/// as XResourceDto ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XResourceDto> GetResource(
|
||||
object owner,
|
||||
object identifier,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Add Or Update Locale for Specified Identitifer ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="locale"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XResourceDto> AddOrUpdateLocale(
|
||||
object owner,
|
||||
object identifier,
|
||||
XLocaleResourceDto locale,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Update a Resource State ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XResourceDto> AddOrUpdateResource(
|
||||
object owner,
|
||||
object identifier,
|
||||
XResourceDto resource,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Remove Specified Language Locale of Specified Identifier ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XResourceDto> RemoveLocale(
|
||||
object owner,
|
||||
object identifier,
|
||||
string language,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Remove all Exists Locales for Specified Identifier ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task RemoveLocales(
|
||||
object owner,
|
||||
object identifier,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Check Specified ocale Exists for Specified Identifier ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> HasLocale(
|
||||
object owner,
|
||||
object identifier,
|
||||
string language,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Get all Exists Languages for Specified Identifier ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<string>> GetLanguages(
|
||||
object owner,
|
||||
object identifier = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Resource Title Action ...
|
||||
/// <summary>
|
||||
/// Retrieve Resource Title ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <returns></returns>
|
||||
string GetResourceTitle(
|
||||
object owner = null,
|
||||
object identifier = null
|
||||
);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xCommons.Extensions;
|
||||
using xModels.Dtos;
|
||||
using xStringService.Interfaces;
|
||||
using xStringService.Interfaces.Dtos;
|
||||
using xStringService.Models.Dtos;
|
||||
|
||||
namespace xStringService.Providers
|
||||
{
|
||||
public abstract class XBaseOwnedItemResourceProvider : IXOwnedItemResourceProvider
|
||||
{
|
||||
//
|
||||
#region Props ...
|
||||
/// <summary>
|
||||
/// Item Name for Resource Providing ...
|
||||
/// </summary>
|
||||
private readonly string item;
|
||||
|
||||
/// <summary>
|
||||
/// String Provider Service ...
|
||||
/// </summary>
|
||||
private readonly IXStringServiceProvider stringProvider;
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Constructor ...
|
||||
protected XBaseOwnedItemResourceProvider(
|
||||
string item,
|
||||
IXStringServiceProvider stringProvider
|
||||
)
|
||||
{
|
||||
//
|
||||
this.item = item;
|
||||
this.stringProvider = stringProvider;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Group Actions ...
|
||||
/// <summary>
|
||||
/// Retrieve a List of Exists Languages for Current Item ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<string>> GetLanguages(
|
||||
object owner,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all Exists Items of type ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XStringDto>> GetResourceLocales(
|
||||
object owner,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all Exists Locales which Related to this Provider ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task RemoveResourceLocales(
|
||||
object owner,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Item Actions ...
|
||||
/// <summary>
|
||||
/// Get all Exists Items for Specified identitifer ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XStringDto>> GetResourceLocales(
|
||||
object owner,
|
||||
object identifier,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all Exists Items for Specified identitifer ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XLocaleResourceDto>> GetLocales(
|
||||
object owner,
|
||||
object identifier,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all Exists Locales Representaion based on Specified Identitifer
|
||||
/// as XResourceDto ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XResourceDto> GetResource(
|
||||
object owner,
|
||||
object identifier,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Or Update Locale for Specified Identitifer ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <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 owner,
|
||||
object identifier,
|
||||
XLocaleResourceDto locale,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update a Resource State ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <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 owner,
|
||||
object identifier,
|
||||
XResourceDto resource,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Specified Language Locale of Specified Identifier ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <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 owner,
|
||||
object identifier,
|
||||
string language,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all Exists Locales for Specified Identifier ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task RemoveLocales(
|
||||
object owner,
|
||||
object identifier,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check Specified ocale Exists for Specified Identifier ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<bool> HasLocale(
|
||||
object owner,
|
||||
object identifier,
|
||||
string language,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all Exists Languages for Specified Identifier ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<string>> GetLanguages(
|
||||
object owner,
|
||||
object identifier = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Resource Title Action ...
|
||||
/// <summary>
|
||||
/// Retrieve Resource Title ...
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="identifier"></param>
|
||||
/// <returns></returns>
|
||||
public virtual string GetResourceTitle(
|
||||
object owner = null,
|
||||
object identifier = null
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = item;
|
||||
|
||||
//
|
||||
// Normalization ...
|
||||
var ownerStr =
|
||||
!owner.IsNull()
|
||||
? $"{owner}"
|
||||
: string.Empty;
|
||||
var identifierStr =
|
||||
!identifier.IsNull()
|
||||
? $"{identifier}"
|
||||
: string.Empty;
|
||||
|
||||
//
|
||||
// Handle Owner Attach ...
|
||||
if (!ownerStr.IsNullOrEmpty())
|
||||
{
|
||||
result = $"{result}_{ownerStr}";
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Identifier Attach ...
|
||||
if (!identifierStr.IsNullOrEmpty())
|
||||
{
|
||||
result = $"{result}_{identifierStr}";
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Private ...
|
||||
private async Task<IEnumerable<XStringDto>> ExtractStrings(
|
||||
string resourceTitle,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
IEnumerable<XStringDto> result = [];
|
||||
|
||||
//
|
||||
if (resourceTitle.IsNullOrEmpty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = await stringProvider.FindManyAsync(
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken,
|
||||
predicate: x => x.ResourceTitle
|
||||
.ToNormalString()
|
||||
.Contains(resourceTitle),
|
||||
orderBuilder: x => x.OrderBy(y => y.Id)
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user