This commit is contained in:
2026-05-28 02:31:45 +03:30
parent af9d2fa00f
commit c977339613
45 changed files with 1503 additions and 1647 deletions
@@ -0,0 +1,15 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using xDataService.Providers;
using xTagService.Models.Entities;
namespace xTagService.Configurations.Entities
{
public class XTagEntityConfiguration : XBaseEntityTypeConfiguration<XTag, int>
{
public override void Configure(EntityTypeBuilder<XTag> builder)
{
builder.ToTable("Tags");
}
}
}
@@ -0,0 +1,33 @@
using System;
using System.Linq;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.Logging;
using xCommons.Configurations;
using xCommons.Providers;
using xDataService.Controllers;
using xDataService.Interfaces;
using xTagService.Interfaces.Entities;
using xTagService.Models.Entities;
namespace xTagService.Controllers
{
public abstract class XTagRepositoryControllerBase : XBaseRepositoryController<XTag, int>, IXBaseRepositoryController<XTag, int>
{
protected XTagRepositoryControllerBase(
ILogger<XTagRepositoryControllerBase> logger,
XAppConfiguration appConfiguration,
XValidationProvider validationProvider,
IXTagRepository repository,
Func<IQueryable<XTag>, IOrderedQueryable<XTag>> defaultOrderBuilder = null,
Func<IQueryable<XTag>, IIncludableQueryable<XTag, object>> defaultIncludeBuilder = null
) : base(
logger,
appConfiguration,
validationProvider,
repository,
defaultOrderBuilder,
defaultIncludeBuilder
)
{ }
}
}
@@ -0,0 +1,37 @@
using System;
using System.Linq;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.Logging;
using xCommons.Configurations;
using xCommons.Providers;
using xIdentityService.Interfaces;
using xPushService.Controllers;
using xPushService.Interfaces;
using xTagService.Interfaces.Entities;
using xTagService.Models.Entities;
using xTagService.Providers.Entities;
namespace xTagService.Controllers
{
public abstract class XTagRepositoryProviderControllerBase : XBaseRepositoryProviderController<XTag, int, XTagEntityHub>, IXBaseRepositoryProviderController<XTag, int, XTagEntityHub>
{
protected XTagRepositoryProviderControllerBase(
ILogger<XTagRepositoryProviderControllerBase> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXTagRepositoryProvider provider,
Func<IQueryable<XTag>, IOrderedQueryable<XTag>> defaultOrderBuilder = null,
Func<IQueryable<XTag>, IIncludableQueryable<XTag, object>> defaultIncludeBuilder = null
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider,
provider,
defaultOrderBuilder,
defaultIncludeBuilder
)
{ }
}
}
+16 -430
View File
@@ -1,448 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.Logging;
using xCommons.Configurations;
using xCommons.Extensions;
using xCommons.Providers;
using xIdentityService.Controllers;
using xIdentityService.Interfaces;
using xModels.Dtos;
using xTagService.Interfaces;
using xDataService.Controllers;
using xDataService.Interfaces;
using xTagService.Interfaces.Dtos;
using xTagService.Models.Dtos;
using xTagService.Models.Entities;
namespace xTagService.Controllers
{
/// <summary>
/// a Controller base Class which implement based Actions to Provides Tag Provider Access ...
/// </summary>
public abstract class XTagServiceControllerBase : XIBaseProviderController, IXTagServiceControllerActions
public abstract class XTagServiceControllerBase : XBaseServiceController<XTag, XTagDto, int>, IXBaseServiceController<XTag, XTagDto, int>
{
//
#region Props ...
public IXTagProvider TagProvider { get; }
#endregion
//
#region Constructor ...
public XTagServiceControllerBase(
ILogger logger,
IXTagProvider tagProvider,
protected XTagServiceControllerBase(
ILogger<XTagServiceControllerBase> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider
XValidationProvider validationProvider,
IXTagRepositoryService repositoryService,
Func<IQueryable<XTag>, IOrderedQueryable<XTag>> defaultOrderBuilder = null,
Func<IQueryable<XTag>, IIncludableQueryable<XTag, object>> defaultIncludeBuilder = null
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider
validationProvider,
repositoryService,
defaultOrderBuilder,
defaultIncludeBuilder
)
{
//
TagProvider = tagProvider;
}
#endregion
//
#region Actions ...
/// <summary>
/// Add Tag by Providing Dto ...
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost("")]
public virtual async Task<ActionResult<XTagDto>> Add(
[FromBody] XTagDto model
)
{
//
// Do ...
try
{
//
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var connectionId = GetConnectionId();
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
var result = await TagProvider.Add(
model: model,
connectionId: connectionId
);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Update Specified Tag ...
/// </summary>
/// <param name="id"></param>
/// <param name="model"></param>
/// <returns></returns>
[HttpPut("{id}")]
public virtual async Task<ActionResult<XTagDto>> Update(
[FromRoute] int id,
[FromBody] XTagDto model
)
{
//
// Do ...
try
{
//
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var connectionId = GetConnectionId();
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
var result = await TagProvider.Update(
id: id,
model: model,
connectionId: connectionId
);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Remove Specified Tag by ID ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete("{id}")]
public virtual async Task<ActionResult<XTagDto>> Remove(
[FromRoute] int id
)
{
//
// Do ...
try
{
//
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var connectionId = GetConnectionId();
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
var result = await TagProvider.Remove(
id: id,
connectionId: connectionId
);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Retrieve Specified Tag Dto by ID ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
public virtual async Task<ActionResult<XTagDto>> Get(
[FromRoute] int id
)
{
//
// Do ...
try
{
//
var result = await TagProvider.Get(
id: id
);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Retrieve Specified Tag Dto by it's Label ...
/// </summary>
/// <param name="tag"></param>
/// <returns></returns>
[HttpGet("GetTag")]
public virtual async Task<ActionResult<XTagDto>> GetTag(
[FromQuery] string tag
)
{
//
// Do ...
try
{
//
var result = await TagProvider.GetTag(
tag: tag
);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Retrieve All Exists Tags ...
/// </summary>
/// <returns></returns>
[HttpGet("All")]
public virtual async Task<ActionResult<IEnumerable<XTagDto>>> GetAll()
{
//
// Do ...
try
{
//
var result = await TagProvider.GetAll();
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Search For Specified Tag by Providing a query on Label ...
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
[HttpGet("FindOne")]
public virtual async Task<ActionResult<XTagDto>> FindOne(
[FromQuery] string query
)
{
//
// Do ...
try
{
//
Expression<Func<XTag, bool>> whereClause = t =>
!query.IsNullOrEmpty() &&
t.Tag.ToNormalString()
.Contains(query.ToNormalString());
var result = await TagProvider.FindOne(
whereClause: whereClause
);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Search For Specified Tags By Providing Query on Labels ...
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
[HttpGet("FindMany")]
public virtual async Task<ActionResult<IEnumerable<XTagDto>>> FindMany(
[FromQuery] string query
)
{
//
// Do ...
try
{
//
Expression<Func<XTag, bool>> whereClause = t =>
!query.IsNullOrEmpty() &&
t.Tag.ToNormalString()
.Contains(query.ToNormalString());
var result = await TagProvider.FindMany(
whereClause: whereClause
);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Retrieve Tags based on Query Model ...
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
[HttpGet("Query")]
public virtual async Task<ActionResult<XQueryResult<XTagDto>>> Query(
[FromQuery] XQuery query
)
{
//
// Do ...
try
{
//
var result = await TagProvider
.Query(query);
//
return Ok(result.
ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Count Exists Tags ...
/// </summary>
/// <returns></returns>
[HttpGet("Count")]
public virtual async Task<ActionResult<int>> Count()
{
//
// Do ...
try
{
//
var result = await TagProvider
.Count();
//
return Ok(result.
ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Check Tag Exists by ID ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}/IsExists")]
public virtual async Task<ActionResult<bool>> IsExists(
[FromRoute] int id
)
{
//
// Do ...
try
{
//
var result = await TagProvider
.IsExists(id);
//
return Ok(result.
ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Check Tag Exists by Providing Label ...
/// </summary>
/// <param name="tag"></param>
/// <returns></returns>
[HttpGet("IsTagExists")]
public virtual async Task<ActionResult<bool>> IsTagExists(
[FromQuery] string tag
)
{
//
// Do ...
try
{
//
var result = await TagProvider
.IsTagExists(tag);
//
return Ok(result.
ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
#endregion
{ }
}
}
@@ -0,0 +1,38 @@
using System;
using System.Linq;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.Logging;
using xCommons.Configurations;
using xCommons.Providers;
using xIdentityService.Interfaces;
using xPushService.Controllers;
using xPushService.Interfaces;
using xTagService.Interfaces.Dtos;
using xTagService.Models.Dtos;
using xTagService.Models.Entities;
using xTagService.Providers.Dtos;
namespace xTagService.Controllers
{
public abstract class XTagServiceProviderControllerBase : XBaseServiceProviderController<XTag, XTagDto, int, XTagDtoHub>, IXBaseServiceProviderController<XTag, XTagDto, int, XTagDtoHub>
{
protected XTagServiceProviderControllerBase(
ILogger<XTagServiceProviderControllerBase> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXTagServiceProvider provider,
Func<IQueryable<XTag>, IOrderedQueryable<XTag>> defaultOrderBuilder = null,
Func<IQueryable<XTag>, IIncludableQueryable<XTag, object>> defaultIncludeBuilder = null
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider,
provider,
defaultOrderBuilder,
defaultIncludeBuilder
)
{ }
}
}
+144 -23
View File
@@ -1,36 +1,108 @@
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using xCommons.Extensions;
using xCommons.Helpers;
using xDataService.Constants;
using xDataService.Db;
using xDataService.DI;
using xDataService.Models;
using xExceptions.Constants;
using xTagService.Interfaces;
using xPushService.DI;
using xPushService.Helpers;
using xTagService.Helpers;
using xTagService.Interfaces.Dtos;
using xTagService.Interfaces.Entities;
using xTagService.Providers;
using xTagService.Providers.Dtos;
using xTagService.Providers.Entities;
namespace xTagService.DI
{
public static class XDIHelperExtension
{
/// <summary>
/// Register Module Provided Service on DI
/// Register Service ...
/// </summary>
/// <param name="services"></param>
/// <param name="config"></param>
/// <param name="repositoryType"></param>
/// <param name="lifeTime"></param>
public static void AddXTagService(
this IServiceCollection services,
ServiceLifetime lifeTime
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
{
AddTagService(
contextType: null,
services: services,
lifeTime: lifeTime,
repositoryType: repositoryType
);
}
/// <summary>
/// Register Service ...
/// </summary>
/// <typeparam name="TContext"></typeparam>
/// <param name="services"></param>
/// <param name="repositoryType"></param>
/// <param name="lifeTime"></param>
public static void AddXTagService<TContext>(
this IServiceCollection services,
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
where TContext : XDbContext
{
AddTagService(
services: services,
lifeTime: lifeTime,
contextType: typeof(TContext),
repositoryType: repositoryType
);
}
/// <summary>
/// Use XTagService Middleware ...
/// </summary>
/// <param name="app"></param>
/// <param name="isDevelopmentEnvironment"></param>
public static void UseXTagService(
this IApplicationBuilder app,
bool isDevelopmentEnvironment = false
)
{
//
AddTagService(
services,
lifeTime
);
#region Using XTag Hubs ...
//
var pushHelper = new XPushServiceHelper();
//
pushHelper.AddHub<XTagDtoHub>("stringDto");
pushHelper.AddHub<XTagEntityHub>("stringEntity");
//
app.UseXPushService(pushHelper);
#endregion
//
// Using XTag Repository Descriptor ...
if (!descriptor.IsNull())
{
//
app.UseXRepository(
descriptor: descriptor,
isDevelopmentEnvironment: isDevelopmentEnvironment
);
}
}
//
#region Private ...
private static XRepositoryDescriptor descriptor = null;
/// <summary>
/// a LogTag for XTagService ...
/// a LogTag for Service ...
/// </summary>
private static string XLogTag = "XTagService";
@@ -44,13 +116,17 @@ namespace xTagService.DI
}
/// <summary>
/// Register Push Service ...
/// Register Service ...
/// </summary>
/// <param name="services"></param>
/// <param name="repositoryType"></param>
/// <param name="contextType"></param>
/// <param name="lifeTime"></param>
private static void AddTagService(
IServiceCollection services,
ServiceLifetime lifeTime
XRepositoryType repositoryType,
Type contextType = null,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
{
//
@@ -62,7 +138,7 @@ namespace xTagService.DI
if (!isServicesExists)
{
//
Log("AddTagService failed, services not provided ...");
Log("Service Registration failed, services not provided ...");
throw exception;
}
@@ -72,28 +148,73 @@ namespace xTagService.DI
if (!isLifetimeExists)
{
//
Log("AddTagService failed, lifetime not provided ...");
Log("Service Registration failed, lifetime not provided ...");
throw exception;
}
//
// Check String Repository Exists ...
var isRepositoryExists = !services
.GetRegisteredService<IXTagRepository>()
.IsNull();
if (!isRepositoryExists)
// Validate Repository Type ...
var isRepositoryTypeValid =
(repositoryType == XRepositoryType.EF &&
!contextType.IsNull()) ||
((repositoryType == XRepositoryType.Mongo ||
repositoryType == XRepositoryType.InMemory) &&
contextType.IsNull());
if (!isRepositoryTypeValid)
{
//
Log("AddTagService failed, IXTagRepository not provided ...");
Log("Service Registration failed, Invalid Repository Type and Context Type ...");
throw exception;
}
//
// Register Main Provider ...
services.Add(new ServiceDescriptor(typeof(IXTagProvider), typeof(XTagProvider), lifeTime));
// Maske Instance of Repository Descriptor
// Based on Provided Type ...
switch (repositoryType)
{
//
case XRepositoryType.EF:
//
descriptor = typeof(XTagServiceHelper)
.InvokeGenericMethod<XRepositoryDescriptor>(
methodName: "GetXTagEFRepositoryDescriptor",
runtimeType: contextType,
args: null
);
break;
//
case XRepositoryType.Mongo:
descriptor = XTagServiceHelper.GetXTagMongoRepositoryDescriptor();
break;
//
case XRepositoryType.InMemory:
descriptor = XTagServiceHelper.GetXTagInMemoryRepositoryDescriptor();
break;
}
//
Log("AddTagService Succeed ...");
// Register XTag Repository Descriptor ...
services.AddXRepository(
lifeTime: lifeTime,
descriptor: descriptor
);
//
// Register Dto Services ...
services.Add(
new ServiceDescriptor(typeof(IXTagServiceProvider), typeof(XTagServiceProvider), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXTagRepositoryService), typeof(XTagRepositoryService), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXTagRepositoryProvider), typeof(XTagRepositoryProvider), lifeTime)
);
//
Log("Service Regitration Succeed ...");
}
#endregion
}
-9
View File
@@ -1,9 +0,0 @@
using xDataService.Events;
using xTagService.Interfaces.Entities;
using xTagService.Models.Entities;
namespace xTagService.DataHelper.Events
{
public class XTagEvents : XBaseRepositoryEvents<XTag>, IXTagEvents
{ }
}
+149
View File
@@ -0,0 +1,149 @@
using System.Collections.Generic;
using System.Linq;
using xCommons.Extensions;
using xDataService.Extensions;
using xDataService.Models;
using xTagService.Models.Dtos;
using xTagService.Models.Entities;
namespace xTagService.Extensions
{
public static class XModelExtensions
{
/// <summary>
/// Extract References of a Model ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static IList<XReference<string>> GetReferences(
this XTag source
)
{
//
var result = new List<XReference<string>>();
//
if (
!source.IsNullOrDefault() &&
!source.References.IsNullOrEmpty()
)
{
//
result = source.References
.ParseXReferenceList<string>()
.ToList();
}
//
return result;
}
/// <summary>
/// Extract References of a Model ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static IList<XReference<string>> GetReferences(
this XTagDto source
)
{
//
var result = new List<XReference<string>>();
//
if (
!source.IsNullOrDefault() &&
!source.References.IsNullOrEmpty()
)
{
//
result = source.References
.ParseXReferenceList<string>()
.ToList();
}
//
return result;
}
/// <summary>
/// Update a Model's References by Providing References List ...
/// </summary>
/// <param name="source"></param>
/// <param name="references"></param>
/// <param name="forceClean"></param>
/// <returns></returns>
public static XTag UpdateReferences(
this XTag source,
IList<XReference<string>> references,
bool forceClean = true
)
{
//
XTag result = source;
//
if (!source.IsNullOrDefault())
{
//
result = source;
//
if (forceClean)
{
result.References = string.Empty;
}
//
if (!references.IsNull() &&
references.HasChild())
{
result.References = references.ToXReferenceString();
}
}
//
return result;
}
/// <summary>
/// Update a Model's References by Providing References List ...
/// </summary>
/// <param name="source"></param>
/// <param name="references"></param>
/// <param name="forceClean"></param>
/// <returns></returns>
public static XTagDto UpdateReferences(
this XTagDto source,
IList<XReference<string>> references,
bool forceClean = true
)
{
//
XTagDto result = source;
//
if (!source.IsNullOrDefault())
{
//
result = source;
//
if (forceClean)
{
result.References = string.Empty;
}
//
if (!references.IsNull() &&
references.HasChild())
{
result.References = references.ToXReferenceString();
}
}
//
return result;
}
}
}
-85
View File
@@ -1,85 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using xCommons.Extensions;
using xDataService.Extensions;
using xTagService.Models.Dtos;
using xTagService.Models.Entities;
namespace xTagService.Extensions
{
public static class xTagServiceExtension
{
/// <summary>
/// Map Global Properties From XFile to XFile Dto ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XTagDto ToDto(this XTag source)
{
//
XTagDto result = null;
//
if (!source.IsNullOrDefault())
{
//
result = new XTagDto();
result = result.UpdateData(
updateWith: source,
propertyBlackList: new List<string>
{
nameof(XTag.Deleted),
nameof(XTag.References),
}
);
//
// Preparing List ...
if (!source.References.IsNullOrEmpty())
{
//
result.References = source.References
.ParseXReferenceList<string>()
.ToList();
}
}
//
return result;
}
/// <summary>
/// Converts a Dto to Entity Representation ...
/// Ignore ID Property ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XTag FromDto(this XTagDto source)
{
//
var result = new XTag();
//
if (!source.IsNull())
{
//
result = result.UpdateData(
updateWith: source,
propertyBlackList: new List<string>
{
nameof(XTag.Deleted),
nameof(XTag.References),
}
);
//
if (!source.References.IsNull() && source.References.HasChild()) {
result.References = source.References.ToXReferenceString();
}
}
//
return result;
}
}
}
View File
+279
View File
@@ -0,0 +1,279 @@
using GraphQL.Types;
using xDataService.Db;
using xDataService.Models;
using xDataService.Providers;
using xTagService.Interfaces;
using xTagService.Interfaces.Entities;
using xTagService.Models.Entities;
using xTagService.Providers.Entities;
using xTagService.Providers.GraphQL;
namespace xTagService.Helpers
{
public static class XTagServiceHelper
{
//
#region EF Repository Descriptor Provider(s) ...
public static XEFRepositoryDescriptor<
XTag,
int,
IXTagKeyGenerator,
XTagKeyGenerator,
IXTagRepositoryEvents,
XTagRepositoryEvents,
XTagGraphType,
IntGraphType,
XTagGraphQuery,
IXTagGraphQLTypeHelper,
XTagGraphQLTypeHelper,
XTagGraphSchema,
IXTagRepository,
XTagEFRepository<TContext>,
TContext
> GetXTagEFRepositoryDescriptor<TContext>()
where TContext : XDbContext
{
//
var result = new XEFRepositoryDescriptor<
XTag,
int,
IXTagKeyGenerator,
XTagKeyGenerator,
IXTagRepositoryEvents,
XTagRepositoryEvents,
XTagGraphType,
IntGraphType,
XTagGraphQuery,
IXTagGraphQLTypeHelper,
XTagGraphQLTypeHelper,
XTagGraphSchema,
IXTagRepository,
XTagEFRepository<TContext>,
TContext
>();
//
return result;
}
public static XEFRepositoryDescriptor<
XTag,
int,
IXTagKeyGenerator,
XTagKeyGenerator,
IXTagRepositoryEvents,
XTagRepositoryEvents,
XTagGraphType,
IntGraphType,
XTagGraphQuery,
IXTagGraphQLTypeHelper,
XTagGraphQLTypeHelper,
XTagGraphSchema,
IXTagRepository,
XTagEFRepository<TContext>,
TContext,
IXTagSeeder,
TSeederImplementation
> GetXTagEFRepositoryDescriptor<TContext, TSeederImplementation>()
where TContext : XDbContext
where TSeederImplementation : XBaseDbSeeder<XTag, int>
{
//
var result = new XEFRepositoryDescriptor<
XTag,
int,
IXTagKeyGenerator,
XTagKeyGenerator,
IXTagRepositoryEvents,
XTagRepositoryEvents,
XTagGraphType,
IntGraphType,
XTagGraphQuery,
IXTagGraphQLTypeHelper,
XTagGraphQLTypeHelper,
XTagGraphSchema,
IXTagRepository,
XTagEFRepository<TContext>,
TContext,
IXTagSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region Mongo Repository Descriptor Provider(s) ...
public static XMongoRepositoryDescriptor<
XTag,
int,
IXTagKeyGenerator,
XTagKeyGenerator,
IXTagRepositoryEvents,
XTagRepositoryEvents,
XTagGraphType,
IntGraphType,
XTagGraphQuery,
IXTagGraphQLTypeHelper,
XTagGraphQLTypeHelper,
XTagGraphSchema,
IXTagRepository,
XTagMongoRepository
> GetXTagMongoRepositoryDescriptor()
{
//
var result = new XMongoRepositoryDescriptor<
XTag,
int,
IXTagKeyGenerator,
XTagKeyGenerator,
IXTagRepositoryEvents,
XTagRepositoryEvents,
XTagGraphType,
IntGraphType,
XTagGraphQuery,
IXTagGraphQLTypeHelper,
XTagGraphQLTypeHelper,
XTagGraphSchema,
IXTagRepository,
XTagMongoRepository
>();
//
return result;
}
public static XMongoRepositoryDescriptor<
XTag,
int,
IXTagKeyGenerator,
XTagKeyGenerator,
IXTagRepositoryEvents,
XTagRepositoryEvents,
XTagGraphType,
IntGraphType,
XTagGraphQuery,
IXTagGraphQLTypeHelper,
XTagGraphQLTypeHelper,
XTagGraphSchema,
IXTagRepository,
XTagMongoRepository,
IXTagSeeder,
TSeederImplementation
> GetXTagMongoRepositoryDescriptor<TSeederImplementation>()
where TSeederImplementation : XBaseDbSeeder<XTag, int>
{
//
var result = new XMongoRepositoryDescriptor<
XTag,
int,
IXTagKeyGenerator,
XTagKeyGenerator,
IXTagRepositoryEvents,
XTagRepositoryEvents,
XTagGraphType,
IntGraphType,
XTagGraphQuery,
IXTagGraphQLTypeHelper,
XTagGraphQLTypeHelper,
XTagGraphSchema,
IXTagRepository,
XTagMongoRepository,
IXTagSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region InMemory Repository Descriptor Provider(s) ...
public static XInMemoryRepositoryDescriptor<
XTag,
int,
IXTagKeyGenerator,
XTagKeyGenerator,
IXTagRepositoryEvents,
XTagRepositoryEvents,
XTagGraphType,
IntGraphType,
XTagGraphQuery,
IXTagGraphQLTypeHelper,
XTagGraphQLTypeHelper,
XTagGraphSchema,
IXTagRepository,
XTagInMemoryRepository
> GetXTagInMemoryRepositoryDescriptor()
{
//
var result = new XInMemoryRepositoryDescriptor<
XTag,
int,
IXTagKeyGenerator,
XTagKeyGenerator,
IXTagRepositoryEvents,
XTagRepositoryEvents,
XTagGraphType,
IntGraphType,
XTagGraphQuery,
IXTagGraphQLTypeHelper,
XTagGraphQLTypeHelper,
XTagGraphSchema,
IXTagRepository,
XTagInMemoryRepository
>();
//
return result;
}
public static XInMemoryRepositoryDescriptor<
XTag,
int,
IXTagKeyGenerator,
XTagKeyGenerator,
IXTagRepositoryEvents,
XTagRepositoryEvents,
XTagGraphType,
IntGraphType,
XTagGraphQuery,
IXTagGraphQLTypeHelper,
XTagGraphQLTypeHelper,
XTagGraphSchema,
IXTagRepository,
XTagInMemoryRepository,
IXTagSeeder,
TSeederImplementation
> GetXTagInMemoryRepositoryDescriptor<TSeederImplementation>()
where TSeederImplementation : XBaseDbSeeder<XTag, int>
{
//
var result = new XInMemoryRepositoryDescriptor<
XTag,
int,
IXTagKeyGenerator,
XTagKeyGenerator,
IXTagRepositoryEvents,
XTagRepositoryEvents,
XTagGraphType,
IntGraphType,
XTagGraphQuery,
IXTagGraphQLTypeHelper,
XTagGraphQLTypeHelper,
XTagGraphSchema,
IXTagRepository,
XTagInMemoryRepository,
IXTagSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
}
}
-16
View File
@@ -1,16 +0,0 @@
using Microsoft.Extensions.Logging;
using xPushService.Base;
using xTagService.Models.Entities;
namespace xTagService.Hubs
{
public class XTagEntityHub : XBaseEntityHub<XTag, int>
{
//
#region Constructor ...
public XTagEntityHub(ILogger<XBaseHub> logger) : base(logger)
{
}
#endregion
}
}
+9
View File
@@ -0,0 +1,9 @@
using xPushService.Interfaces;
using xTagService.Models.Dtos;
using xTagService.Models.Entities;
namespace xTagService.Interfaces.Dtos
{
public interface IXTagDtoHub : IXBaseDtoHub<XTag, XTagDto, int>
{ }
}
@@ -0,0 +1,9 @@
using xDataService.Interfaces;
using xTagService.Models.Dtos;
using xTagService.Models.Entities;
namespace xTagService.Interfaces.Dtos
{
public interface IXTagRepositoryService : IXBaseRepositoryService<XTag, XTagDto, int>
{ }
}
+10
View File
@@ -0,0 +1,10 @@
using xPushService.Interfaces;
using xTagService.Models.Dtos;
using xTagService.Models.Entities;
using xTagService.Providers.Dtos;
namespace xTagService.Interfaces.Dtos
{
public interface IXTagServiceProvider : IXBaseDtoProvider<XTag, XTagDto, int, XTagDtoHub>
{ }
}
+8
View File
@@ -0,0 +1,8 @@
using xPushService.Interfaces;
using xTagService.Models.Entities;
namespace xTagService.Interfaces.Entities
{
public interface IXTagEntityHub : IXBaseEntityHub<XTag, int>
{ }
}
@@ -3,6 +3,6 @@ using xTagService.Models.Entities;
namespace xTagService.Interfaces.Entities
{
public interface IXTagEvents: IXBaseRepositoryEvents<XTag>
public interface IXTagKeyGenerator : IXKeyGenerator<XTag, int>
{ }
}
@@ -0,0 +1,8 @@
using xDataService.Interfaces;
using xTagService.Models.Entities;
namespace xTagService.Interfaces.Entities
{
public interface IXTagRepositoryEvents : IXBaseRepositoryEvents<XTag>
{ }
}
@@ -0,0 +1,9 @@
using xPushService.Interfaces;
using xTagService.Models.Entities;
using xTagService.Providers.Entities;
namespace xTagService.Interfaces.Entities
{
public interface IXTagRepositoryProvider : IXBaseEntityProvider<XTag, int, XTagEntityHub>
{ }
}
+15 -18
View File
@@ -1,3 +1,4 @@
using System.Threading;
using System.Threading.Tasks;
using xDataService.Interfaces;
using xDataService.Models;
@@ -5,20 +6,8 @@ using xTagService.Models.Dtos;
namespace xTagService.Interfaces
{
/// <summary>
/// Implementing XBaseTagProvider ...
/// </summary>
/// <typeparam name="TKey"></typeparam>
public interface IXBaseTagProvider<TKey> : IXBaseReferencedProvider<XTagDto, TKey>
{
//
#region Props ...
/// <summary>
/// Provider Identifier ...
/// </summary>
IXTagProvider TagProvider { get; }
#endregion
//
#region Tools ...
/// <summary>
@@ -27,11 +16,13 @@ namespace xTagService.Interfaces
/// <param name="tag"></param>
/// <param name="providedForId"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> AddReference(
string tag,
TKey providedForId,
string connectionId = null
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
@@ -40,11 +31,13 @@ namespace xTagService.Interfaces
/// <param name="tag"></param>
/// <param name="reference"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> AddReference(
string tag,
XReference<TKey> reference,
string connectionId = null
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
@@ -53,25 +46,29 @@ namespace xTagService.Interfaces
/// <param name="tag"></param>
/// <param name="providedForId"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> RemoveReference(
string tag,
TKey providedForId,
string connectionId = null
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove Reference a Tag for Specific XRefence<TKey> ...
/// </summary>
/// <param name="tag"></param>
/// <param name="providedForId"></param>
/// <param name="reference"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> RemoveReference(
string tag,
XReference<TKey> reference,
string connectionId = null
string connectionId = null,
CancellationToken cancellationToken = default
);
#endregion
#endregion
}
}
-172
View File
@@ -1,172 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using xDataService.Configuration;
using xIdentityService.Interfaces;
using xModels.Dtos;
using xTagService.Hubs;
using xTagService.Interfaces.Entities;
using xTagService.Models.Dtos;
using xTagService.Models.Entities;
namespace xTagService.Interfaces
{
public interface IXTagProvider
{
//
#region Props ...
IXTagRepository Repository { get; }
IHubContext<XTagEntityHub> Hub { get; }
IXIdentityProvider IdentityProvider { get; }
XDataServiceConfiguration DataConfiguration { get; }
#endregion
//
#region Helpers ...
/// <summary>
/// Converts an Entity to Dto ...
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
XTagDto ToDto(XTag model);
/// <summary>
/// Converts a List of Entitiies to List of Dto's ...
/// </summary>
/// <param name="models"></param>
/// <returns></returns>
IEnumerable<XTagDto> ToDtoList(IEnumerable<XTag> models);
/// <summary>
/// Converts Query Result of Entities to Dto ...
/// </summary>
/// <param name="queryResult"></param>
/// <returns></returns>
XQueryResult<XTagDto> ToDtoQueryResult(XQueryResult<XTag> queryResult);
#endregion
//
#region Tools ...
/// <summary>
/// Add Specified Tag ...
/// </summary>
/// <param name="model"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XTagDto> Add(
XTagDto model,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Update Specified Dto ...
/// </summary>
/// <param name="id"></param>
/// <param name="model"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task<XTagDto> Update(
int id,
XTagDto model,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove Specified Dto ...
/// </summary>
/// <param name="id"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task<XTagDto> Remove(
int id,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve Specified Item as Dto ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<XTagDto> Get(
int id,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve Specified Tag by it's Label ...
/// </summary>
/// <param name="tag"></param>
/// <returns></returns>
Task<XTagDto> GetTag(
string tag,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve All Items as Dto ...
/// </summary>
/// <returns></returns>
Task<IEnumerable<XTagDto>> GetAll(
CancellationToken cancellationToken = default
);
/// <summary>
/// Find Specified Item by Condition ...
/// </summary>
/// <param name="whereClause"></param>
/// <returns></returns>
Task<XTagDto> FindOne(
Expression<Func<XTag, bool>> whereClause,
CancellationToken cancellationToken = default
);
/// <summary>
/// Find Many Items based on Conditions ...
/// </summary>
/// <param name="whereClause"></param>
/// <returns></returns>
Task<IEnumerable<XTagDto>> FindMany(
Expression<Func<XTag, bool>> whereClause,
CancellationToken cancellationToken = default
);
/// <summary>
/// Query Model retrieving Dtos ...
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
Task<XQueryResult<XTagDto>> Query(
XQuery query,
Expression<Func<XTag, bool>> whereClause = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Count Exists Entities ...
/// </summary>
/// <returns></returns>
Task<int> Count();
/// <summary>
/// Check Entity Exists or not ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<bool> IsExists(int id);
/// <summary>
/// Check Tag Exists by Label ...
/// </summary>
/// <param name="tag"></param>
/// <returns></returns>
Task<bool> IsTagExists(string tag);
#endregion
}
}
+8
View File
@@ -0,0 +1,8 @@
using xDataService.Interfaces;
using xTagService.Models.Entities;
namespace xTagService.Interfaces
{
public interface IXTagSeeder : IXBaseDbSeeder<XTag, int>
{ }
}
-118
View File
@@ -1,118 +0,0 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using xModels.Dtos;
using xTagService.Models.Dtos;
namespace xTagService.Interfaces
{
public interface IXTagServiceControllerActions
{
//
#region Actions ...
/// <summary>
/// Add Tag by Providing Dto ...
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
Task<ActionResult<XTagDto>> Add(
[FromBody] XTagDto model
);
/// <summary>
/// Retrieve Specified Tag Dto by ID ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<ActionResult<XTagDto>> Get(
[FromRoute ]int id
);
/// <summary>
/// Retrieve Specified Tag Dto by it's Label ...
/// </summary>
/// <param name="tag"></param>
/// <returns></returns>
Task<ActionResult<XTagDto>> GetTag(
[FromQuery] string tag
);
/// <summary>
/// Retrieve All Exists Tags ...
/// </summary>
/// <returns></returns>
Task<ActionResult<IEnumerable<XTagDto>>> GetAll();
/// <summary>
/// Search For Specified Tag by Providing a query on Label ...
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
Task<ActionResult<XTagDto>> FindOne(
[FromQuery] string query
);
/// <summary>
/// Search For Specified Tags By Providing Query on Labels ...
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
Task<ActionResult<IEnumerable<XTagDto>>> FindMany(
[FromQuery] string query
);
/// <summary>
/// Retrieve Tags based on Query Model ...
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
Task<ActionResult<XQueryResult<XTagDto>>> Query(
[FromQuery] XQuery query
);
/// <summary>
/// Update Specified Tag ...
/// </summary>
/// <param name="id"></param>
/// <param name="model"></param>
/// <returns></returns>
Task<ActionResult<XTagDto>> Update(
[FromRoute] int id,
[FromBody] XTagDto model
);
/// <summary>
/// Remove Specified Tag by ID ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<ActionResult<XTagDto>> Remove(
[FromRoute] int id
);
/// <summary>
/// Count Exists Tags ...
/// </summary>
/// <returns></returns>
Task<ActionResult<int>> Count();
/// <summary>
/// Check Tag Exists by ID ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<ActionResult<bool>> IsExists(
[FromRoute] int id
);
/// <summary>
/// Check Tag Exists by Providing Label ...
/// </summary>
/// <param name="tag"></param>
/// <returns></returns>
Task<ActionResult<bool>> IsTagExists(
[FromQuery]string tag
);
#endregion
}
}
+2 -5
View File
@@ -1,13 +1,10 @@
using System.Collections.Generic;
using xDataService.Models;
using xModels.Base;
namespace xTagService.Models.Dtos
{
public class XTagDto : XBaseDto
public class XTagDto : XBaseIntIDEntityDto
{
public int Id { get; set; }
public string Tag { get; set; }
public IList<XReference<string>> References = new List<XReference<string>>();
public string References { get; set; }
}
}
+2 -2
View File
@@ -4,7 +4,7 @@ using xModels.Base;
namespace xTagService.Models.Entities
{
/// <summary>
/// Describing References ...
/// a Tag Model ...
/// </summary>
public class XTag : XBaseIntIDEntity
{
@@ -21,6 +21,6 @@ namespace xTagService.Models.Entities
/// Model for Describe ...
/// </summary>
/// <value></value>
public string References { get; set; }
public string References { get; set; }
}
}
+16
View File
@@ -0,0 +1,16 @@
using Microsoft.Extensions.Logging;
using xPushService.Base;
using xTagService.Interfaces.Dtos;
using xTagService.Models.Dtos;
using xTagService.Models.Entities;
namespace xTagService.Providers.Dtos
{
public class XTagDtoHub : XBaseDtoHub<XTag, XTagDto, int>, IXTagDtoHub
{
public XTagDtoHub(
ILogger<XTagDtoHub> logger
) : base(logger)
{ }
}
}
+22
View File
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using AutoMapper;
using xDataService.Providers;
using xTagService.Interfaces.Dtos;
using xTagService.Interfaces.Entities;
using xTagService.Models.Dtos;
using xTagService.Models.Entities;
namespace xTagService.Providers.Dtos
{
public class XTagRepositoryService : XBaseRepositoryService<XTag, XTagDto, int>, IXTagRepositoryService
{
public XTagRepositoryService(
IXTagRepository repository,
IEnumerable<Profile> mapperProfiles = null
) : base(
repository,
mapperProfiles
)
{ }
}
}
+26
View File
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.SignalR;
using xDataService.Configuration;
using xIdentityService.Interfaces;
using xPushService.Base;
using xTagService.Interfaces.Dtos;
using xTagService.Models.Dtos;
using xTagService.Models.Entities;
namespace xTagService.Providers.Dtos
{
public class XTagServiceProvider : XBaseDtoProvider<XTag, XTagDto, int, XTagDtoHub>, IXTagServiceProvider
{
public XTagServiceProvider(
IHubContext<XTagDtoHub> hub,
XDataServiceConfiguration dataConfiguration,
IXTagRepositoryService service,
IXIdentityProvider identityProvider = null
) : base(
hub,
dataConfiguration,
service,
identityProvider
)
{ }
}
}
+26
View File
@@ -0,0 +1,26 @@
using xDataService.Configuration;
using xDataService.Db;
using xDataService.Interfaces;
using xDataService.Providers;
using xTagService.Interfaces.Entities;
using xTagService.Models.Entities;
namespace xTagService.Providers.Entities
{
public class XTagEFRepository<TContext> : XBaseEFRepository<XTag, int, TContext>, IXTagRepository
where TContext : XDbContext
{
public XTagEFRepository(
IXUnitOfWorks<TContext> unitOfWorks,
XDataServiceConfiguration configuration,
IXTagKeyGenerator keyGenerator = null,
IXTagRepositoryEvents baseRepositoryEvents = null
) : base(
unitOfWorks,
configuration,
keyGenerator,
baseRepositoryEvents
)
{ }
}
}
+15
View File
@@ -0,0 +1,15 @@
using Microsoft.Extensions.Logging;
using xPushService.Base;
using xTagService.Interfaces.Entities;
using xTagService.Models.Entities;
namespace xTagService.Providers.Entities
{
public class XTagEntityHub : XBaseEntityHub<XTag, int>, IXTagEntityHub
{
public XTagEntityHub(
ILogger<XTagEntityHub> logger
) : base(logger)
{ }
}
}
@@ -0,0 +1,21 @@
using xDataService.Configuration;
using xDataService.Providers;
using xTagService.Interfaces.Entities;
using xTagService.Models.Entities;
namespace xTagService.Providers.Entities
{
public class XTagInMemoryRepository : XBaseInMemoryRepository<XTag, int>, IXTagRepository
{
public XTagInMemoryRepository(
XDataServiceConfiguration configuration,
IXTagKeyGenerator keyGenerator = null,
IXTagRepositoryEvents baseRepositoryEvents = null
) : base(
configuration,
keyGenerator,
baseRepositoryEvents
)
{ }
}
}
+9
View File
@@ -0,0 +1,9 @@
using xDataService.Providers;
using xTagService.Interfaces.Entities;
using xTagService.Models.Entities;
namespace xTagService.Providers.Entities
{
public class XTagKeyGenerator : XIntKeyGenerator<XTag>, IXTagKeyGenerator
{ }
}
+25
View File
@@ -0,0 +1,25 @@
using xDataService.Configuration;
using xDataService.Providers;
using xTagService.Interfaces.Entities;
using xTagService.Models.Entities;
namespace xTagService.Providers.Entities
{
public class XTagMongoRepository : XBaseMongoRepository<XTag, int>, IXTagRepository
{
public XTagMongoRepository(
XDataBaseConfiguration dbConfiguration,
XDataServiceConfiguration configuration,
string collectionName = null,
IXTagKeyGenerator keyGenerator = null,
IXTagRepositoryEvents baseRepositoryEvents = null
) : base(
dbConfiguration,
configuration,
collectionName,
keyGenerator,
baseRepositoryEvents
)
{ }
}
}
@@ -0,0 +1,9 @@
using xDataService.Providers;
using xTagService.Interfaces.Entities;
using xTagService.Models.Entities;
namespace xTagService.Providers.Entities
{
public class XTagRepositoryEvents : XBaseRepositoryEvents<XTag>, IXTagRepositoryEvents
{ }
}
@@ -0,0 +1,25 @@
using Microsoft.AspNetCore.SignalR;
using xDataService.Configuration;
using xIdentityService.Interfaces;
using xPushService.Base;
using xTagService.Interfaces.Entities;
using xTagService.Models.Entities;
namespace xTagService.Providers.Entities
{
public class XTagRepositoryProvider : XBaseEntityProvider<XTag, int, XTagEntityHub>, IXTagRepositoryProvider
{
public XTagRepositoryProvider(
IHubContext<XTagEntityHub> hub,
IXTagRepository repository,
XDataServiceConfiguration dataConfiguration,
IXIdentityProvider identityProvider = null
) : base(
hub,
repository,
dataConfiguration,
identityProvider
)
{ }
}
}
+24
View File
@@ -0,0 +1,24 @@
using xDataService.Configuration;
using xDataService.Interfaces;
using xDataService.Providers;
using xTagService.Interfaces;
using xTagService.Models.Entities;
namespace xTagService.Providers.Entities
{
public abstract class XTagSeederBase : XBaseDbSeeder<XTag, int>, IXTagSeeder
{
protected XTagSeederBase(
string entity,
string database,
IXBaseRepository<XTag, int> repository,
XDataServiceConfiguration dataServiceConfiguration
) : base(
entity,
database,
repository,
dataServiceConfiguration
)
{ }
}
}
@@ -3,7 +3,7 @@ using xDataService.GraphQL;
using xTagService.Interfaces.Entities;
using xTagService.Models.Entities;
namespace xTagService.DataHelper.GraphQL
namespace xTagService.Providers.GraphQL
{
public class XTagGraphQLTypeHelper : XBaseGraphQLTypeHelper<XTag, int>, IXTagGraphQLTypeHelper
{
@@ -4,7 +4,7 @@ using xDataService.GraphQL;
using xTagService.Interfaces.Entities;
using xTagService.Models.Entities;
namespace xTagService.DataHelper.GraphQL
namespace xTagService.Providers.GraphQL
{
public class XTagGraphQuery : XBaseGraphQLQuery<XTag, int, XTagGraphType, IntGraphType>
{
@@ -1,7 +1,7 @@
using System;
using GraphQL.Types;
namespace xTagService.DataHelper.GraphQL
namespace xTagService.Providers.GraphQL
{
public class XTagGraphSchema : Schema
{
@@ -9,5 +9,6 @@ namespace xTagService.DataHelper.GraphQL
{
Query = (XTagGraphQuery)services.GetService(typeof(XTagGraphQuery));
}
}
}
@@ -1,7 +1,7 @@
using xDataService.GraphQL;
using xTagService.Models.Entities;
namespace xTagService.DataHelper.GraphQL
namespace xTagService.Providers.GraphQL
{
public class XTagGraphType : XBaseGraphObjectType<XTag, int>
{
+251 -190
View File
@@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using xCommons.Extensions;
using xDataService.Extensions;
using xDataService.Models;
@@ -10,6 +9,7 @@ using xExceptions.Constants;
using xModels.Dtos;
using xTagService.Extensions;
using xTagService.Interfaces;
using xTagService.Interfaces.Dtos;
using xTagService.Models.Dtos;
namespace xTagService.Providers
@@ -26,14 +26,14 @@ namespace xTagService.Providers
/// <summary>
/// Tag Provider for Maipulating Tags ...
/// </summary>
public IXTagProvider TagProvider { get; }
public IXTagServiceProvider TagProvider { get; }
#endregion
//
#region Constructor ...
public XBaseTagProvider(
string providedFor,
IXTagProvider tagProvider
IXTagServiceProvider tagProvider
)
{
//
@@ -49,10 +49,12 @@ namespace xTagService.Providers
/// </summary>
/// <param name="providedForId"></param>
/// <param name="forIndex"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XTagDto> GetReference(
TKey providedForId,
int forIndex = 0
int forIndex = 0,
CancellationToken cancellationToken = default
)
{
//
@@ -71,7 +73,11 @@ namespace xTagService.Providers
//
// Retrieve Last Index ...
var maxIndex = (await GetReferencingIndexes(providedForId)).Max();
var maxIndex = (await GetReferencingIndexes(
providedForId: providedForId,
cancellationToken: cancellationToken
))
.Max();
if (forIndex > maxIndex)
{
XException.NotFound.Throw();
@@ -82,17 +88,18 @@ namespace xTagService.Providers
forIndex: forIndex,
providedForId: providedForId
);
var entity = TagProvider.Repository
.AsQueryable()
.Where(t => t.References.Contains(indexedIdentifier))
.FirstOrDefault();
if (entity.IsNullOrDefault())
var result = await TagProvider.FindOneAsync(
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken,
predicate: x => x.References.Contains(indexedIdentifier)
);
if (result.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
var result = await Task.FromResult(entity.ToDto());
return result;
}
@@ -100,8 +107,12 @@ namespace xTagService.Providers
/// Retrieve all Exists References of Specific Provided ID ...
/// </summary>
/// <param name="providedForId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<XTagDto>> GetAllReferences(TKey providedForId)
public async Task<IEnumerable<XTagDto>> GetAllReferences(
TKey providedForId,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
@@ -112,34 +123,28 @@ namespace xTagService.Providers
//
var identifier = GetProvidedID(providedForId);
var entities = TagProvider.Repository
.AsQueryable()
.Where(t => t.References.Contains(identifier))
.AsEnumerable();
var result = await TagProvider.FindManyAsync(
orderBuilder: null,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken,
predicate: x => x.References.Contains(identifier)
);
//
var result = new List<XTagDto>();
foreach (var entity in entities)
{
//
var dto = entity.ToDto();
if (!dto.IsNullOrDefault())
{
//
result.Add(dto);
}
}
//
return await Task.FromResult(result);
return result;
}
/// <summary>
/// Extract all Referencing Models for Specified Key ...
/// </summary>
/// <param name="providedForId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<XReference<TKey>>> GetAllReferencings(TKey providedForId)
public async Task<IEnumerable<XReference<TKey>>> GetAllReferencings(
TKey providedForId,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
@@ -154,27 +159,34 @@ namespace xTagService.Providers
var identifier = GetProvidedID(providedForId);
//
var result = TagProvider.Repository
.AsQueryable()
.Where(te => te.References.Contains(identifier))
.Select(te => te.References)
.ToList()
.SelectMany(tr => tr.ParseXReferenceList<TKey>())
.Where(tr => tr.ProvidedFor == Provider && $"{tr.ReferencedTo}" == $"{providedForId}")
.OrderBy(tr => tr.Index)
.AsEnumerable()
;
var result = (await TagProvider.FindManyAsync(
orderBuilder: null,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken,
predicate: x => x.References.Contains(identifier)
))
.Select(x => x.References)
.ToList()
.SelectMany(x => x.ParseXReferenceList<TKey>())
.Where(x => x.ProvidedFor == Provider && $"{x.ReferencedTo}" == $"{providedForId}")
.OrderBy(x => x.Index)
.AsEnumerable();
//
return await Task.FromResult(result);
return result;
}
/// <summary>
/// Count References ...
/// </summary>
/// <param name="providedForId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<int> CountReferences(TKey providedForId)
public async Task<int> CountReferences(
TKey providedForId,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
@@ -186,23 +198,29 @@ namespace xTagService.Providers
//
var identifier = GetProvidedID(providedForId);
var result = TagProvider.Repository
.AsQueryable()
.Where(t => t.References.Contains(identifier))
.Count();
var result = (await TagProvider.FindManyAsync(
orderBuilder: null,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken,
predicate: x => x.References.Contains(identifier)
))
.Count();
//
return await Task.FromResult(result);
return result;
}
/// <summary>
/// Retrieve References of Specific Provided ID as Query ...
/// </summary>
/// <param name="providedForId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XQueryResult<XTagDto>> QueryReferences(
XQuery query,
TKey providedForId
TKey providedForId,
CancellationToken cancellationToken = default
)
{
//
@@ -213,64 +231,15 @@ namespace xTagService.Providers
}
//
// Normalize ...
query = query.NormalizeQuery(TagProvider.DataConfiguration);
//
var items = await GetAllReferences(providedForId);
var totalItemsCount = items.Count();
//
// Apply Filter ...
if (!query.Filter.IsNullOrEmpty())
{
//
items = items
.ApplyFilter(query.Filter);
}
int filteredItemsCount = items.Count();
//
// Count Pages ...
var totalPagesCount = query.CountPages(totalItemsCount);
var filteredPagesCount = query.CountPages(filteredItemsCount);
//
// Apply Paging and Sorting ...
if (totalItemsCount > 0 &&
filteredItemsCount > 0)
{
//
// Apply Sorting ...
items = items
.ToList()
.ApplySorting(
query.SortBy,
query.IsAscending
);
//
// Apply Paging ...
items = items
.ToList()
.ApplyPaging(
query.Page,
query.PageSize
);
}
//
// Prepare Result ...
var result = new XQueryResult<XTagDto>
{
Page = query.Page,
Items = items.ToList(),
PageSize = query.PageSize,
TotalPages = totalPagesCount,
TotalItems = totalItemsCount,
TotalFilteredPages = filteredPagesCount,
TotalFilteredItems = filteredItemsCount
};
var identifier = GetProvidedID(providedForId);
var result = await TagProvider.QueryAsync(
query: query,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken,
orderBuilder: x => x.OrderBy(y => y.Id),
predicate: x => x.References.Contains(identifier)
);
//
return result;
@@ -281,13 +250,14 @@ namespace xTagService.Providers
/// </summary>
/// <param name="model"></param>
/// <param name="providedForId"></param>
/// <param name="forIndex"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<bool> AddReference(
XTagDto model,
TKey providedForId,
string connectionId = null
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
@@ -306,7 +276,7 @@ namespace xTagService.Providers
//
// Check Model Exists ...
result = await TagProvider.IsExists(model.Id);
result = await TagProvider.IsExistsAsync(model.Id);
if (!result)
{
XException.NotFound.Throw();
@@ -314,17 +284,29 @@ namespace xTagService.Providers
//
// Update Model by Retrieving ...
model = await TagProvider.Get(model.Id);
model = await TagProvider.GetAsync(
id: model.Id,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
);
//
// Retrieve all References ...
var references = await GetAllReferences(providedForId);
var references = await GetAllReferences(
providedForId: providedForId,
cancellationToken: cancellationToken
);
//
// Check isReferenced or not ...
result = references.Any(r => r.Id == model.Id &&
r.References.Any(rf => rf.ProvidedFor == Provider &&
rf.ReferencedTo == $"{providedForId}"));
result = references
.Any(r =>
r.Id == model.Id &&
r.GetReferences()
.Any(rf =>
rf.ProvidedFor == Provider &&
rf.ReferencedTo == $"{providedForId}"));
if (result)
{
return result;
@@ -332,21 +314,30 @@ namespace xTagService.Providers
//
// Here means there is not any reference to ProvidedForId ...
int forIndex = await CountReferences(providedForId);
model.References.Add(new XReference<string>
int forIndex = await CountReferences(
providedForId: providedForId,
cancellationToken: cancellationToken
);
var modelReferences = model.GetReferences();
modelReferences.Add(new XReference<string>
{
Index = forIndex,
ProvidedFor = Provider,
ReferencedTo = $"{providedForId}"
});
modelReferences = modelReferences
.OrderBy(r => r.Index)
.ToList();
model = model.UpdateReferences(modelReferences);
//
// Update Data Base ...
model = await TagProvider
.Update(
id: model.Id,
model: model,
connectionId: connectionId
model = await TagProvider.UpdateAsync(
id: model.Id,
item: model,
saveChanges: true,
connectionId: connectionId,
cancellationToken: cancellationToken
);
result = !model.IsNullOrDefault();
@@ -360,11 +351,13 @@ namespace xTagService.Providers
/// <param name="model"></param>
/// <param name="reference"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<bool> AddReference(
XTagDto model,
XReference<TKey> reference,
string connectionId = null
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
@@ -384,6 +377,7 @@ namespace xTagService.Providers
result = await AddReference(
model: model,
connectionId: connectionId,
cancellationToken: cancellationToken,
providedForId: reference.ReferencedTo
);
@@ -397,12 +391,13 @@ namespace xTagService.Providers
/// <param name="model"></param>
/// <param name="providedForId"></param>
/// <param name="connectionId"></param>
/// <param name="forIndex">if null, removes all</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<bool> RemoveReference(
XTagDto model,
TKey providedForId,
string connectionId = null
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
@@ -418,7 +413,12 @@ namespace xTagService.Providers
//
// Retrieve Model ...
model = await TagProvider.Get(model.Id);
model = await TagProvider.GetAsync(
id: model.Id,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
);
result = !model.IsNullOrDefault();
if (!result)
{
@@ -427,11 +427,17 @@ namespace xTagService.Providers
//
// Reading Referencing Indexes ...
var indexes = await GetReferencingIndexes(providedForId);
var indexes = await GetReferencingIndexes(
providedForId: providedForId,
cancellationToken: cancellationToken
);
//
// Check Model Reference to ID ...
var referencesCount = await CountReferences(providedForId);
var referencesCount = await CountReferences(
providedForId: providedForId,
cancellationToken: cancellationToken
);
result = referencesCount == 0;
if (result)
{
@@ -442,9 +448,11 @@ namespace xTagService.Providers
//
// Check Model is Trully Referenced to ProvidedForId or not ...
var reference = model.References
.FirstOrDefault(r => r.ProvidedFor == Provider &&
r.ReferencedTo == $"{providedForId}");
var reference = model
.GetReferences()
.FirstOrDefault(r =>
r.ProvidedFor == Provider &&
r.ReferencedTo == $"{providedForId}");
result = !reference.IsNullOrDefault();
if (!result)
{
@@ -453,17 +461,22 @@ namespace xTagService.Providers
//
// Remove Referenced Item from Model ...
model.References = model.References
.Where(r => !(r.ProvidedFor == Provider &&
r.ReferencedTo == $"{providedForId}"))
var modelReferences = model
.GetReferences()
.Where(r =>
!(r.ProvidedFor == Provider &&
r.ReferencedTo == $"{providedForId}"))
.ToList();
model = model.UpdateReferences(modelReferences);
//
// Update DataBase ...
model = await TagProvider.Update(
model = await TagProvider.UpdateAsync(
item: model,
id: model.Id,
model: model,
connectionId: connectionId
saveChanges: true,
connectionId: connectionId,
cancellationToken: cancellationToken
);
//
@@ -488,12 +501,14 @@ namespace xTagService.Providers
//
var dto = await GetReference(
forIndex: i,
providedForId: providedForId
providedForId: providedForId,
cancellationToken: cancellationToken
);
if (!dto.IsNullOrDefault())
{
//
dto.References
var dtoReferences = dto.GetReferences();
dtoReferences
.ToList()
.ForEach(iref =>
{
@@ -507,12 +522,15 @@ namespace xTagService.Providers
iref.Index = i - 1;
}
});
dto = dto.UpdateReferences(dtoReferences);
//
dto = await TagProvider.Update(
dto = await TagProvider.UpdateAsync(
item: dto,
id: dto.Id,
model: dto,
connectionId: connectionId
saveChanges: true,
connectionId: connectionId,
cancellationToken: cancellationToken
);
}
}
@@ -526,13 +544,15 @@ namespace xTagService.Providers
/// Remove Reference a Model for Specific XRefence<TKey> ...
/// </summary>
/// <param name="model"></param>
/// <param name="providedForId"></param>
/// <param name="reference"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<bool> RemoveReference(
XTagDto model,
XReference<TKey> reference,
string connectionId = null
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
@@ -548,6 +568,7 @@ namespace xTagService.Providers
var result = await RemoveReference(
model: model,
connectionId: connectionId,
cancellationToken: cancellationToken,
providedForId: reference.ReferencedTo
);
@@ -560,10 +581,12 @@ namespace xTagService.Providers
/// </summary>
/// <param name="providedForId"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<bool> RemoveReferences(
TKey providedForId,
string connectionId = null
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
@@ -575,7 +598,10 @@ namespace xTagService.Providers
//
var result = false;
var references = await GetAllReferences(providedForId);
var references = await GetAllReferences(
providedForId: providedForId,
cancellationToken: cancellationToken
);
if (!references.IsNull() && references.HasChild())
{
//
@@ -583,16 +609,19 @@ namespace xTagService.Providers
{
//
// Remove Reference ...
reference.References = reference.References
var itemReferences = reference.GetReferences()
.Where(r =>
r.ProvidedFor != Provider ||
(r.ProvidedFor == Provider &&
r.ReferencedTo != $"{providedForId}"))
.ToList();
var updatedModel = await TagProvider.Update(
id: reference.Id,
model: reference,
connectionId: connectionId
var updatedModel = reference.UpdateReferences(itemReferences);
updatedModel = await TagProvider.UpdateAsync(
saveChanges: true,
item: updatedModel,
id: updatedModel.Id,
connectionId: connectionId,
cancellationToken: cancellationToken
);
if (!updatedModel.IsNullOrDefault())
{
@@ -613,13 +642,14 @@ namespace xTagService.Providers
/// </summary>
/// <param name="tag"></param>
/// <param name="providedForId"></param>
/// <param name="forIndex"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<bool> AddReference(
string tag,
TKey providedForId,
string connectionId = null
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
@@ -635,7 +665,10 @@ namespace xTagService.Providers
//
// Check Tag Exists ...
result = IsExists(tag);
result = await IsExists(
tag: tag,
cancellationToken: cancellationToken
);
if (!result)
{
//
@@ -644,9 +677,11 @@ namespace xTagService.Providers
{
Tag = tag,
};
tagDto = await TagProvider.Add(
model: tagDto,
connectionId: connectionId
tagDto = await TagProvider.AddAsync(
item: tagDto,
saveChanges: true,
connectionId: connectionId,
cancellationToken: cancellationToken
);
result = !tagDto.IsNullOrDefault();
if (!result)
@@ -656,7 +691,10 @@ namespace xTagService.Providers
}
//
var dto = GetTagByTag(tag);
var dto = await GetTagByTag(
tag: tag,
cancellationToken: cancellationToken
);
result = !dto.IsNullOrDefault();
if (!result)
{
@@ -667,7 +705,8 @@ namespace xTagService.Providers
result = await AddReference(
model: dto,
connectionId: connectionId,
providedForId: providedForId
providedForId: providedForId,
cancellationToken: cancellationToken
);
//
@@ -680,11 +719,13 @@ namespace xTagService.Providers
/// <param name="tag"></param>
/// <param name="reference"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<bool> AddReference(
string tag,
XReference<TKey> reference,
string connectionId = null
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
@@ -706,6 +747,7 @@ namespace xTagService.Providers
result = await AddReference(
tag: tag,
connectionId: connectionId,
cancellationToken: cancellationToken,
providedForId: reference.ReferencedTo
);
@@ -718,21 +760,19 @@ namespace xTagService.Providers
/// </summary>
/// <param name="tag"></param>
/// <param name="providedForId"></param>
/// <param name="forIndex">if null, removes all</param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<bool> RemoveReference(
string tag,
TKey providedForId,
string connectionId = null
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
var result = false;
//
// Validate ...
result =
var result =
!tag.IsNullOrEmpty() &&
!providedForId.IsNull();
if (!result)
@@ -742,14 +782,20 @@ namespace xTagService.Providers
//
// Check Tag Exists ...
result = IsExists(tag);
result = await IsExists(
tag: tag,
cancellationToken: cancellationToken
);
if (!result)
{
XException.NotFound.Throw();
}
//
var dto = GetTagByTag(tag);
var dto = await GetTagByTag(
tag: tag,
cancellationToken: cancellationToken
);
result = !dto.IsNullOrDefault();
if (!result)
{
@@ -760,7 +806,8 @@ namespace xTagService.Providers
result = await RemoveReference(
model: dto,
connectionId: connectionId,
providedForId: providedForId
providedForId: providedForId,
cancellationToken: cancellationToken
);
//
@@ -771,21 +818,20 @@ namespace xTagService.Providers
/// Remove Reference a Tag for Specific XRefence<TKey> ...
/// </summary>
/// <param name="tag"></param>
/// <param name="providedForId"></param>
/// <param name="reference"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<bool> RemoveReference(
string tag,
XReference<TKey> reference,
string connectionId = null
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
var result = false;
//
// Validate ...
result =
var result =
!tag.IsNullOrEmpty() &&
!reference.IsNullOrDefault() &&
!reference.ReferencedTo.IsNull() &&
@@ -799,6 +845,7 @@ namespace xTagService.Providers
result = await RemoveReference(
tag: tag,
connectionId: connectionId,
cancellationToken: cancellationToken,
providedForId: reference.ReferencedTo
);
@@ -839,7 +886,10 @@ namespace xTagService.Providers
return result;
}
private async Task<IEnumerable<int>> GetReferencingIndexes(TKey providedForId)
private async Task<IEnumerable<int>> GetReferencingIndexes(
TKey providedForId,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
@@ -852,8 +902,12 @@ namespace xTagService.Providers
//
var result = new List<int>();
var referencings = await GetAllReferencings(providedForId);
isValid = !referencings.IsNull() &&
var referencings = await GetAllReferencings(
providedForId: providedForId,
cancellationToken: cancellationToken
);
isValid =
!referencings.IsNull() &&
referencings.HasChild();
if (!isValid)
{
@@ -871,7 +925,10 @@ namespace xTagService.Providers
return result;
}
private XTagDto GetTagByTag(string tag)
private async Task<XTagDto> GetTagByTag(
string tag,
CancellationToken cancellationToken = default
)
{
//
XTagDto result = null;
@@ -880,20 +937,21 @@ namespace xTagService.Providers
if (!tag.IsNullOrEmpty())
{
//
var entity = TagProvider.Repository
.AsQueryable()
.FirstOrDefault(e => e.Tag == tag);
if (!entity.IsNullOrDefault())
{
result = entity.ToDto();
}
result = await TagProvider
.FindOneAsync(
predicate: x => x.Tag == tag,
cancellationToken: cancellationToken
);
}
//
return result;
}
private bool IsExists(string tag)
private async Task<bool> IsExists(
string tag,
CancellationToken cancellationToken = default
)
{
//
var result = false;
@@ -902,13 +960,16 @@ namespace xTagService.Providers
if (!tag.IsNullOrEmpty())
{
//
var dto = GetTagByTag(tag);
var dto = await GetTagByTag(
tag: tag,
cancellationToken: cancellationToken
);
result = !dto.IsNullOrDefault();
}
//
return result;
}
#endregion
#endregion
}
}
+27
View File
@@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore;
using xDataService.Interfaces;
using xDataService.Providers;
using xTagService.Models.Entities;
namespace xTagService.Providers
{
public class XTagEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar
{
public XTagEntityRegisterar()
: base(nameof(XTagEntityRegisterar))
{
//
// Add XTag Entity ...
AddEntity<XTag, int>();
}
/// <summary>
/// Configure Entities ...
/// </summary>
/// <param name="modelBuilder"></param>
public override void ConfigureEntities(ModelBuilder modelBuilder)
{
base.ConfigureEntities(modelBuilder);
}
}
}
-571
View File
@@ -1,571 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using xCommons.Extensions;
using xDataService.Configuration;
using xExceptions.Constants;
using xIdentityService.Interfaces;
using xModels.Dtos;
using xPushService.Constants;
using xTagService.Extensions;
using xTagService.Hubs;
using xTagService.Interfaces;
using xTagService.Interfaces.Entities;
using xTagService.Models.Dtos;
using xTagService.Models.Entities;
namespace xTagService.Providers
{
public class XTagProvider : IXTagProvider
{
//
#region Props ...
public IXTagRepository Repository { get; }
public IHubContext<XTagEntityHub> Hub { get; }
public IXIdentityProvider IdentityProvider { get; }
public XDataServiceConfiguration DataConfiguration { get; }
#endregion
//
#region Constructor ...
public XTagProvider(
IXTagRepository repository,
IXIdentityProvider identityProvider,
XDataServiceConfiguration dataConfiguration,
IHubContext<XTagEntityHub> hub = null
)
{
//
Hub = hub;
Repository = repository;
IdentityProvider = identityProvider;
DataConfiguration = dataConfiguration;
}
#endregion
//
#region Helpers ....
/// <summary>
/// Converts an Entity to Dto ...
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public XTagDto ToDto(XTag model)
{
return model.ToDto();
}
/// <summary>
/// Converts a List of Entitiies to List of Dto's ...
/// </summary>
/// <param name="models"></param>
/// <returns></returns>
public IEnumerable<XTagDto> ToDtoList(IEnumerable<XTag> models)
{
//
var result = new List<XTagDto>();
//
if (!models.IsNull() && models.HasChild())
{
//
foreach (var model in models)
{
//
var dto = ToDto(model);
if (!dto.IsNullOrDefault())
{
result.Add(dto);
}
}
}
//
return result;
}
/// <summary>
/// Converts Query Result of Entities to Dto ...
/// </summary>
/// <param name="queryResult"></param>
/// <returns></returns>
public XQueryResult<XTagDto> ToDtoQueryResult(XQueryResult<XTag> queryResult)
{
//
var result = new XQueryResult<XTagDto>();
//
if (!queryResult.IsNullOrDefault())
{
//
result.Page = queryResult.Page;
result.PageSize = queryResult.PageSize;
result.TotalItems = queryResult.TotalItems;
result.TotalPages = queryResult.TotalPages;
result.TotalFilteredItems = queryResult.TotalFilteredItems;
result.TotalFilteredPages = queryResult.TotalFilteredPages;
//
if (!queryResult.Items.IsNull() && queryResult.Items.HasChild())
{
result.Items = ToDtoList(queryResult.Items);
}
}
//
return result;
}
#endregion
//
#region Tools ...
/// <summary>
/// Add Specified Tag ...
/// </summary>
/// <param name="model"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public async Task<XTagDto> Add(
XTagDto model,
string connectionId = null
)
{
//
XTagDto result = null;
//
// Converts to Entity ...
var entity = model.FromDto();
if (!model.IsNullOrDefault())
{
//
// Validate ...
if (entity.IsNullOrDefault())
{
XException.ActionFailed.Throw();
}
//
entity = await Repository.AddAsync(entity);
if (entity.IsNullOrDefault())
{
XException.ActionFailed.Throw();
}
//
result = ToDto(entity);
}
//
if (!result.IsNullOrDefault())
{
//
await SendPush(
action: XBaseEntityHubAction.Add.GetStringValue(),
payLoad: entity.ToJSON(camelCase: true),
connectionId: connectionId
);
}
//
return result;
}
/// <summary>
/// Update Specified Dto ...
/// </summary>
/// <param name="id"></param>
/// <param name="model"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public async Task<XTagDto> Update(
int id,
XTagDto model,
string connectionId = null
)
{
//
// Validate ...
var isValid = id.IsValidIntId();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
XTagDto result = null;
//
// Check Exists ...
isValid = await IsExists(id);
if (!isValid)
{
XException.NotFound.Throw();
}
//
var entity = await Repository.GetAsync(id);
if (entity.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
var tagEntity = model.FromDto();
entity = entity.UpdateData(
updateWith: tagEntity,
propertyBlackList: new List<string>
{
nameof(XTagDto.Id),
nameof(XTagDto.References)
}
);
entity.References = tagEntity.References;
entity = await Repository.UpdateAsync(id, entity);
if (!entity.IsNullOrDefault())
{
result = ToDto(entity);
}
//
if (!result.IsNullOrDefault())
{
//
await SendPush(
action: XBaseEntityHubAction.Update.GetStringValue(),
payLoad: entity.ToJSON(camelCase: true),
connectionId: connectionId
);
}
//
return result;
}
/// <summary>
/// Remove Specified Dto ...
/// </summary>
/// <param name="id"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public async Task<XTagDto> Remove(
int id,
string connectionId = null
)
{
//
// Validate ...
var isValid = id.IsValidIntId();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
// Check Exists ...
isValid = await IsExists(id);
if (!isValid)
{
XException.NotFound.Throw();
}
//
var entity = await Repository.RemoveAsync(id);
//
XTagDto result = null;
if (!entity.IsNullOrDefault())
{
result = ToDto(entity);
}
//
if (!result.IsNullOrDefault())
{
//
await SendPush(
action: XBaseEntityHubAction.Delete.GetStringValue(),
payLoad: entity.ToJSON(camelCase: true),
connectionId: connectionId
);
}
//
return result;
}
/// <summary>
/// Retrieve Specified Item as Dto ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<XTagDto> Get(int id)
{
//
var result = new XTagDto();
if (!id.IsValidIntId())
{
XException.InvalidArgs.Throw();
}
//
if (id.IsValidIntId())
{
//
var entity = await Repository.GetAsync(id);
if (entity.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
result = ToDto(entity);
if (result.IsNullOrDefault())
{
XException.NotFound.Throw();
}
}
//
return result;
}
/// <summary>
/// Retrieve Specified Tag by it's Label ...
/// </summary>
/// <param name="tag"></param>
/// <returns></returns>
public async Task<XTagDto> GetTag(string tag)
{
//
// Validate ...
if (tag.IsNullOrEmpty())
{
XException.InvalidArgs.Throw();
}
//
var result = await FindOne(e => e.Tag.ToNormalString() == tag.ToNormalString());
if (result.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
return result;
}
/// <summary>
/// Retrieve All Items as Dto ...
/// </summary>
/// <returns></returns>
public async Task<IEnumerable<XTagDto>> GetAll()
{
//
var result = new List<XTagDto>();
//
var entities = await Repository.GetAllAsync();
if (!entities.IsNull() && entities.HasChild())
{
//
result = ToDtoList(entities)
.ToList();
}
//
return result;
}
/// <summary>
/// Find Specified Item by Condition ...
/// </summary>
/// <param name="whereClause"></param>
/// <returns></returns>
public async Task<XTagDto> FindOne(Expression<Func<XTag, bool>> whereClause)
{
//
XTagDto result = null;
//
var entitiy = await Repository.FindOneAsync(whereClause);
if (!entitiy.IsNullOrDefault())
{
result = ToDto(entitiy);
}
//
return result;
}
/// <summary>
/// Find Many Items based on Conditions ...
/// </summary>
/// <param name="whereClause"></param>
/// <returns></returns>
public async Task<IEnumerable<XTagDto>> FindMany(Expression<Func<XTag, bool>> whereClause)
{
//
var result = new List<XTagDto>();
//
var entities = await Repository.FindManyAsync(whereClause);
if (!entities.IsNull() || entities.HasChild())
{
//
result = ToDtoList(entities)
.ToList();
}
//
return result;
}
/// <summary>
/// Query Model retrieving Dtos ...
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public async Task<XQueryResult<XTagDto>> Query(XQuery query)
{
//
var result = new XQueryResult<XTagDto>();
//
var queryResult = await Repository.QueryAsync(query);
if (!queryResult.IsNull())
{
result = ToDtoQueryResult(queryResult);
}
//
return result;
}
/// <summary>
/// Query Conditional Retrieving Dtos ...
/// </summary>
/// <param name="query"></param>
/// <param name="whereClause"></param>
/// <returns></returns>
public async Task<XQueryResult<XTagDto>> ConditionalQuery(
XQuery query,
Expression<Func<XTag, bool>> whereClause
)
{
//
var result = new XQueryResult<XTagDto>();
//
var queryResult = await Repository.ConditionalQueryAsync(
query: query,
whereClause: whereClause
);
if (!queryResult.IsNull())
{
result = ToDtoQueryResult(queryResult);
}
//
return result;
}
/// <summary>
/// Count Exists Entities ...
/// </summary>
/// <returns></returns>
public async Task<int> Count()
{
return await Repository.CountAsync();
}
/// <summary>
/// Check Entity Exists or not ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<bool> IsExists(int id)
{
return await Repository.IsExistsAsync(id);
}
/// <summary>
/// Check Tag Exists by Label ...
/// </summary>
/// <param name="tag"></param>
/// <returns></returns>
public async Task<bool> IsTagExists(string tag)
{
//
var result = false;
//
if (!tag.IsNullOrEmpty())
{
//
var dto = await FindOne(e => e.Tag.ToNormalString() == tag.ToNormalString());
result = !dto.IsNullOrDefault();
}
//
return result;
}
#endregion
//
#region Hub Actions ...
/// <summary>
/// Send Custom Push Message ...
/// </summary>
/// <param name="action"></param>
/// <param name="payLoad"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public async Task SendPush(
string action,
string payLoad,
string connectionId = null
)
{
//
var actions = new List<string>
{
XBaseEntityHubAction.Add.GetStringValue(),
XBaseEntityHubAction.Update.GetStringValue(),
XBaseEntityHubAction.Delete.GetStringValue(),
XBaseEntityHubAction.AddMany.GetStringValue(),
XBaseEntityHubAction.DeleteMany.GetStringValue(),
XBaseEntityHubAction.UpdateMany.GetStringValue(),
XBaseEntityHubAction.AddOrUpdate.GetStringValue(),
};
//
// Validate ...
var isValid =
!Hub.IsNull() &&
!action.IsNullOrEmpty() &&
actions.Contains(action);
if (!isValid)
{
return;
}
//
var clients = Hub.Clients.All;
if (!connectionId.IsNullOrEmpty())
{
clients = Hub.Clients.AllExcept(connectionId);
}
try
{
await clients.SendAsync(action, payLoad, connectionId);
}
catch { }
}
#endregion
}
}
+207
View File
@@ -2,6 +2,213 @@
it is a Part of xDashboard on SaherElm IT Center which provides all Tag Related Futures ...
this module has following dependencies :
- xDataService
- xPushService
- xIdentityService
for configure and use this Module refer to DI.XDIHelperExtension.cs file.
## Tag
is a Global Identitifer which act as semantic value that can be represent some metadata about a data.
Tags can attach/detach to another Items for Describing Metadata about them.
**xDashboard** Provides Tag Management tools in this Module for adding this Feature to
applications.
## Data Persists
all of Provided features of this Module is works based on Data Persistance. so data models is Very Important.
in this section all Data models explained.
data manipulation done using **xDataService** provided Features.
- **XTag**: an Entity Model for Mapping to Tables.
- **XTagDto**: a Data Transfer Object for Representing a Data Model.
- **XTagEntityConfiguration**: a Configuration file for XTag Entity.
- **XTagEntityHub**: a Hub Implementation for XTag Entity Model.
- **XTagDtoHub**: a Hub Implementation for XTagDto Model.
- **XTagEntityRegisterar**: an Implementation class for Dynamically Register XTag Entity in a DbContext.
- **IXTagRepositoryEvents**: an Interface for Repository Events Describing of XTag Entity.
- **XTagRepositoryEvents**: an Implementation for Repository Events of XTag Entity.
- **IXTagKeyGenerator**: an Interface for Describing Key Generator Actions for XTag Entity.
- **XTagKeyGenerator**: an Implementation for Describing Key Generator Actions for XTag Entity.
- **IXTagRepository**: an Interface for Describing XTag Repository Actions.
- **XTagEFRepository**: an Implementation of EF Core based XTag Repository Actions.
- **XTagMongoRepository**: an Implementation of MongoDb based XTag Repository Actions.
- **XTagMongoRepository**: an Implementation of MongoDb based XTag Repository Actions.
- **XTagInMemoryRepository**: an Implementation of InMemory based XTag Repository Actions.
- **IXTagSeeder**: an Interface for Describe XTag DbSeeder actions.
- **XTagSeederBase**: an abstraction of Implementation of XTag DbSeeder actions.
- **IXTagRepositoryProvider**: an Interface for Describing XTag Repository Provider (using Hubs) actions.
- **XTagRepositoryProvider**: an Implementation of XTag Repository Provider (using Hubs) actions.
- **IXTagRepositoryService**: an Interface for Describing XTag Repository Service Actions (using XTagDto).
- **XTagRepositoryService**: an Implementation of XTag Repository Service Actions (using XTagDto).
- **IXTagServiceProvider**: an Interface for Describing XTag Repository Service Actions Provider (using Hubs and XTagDto).
- **XTagServiceProvider**: an Implementation of XTag Repository Service Actions Provider (using Hubs and XTagDto).
- **XTagGraphType**: introduce XTag Data model for GraphQL using.
- **XTagGraphQuery**: introduce Repositry Implementation of XTag model actions as Query Actions for GraphQL using.
- **XTagGraphSchema**: introduce XTag Query Schema for GraphQL using.
- **IXTagGraphQLTypeHelper**: an Interface for Describing XTag GraphQL Type Helper Provided Actions.
- **IXTagGraphQLTypeHelper**: an Implementation of XTag GraphQL Type Helper Provided Actions.
data presistance almost is a Down Layer works which handled using Service it self.
but in some Used cases of Applications Business Logics, for Manipulating resources you can use above Registered Services by Injecting them.
## Providers
this module actually used to act as a base Provider for implementing Features based on it.
for this purpose, provides some Features which described in this section.
### String Resource Provider
some services used XTag model for Provide Specially Concept's of Actions. for example Terms and Conditions Services use XTag Persisted Resource for Specified Purpose.
this Module provides some sort of tools for this purpose. which described in this section.
#### Data Transfer Models
this service used some Data Transfer Models for Data Providing. which Described in this section.
```C#
public class XReference<T>
{
public int Index { get; set; }
public T ReferencedTo { get; set; }
public string ProvidedFor { get; set; }
}
```
#### IXBaseTagProvider
an interface for Describe Provided Actions of Tag based Service.
```C#
public interface IXBaseTagProvider<TKey> : IXBaseReferencedProvider<XTagDto, TKey>
{
//
#region Tools ...
/// <summary>
/// Add Reference a Tag to Specific Provided ID ...
/// </summary>
/// <param name="tag"></param>
/// <param name="providedForId"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> AddReference(
string tag,
TKey providedForId,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Add Reference a Tag to Specific XRefence<TKey> ...
/// </summary>
/// <param name="tag"></param>
/// <param name="reference"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> AddReference(
string tag,
XReference<TKey> reference,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove Reference a Tag for Specific Provided ID ...
/// </summary>
/// <param name="tag"></param>
/// <param name="providedForId"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> RemoveReference(
string tag,
TKey providedForId,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove Reference a Tag for Specific XRefence<TKey> ...
/// </summary>
/// <param name="tag"></param>
/// <param name="reference"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> RemoveReference(
string tag,
XReference<TKey> reference,
string connectionId = null,
CancellationToken cancellationToken = default
);
#endregion
}
```
#### XBaseTagProvider
an implementation of Provided Actions of Resource based Service.
```C#
public abstract class XBaseTagProvider<TKey> : IXBaseTagProvider<TKey>
{ }
```
### Controllers
there are some abstraction Layer of Controller Implementation for using Provided Services for managing data.
- **XTagRepositoryControllerBase**: an abstract Controller for Provide Repository Actions (using Entity).
- **XTagRepositoryProviderControllerBase**: an abstract Controller for Provide Repository Actions (using Entity and XEntityHub).
- **XTagServiceControllerBase**: an abstract Controller for Provide Service Actions (using Dto).
- **XTagServiceProviderControllerBase**: an abstract Controller for Provide Service Actions (using Dto and XDtoHub).
## Implementation
you have to follow these steps for using this Module.
- **DI Registration**: in this phase, all Provided Services Registered in DI.
- **Middleware Usage**: in this phase, Service Middlewares Use to Handle Features.
```C#
public class Startup
{
//
public void ConfigureServices(IServiceCollection services)
{
...
//
// Register Tag Service ...
services.AddXTagService<XApiDbContext>(
lifeTime: lifeTime,
repositoryType: xDataService.Constants.XRepositoryType.EF
);
...
}
//
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
//
// Using Tag Service ...
app.UseXTagService(
isDevelopmentEnvironment: isDevelopmentEnvironment
);
...
}
}
```
## Maintainer
Hadi Khazaee asl
+3 -3
View File
@@ -23,15 +23,15 @@
<!-- Local Modules -->
<ItemGroup>
<!-- <PackageReference Include="xDashboard.xDataService" Version="1.0.0" /> -->
<!-- <PackageReference Include="xDashboard.xStringService" Version="1.0.0" /> -->
<!-- <PackageReference Include="xDashboard.xPushService" Version="1.0.0" /> -->
<!-- <PackageReference Include="xDashboard.xIdentityService" Version="1.0.0" /> -->
</ItemGroup>
<!-- Local Dependencies -->
<ItemGroup>
<ProjectReference Include="../xPushService/xPushService.csproj" />
<ProjectReference Include="../xDataService/xDataService.csproj" />
<ProjectReference Include="../xIdentityService/xIdentityService.csproj" />
<ProjectReference Include="../xPushService/xPushService.csproj" />
<ProjectReference Include="../xIdentityService/xIdentityService.csproj" />
</ItemGroup>
</Project>