From 13cd3ed5112e02530a15091cb252970f3dcf248d Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 16 Nov 2025 17:30:15 +0330 Subject: [PATCH] Add Support for Hub Action Implementation ... --- Constants/XStringHubAction.cs | 7 +----- Hubs/{XStringHub.cs => XStringEntityHub.cs} | 4 +-- Interfaces/IXStringProvider.cs | 2 +- Providers/XStringProvider.cs | 28 ++++++++++++--------- 4 files changed, 20 insertions(+), 21 deletions(-) rename Hubs/{XStringHub.cs => XStringEntityHub.cs} (61%) diff --git a/Constants/XStringHubAction.cs b/Constants/XStringHubAction.cs index 2cf4c3e..793f7ce 100644 --- a/Constants/XStringHubAction.cs +++ b/Constants/XStringHubAction.cs @@ -1,10 +1,5 @@ -using xExceptions.Attributes; - namespace xStringService.Constants { public enum XStringHubAction - { - [StringValue("ItemsDeleted")] - ItemsDeleted - } + { } } \ No newline at end of file diff --git a/Hubs/XStringHub.cs b/Hubs/XStringEntityHub.cs similarity index 61% rename from Hubs/XStringHub.cs rename to Hubs/XStringEntityHub.cs index 78076c9..2f34dac 100644 --- a/Hubs/XStringHub.cs +++ b/Hubs/XStringEntityHub.cs @@ -4,11 +4,11 @@ using xStringService.Models.Entities; namespace xStringService.Hubs { - public class XStringHub : XBaseEntityHub + public class XStringEntityHub : XBaseEntityHub { // #region Constructor ... - public XStringHub(ILogger logger) : base(logger) + public XStringEntityHub(ILogger logger) : base(logger) { } #endregion } diff --git a/Interfaces/IXStringProvider.cs b/Interfaces/IXStringProvider.cs index 6e9c08f..26b5327 100644 --- a/Interfaces/IXStringProvider.cs +++ b/Interfaces/IXStringProvider.cs @@ -17,7 +17,7 @@ namespace xStringService.Interfaces { // #region Props ... - IHubContext Hub { get; } + IHubContext Hub { get; } IXStringRepository Repository { get; } XAppConfiguration AppConfiguration { get; } XDataServiceConfiguration DataConfiguration { get; } diff --git a/Providers/XStringProvider.cs b/Providers/XStringProvider.cs index 04d9c31..fb1faf5 100644 --- a/Providers/XStringProvider.cs +++ b/Providers/XStringProvider.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; -using DnsClient.Protocol; using Microsoft.AspNetCore.SignalR; using xCommons.Configurations; using xCommons.Extensions; @@ -12,7 +11,6 @@ using xDataService.Extensions; using xExceptions.Constants; using xModels.Dtos; using xPushService.Constants; -using xStringService.Constants; using xStringService.Extensions; using xStringService.Hubs; using xStringService.Interfaces; @@ -26,7 +24,7 @@ namespace xStringService.Providers { // #region Props ... - public IHubContext Hub { get; } + public IHubContext Hub { get; } public IXStringRepository Repository { get; } public XAppConfiguration AppConfiguration { get; } public XDataServiceConfiguration DataConfiguration { get; } @@ -38,7 +36,7 @@ namespace xStringService.Providers IXStringRepository repository, XAppConfiguration appConfiguration, XDataServiceConfiguration dataConfiguration, - IHubContext hub = null + IHubContext hub = null ) { // @@ -1210,7 +1208,7 @@ namespace xStringService.Providers // var entitieIds = entities.Select(e => e.Id); await SendCustomPush( - action: XStringHubAction.ItemsDeleted.GetStringValue(), + action: XBaseEntityHubAction.DeleteMany.GetStringValue(), payLoad: entitieIds.ToJSON(), connectionId: connectionId ); @@ -1258,7 +1256,7 @@ namespace xStringService.Providers // var ids = result.Select(i => i.Id); await SendCustomPush( - action: XStringHubAction.ItemsDeleted.GetStringValue(), + action: XBaseEntityHubAction.DeleteMany.GetStringValue(), payLoad: ids.ToJSON(), connectionId: connectionId ); @@ -1390,11 +1388,15 @@ namespace xStringService.Providers ) { // - var hubActions = new List + var actions = new List { XBaseEntityHubAction.Add.GetStringValue(), - XBaseEntityHubAction.Delete.GetStringValue(), XBaseEntityHubAction.Update.GetStringValue(), + XBaseEntityHubAction.Delete.GetStringValue(), + XBaseEntityHubAction.AddMany.GetStringValue(), + XBaseEntityHubAction.DeleteMany.GetStringValue(), + XBaseEntityHubAction.UpdateMany.GetStringValue(), + XBaseEntityHubAction.AddOrUpdate.GetStringValue(), }; // @@ -1403,7 +1405,7 @@ namespace xStringService.Providers entityId > 0 && !Hub.IsNull() && !action.IsNullOrEmpty() && - hubActions.Contains(action); + actions.Contains(action); if (!isValid) { return; @@ -1429,7 +1431,7 @@ namespace xStringService.Providers { clients = Hub.Clients.AllExcept(connectionId); } - await clients.SendAsync(action, entity, connectionId); + await clients.SendAsync(action, entity.ToJSON(), connectionId); } /// @@ -1448,12 +1450,14 @@ namespace xStringService.Providers // var customActions = new List { - XStringHubAction.ItemsDeleted.GetStringValue(), + XBaseEntityHubAction.DeleteMany.GetStringValue(), }; // // Validate ... - var isValid = !action.IsNullOrEmpty() && + var isValid = + !Hub.IsNull() && + !action.IsNullOrEmpty() && customActions.Contains(action); if (!isValid) {