Правка по результатам ревью

This commit is contained in:
Olga Nemt 2023-11-09 15:18:07 +05:00
parent 11163bf977
commit 107a81f24d
7 changed files with 68 additions and 24 deletions

View File

@ -2,6 +2,7 @@
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudWebApi.SignalR; using AsbCloudWebApi.SignalR;
using AsbCloudWebApi.SignalR.Clients;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
@ -23,20 +24,22 @@ namespace AsbCloudWebApi.Controllers.SAUB
protected readonly IWellService wellService; protected readonly IWellService wellService;
private readonly ITelemetryService telemetryService; private readonly ITelemetryService telemetryService;
private readonly ITelemetryDataService<TDto> telemetryDataService; private readonly ITelemetryDataService<TDto> telemetryDataService;
private readonly IHubContext<TelemetryHub> telemetryHubContext; protected readonly IHubContext<TelemetryHub, ITelemetryHubClient> telemetryHubContext;
public Action<int?, IEnumerable<TDto>> SignalrReceiveDataOperation { get; set; }
public string SignalRMethodGetDataName { get; protected set; } = "ReceiveData";
public TelemetryDataBaseController( public TelemetryDataBaseController(
ITelemetryService telemetryService, ITelemetryService telemetryService,
ITelemetryDataService<TDto> telemetryDataService, ITelemetryDataService<TDto> telemetryDataService,
IWellService wellService, IWellService wellService,
IHubContext<TelemetryHub> telemetryHubContext) IHubContext<TelemetryHub, ITelemetryHubClient> telemetryHubContext)
{ {
this.telemetryService = telemetryService; this.telemetryService = telemetryService;
this.telemetryDataService = telemetryDataService; this.telemetryDataService = telemetryDataService;
this.wellService = wellService; this.wellService = wellService;
this.telemetryHubContext = telemetryHubContext; this.telemetryHubContext = telemetryHubContext;
this.SignalrReceiveDataOperation = (int? idWell, IEnumerable<TDto> dtos) => {
telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveData<TDto>(dtos, CancellationToken.None);
};
} }
/// <summary> /// <summary>
@ -55,8 +58,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
var idWell = telemetryService.GetIdWellByTelemetryUid(uid); var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
if (idWell is not null && dtos.Any()) if (idWell is not null && dtos.Any())
_ = Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}") _ = Task.Run(() => SignalrReceiveDataOperation.Invoke(idWell, dtos));
.SendAsync(SignalRMethodGetDataName, dtos), CancellationToken.None);
return Ok(); return Ok();
} }

View File

@ -1,12 +1,14 @@
using AsbCloudApp.Data.SAUB; using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudWebApi.SignalR; using AsbCloudWebApi.SignalR;
using AsbCloudWebApi.SignalR.Clients;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;
using System.Threading;
using System; using System;
using Microsoft.AspNetCore.Http; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers.SAUB namespace AsbCloudWebApi.Controllers.SAUB
{ {
@ -23,14 +25,16 @@ namespace AsbCloudWebApi.Controllers.SAUB
ITelemetryService telemetryService, ITelemetryService telemetryService,
ITelemetryDataSaubService telemetryDataService, ITelemetryDataSaubService telemetryDataService,
IWellService wellService, IWellService wellService,
IHubContext<TelemetryHub> telemetryHubContext) IHubContext<TelemetryHub, ITelemetryHubClient> telemetryHubContext)
: base( : base(
telemetryService, telemetryService,
telemetryDataService, telemetryDataService,
wellService, wellService,
telemetryHubContext) telemetryHubContext)
{ {
SignalRMethodGetDataName = "ReceiveDataSaub"; SignalrReceiveDataOperation = (int? idWell, IEnumerable<TelemetryDataSaubDto> dtos) => {
telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataSaub<TelemetryDataSaubDto>(dtos, CancellationToken.None);
};
telemetryDataSaubService = telemetryDataService; telemetryDataSaubService = telemetryDataService;
} }

View File

