From b693aaa37579971877704ed14a4f5d01ea14e8fe Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 16 Nov 2025 16:00:30 +0330 Subject: [PATCH] last ... --- Base/XBaseEntityHub.cs | 128 +++++++++++++++++++++++++++++++++++++++ Base/XBaseHub.cs | 6 ++ Constants/XPushAction.cs | 21 +++++++ xPushService.csproj | 8 ++- 4 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 Base/XBaseEntityHub.cs diff --git a/Base/XBaseEntityHub.cs b/Base/XBaseEntityHub.cs new file mode 100644 index 0000000..b209576 --- /dev/null +++ b/Base/XBaseEntityHub.cs @@ -0,0 +1,128 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.SignalR; +using Microsoft.Extensions.Logging; +using xCommons.Extensions; +using xModels.Base; +using xPushService.Constants; + +namespace xPushService.Base +{ + public abstract class XBaseEntityHub : XBaseHub + where TEntity : XBaseEntity + { + // + #region Constructor ... + protected XBaseEntityHub(ILogger logger) : base(logger) + { } + #endregion + + // + #region Actions ... + /// + /// Notify a New Entity added ... + /// + /// + /// + public async Task Add(TEntity entity) + { + // + var connectionId = Context.ConnectionId; + if (!connectionId.IsNullOrEmpty()) + { + await Clients.AllExcept(connectionId).SendAsync(XBaseEntityHubAction.Add.GetStringValue(), entity, connectionId); + } + } + + /// + /// Notify a New Entity added ... + /// + /// + /// + public async Task AddOrUpdate(TEntity entity) + { + // + var connectionId = Context.ConnectionId; + if (!connectionId.IsNullOrEmpty()) + { + await Clients.AllExcept(connectionId).SendAsync(XBaseEntityHubAction.AddOrUpdate.GetStringValue(), entity, connectionId); + } + } + + /// + /// Notify Add Many Entities ... + /// + /// + /// + public async Task AddMany(IEnumerable entities) + { + // + var connectionId = Context.ConnectionId; + if (!connectionId.IsNullOrEmpty()) + { + await Clients.AllExcept(connectionId).SendAsync(XBaseEntityHubAction.AddOrUpdate.GetStringValue(), entities.ToJSON(), connectionId); + } + } + + /// + /// Notify an Entity Deleted ... + /// + /// + /// + public async Task Delete(TEntity entity) + { + // + var connectionId = Context.ConnectionId; + if (!connectionId.IsNullOrEmpty()) + { + await Clients.AllExcept(connectionId).SendAsync(XBaseEntityHubAction.Delete.GetStringValue(), entity, connectionId); + } + } + + /// + /// Notify Delete Many Entities ... + /// + /// + /// + public async Task DeleteMany(IEnumerable entities) + { + // + var connectionId = Context.ConnectionId; + if (!connectionId.IsNullOrEmpty()) + { + await Clients.AllExcept(connectionId).SendAsync(XBaseEntityHubAction.DeleteMany.GetStringValue(), entities.ToJSON(), connectionId); + } + } + + /// + /// Notify an Entity Updated ... + /// + /// + /// + public async Task Update(TEntity entity) + { + // + var connectionId = Context.ConnectionId; + if (!connectionId.IsNullOrEmpty()) + { + await Clients.AllExcept(connectionId).SendAsync(XBaseEntityHubAction.Update.GetStringValue(), entity, connectionId); + } + } + + /// + /// Notify Update Many Entities ... + /// + /// + /// + public async Task UpdateMany(IEnumerable entities) + { + // + var connectionId = Context.ConnectionId; + if (!connectionId.IsNullOrEmpty()) + { + await Clients.AllExcept(connectionId).SendAsync(XBaseEntityHubAction.UpdateMany.GetStringValue(), entities.ToJSON(), connectionId); + } + } + #endregion + } +} \ No newline at end of file diff --git a/Base/XBaseHub.cs b/Base/XBaseHub.cs index c1ad503..13fbf37 100644 --- a/Base/XBaseHub.cs +++ b/Base/XBaseHub.cs @@ -58,6 +58,12 @@ namespace xPushService.Base // #region Actions ... + public async Task SendCustomAction(string actionName, string payLoad) + { + // + var connectionId = Context.ConnectionId; + await Clients.AllExcept(connectionId).SendAsync(actionName, payLoad, connectionId); + } #endregion } } \ No newline at end of file diff --git a/Constants/XPushAction.cs b/Constants/XPushAction.cs index 900b794..8f40630 100644 --- a/Constants/XPushAction.cs +++ b/Constants/XPushAction.cs @@ -31,4 +31,25 @@ namespace xPushService.Constants [StringValue("Candidate")] Candidate, } + + /// + /// Provides All Actions Based on Entities ... + /// + public enum XBaseEntityHubAction + { + [StringValue("Add")] + Add, + [StringValue("AddOrUpdate")] + AddOrUpdate, + [StringValue("AddMany")] + AddMany, + [StringValue("Update")] + Update, + [StringValue("UpdateMany")] + UpdateMany, + [StringValue("Delete")] + Delete, + [StringValue("DeleteMany")] + DeleteMany, + } } \ No newline at end of file diff --git a/xPushService.csproj b/xPushService.csproj index 8475403..ddd08dd 100644 --- a/xPushService.csproj +++ b/xPushService.csproj @@ -25,14 +25,16 @@ - + - + --> +