2024-07-04 11:02:45 +05:00
|
|
|
using AsbCloudApp.Data.Progress;
|
2023-12-26 14:31:20 +05:00
|
|
|
using AsbCloudApp.Requests;
|
2023-12-25 10:53:45 +05:00
|
|
|
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-25 10:53:45 +05:00
|
|
|
|
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-26 14:31:20 +05:00
|
|
|
|
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-25 10:53:45 +05:00
|
|
|
|
2023-12-27 13:07:41 +05:00
|
|
|
Id = $"create report by wellid:{idWell} for userid:{idUser} requested at {DateTime.Now}";
|
|
|
|
}
|
2023-12-25 10:53:45 +05:00
|
|
|
|
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-25 10:53:45 +05:00
|
|
|
{
|
2023-12-27 13:07:41 +05:00
|
|
|
onProgress(state.Operation ?? string.Empty, state.Progress);
|
|
|
|
progressHandler(state, workId);
|
2023-12-25 10:53:45 +05:00
|
|
|
}
|
2023-12-27 13:07:41 +05:00
|
|
|
await reportService.CreateReportAsync(Id, idWell, idUser, request, handler, token);
|
2023-12-25 10:53:45 +05:00
|
|
|
}
|
|
|
|
}
|