This commit is contained in:
ngfrolov 2023-11-09 15:55:49 +05:00
parent 9cf113f640
commit 030222311a
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7
5 changed files with 25 additions and 29 deletions

View File

@ -25,7 +25,6 @@ namespace AsbCloudWebApi.Controllers.SAUB
private readonly ITelemetryService telemetryService; private readonly ITelemetryService telemetryService;
private readonly ITelemetryDataService<TDto> telemetryDataService; private readonly ITelemetryDataService<TDto> telemetryDataService;
protected readonly IHubContext<TelemetryHub, ITelemetryHubClient> telemetryHubContext; protected readonly IHubContext<TelemetryHub, ITelemetryHubClient> telemetryHubContext;
public Action<int?, IEnumerable<TDto>> SignalrReceiveDataOperation { get; set; }
public TelemetryDataBaseController( public TelemetryDataBaseController(
ITelemetryService telemetryService, ITelemetryService telemetryService,
@ -37,11 +36,11 @@ namespace AsbCloudWebApi.Controllers.SAUB
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);
};
} }
protected abstract Task SignalRNotifyAsync(int idWell, IEnumerable<TDto> dtos, CancellationToken token);
/// <summary> /// <summary>
/// Принимает данные от разных систем по скважине /// Принимает данные от разных систем по скважине
/// </summary> /// </summary>
@ -58,7 +57,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(() => SignalrReceiveDataOperation.Invoke(idWell, dtos)); _ = Task.Run(() => SignalRNotifyAsync(idWell.Value, dtos, CancellationToken.None));
return Ok(); return Ok();
} }

View File

@ -32,9 +32,6 @@ namespace AsbCloudWebApi.Controllers.SAUB
wellService, wellService,
telemetryHubContext) telemetryHubContext)
{ {
SignalrReceiveDataOperation = (int? idWell, IEnumerable<TelemetryDataSaubDto> dtos) => {
telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataSaub<TelemetryDataSaubDto>(dtos, CancellationToken.None);
};
telemetryDataSaubService = telemetryDataService; 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"; var fileName = $"DataSaub idWell{idWell} {beginDate:yyyy-MM-DDTHH-mm} - {endDate:yyyy-MM-DDTHH-mm}.zip";
return File(stream, "application/octet-stream", fileName); return File(stream, "application/octet-stream", fileName);
} }
protected override Task SignalRNotifyAsync(int idWell, IEnumerable<TelemetryDataSaubDto> dtos, CancellationToken token)
{
return telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataSaub(dtos, token);
}
} }
} }

View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers.SAUB namespace AsbCloudWebApi.Controllers.SAUB
{ {
@ -26,10 +27,11 @@ namespace AsbCloudWebApi.Controllers.SAUB
telemetryDataService, telemetryDataService,
wellService, wellService,
telemetryHubContext) telemetryHubContext)
{}
protected override Task SignalRNotifyAsync(int idWell, IEnumerable<TelemetryDataSpinDto> dtos, CancellationToken token)
{ {
SignalrReceiveDataOperation = (int? idWell, IEnumerable<TelemetryDataSpinDto> dtos) => { return telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataSpin(dtos, token);
telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataSpin<TelemetryDataSpinDto>(dtos, CancellationToken.None);
};
} }
} }
} }

View File

@ -19,6 +19,7 @@ using AsbCloudWebApi.SignalR;
using AsbCloudWebApi.SignalR.Services; using AsbCloudWebApi.SignalR.Services;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Any;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace AsbCloudWebApi namespace AsbCloudWebApi
{ {
@ -80,11 +81,11 @@ namespace AsbCloudWebApi
c.IncludeXmlComments(xmlPath, includeControllerXmlComment); c.IncludeXmlComments(xmlPath, includeControllerXmlComment);
c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "AsbCloudApp.xml"), includeControllerXmlComment); c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "AsbCloudApp.xml"), includeControllerXmlComment);
c.AddSignalRSwaggerGen((_) => { c.AddSignalRSwaggerGen(options => {
_.DisplayInDocument("signalr"); options.DisplayInDocument("signalr");
_.UseHubXmlCommentsSummaryAsTagDescription = true; options.UseHubXmlCommentsSummaryAsTagDescription = true;
_.UseHubXmlCommentsSummaryAsTag = true; options.UseHubXmlCommentsSummaryAsTag = true;
_.UseXmlComments(xmlPath); options.UseXmlComments(xmlPath);
}); });
}); });
} }

View File

@ -1,6 +1,8 @@
using AsbCloudApp.Data.SAUB; using AsbCloudApp.Data.SAUB;
using Microsoft.AspNetCore.Mvc;
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;
@ -28,17 +30,7 @@ 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); Task UpdateProcessMap<T>(IEnumerable<T> 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> /// <summary>
/// Отправка сауб-данных клиенту. /// Отправка сауб-данных клиенту.
@ -48,7 +40,7 @@ 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 ReceiveDataSaub<T>(IEnumerable dtos, CancellationToken token); Task ReceiveDataSaub(IEnumerable<TelemetryDataSaubDto> dtos, CancellationToken token);
/// <summary> /// <summary>
/// Отправка спин-данных клиенту. /// Отправка спин-данных клиенту.
@ -58,7 +50,7 @@ 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 ReceiveDataSpin<T>(IEnumerable dtos, CancellationToken token); Task ReceiveDataSpin(IEnumerable<TelemetryDataSpinDto> dtos, CancellationToken token);
} }
} }