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 ...
|
#region Actions ...
|
||||||
|
public async Task SendCustomAction(string actionName, string payLoad)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var connectionId = Context.ConnectionId;
|
||||||
|
await Clients.AllExcept(connectionId).SendAsync(actionName, payLoad, connectionId);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,4 +31,25 @@ namespace xPushService.Constants
|
|||||||
[StringValue("Candidate")]
|
[StringValue("Candidate")]
|
||||||
Candidate,
|
Candidate,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides All Actions Based on Entities ...
|
||||||
|
/// </summary>
|
||||||
|
public enum XBaseEntityHubAction
|
||||||
|
{
|
||||||
|
[StringValue("Add")]
|
||||||
|
Add,
|
||||||
|
[StringValue("AddOrUpdate")]
|
||||||
|
AddOrUpdate,
|
||||||
|
[StringValue("AddMany")]
|
||||||
|
AddMany,
|
||||||
|
[StringValue("Update")]
|
||||||
|
Update,
|
||||||
|
[StringValue("UpdateMany")]
|
||||||
|
UpdateMany,
|
||||||
|
[StringValue("Delete")]
|
||||||
|
Delete,
|
||||||
|
[StringValue("DeleteMany")]
|
||||||
|
DeleteMany,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+5
-3
@@ -25,14 +25,16 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="xDashboard.xModels" Version="1.0.0" />
|
<PackageReference Include="xDashboard.xModels" Version="1.0.0" />
|
||||||
<PackageReference Include="xDashboard.xCommons" Version="1.0.0" />
|
<PackageReference Include="xDashboard.xCommons" Version="1.0.0" />
|
||||||
<PackageReference Include="xDashboard.xIdentityService" Version="1.0.0" />
|
<!-- <PackageReference Include="xDashboard.xIdentityService" Version="1.0.0" /> -->
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Local Dependencies -->
|
<!-- Local Dependencies -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- <ProjectReference Include="..\xModels\xModels.csproj" />
|
<!--
|
||||||
|
<ProjectReference Include="..\xModels\xModels.csproj" />
|
||||||
<ProjectReference Include="..\xCommons\xCommons.csproj" />
|
<ProjectReference Include="..\xCommons\xCommons.csproj" />
|
||||||
<ProjectReference Include="..\xIdentityService\xIdentityService.csproj" /> -->
|
-->
|
||||||
|
<ProjectReference Include="..\xIdentityService\xIdentityService.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Package Dependencies -->
|
<!-- Package Dependencies -->
|
||||||
|
|||||||
Reference in New Issue
Block a user