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 ITelemetryDataService<TDto> telemetryDataService;
protected readonly IHubContext<TelemetryHub, ITelemetryHubClient> telemetryHubContext;
public Action<int?, IEnumerable<TDto>> 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<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>
@ -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();
}

View File

@ -32,9 +32,6 @@ namespace AsbCloudWebApi.Controllers.SAUB
wellService,
telemetryHubContext)
{
SignalrReceiveDataOperation = (int? idWell, IEnumerable<TelemetryDataSaubDto> dtos) => {
telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataSaub<TelemetryDataSaubDto>(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<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 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<TelemetryDataSpinDto> dtos, CancellationToken token)
{
SignalrReceiveDataOperation = (int? idWell, IEnumerable<TelemetryDataSpinDto> dtos) => {
telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataSpin<TelemetryDataSpinDto>(dtos, CancellationToken.None);
};
return telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataSpin(dtos, token);
}
}
}

View File

@ -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);
});
});
}

View File

@ -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
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
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);
Task UpdateProcessMap<T>(IEnumerable<T> dtos, CancellationToken token);
/// <summary>
/// Отправка сауб-данных клиенту.
@ -48,7 +40,7 @@ namespace AsbCloudWebApi.SignalR.Clients
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task ReceiveDataSaub<T>(IEnumerable dtos, CancellationToken token);
Task ReceiveDataSaub(IEnumerable<TelemetryDataSaubDto> dtos, CancellationToken token);
/// <summary>
/// Отправка спин-данных клиенту.
@ -58,7 +50,7 @@ namespace AsbCloudWebApi.SignalR.Clients
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task ReceiveDataSpin<T>(IEnumerable dtos, CancellationToken token);
Task ReceiveDataSpin(IEnumerable<TelemetryDataSpinDto> dtos, CancellationToken token);
}
}