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 ...
///
/// Item Name for Resource Providing ...
///
private readonly string item;
///
/// String Provider Service ...
///
private readonly IXStringServiceProvider stringProvider;
#endregion
//
#region Constructor ...
protected XBaseOwnedItemResourceProvider(
string item,
IXStringServiceProvider stringProvider
)
{
//
this.item = item;
this.stringProvider = stringProvider;
}
#endregion
//
#region Group Actions ...
///
/// Retrieve a List of Exists Languages for Current Item ...
///
///
///
///
public virtual async Task> GetLanguages(
object owner,
CancellationToken cancellationToken = default
)
{
throw new NotImplementedException();
}
///
/// Retrieve all Exists Items of type ...
///
///
///
///
public virtual async Task> GetResourceLocales(
object owner,
CancellationToken cancellationToken = default
)
{
throw new NotImplementedException();
}
///
/// Remove all Exists Locales which Related to this Provider ...
///
///
///
///
///
public virtual async Task RemoveResourceLocales(
object owner,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
throw new NotImplementedException();
}
#endregion
//
#region Item Actions ...
///
/// Get all Exists Items for Specified identitifer ...
///
///
///
///
///
public virtual async Task> GetResourceLocales(
object owner,
object identifier,
CancellationToken cancellationToken = default
)
{
throw new NotImplementedException();
}
///
/// Get all Exists Items for Specified identitifer ...
///
///
///
///
///
public virtual async Task> GetLocales(
object owner,
object identifier,
CancellationToken cancellationToken = default
)
{
throw new NotImplementedException();
}
///
/// Get all Exists Locales Representaion based on Specified Identitifer
/// as XResourceDto ...
///
///
///
///
///
public virtual async Task GetResource(
object owner,
object identifier,
CancellationToken cancellationToken = default
)
{
throw new NotImplementedException();
}
///
/// Add Or Update Locale for Specified Identitifer ...
///
///
///
///
///
///
///
public virtual async Task AddOrUpdateLocale(
object owner,
object identifier,
XLocaleResourceDto locale,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
throw new NotImplementedException();
}
///
/// Update a Resource State ...
///
///
///
///
///
///
///
public virtual async Task AddOrUpdateResource(
object owner,
object identifier,
XResourceDto resource,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
throw new NotImplementedException();
}
///
/// Remove Specified Language Locale of Specified Identifier ...
///
///
///
///
///
///
///
public virtual async Task RemoveLocale(
object owner,
object identifier,
string language,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
throw new NotImplementedException();
}
///
/// Remove all Exists Locales for Specified Identifier ...
///
///
///
///
///
///
public virtual async Task RemoveLocales(
object owner,
object identifier,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
throw new NotImplementedException();
}
///
/// Check Specified ocale Exists for Specified Identifier ...
///
///
///
///
///
///
public virtual async Task HasLocale(
object owner,
object identifier,
string language,
CancellationToken cancellationToken = default
)
{
throw new NotImplementedException();
}
///
/// Get all Exists Languages for Specified Identifier ...
///
///
///
///
///
public virtual async Task> GetLanguages(
object owner,
object identifier = null,
CancellationToken cancellationToken = default
)
{
throw new NotImplementedException();
}
#endregion
//
#region Resource Title Action ...
///
/// Retrieve Resource Title ...
///
///
///
///
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> ExtractStrings(
string resourceTitle,
CancellationToken cancellationToken = default
)
{
//
IEnumerable 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
}
}