DD.WellWorkover.Cloud/AsbCloudInfrastructure/Background/WorkToCreateReport.cs

42 lines
1.4 KiB
C#
Raw Permalink Normal View History

using AsbCloudApp.Data.Progress;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading;
using System.Threading.Tasks;
2023-12-27 13:07:41 +05:00
namespace AsbCloudInfrastructure.Background;
2023-12-27 13:07:41 +05:00
/// <summary>
/// Класс для создания отчета
/// </summary>
internal class WorkToCreateReport : Work
{
private readonly int idWell;
private readonly int idUser;
private readonly ReportParametersRequest request;
private readonly Action<object, string> progressHandler;
2023-12-27 13:07:41 +05:00
public WorkToCreateReport(int idWell, int idUser, ReportParametersRequest request, Action<object, string> progressHandler) : base("")
{
this.idWell = idWell;
this.idUser = idUser;
this.request = request;
this.progressHandler = progressHandler;
2023-12-27 13:07:41 +05:00
Id = $"create report by wellid:{idWell} for userid:{idUser} requested at {DateTime.Now}";
}
2023-12-27 13:07:41 +05:00
protected override async Task Action(string id, IServiceProvider services, Action<string, double?> onProgress, CancellationToken token)
{
var reportService = services.GetRequiredService<IReportService>();
void handler(ProgressDto state, string workId)
{
2023-12-27 13:07:41 +05:00
onProgress(state.Operation ?? string.Empty, state.Progress);
progressHandler(state, workId);
}
2023-12-27 13:07:41 +05:00
await reportService.CreateReportAsync(Id, idWell, idUser, request, handler, token);
}
}