Add String Service and Implement all of it's requirements as an xDashboard Package ...
This commit is contained in:
@@ -1,3 +1,83 @@
|
||||
namespace xStringService.DI {
|
||||
public static class XDIHelperExtension { }
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using xExceptions.Constants;
|
||||
using xCommons.Extensions;
|
||||
using xStringService.Interfaces;
|
||||
using xStringService.Providers;
|
||||
|
||||
namespace xStringService.DI
|
||||
{
|
||||
public static class XDIHelperExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Register Module Provided Service on DI
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="config"></param>
|
||||
public static void AddXStringService(
|
||||
this IServiceCollection services,
|
||||
ServiceLifetime lifeTime
|
||||
)
|
||||
{
|
||||
AddStringService(
|
||||
services,
|
||||
lifeTime
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
#region Private ...
|
||||
/// <summary>
|
||||
/// a LogTag for XStringService ...
|
||||
/// </summary>
|
||||
private static string XLogTag = "XStringService";
|
||||
|
||||
/// <summary>
|
||||
/// print a log in Console ...
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
private static void Log(string message)
|
||||
{
|
||||
Console.WriteLine($"{XLogTag} => {message}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register Push Service ...
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="lifeTime"></param>
|
||||
private static void AddStringService(
|
||||
IServiceCollection services,
|
||||
ServiceLifetime lifeTime
|
||||
)
|
||||
{
|
||||
//
|
||||
var exception = XException.InvalidArgs.ToException(); ;
|
||||
|
||||
//
|
||||
// Services ...
|
||||
var isServicesExists = !services.IsNull();
|
||||
if (!isServicesExists)
|
||||
{
|
||||
//
|
||||
Log("AddStringService failed, services not provided ...");
|
||||
throw exception;
|
||||
}
|
||||
|
||||
//
|
||||
// Lifetime ...
|
||||
var isLifetimeExists = !lifeTime.IsNull();
|
||||
if (!isLifetimeExists)
|
||||
{
|
||||
//
|
||||
Log("AddStringService failed, lifetime not provided ...");
|
||||
throw exception;
|
||||
}
|
||||
|
||||
//
|
||||
services.Add(new ServiceDescriptor(typeof(IXStringProvider), typeof(XStringProvider), lifeTime));
|
||||
Log("AddStringService Succeed ...");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using xDataService.Events;
|
||||
using xStringService.Interfaces.Entities;
|
||||
using xStringService.Models.Entities;
|
||||
|
||||
namespace xStringService.DataHelper.Events
|
||||
{
|
||||
public class XStringEvents : XBaseRepositoryEvents<XString>, IXStringEvents
|
||||
{}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using xDataService.Configuration;
|
||||
using xDataService.GraphQL;
|
||||
using xStringService.Interfaces.Entities;
|
||||
using xStringService.Models.Entities;
|
||||
|
||||
namespace xStringService.DataHelper.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.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.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.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,118 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using xCommons.Extensions;
|
||||
using xModels.Dtos;
|
||||
using xStringService.Models.Dtos;
|
||||
using xStringService.Models.Entities;
|
||||
|
||||
namespace xStringService.Extensions
|
||||
{
|
||||
public static class XModelExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts an Entity to Dto Representation ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static XStringDto ToXStringDto(this XString source)
|
||||
{
|
||||
//
|
||||
XStringDto result = new XStringDto();
|
||||
|
||||
//
|
||||
result.Id = source.Id;
|
||||
result.Language = source.Language;
|
||||
result.ResourceTitle = source.ResourceTitle;
|
||||
result.TranslatedValue = source.TranslatedValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Collection of Entities to Dto ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<XStringDto> ToXStringDtos(this IEnumerable<XString> source)
|
||||
{
|
||||
//
|
||||
var list = new List<XStringDto>();
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool isValid = source.HasChild();
|
||||
if (!isValid)
|
||||
{
|
||||
return list.AsEnumerable();
|
||||
}
|
||||
|
||||
//
|
||||
var result = source.Select(e => ToXStringDto(e));
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an Entity to LocaleResource Dto ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static XLocaleResourceDto ToXLocaleResourceDto(this XString source)
|
||||
{
|
||||
//
|
||||
var result = new XLocaleResourceDto
|
||||
{
|
||||
Language = source.IsNull() ? "" : source.Language,
|
||||
Value = source.IsNull() ? "" : source.TranslatedValue,
|
||||
};
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an Dto to LocaleResource Dto ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static XLocaleResourceDto ToXLocaleResourceDto(this XStringDto source)
|
||||
{
|
||||
//
|
||||
var result = new XLocaleResourceDto
|
||||
{
|
||||
Language = source.IsNull() ? "" : source.Language,
|
||||
Value = source.IsNull() ? "" : source.TranslatedValue,
|
||||
};
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Collection of Entities to Locale Resource Presentation ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<XLocaleResourceDto> ToXLocaleResourceDtos(this IEnumerable<XString> source)
|
||||
{
|
||||
//
|
||||
var result = source.Select(e => ToXLocaleResourceDto(e));
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Collection of Dtos to Locale Resource Presentation ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<XLocaleResourceDto> ToXLocaleResourceDtos(this IEnumerable<XStringDto> source)
|
||||
{
|
||||
//
|
||||
var result = source.Select(e => ToXLocaleResourceDto(e));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using xDataService.Interfaces;
|
||||
using xStringService.Models.Entities;
|
||||
|
||||
namespace xStringService.Interfaces.Entities
|
||||
{
|
||||
public interface IXStringEvents : IXBaseRepositoryEvents<XString>
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using xDataService.Interfaces;
|
||||
using xStringService.Models.Entities;
|
||||
|
||||
namespace xStringService.Interfaces.Entities
|
||||
{
|
||||
public interface IXStringGraphQLTypeHelper : IXBaseGraphQLTypeHelper<XString, int>
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using xDataService.Interfaces;
|
||||
using xStringService.Models.Entities;
|
||||
|
||||
namespace xStringService.Interfaces.Entities
|
||||
{
|
||||
public interface IXStringRepository : IXBaseRepository<XString, int>
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using xCommons.Configurations;
|
||||
using xDataService.Configuration;
|
||||
using xModels.Dtos;
|
||||
using xStringService.Interfaces.Entities;
|
||||
using xStringService.Models.Dtos;
|
||||
using xStringService.Models.Entities;
|
||||
|
||||
namespace xStringService.Interfaces
|
||||
{
|
||||
public interface IXStringProvider
|
||||
{
|
||||
//
|
||||
#region Props ...
|
||||
IXStringRepository Repository { get; }
|
||||
XAppConfiguration AppConfiguration { get; }
|
||||
XDataServiceConfiguration DataConfiguration { get; }
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Retrievers ...
|
||||
/// <summary>
|
||||
/// Retrieve all Exists Languages ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<string>> GetLanguages();
|
||||
|
||||
/// <summary>
|
||||
/// Check Specified Resource Exists or not ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> IsResourceExists(
|
||||
string resource,
|
||||
string language = null
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Specified Translation of Specified Resource ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> GetResourceValue(
|
||||
string resource,
|
||||
string language = null
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve an Specified Resource Items ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XStringDto>> GetResources(string resource);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Specified Resource Items as XResourceDto Presentation ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <returns></returns>
|
||||
Task<XResourceDto> GetResource(string resource);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Query ...
|
||||
/// <summary>
|
||||
/// Query Resource IDs ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <returns></returns>
|
||||
Task<XQueryResult<string>> QueryResourceIds(XQuery query);
|
||||
|
||||
/// <summary>
|
||||
/// Query Specified Language Resources ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
Task<XQueryResult<XStringDto>> QueryLanguageResources(
|
||||
XQuery query,
|
||||
string language = null //
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Query Locale Resources ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
Task<XQueryResult<XLocaleResourceDto>> QueryLocaleResources(
|
||||
XQuery query,
|
||||
string language = null //
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Conditional Query Resources ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="condition"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
Task<XQueryResult<XStringDto>> ConditionalQueryResources(
|
||||
XQuery query,
|
||||
Expression<Func<XString, bool>> condition,
|
||||
string language = null
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Add/Update Actions ...
|
||||
/// <summary>
|
||||
/// Add Specified Resource ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> Add(
|
||||
string resource,
|
||||
string value,
|
||||
string language = null
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Update Resource ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> Update(
|
||||
string resource,
|
||||
string value,
|
||||
string language = null
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Add Or Update Resource ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> AddOrUpdate(
|
||||
string resource,
|
||||
string value,
|
||||
string language = null
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Add Specified Resource ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
Task<XStringDto> AddEntity(XStringDto item);
|
||||
|
||||
/// <summary>
|
||||
/// Update Specified Entity ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
Task<XStringDto> UpdateEntity(XStringDto item);
|
||||
|
||||
/// <summary>
|
||||
/// Add Or Update Specified Entitiy ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
Task<XStringDto> AddOrUpdateEntity(XStringDto item);
|
||||
|
||||
/// <summary>
|
||||
/// Add Specified Locale Resource ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="resource"></param>
|
||||
/// <returns></returns>
|
||||
Task<XStringDto> AddByLocaleResource(
|
||||
XLocaleResourceDto item,
|
||||
string resource
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Update Specified Locale Resource ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="resource"></param>
|
||||
/// <returns></returns>
|
||||
Task<XStringDto> UpdateByLocaleResource(
|
||||
XLocaleResourceDto item,
|
||||
string resource
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Add Or Update Resource By Locale ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="resource"></param>
|
||||
/// <returns></returns>
|
||||
Task<XStringDto> AddOrUpdateByLocaleResource(
|
||||
XLocaleResourceDto item,
|
||||
string resource
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Add Or Update all XResourceDto(s) Locales ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XStringDto>> AddByResource(XResourceDto item);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Remove Actions ...
|
||||
/// <summary>
|
||||
/// Remove all Specified Language's Resources ...
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
Task RemoveLanguageResources(string language);
|
||||
|
||||
/// <summary>
|
||||
/// Remove all Specified Resource Ids instances ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XStringDto>> RemoveResource(string resource);
|
||||
|
||||
/// <summary>
|
||||
/// Remove Specified Resource ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> Remove(
|
||||
string resource,
|
||||
string language = null
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Remove all Resource of Specified XResourceDto ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
Task RemoveByResource(XResourceDto item);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using xModels.Base;
|
||||
|
||||
namespace xStringService.Models.Dtos
|
||||
{
|
||||
public class XStringDto : XBaseDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Language { get; set; }
|
||||
public string ResourceTitle { get; set; }
|
||||
public string TranslatedValue { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xStringService.Models.Entities
|
||||
{
|
||||
public class XString : XBaseIntIDEntity
|
||||
{
|
||||
[Required]
|
||||
[StringLength (10)]
|
||||
public string Language { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength (255)]
|
||||
public string ResourceTitle { get; set; }
|
||||
|
||||
[Required]
|
||||
public string TranslatedValue { get; set; }
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user