2023-10-25 16:03:07 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudInfrastructure.Background;
|
2023-10-30 12:13:38 +05:00
|
|
|
|
using AsbCloudWebApi.SignalR.Clients;
|
2023-10-25 16:03:07 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-05-20 11:07:45 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.SignalR
|
|
|
|
|
{
|
|
|
|
|
// SignalR manual:
|
|
|
|
|
// https://docs.microsoft.com/ru-ru/aspnet/core/signalr/introduction?view=aspnetcore-5.0
|
2023-10-30 12:13:38 +05:00
|
|
|
|
//[SignalRHub]
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// ReportsHub
|
|
|
|
|
/// </summary>
|
2021-05-20 11:07:45 +05:00
|
|
|
|
[Authorize]
|
2023-10-30 12:33:42 +05:00
|
|
|
|
public class ReportsHub : BaseHub<IReportHubClient>
|
2021-05-20 11:07:45 +05:00
|
|
|
|
{
|
2023-10-25 16:03:07 +05:00
|
|
|
|
private readonly BackgroundWorker backgroundWorker;
|
|
|
|
|
|
2023-10-25 16:09:17 +05:00
|
|
|
|
public ReportsHub(BackgroundWorker backgroundWorker)
|
2023-10-25 16:03:07 +05:00
|
|
|
|
{
|
|
|
|
|
this.backgroundWorker = backgroundWorker;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 12:13:38 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление в группу, отправка данных о формировании отчета
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="groupName"></param>
|
|
|
|
|
/// <returns></returns>
|
2023-10-30 12:33:42 +05:00
|
|
|
|
public override async Task AddToGroup(string groupName)
|
2023-10-25 16:03:07 +05:00
|
|
|
|
{
|
2023-10-30 12:33:42 +05:00
|
|
|
|
await base.AddToGroup(groupName);
|
2023-10-25 16:12:35 +05:00
|
|
|
|
|
2023-10-25 16:03:07 +05:00
|
|
|
|
var workId = groupName.Replace("Report_", "");
|
2023-11-03 17:02:44 +05:00
|
|
|
|
var work = backgroundWorker.Works.FirstOrDefault(work => work.Id == workId);
|
2023-10-25 16:03:07 +05:00
|
|
|
|
|
|
|
|
|
var progress = new ReportProgressDto()
|
|
|
|
|
{
|
|
|
|
|
Operation = "Ожидает начала в очереди.",
|
|
|
|
|
Progress = 0f,
|
|
|
|
|
};
|
2023-10-25 16:12:35 +05:00
|
|
|
|
|
2023-10-30 12:13:38 +05:00
|
|
|
|
var state = work?.CurrentState;
|
2023-10-25 16:03:07 +05:00
|
|
|
|
if (state is not null)
|
|
|
|
|
{
|
2023-10-25 16:30:35 +05:00
|
|
|
|
progress.Operation = state.State;
|
|
|
|
|
progress.Progress = (float)state.Progress;
|
2023-10-25 16:03:07 +05:00
|
|
|
|
}
|
2023-10-30 12:13:38 +05:00
|
|
|
|
|
2023-10-30 12:33:42 +05:00
|
|
|
|
await Clients.Group(groupName).GetReportProgress(progress, CancellationToken.None);
|
2023-10-25 16:03:07 +05:00
|
|
|
|
}
|
2021-05-20 11:07:45 +05:00
|
|
|
|
}
|
|
|
|
|
}
|