Рефактор: один экшн, который передается в качестве параметра в метод CreateReportAsync. Внутри экшна вызываются 2 метода: onProgress и progressHandler.

This commit is contained in:
Olga Nemt 2023-12-26 14:31:20 +05:00
parent 38ef2941c4
commit 1d3294e799
4 changed files with 20 additions and 6 deletions

View File

@ -5,6 +5,11 @@
/// </summary>
public class ReportProgressDto
{
/// <summary>
/// файл
/// </summary>
public FileInfoDto file { get; set; }
/// <summary>
/// прогресс 0 - 100%
/// </summary>

View File

@ -27,13 +27,14 @@ namespace AsbCloudApp.Services
/// <summary>
/// Создание отчета
/// </summary>
/// <param name="workId"></param>
/// <param name="idWell"></param>
/// <param name="idUser"></param>
/// <param name="request"></param>
/// <param name="progressHandler"></param>
/// <param name="token"></param>
/// <returns></returns>
Task CreateReportAsync(int idWell, int idUser, ReportParametersRequest request, Action<object, string> progressHandler, CancellationToken token);
Task CreateReportAsync(string workId, int idWell, int idUser, ReportParametersRequest request, Action<ReportProgressDto, string> progressHandler, CancellationToken token);
/// <summary>
/// Получить предполагаемый список страниц рапорта

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Requests;
using AsbCloudApp.Data;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using Microsoft.Extensions.DependencyInjection;
using System;
@ -23,13 +24,20 @@ namespace AsbCloudInfrastructure.Background
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<string, double?> onProgress, CancellationToken token)
{
var reportService = services.GetRequiredService<IReportService>();
await reportService.CreateReportAsync(idWell, idUser, request, progressHandler, token);
Action<ReportProgressDto, string> handler = (state, workId) =>
{
onProgress?.Invoke(state.Operation ?? string.Empty, state.Progress);
progressHandler?.Invoke(state, workId);
};
await reportService.CreateReportAsync(Id, idWell, idUser, request, handler, token);
}
}
}

View File

@ -117,13 +117,13 @@ public class ReportService : IReportService
public async Task CreateReportAsync(
string workId,
int idWell,
int idUser,
ReportParametersRequest request,
Action<object, string> progressHandler,
Action<ReportProgressDto, string> progressHandler,
CancellationToken token)
{
var workId = $"create report by wellid:{idWell} for userid:{idUser} requested at {DateTime.Now}";
var timezoneOffset = wellService.GetTimezone(idWell).Hours;
var beginRemote = request.Begin.ToTimeZoneOffsetHours(timezoneOffset);
var endRemote = request.End.ToTimeZoneOffsetHours(timezoneOffset);
@ -150,7 +150,7 @@ public class ReportService : IReportService
var fileInfo = (await fileService.MoveAsync(idWell, idUser, ReportCategoryId, reportFileName, reportFileName, token))!;
progressHandler(new
progressHandler(new ReportProgressDto()
{
Operation = "done",
Progress = 100f,