From 030222311abe06ddd341cfeae0d7e7aafca78794 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Thu, 9 Nov 2023 15:55:49 +0500 Subject: [PATCH] nit --- .../SAUB/TelemetryDataBaseController.cs | 9 ++++----- .../SAUB/TelemetryDataSaubController.cs | 8 +++++--- .../SAUB/TelemetryDataSpinController.cs | 8 +++++--- AsbCloudWebApi/DependencyInjection.cs | 11 ++++++----- .../SignalR/Clients/ITelemetryHubClient.cs | 18 +++++------------- 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/AsbCloudWebApi/Controllers/SAUB/TelemetryDataBaseController.cs b/AsbCloudWebApi/Controllers/SAUB/TelemetryDataBaseController.cs index 9c04bd58..57a97043 100644 --- a/AsbCloudWebApi/Controllers/SAUB/TelemetryDataBaseController.cs +++ b/AsbCloudWebApi/Controllers/SAUB/TelemetryDataBaseController.cs @@ -25,7 +25,6 @@ namespace AsbCloudWebApi.Controllers.SAUB private readonly ITelemetryService telemetryService; private readonly ITelemetryDataService telemetryDataService; protected readonly IHubContext telemetryHubContext; - public Action> SignalrReceiveDataOperation { get; set; } public TelemetryDataBaseController( ITelemetryService telemetryService, @@ -37,11 +36,11 @@ namespace AsbCloudWebApi.Controllers.SAUB this.telemetryDataService = telemetryDataService; this.wellService = wellService; this.telemetryHubContext = telemetryHubContext; - this.SignalrReceiveDataOperation = (int? idWell, IEnumerable dtos) => { - telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveData(dtos, CancellationToken.None); - }; + } + protected abstract Task SignalRNotifyAsync(int idWell, IEnumerable dtos, CancellationToken token); + /// /// Принимает данные от разных систем по скважине /// @@ -58,7 +57,7 @@ namespace AsbCloudWebApi.Controllers.SAUB var idWell = telemetryService.GetIdWellByTelemetryUid(uid); if (idWell is not null && dtos.Any()) - _ = Task.Run(() => SignalrReceiveDataOperation.Invoke(idWell, dtos)); + _ = Task.Run(() => SignalRNotifyAsync(idWell.Value, dtos, CancellationToken.None)); return Ok(); } diff --git a/AsbCloudWebApi/Controllers/SAUB/TelemetryDataSaubController.cs b/AsbCloudWebApi/Controllers/SAUB/TelemetryDataSaubController.cs index 6cee68c0..e3791655 100644 --- a/AsbCloudWebApi/Controllers/SAUB/TelemetryDataSaubController.cs +++ b/AsbCloudWebApi/Controllers/SAUB/TelemetryDataSaubController.cs @@ -32,9 +32,6 @@ namespace AsbCloudWebApi.Controllers.SAUB wellService, telemetryHubContext) { - SignalrReceiveDataOperation = (int? idWell, IEnumerable dtos) => { - telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataSaub(dtos, CancellationToken.None); - }; telemetryDataSaubService = telemetryDataService; } @@ -66,5 +63,10 @@ namespace AsbCloudWebApi.Controllers.SAUB var fileName = $"DataSaub idWell{idWell} {beginDate:yyyy-MM-DDTHH-mm} - {endDate:yyyy-MM-DDTHH-mm}.zip"; return File(stream, "application/octet-stream", fileName); } + + protected override Task SignalRNotifyAsync(int idWell, IEnumerable dtos, CancellationToken token) + { + return telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataSaub(dtos, token); + } } } diff --git a/AsbCloudWebApi/Controllers/SAUB/TelemetryDataSpinController.cs b/AsbCloudWebApi/Controllers/SAUB/TelemetryDataSpinController.cs index 05ae423f..9c81af02 100644 --- a/AsbCloudWebApi/Controllers/SAUB/TelemetryDataSpinController.cs +++ b/AsbCloudWebApi/Controllers/SAUB/TelemetryDataSpinController.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; using System.Collections.Generic; using System.Threading; +using System.Threading.Tasks; namespace AsbCloudWebApi.Controllers.SAUB { @@ -26,10 +27,11 @@ namespace AsbCloudWebApi.Controllers.SAUB telemetryDataService, wellService, telemetryHubContext) + {} + + protected override Task SignalRNotifyAsync(int idWell, IEnumerable dtos, CancellationToken token) { - SignalrReceiveDataOperation = (int? idWell, IEnumerable dtos) => { - telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataSpin(dtos, CancellationToken.None); - }; + return telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataSpin(dtos, token); } } } diff --git a/AsbCloudWebApi/DependencyInjection.cs b/AsbCloudWebApi/DependencyInjection.cs index be2baf9b..788c661d 100644 --- a/AsbCloudWebApi/DependencyInjection.cs +++ b/AsbCloudWebApi/DependencyInjection.cs @@ -19,6 +19,7 @@ using AsbCloudWebApi.SignalR; using AsbCloudWebApi.SignalR.Services; using Microsoft.AspNetCore.Mvc; using Microsoft.OpenApi.Any; +using Swashbuckle.AspNetCore.SwaggerGen; namespace AsbCloudWebApi { @@ -80,11 +81,11 @@ namespace AsbCloudWebApi c.IncludeXmlComments(xmlPath, includeControllerXmlComment); c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "AsbCloudApp.xml"), includeControllerXmlComment); - c.AddSignalRSwaggerGen((_) => { - _.DisplayInDocument("signalr"); - _.UseHubXmlCommentsSummaryAsTagDescription = true; - _.UseHubXmlCommentsSummaryAsTag = true; - _.UseXmlComments(xmlPath); + c.AddSignalRSwaggerGen(options => { + options.DisplayInDocument("signalr"); + options.UseHubXmlCommentsSummaryAsTagDescription = true; + options.UseHubXmlCommentsSummaryAsTag = true; + options.UseXmlComments(xmlPath); }); }); } diff --git a/AsbCloudWebApi/SignalR/Clients/ITelemetryHubClient.cs b/AsbCloudWebApi/SignalR/Clients/ITelemetryHubClient.cs index 6e1578be..d0933bbb 100644 --- a/AsbCloudWebApi/SignalR/Clients/ITelemetryHubClient.cs +++ b/AsbCloudWebApi/SignalR/Clients/ITelemetryHubClient.cs @@ -1,6 +1,8 @@ using AsbCloudApp.Data.SAUB; +using Microsoft.AspNetCore.Mvc; using SignalRSwaggerGen.Attributes; using System.Collections; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -28,17 +30,7 @@ namespace AsbCloudWebApi.SignalR.Clients /// /// /// - Task UpdateProcessMap(IEnumerable dtos, CancellationToken token); - - /// - /// Отправка данных клиенту. - /// Для подписки на метод необходимо отправить сообщение в формате $"well_{idWell}" - /// - /// - /// - /// - /// - Task ReceiveData(IEnumerable dtos, CancellationToken token); + Task UpdateProcessMap(IEnumerable dtos, CancellationToken token); /// /// Отправка сауб-данных клиенту. @@ -48,7 +40,7 @@ namespace AsbCloudWebApi.SignalR.Clients /// /// /// - Task ReceiveDataSaub(IEnumerable dtos, CancellationToken token); + Task ReceiveDataSaub(IEnumerable dtos, CancellationToken token); /// /// Отправка спин-данных клиенту. @@ -58,7 +50,7 @@ namespace AsbCloudWebApi.SignalR.Clients /// /// /// - Task ReceiveDataSpin(IEnumerable dtos, CancellationToken token); + Task ReceiveDataSpin(IEnumerable dtos, CancellationToken token); } }