forked from ddrilling/AsbCloudServer
Метод CreateReport внутри ReportsHub для скачивания отчета и одновременной подписки
This commit is contained in:
parent
c28ea98569
commit
82e7ff8cb4
@ -1,8 +1,9 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudInfrastructure.Background;
|
||||
using AsbCloudWebApi.SignalR.Clients;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -17,39 +18,44 @@ namespace AsbCloudWebApi.SignalR
|
||||
[Authorize]
|
||||
public class ReportsHub : BaseHub<IReportHubClient>
|
||||
{
|
||||
private readonly BackgroundWorker backgroundWorker;
|
||||
private readonly IWellService wellService;
|
||||
private readonly IReportService reportService;
|
||||
|
||||
public ReportsHub(BackgroundWorker backgroundWorker)
|
||||
public ReportsHub(IWellService wellService, IReportService reportService)
|
||||
{
|
||||
this.backgroundWorker = backgroundWorker;
|
||||
this.wellService = wellService;
|
||||
this.reportService = reportService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление в группу, отправка данных о формировании отчета
|
||||
/// </summary>
|
||||
/// <param name="groupName"></param>
|
||||
/// <param name="groupName">группа</param>
|
||||
/// <param name="idWell">ключ скважины</param>
|
||||
/// <param name="request">параметры запроса</param>
|
||||
/// <returns></returns>
|
||||
public override async Task AddToGroup(string groupName)
|
||||
public async Task CreateReport(string groupName, int idWell, ReportParametersRequest request)
|
||||
{
|
||||
var idUser = Context.User?.GetUserId();
|
||||
var idCompany = Context.User?.GetCompanyId();
|
||||
|
||||
if ((idCompany is null) || (idUser is null))
|
||||
return;
|
||||
|
||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, CancellationToken.None).ConfigureAwait(false))
|
||||
return;
|
||||
|
||||
await base.AddToGroup(groupName);
|
||||
|
||||
var workId = groupName.Replace("Report_", "");
|
||||
var work = backgroundWorker.Works.FirstOrDefault(work => work.Id == workId);
|
||||
|
||||
var progress = new ReportProgressDto()
|
||||
void HandleReportProgressAsync(object progress, string id) =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
Operation = "Ожидает начала в очереди.",
|
||||
Progress = 0f,
|
||||
};
|
||||
await Clients.Group(groupName)
|
||||
.GetReportProgress(progress, CancellationToken.None);
|
||||
}, CancellationToken.None);
|
||||
|
||||
var state = work?.CurrentState;
|
||||
if (state is not null)
|
||||
{
|
||||
progress.Operation = state.State;
|
||||
progress.Progress = (float)state.Progress;
|
||||
}
|
||||
|
||||
await Clients.Group(groupName).GetReportProgress(progress, CancellationToken.None);
|
||||
var id = reportService.EnqueueCreateReportWork(idWell, (int)idUser,
|
||||
request.StepSeconds, request.Format, request.Begin, request.End, HandleReportProgressAsync);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user