forked from ddrilling/AsbCloudServer
Степанов Дмитрий Александрович
c50878f5f1
На клиенте нет возможности передавать аргументы в функции. Сделал реализацию через группы
43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using AsbCloudApp.IntegrationEvents;
|
|
using AsbCloudApp.IntegrationEvents.Interfaces;
|
|
using AsbCloudInfrastructure.Services;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
namespace AsbCloudWebApi.SignalR;
|
|
|
|
public class WellInfoHub : BaseHub, IIntegrationEventHandler<UpdateWellInfoEvent>
|
|
{
|
|
private readonly IHubContext<WellInfoHub> hubContext;
|
|
private readonly WellInfoService wellInfoService;
|
|
|
|
public WellInfoHub(IHubContext<WellInfoHub> hubContext,
|
|
WellInfoService wellInfoService)
|
|
{
|
|
this.hubContext = hubContext;
|
|
this.wellInfoService = wellInfoService;
|
|
}
|
|
|
|
public override async Task AddToGroup(string groupName)
|
|
{
|
|
var idWell = int.Parse(groupName.Split('_')[2]);
|
|
|
|
await Groups.AddToGroupAsync(Context.ConnectionId, groupName);
|
|
|
|
await HandleAsync(new UpdateWellInfoEvent(idWell), CancellationToken.None);
|
|
}
|
|
|
|
public async Task HandleAsync(UpdateWellInfoEvent integrationEvent, CancellationToken cancellationToken)
|
|
{
|
|
const string method = "update_well_info";
|
|
|
|
var wellInfo = wellInfoService.FirstOrDefault(w => w.Id == integrationEvent.IdWell);
|
|
|
|
if (wellInfo is null)
|
|
return;
|
|
|
|
await hubContext.Clients.Group($"well_info_{integrationEvent.IdWell}")
|
|
.SendAsync(method, wellInfo, cancellationToken);
|
|
}
|
|
} |