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