DD.WellWorkover.Cloud/AsbCloudWebApi/SignalR/ReportsHub.cs

56 lines
1.7 KiB
C#
Raw Normal View History

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