forked from ddrilling/AsbCloudServer
Фиксы
На клиенте нет возможности передавать аргументы в функции. Сделал реализацию через группы
This commit is contained in:
parent
4541fb42a9
commit
c50878f5f1
@ -11,10 +11,8 @@ using Microsoft.AspNetCore.SignalR;
|
|||||||
|
|
||||||
namespace AsbCloudWebApi.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 IHubContext<WellHub> hubContext;
|
||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
private readonly IWellOperationRepository wellOperationRepository;
|
private readonly IWellOperationRepository wellOperationRepository;
|
||||||
@ -28,11 +26,11 @@ public class WellHub : Hub, IIntegrationEventHandler<UpdateWellEvent>
|
|||||||
this.wellOperationRepository = wellOperationRepository;
|
this.wellOperationRepository = wellOperationRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task OnConnectedAsync(int idWell)
|
public override async Task AddToGroup(string groupName)
|
||||||
{
|
{
|
||||||
await base.OnConnectedAsync();
|
var idWell = int.Parse(groupName.Split('_')[1]);
|
||||||
|
|
||||||
await Groups.AddToGroupAsync(Context.ConnectionId, string.Format(groupTemplate, idWell));
|
await Groups.AddToGroupAsync(Context.ConnectionId, groupName);
|
||||||
|
|
||||||
await HandleAsync(new UpdateWellEvent(idWell), CancellationToken.None);
|
await HandleAsync(new UpdateWellEvent(idWell), CancellationToken.None);
|
||||||
}
|
}
|
||||||
@ -52,7 +50,7 @@ public class WellHub : Hub, IIntegrationEventHandler<UpdateWellEvent>
|
|||||||
OperationType = WellOperation.IdOperationTypeFact
|
OperationType = WellOperation.IdOperationTypeFact
|
||||||
}, cancellationToken)).MaxBy(o => o.DateStart)?.WellSectionTypeName;
|
}, 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);
|
.SendAsync(method, new object[] { well }, cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,10 +7,8 @@ using Microsoft.AspNetCore.SignalR;
|
|||||||
|
|
||||||
namespace AsbCloudWebApi.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 IHubContext<WellInfoHub> hubContext;
|
||||||
private readonly WellInfoService wellInfoService;
|
private readonly WellInfoService wellInfoService;
|
||||||
|
|
||||||
@ -21,11 +19,11 @@ public class WellInfoHub : Hub, IIntegrationEventHandler<UpdateWellInfoEvent>
|
|||||||
this.wellInfoService = wellInfoService;
|
this.wellInfoService = wellInfoService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task OnConnectedAsync(int idWell)
|
public override async Task AddToGroup(string groupName)
|
||||||
{
|
{
|
||||||
await base.OnConnectedAsync();
|
var idWell = int.Parse(groupName.Split('_')[2]);
|
||||||
|
|
||||||
await Groups.AddToGroupAsync(Context.ConnectionId, string.Format(groupTemplate, idWell));
|
await Groups.AddToGroupAsync(Context.ConnectionId, groupName);
|
||||||
|
|
||||||
await HandleAsync(new UpdateWellInfoEvent(idWell), CancellationToken.None);
|
await HandleAsync(new UpdateWellInfoEvent(idWell), CancellationToken.None);
|
||||||
}
|
}
|
||||||
@ -39,7 +37,7 @@ public class WellInfoHub : Hub, IIntegrationEventHandler<UpdateWellInfoEvent>
|
|||||||
if (wellInfo is null)
|
if (wellInfo is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await hubContext.Clients.Group(string.Format(groupTemplate, integrationEvent.IdWell))
|
await hubContext.Clients.Group($"well_info_{integrationEvent.IdWell}")
|
||||||
.SendAsync(method, wellInfo, cancellationToken);
|
.SendAsync(method, wellInfo, cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user