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 } }