@ -1,8 +1,11 @@
using AsbCloudApp.Data.SAUB; using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudWebApi.SignalR; using AsbCloudWebApi.SignalR;
using AsbCloudWebApi.SignalR.Clients;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using System.Collections.Generic;
using System.Threading;
namespace AsbCloudWebApi.Controllers.SAUB namespace AsbCloudWebApi.Controllers.SAUB
{ {
@ -17,14 +20,16 @@ namespace AsbCloudWebApi.Controllers.SAUB
ITelemetryService telemetryService, ITelemetryService telemetryService,
ITelemetryDataService<TelemetryDataSpinDto> telemetryDataService, ITelemetryDataService<TelemetryDataSpinDto> telemetryDataService,
IWellService wellService, IWellService wellService,
IHubContext<TelemetryHub> telemetryHubContext) IHubContext<TelemetryHub, ITelemetryHubClient> telemetryHubContext)
: base( : base(
telemetryService, telemetryService,
telemetryDataService, telemetryDataService,
wellService, wellService,
telemetryHubContext) telemetryHubContext)
{ {
SignalRMethodGetDataName = "ReceiveDataSpin"; SignalrReceiveDataOperation = (int? idWell, IEnumerable<TelemetryDataSpinDto> dtos) => {
telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataSpin<TelemetryDataSpinDto>(dtos, CancellationToken.None);
};
} }
} }
} }

View File

@ -12,11 +12,12 @@ namespace AsbCloudWebApi.SignalR.Clients
public interface INotificationHubClient public interface INotificationHubClient
{ {
/// <summary> /// <summary>
/// Отправка клиенту сообщения с уведомлением /// Отправка клиенту сообщения с уведомлением.
/// Для подписки на метод необходимо отправить connectionId
/// </summary> /// </summary>
/// <param name="message">сообщение с уведомлением</param> /// <param name="message">сообщение с уведомлением</param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task ReceiveNotifications(NotificationMessage message, CancellationToken token = default); Task ReceiveNotifications(NotificationMessage message, CancellationToken token);
} }
} }

View File

@ -11,7 +11,8 @@ namespace AsbCloudWebApi.SignalR.Clients
public interface IReportHubClient public interface IReportHubClient
{ {
/// <summary> /// <summary>
/// Отправка клиенту сообщения о статусе формирования отчета /// Отправка клиенту сообщения о статусе формирования отчета.
/// Для подписки на метод необходимо отправить сообщение в формате $"Report_{id}"
/// </summary> /// </summary>
/// <param name="progress">статус формирования отчета</param> /// <param name="progress">статус формирования отчета</param>
/// <param name="token"></param> /// <param name="token"></param>

View File

@ -1,8 +1,6 @@
using AsbCloudApp.Data; using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Data.SAUB;
using SignalRSwaggerGen.Attributes; using SignalRSwaggerGen.Attributes;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -15,12 +13,13 @@ namespace AsbCloudWebApi.SignalR.Clients
public interface ITelemetryHubClient public interface ITelemetryHubClient
{ {
/// <summary> /// <summary>
/// Отправка клиенту уведомления о доставке с панели drill test данных /// Отправка клиенту уведомления о доставке с панели drill test данных.
/// Для подписки на метод необходимо отправить сообщение в формате $"well_{idWell}"
/// </summary> /// </summary>
/// <param name="dto"></param> /// <param name="dto"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task ReceiveDrilltestData(DrillTestDto dto, CancellationToken token = default); Task ReceiveDrilltestData(DrillTestDto dto, CancellationToken token);
/// <summary> /// <summary>
/// ///
@ -29,6 +28,37 @@ namespace AsbCloudWebApi.SignalR.Clients
/// <param name="dtos"></param> /// <param name="dtos"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task UpdateProcessMap<T>(IEnumerable dtos, CancellationToken token = default); Task UpdateProcessMap<T>(IEnumerable dtos, CancellationToken token);
/// <summary>
/// Отправка данных клиенту.
/// Для подписки на метод необходимо отправить сообщение в формате $"well_{idWell}"
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task ReceiveData<T>(IEnumerable dtos, CancellationToken token);
/// <summary>
/// Отправка сауб-данных клиенту.
/// Для подписки на метод необходимо отправить сообщение в формате $"well_{idWell}"
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task ReceiveDataSaub<T>(IEnumerable dtos, CancellationToken token);
/// <summary>
/// Отправка спин-данных клиенту.
/// Для подписки на метод необходимо отправить сообщение в формате $"well_{idWell}"
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task ReceiveDataSpin<T>(IEnumerable dtos, CancellationToken token);
} }
} }

View File

@ -13,10 +13,11 @@ namespace AsbCloudWebApi.SignalR.Clients
{ {
/// <summary> /// <summary>
/// Отправка клиенту сообщения об обновлении информации о скважине /// Отправка клиенту сообщения об обновлении информации о скважине
/// Для подписки на метод необходимо отправить сообщение в формате $"well_info_{idWell}"
/// </summary> /// </summary>
/// <param name="wellInfo">информация о скважине</param> /// <param name="wellInfo">информация о скважине</param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task UpdateWellInfo(object wellInfo, CancellationToken token = default); Task UpdateWellInfo(object wellInfo, CancellationToken token);
} }
} }