Фиксы

На клиенте нет возможности передавать аргументы в функции. Сделал реализацию через группы
This commit is contained in:
parent 4541fb42a9
commit c50878f5f1
2 changed files with 12 additions and 16 deletions

View File

@ -11,10 +11,8 @@ using Microsoft.AspNetCore.SignalR;
namespace AsbCloudWebApi.SignalR;
public class WellHub : Hub, IIntegrationEventHandler<UpdateWellEvent>
public class WellHub : BaseHub, IIntegrationEventHandler<UpdateWellEvent>
{
private const string groupTemplate = "update_id_well_{0}";
private readonly IHubContext<WellHub> hubContext;
private readonly IWellService wellService;
private readonly IWellOperationRepository wellOperationRepository;
@ -28,11 +26,11 @@ public class WellHub : Hub, IIntegrationEventHandler<UpdateWellEvent>
this.wellOperationRepository = wellOperationRepository;
}
public async Task OnConnectedAsync(int idWell)
public override async Task AddToGroup(string groupName)
{
await base.OnConnectedAsync();
await Groups.AddToGroupAsync(Context.ConnectionId, string.Format(groupTemplate, idWell));
var idWell = int.Parse(groupName.Split('_')[1]);
await Groups.AddToGroupAsync(Context.ConnectionId, groupName);
await HandleAsync(new UpdateWellEvent(idWell), CancellationToken.None);
}
@ -52,7 +50,7 @@ public class WellHub : Hub, IIntegrationEventHandler<UpdateWellEvent>
OperationType = WellOperation.IdOperationTypeFact
}, cancellationToken)).MaxBy(o => o.DateStart)?.WellSectionTypeName;
await hubContext.Clients.Group(string.Format(groupTemplate, integrationEvent.IdWell))
await hubContext.Clients.Group($"well_{integrationEvent.IdWell}")
.SendAsync(method, new object[] { well }, cancellationToken);
}
}

View File

@ -7,10 +7,8 @@ using Microsoft.AspNetCore.SignalR;
namespace AsbCloudWebApi.SignalR;
public class WellInfoHub : Hub, IIntegrationEventHandler<UpdateWellInfoEvent>
public class WellInfoHub : BaseHub, IIntegrationEventHandler<UpdateWellInfoEvent>
{
private const string groupTemplate = "well_info_id_well_{0}";
private readonly IHubContext<WellInfoHub> hubContext;
private readonly WellInfoService wellInfoService;
@ -21,11 +19,11 @@ public class WellInfoHub : Hub, IIntegrationEventHandler<UpdateWellInfoEvent>
this.wellInfoService = wellInfoService;
}
public async Task OnConnectedAsync(int idWell)
public override async Task AddToGroup(string groupName)
{
await base.OnConnectedAsync();
await Groups.AddToGroupAsync(Context.ConnectionId, string.Format(groupTemplate, idWell));
var idWell = int.Parse(groupName.Split('_')[2]);
await Groups.AddToGroupAsync(Context.ConnectionId, groupName);
await HandleAsync(new UpdateWellInfoEvent(idWell), CancellationToken.None);
}
@ -39,7 +37,7 @@ public class WellInfoHub : Hub, IIntegrationEventHandler<UpdateWellInfoEvent>
if (wellInfo is null)
return;
await hubContext.Clients.Group(string.Format(groupTemplate, integrationEvent.IdWell))
await hubContext.Clients.Group($"well_info_{integrationEvent.IdWell}")
.SendAsync(method, wellInfo, cancellationToken);
}
}