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
+97 -95
View File
@@ -16,105 +16,107 @@ using xPushService.Constants;
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 ...
protected XIBaseV1EntityController(
ILogger<XIBaseV1EntityController<TEntity, TKey>> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXBaseRepository<TEntity, TKey> repository
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider,
repository
)
{ }
#endregion
}
//
// TODO: Fix this ...
// [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 ...
// protected XIBaseV1EntityController(
// ILogger<XIBaseV1EntityController<TEntity, TKey>> logger,
// XAppConfiguration appConfiguration,
// IXIdentityProvider identityProvider,
// XValidationProvider validationProvider,
// IXBaseRepository<TEntity, TKey> repository
// ) : base(
// logger,
// appConfiguration,
// identityProvider,
// validationProvider,
// repository
// )
// { }
// #endregion
// }
public abstract class XIBaseV1EntityHubController<TEntity, TKey> : XIBaseV1EntityController<TEntity, TKey>
where TEntity : XBaseEntity<TKey>
{
//
#region Props ...
public IHubContext<XBaseEntityHub<TEntity, TKey>> Hub { get; }
#endregion
// public abstract class XIBaseV1EntityHubController<TEntity, TKey> : XIBaseV1EntityController<TEntity, TKey>
// where TEntity : XBaseEntity<TKey>
// {
// //
// #region Props ...
// public IHubContext<XBaseEntityHub<TEntity, TKey>> Hub { get; }
// #endregion
//
#region Constructor ...
protected XIBaseV1EntityHubController(
ILogger<XIBaseV1EntityHubController<TEntity, TKey>> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXBaseRepository<TEntity, TKey> repository,
IHubContext<XBaseEntityHub<TEntity, TKey>> hub = null
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider,
repository
)
{
Hub = hub;
}
#endregion
// //
// #region Constructor ...
// protected XIBaseV1EntityHubController(
// ILogger<XIBaseV1EntityHubController<TEntity, TKey>> logger,
// XAppConfiguration appConfiguration,
// IXIdentityProvider identityProvider,
// XValidationProvider validationProvider,
// IXBaseRepository<TEntity, TKey> repository,
// IHubContext<XBaseEntityHub<TEntity, TKey>> hub = null
// ) : base(
// logger,
// appConfiguration,
// identityProvider,
// validationProvider,
// repository
// )
// {
// Hub = hub;
// }
// #endregion
//
#region Hub ...
[NonAction]
public async Task SendPush(
string action,
string payLoad
)
{
//
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(),
};
// //
// #region Hub ...
// [NonAction]
// public async Task SendPush(
// string action,
// string payLoad
// )
// {
// //
// 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() &&
!payLoad.IsNullOrEmpty() &&
actions.Contains(action);
if (!isValid)
{
return;
}
// //
// // Validate ...
// var isValid =
// !Hub.IsNull() &&
// !action.IsNullOrEmpty() &&
// !payLoad.IsNullOrEmpty() &&
// actions.Contains(action);
// if (!isValid)
// {
// return;
// }
//
// Retrieve Connection Id ...
var connectionId = GetConnectionId();
var clients = Hub.Clients.All;
if (!connectionId.IsNullOrEmpty())
{
clients = Hub.Clients.AllExcept(connectionId);
}
// //
// // Retrieve Connection Id ...
// var connectionId = GetConnectionId();
// var clients = Hub.Clients.All;
// if (!connectionId.IsNullOrEmpty())
// {
// clients = Hub.Clients.AllExcept(connectionId);
// }
//
await clients.SendAsync(action, payLoad, connectionId);
}
#endregion
}
// //
// await clients.SendAsync(action, payLoad, connectionId);
// }
// #endregion
// }
}