This commit is contained in:
2026-05-15 03:21:27 +03:30
parent d5da4c9d7b
commit 1f4b6e7c9a
3 changed files with 118 additions and 153 deletions
+96 -94
View File
@@ -15,106 +15,108 @@ using xPushService.Base;
using xPushService.Constants; using xPushService.Constants;
namespace xApi.Base namespace xApi.Base
{
[ApiController]
[ApiVersion("1.0")]
[RequireXPowered(true)]
[Route("api/v{version:apiVersion}/entities/[controller]")]
public abstract class XIBaseV1EntityController<TEntity, TKey> : XIBaseEntityController<TEntity, TKey>
where TEntity : XBaseEntity<TKey>
{ {
// //
#region Constructor ... // TODO: Fix this ...
protected XIBaseV1EntityController( // [ApiController]
ILogger<XIBaseV1EntityController<TEntity, TKey>> logger, // [ApiVersion("1.0")]
XAppConfiguration appConfiguration, // [RequireXPowered(true)]
IXIdentityProvider identityProvider, // [Route("api/v{version:apiVersion}/entities/[controller]")]
XValidationProvider validationProvider, // public abstract class XIBaseV1EntityController<TEntity, TKey> : XIBaseEntityController<TEntity, TKey>
IXBaseRepository<TEntity, TKey> repository // where TEntity : XBaseEntity<TKey>
) : base( // {
logger, // //
appConfiguration, // #region Constructor ...
identityProvider, // protected XIBaseV1EntityController(
validationProvider, // ILogger<XIBaseV1EntityController<TEntity, TKey>> logger,
repository // XAppConfiguration appConfiguration,
) // IXIdentityProvider identityProvider,
{ } // XValidationProvider validationProvider,
#endregion // IXBaseRepository<TEntity, TKey> repository
} // ) : base(
// logger,
// appConfiguration,
// identityProvider,
// validationProvider,
// repository
// )
// { }
// #endregion
// }
public abstract class XIBaseV1EntityHubController<TEntity, TKey> : XIBaseV1EntityController<TEntity, TKey> // public abstract class XIBaseV1EntityHubController<TEntity, TKey> : XIBaseV1EntityController<TEntity, TKey>
where TEntity : XBaseEntity<TKey> // where TEntity : XBaseEntity<TKey>
{ // {
// // //
#region Props ... // #region Props ...
public IHubContext<XBaseEntityHub<TEntity, TKey>> Hub { get; } // public IHubContext<XBaseEntityHub<TEntity, TKey>> Hub { get; }
#endregion // #endregion
// // //
#region Constructor ... // #region Constructor ...
protected XIBaseV1EntityHubController( // protected XIBaseV1EntityHubController(
ILogger<XIBaseV1EntityHubController<TEntity, TKey>> logger, // ILogger<XIBaseV1EntityHubController<TEntity, TKey>> logger,
XAppConfiguration appConfiguration, // XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider, // IXIdentityProvider identityProvider,
XValidationProvider validationProvider, // XValidationProvider validationProvider,
IXBaseRepository<TEntity, TKey> repository, // IXBaseRepository<TEntity, TKey> repository,
IHubContext<XBaseEntityHub<TEntity, TKey>> hub = null // IHubContext<XBaseEntityHub<TEntity, TKey>> hub = null
) : base( // ) : base(
logger, // logger,
appConfiguration, // appConfiguration,
identityProvider, // identityProvider,
validationProvider, // validationProvider,
repository // repository
) // )
{ // {
Hub = hub; // Hub = hub;
} // }
#endregion // #endregion
// // //
#region Hub ... // #region Hub ...
[NonAction] // [NonAction]
public async Task SendPush( // public async Task SendPush(
string action, // string action,
string payLoad // string payLoad
) // )
{ // {
// // //
var actions = new List<string> // var actions = new List<string>
{ // {
XBaseEntityHubAction.Add.GetStringValue(), // XBaseEntityHubAction.Add.GetStringValue(),
XBaseEntityHubAction.Update.GetStringValue(), // XBaseEntityHubAction.Update.GetStringValue(),
XBaseEntityHubAction.Delete.GetStringValue(), // XBaseEntityHubAction.Delete.GetStringValue(),
XBaseEntityHubAction.AddMany.GetStringValue(), // XBaseEntityHubAction.AddMany.GetStringValue(),
XBaseEntityHubAction.DeleteMany.GetStringValue(), // XBaseEntityHubAction.DeleteMany.GetStringValue(),
XBaseEntityHubAction.UpdateMany.GetStringValue(), // XBaseEntityHubAction.UpdateMany.GetStringValue(),
XBaseEntityHubAction.AddOrUpdate.GetStringValue(), // XBaseEntityHubAction.AddOrUpdate.GetStringValue(),
}; // };
// // //
// Validate ... // // Validate ...
var isValid = // var isValid =
!Hub.IsNull() && // !Hub.IsNull() &&
!action.IsNullOrEmpty() && // !action.IsNullOrEmpty() &&
!payLoad.IsNullOrEmpty() && // !payLoad.IsNullOrEmpty() &&
actions.Contains(action); // actions.Contains(action);
if (!isValid) // if (!isValid)
{ // {
return; // return;
} // }
// // //
// Retrieve Connection Id ... // // Retrieve Connection Id ...
var connectionId = GetConnectionId(); // var connectionId = GetConnectionId();
var clients = Hub.Clients.All; // var clients = Hub.Clients.All;
if (!connectionId.IsNullOrEmpty()) // if (!connectionId.IsNullOrEmpty())
{ // {
clients = Hub.Clients.AllExcept(connectionId); // clients = Hub.Clients.AllExcept(connectionId);
} // }
// // //
await clients.SendAsync(action, payLoad, connectionId); // await clients.SendAsync(action, payLoad, connectionId);
} // }
#endregion // #endregion
} // }
} }
+20 -41
View File
@@ -1,11 +1,11 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Net.Http; using System.Net.Http;
using System.Reflection; using System.Reflection;
using IdentityModel.AspNetCore.OAuth2Introspection; using IdentityModel.AspNetCore.OAuth2Introspection;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@@ -15,10 +15,11 @@ using Newtonsoft.Json.Serialization;
using xApi.Extensions; using xApi.Extensions;
using xCommons.Configurations; using xCommons.Configurations;
using xCommons.Extensions; using xCommons.Extensions;
using xDataService.DI; using xDataService.Models;
using xHttpService.DI; using xHttpService.DI;
using xIdentityService.DI; using xIdentityService.DI;
using xServices.Databases; using xServices.Databases;
using xServices.DI;
namespace xApi namespace xApi
{ {
@@ -32,6 +33,9 @@ namespace xApi
{ {
// //
Configuration = configuration; Configuration = configuration;
//
// Create an Api Descriptor Class Instance ...
apiDatabaseDescriptor = new XApiDatabaseDescriptor(); apiDatabaseDescriptor = new XApiDatabaseDescriptor();
} }
@@ -61,24 +65,8 @@ namespace xApi
services.AddXHttpService(Configuration); services.AddXHttpService(Configuration);
// //
// Register Api Versioning ... // Add Api V1 Versioning ...
services.AddApiVersioning(opt => services.AddXApiV1Versioning();
{
//
// Set Default Api Version ...
opt.DefaultApiVersion = new ApiVersion(1, 0);
//
// Set Routing to Default API Version, if Version unspecified ...
opt.AssumeDefaultVersionWhenUnspecified = true;
//
// Report All Available Api Versions on Response ...
opt.ReportApiVersions = true;
});
//
var lifeTime = ServiceLifetime.Scoped;
// //
// OAuthIntrospectin Http Client Handler ... // OAuthIntrospectin Http Client Handler ...
@@ -120,26 +108,22 @@ namespace xApi
}); });
// //
// Check Data Service ... // Register Services ...
var dataServiceConfig = Configuration.GetXDataServiceConfiguration(); services.AddXServices(
//
// Check DataBase Registration ...
services.AddXDatabase(
lifetime: lifeTime,
configuration: Configuration, configuration: Configuration,
descriptor: apiDatabaseDescriptor databases: new List<XDatabaseDescriptor>
{
apiDatabaseDescriptor
},
lifeTime: ServiceLifetime.Scoped
); );
} }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{ {
// //
var withPlayground = false;
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
//
withPlayground = true;
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }
@@ -181,18 +165,13 @@ namespace xApi
// //
// Use xDataService Middleware ... // Use xDataService Middleware ...
app.UseXDatabase( app.UseXServices(
descriptor: apiDatabaseDescriptor, databases: new List<XDatabaseDescriptor>
{
apiDatabaseDescriptor
},
isDevelopmentEnvironment: env.IsDevelopment() isDevelopmentEnvironment: env.IsDevelopment()
); );
//
// Using Services ...
// app.UseXServices();
//
// Use xGraphQL Middleware ...
// app.UseXGraphQL(withPlayground: withPlayground);
} }
} }
} }
+1 -17
View File
@@ -70,7 +70,7 @@
} }
}, },
"EnableTracking": true, "EnableTracking": true,
"EnableSoftDelete": false, "EnableSoftDelete": true,
"EnableDetailedErrors": false, "EnableDetailedErrors": false,
"SeedingMode": "AddIfNotExists", "SeedingMode": "AddIfNotExists",
"EnableSensitiveDataLogging": true, "EnableSensitiveDataLogging": true,
@@ -81,22 +81,6 @@
}, },
"GraphQLBasePath": "/graphs" "GraphQLBasePath": "/graphs"
}, },
"DbSeeder": {
"UpdateExists": false,
"Strings": [],
"Terms": [
{
"Language": "fa-IR",
"ResourceTitle": "terms",
"TranslatedValue": "توافقنامه استفاده از خدمات و شرایط و ضوابط عضویت"
},
{
"Language": "en-US",
"ResourceTitle": "terms",
"TranslatedValue": "Terms and Conditions of Using Yuze Services"
}
]
},
"HttpServiceConfiguration": { "HttpServiceConfiguration": {
"DisableSSLCheck": true, "DisableSSLCheck": true,
"DefaultClientTimeout": -1 "DefaultClientTimeout": -1