forked from ddrilling/AsbCloudServer
Merge pull request 'fix/#13108961-signalR-create-report' (#142) from fix/#13108961-signalR-create-report into dev
Reviewed-on: http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer/pulls/142
This commit is contained in:
commit
afaa1212c5
@ -1,4 +1,10 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudInfrastructure.Background;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.SignalR
|
||||
{
|
||||
@ -8,6 +14,39 @@ namespace AsbCloudWebApi.SignalR
|
||||
[Authorize]
|
||||
public class ReportsHub : BaseHub<IReportHubClient>
|
||||
{
|
||||
|
||||
private readonly BackgroundWorker backgroundWorker;
|
||||
|
||||
public ReportsHub(BackgroundWorker backgroundWorker)
|
||||
{
|
||||
this.backgroundWorker = backgroundWorker;
|
||||
}
|
||||
|
||||
public override async Task AddToGroup(string groupName)
|
||||
{
|
||||
await base.AddToGroup(groupName);
|
||||
|
||||
var workId = groupName.Replace("Report_", "");
|
||||
var work = backgroundWorker.WorkStore.RunOnceQueue.FirstOrDefault(work => work.Id == workId);
|
||||
|
||||
var progress = new ReportProgressDto()
|
||||
{
|
||||
Operation = "Ожидает начала в очереди.",
|
||||
Progress = 0f,
|
||||
};
|
||||
|
||||
var state = work?.CurrentState;
|
||||
if (state is not null)
|
||||
{
|
||||
progress.Operation = state.State;
|
||||
progress.Progress = (float)state.Progress;
|
||||
}
|
||||
|
||||
await Clients.Group(groupName).SendAsync(
|
||||
nameof(IReportHubClient.GetReportProgress),
|
||||
progress,
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user