271 lines
8.4 KiB
C#
271 lines
8.4 KiB
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using Microsoft.Extensions.Logging;
|
|
using xAiModels.Constants;
|
|
using xAiModels.Models.Dtos;
|
|
using xCommons.Extensions;
|
|
using xPushService.Base;
|
|
|
|
namespace xAiModels.Providers.Hubs
|
|
{
|
|
public class XAiDataProviderHub : XBaseHub
|
|
{
|
|
public XAiDataProviderHub(
|
|
ILogger<XBaseHub> logger
|
|
) : base(logger)
|
|
{ }
|
|
|
|
//
|
|
#region XAiProject ...
|
|
/// <summary>
|
|
/// Notify a New Item Created ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task ProjectCreated(
|
|
XAiProjectDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var connectionId = Context.ConnectionId;
|
|
if (!connectionId.IsNullOrEmpty())
|
|
{
|
|
//
|
|
await Clients
|
|
.AllExcept(connectionId)
|
|
.SendAsync(
|
|
XAiDataProviderHubActions.ProjectCreated.GetStringValue(),
|
|
item.ToJSON(camelCase: true),
|
|
connectionId,
|
|
cancellationToken
|
|
);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Notify an Item Removed ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task ProjectRemoved(
|
|
XAiProjectDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var connectionId = Context.ConnectionId;
|
|
if (!connectionId.IsNullOrEmpty())
|
|
{
|
|
//
|
|
await Clients
|
|
.AllExcept(connectionId)
|
|
.SendAsync(
|
|
XAiDataProviderHubActions.ProjectRemoved.GetStringValue(),
|
|
item.ToJSON(camelCase: true),
|
|
connectionId,
|
|
cancellationToken
|
|
);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Notify an Item Updated ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task ProjectUpdated(
|
|
XAiProjectDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var connectionId = Context.ConnectionId;
|
|
if (!connectionId.IsNullOrEmpty())
|
|
{
|
|
//
|
|
await Clients
|
|
.AllExcept(connectionId)
|
|
.SendAsync(
|
|
XAiDataProviderHubActions.ProjectUpdated.GetStringValue(),
|
|
item.ToJSON(camelCase: true),
|
|
connectionId,
|
|
cancellationToken
|
|
);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region XAiConversation ...
|
|
/// <summary>
|
|
/// Notify a New Item Created ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task ConversationCreated(
|
|
XAiProjectDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var connectionId = Context.ConnectionId;
|
|
if (!connectionId.IsNullOrEmpty())
|
|
{
|
|
//
|
|
await Clients
|
|
.AllExcept(connectionId)
|
|
.SendAsync(
|
|
XAiDataProviderHubActions.ConversationCreated.GetStringValue(),
|
|
item.ToJSON(camelCase: true),
|
|
connectionId,
|
|
cancellationToken
|
|
);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Notify an Item Removed ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task ConversationRemoved(
|
|
XAiProjectDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var connectionId = Context.ConnectionId;
|
|
if (!connectionId.IsNullOrEmpty())
|
|
{
|
|
//
|
|
await Clients
|
|
.AllExcept(connectionId)
|
|
.SendAsync(
|
|
XAiDataProviderHubActions.ConversationRemoved.GetStringValue(),
|
|
item.ToJSON(camelCase: true),
|
|
connectionId,
|
|
cancellationToken
|
|
);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Notify an Item Updated ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task ConversationUpdated(
|
|
XAiProjectDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var connectionId = Context.ConnectionId;
|
|
if (!connectionId.IsNullOrEmpty())
|
|
{
|
|
//
|
|
await Clients
|
|
.AllExcept(connectionId)
|
|
.SendAsync(
|
|
XAiDataProviderHubActions.ConversationUpdated.GetStringValue(),
|
|
item.ToJSON(camelCase: true),
|
|
connectionId,
|
|
cancellationToken
|
|
);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region XAiMessage ...
|
|
/// <summary>
|
|
/// Notify a New Item Created ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task MessageCreated(
|
|
XAiProjectDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var connectionId = Context.ConnectionId;
|
|
if (!connectionId.IsNullOrEmpty())
|
|
{
|
|
//
|
|
await Clients
|
|
.AllExcept(connectionId)
|
|
.SendAsync(
|
|
XAiDataProviderHubActions.MessageCreated.GetStringValue(),
|
|
item.ToJSON(camelCase: true),
|
|
connectionId,
|
|
cancellationToken
|
|
);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Notify an Item Removed ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task MessageRemoved(
|
|
XAiProjectDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var connectionId = Context.ConnectionId;
|
|
if (!connectionId.IsNullOrEmpty())
|
|
{
|
|
//
|
|
await Clients
|
|
.AllExcept(connectionId)
|
|
.SendAsync(
|
|
XAiDataProviderHubActions.MessageRemoved.GetStringValue(),
|
|
item.ToJSON(camelCase: true),
|
|
connectionId,
|
|
cancellationToken
|
|
);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Notify an Item Updated ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task MessageUpdated(
|
|
XAiProjectDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var connectionId = Context.ConnectionId;
|
|
if (!connectionId.IsNullOrEmpty())
|
|
{
|
|
//
|
|
await Clients
|
|
.AllExcept(connectionId)
|
|
.SendAsync(
|
|
XAiDataProviderHubActions.MessageUpdated.GetStringValue(),
|
|
item.ToJSON(camelCase: true),
|
|
connectionId,
|
|
cancellationToken
|
|
);
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |