last ...
This commit is contained in:
@@ -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<TEntity, TKey> : XBaseHub
|
||||
where TEntity : XBaseEntity<TKey>
|
||||
{
|
||||
//
|
||||
#region Constructor ...
|
||||
protected XBaseEntityHub(ILogger<XBaseHub> logger) : base(logger)
|
||||
{ }
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
/// <summary>
|
||||
/// Notify a New Entity added ...
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Add(TEntity entity)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
await Clients.AllExcept(connectionId).SendAsync(XBaseEntityHubAction.Add.GetStringValue(), entity, connectionId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notify a New Entity added ...
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task AddOrUpdate(TEntity entity)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
await Clients.AllExcept(connectionId).SendAsync(XBaseEntityHubAction.AddOrUpdate.GetStringValue(), entity, connectionId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notify Add Many Entities ...
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task AddMany(IEnumerable<TEntity> entities)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
await Clients.AllExcept(connectionId).SendAsync(XBaseEntityHubAction.AddOrUpdate.GetStringValue(), entities.ToJSON(), connectionId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notify an Entity Deleted ...
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Delete(TEntity entity)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
await Clients.AllExcept(connectionId).SendAsync(XBaseEntityHubAction.Delete.GetStringValue(), entity, connectionId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notify Delete Many Entities ...
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task DeleteMany(IEnumerable<TEntity> entities)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
await Clients.AllExcept(connectionId).SendAsync(XBaseEntityHubAction.DeleteMany.GetStringValue(), entities.ToJSON(), connectionId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notify an Entity Updated ...
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Update(TEntity entity)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
await Clients.AllExcept(connectionId).SendAsync(XBaseEntityHubAction.Update.GetStringValue(), entity, connectionId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notify Update Many Entities ...
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task UpdateMany(IEnumerable<TEntity> entities)
|
||||
{
|
||||
//
|
||||
var connectionId = Context.ConnectionId;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
await Clients.AllExcept(connectionId).SendAsync(XBaseEntityHubAction.UpdateMany.GetStringValue(), entities.ToJSON(), connectionId);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user