Report* форматирование

This commit is contained in:
ngfrolov 2023-12-27 13:07:41 +05:00
parent 2526fc0bb5
commit 4c97c64594
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7
6 changed files with 97 additions and 72 deletions

View File

@ -1,5 +1,5 @@
namespace AsbCloudApp.Data.Progress namespace AsbCloudApp.Data.Progress;
{
/// <summary> /// <summary>
/// DTO прогресса /// DTO прогресса
/// </summary> /// </summary>
@ -16,4 +16,3 @@
public string? Operation { get; set; } public string? Operation { get; set; }
} }
}

View File

@ -0,0 +1,29 @@
using System;
namespace AsbCloudApp.Data.Progress;
/// <summary>
/// DTO прогресса с ошибкой
/// </summary>
public class ProgressExceptionDto
{
/// <summary>
/// прогресс 0 - 100%
/// </summary>
public float Progress { get; set; }
/// <summary>
/// название текущей операции генерации
/// </summary>
public string? Operation { get; set; }
/// <summary>
/// Отображаемый текст ошибки
/// </summary>
public string Message { get; set; } = null!;
/// <summary>
/// Инфо об исключении
/// </summary>
public Exception Exception { get; set; } = null!;
}

View File

@ -1,5 +1,5 @@
namespace AsbCloudApp.Data.Progress namespace AsbCloudApp.Data.Progress;
{
/// <summary> /// <summary>
/// DTO завершенного прогресса генерации рапорта-диаграммы /// DTO завершенного прогресса генерации рапорта-диаграммы
/// </summary> /// </summary>
@ -10,4 +10,3 @@
/// </summary> /// </summary>
public FileInfoDto file { get; set; } public FileInfoDto file { get; set; }
} }
}

View File

@ -1,5 +1,5 @@
namespace AsbCloudApp.Data.Progress namespace AsbCloudApp.Data.Progress;
{
/// <summary> /// <summary>
/// DTO прогресса генерации рапорта-диаграммы /// DTO прогресса генерации рапорта-диаграммы
/// </summary> /// </summary>
@ -15,4 +15,3 @@
/// </summary> /// </summary>
public int TotalPages { get; set; } public int TotalPages { get; set; }
} }
}

View File

@ -6,17 +6,17 @@ using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Background namespace AsbCloudInfrastructure.Background;
{
/// <summary> /// <summary>
/// Класс для создания отчета /// Класс для создания отчета
/// </summary> /// </summary>
internal class WorkToCreateReport : Work internal class WorkToCreateReport : Work
{ {
private int idWell; private readonly int idWell;
private int idUser; private readonly int idUser;
private ReportParametersRequest request; private readonly ReportParametersRequest request;
private Action<object, string> progressHandler; private readonly Action<object, string> progressHandler;
public WorkToCreateReport(int idWell, int idUser, ReportParametersRequest request, Action<object, string> progressHandler) : base("") public WorkToCreateReport(int idWell, int idUser, ReportParametersRequest request, Action<object, string> progressHandler) : base("")
{ {
@ -28,16 +28,14 @@ namespace AsbCloudInfrastructure.Background
Id = $"create report by wellid:{idWell} for userid:{idUser} requested at {DateTime.Now}"; 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) protected override async Task Action(string id, IServiceProvider services, Action<string, double?> onProgress, CancellationToken token)
{ {
var reportService = services.GetRequiredService<IReportService>(); var reportService = services.GetRequiredService<IReportService>();
Action<ProgressDto, string> handler = (state, workId) => void handler(ProgressDto state, string workId)
{ {
onProgress?.Invoke(state.Operation ?? string.Empty, state.Progress); onProgress(state.Operation ?? string.Empty, state.Progress);
progressHandler?.Invoke(state, workId); progressHandler(state, workId);
}; }
await reportService.CreateReportAsync(Id, idWell, idUser, request, handler, token); await reportService.CreateReportAsync(Id, idWell, idUser, request, handler, token);
} }
} }
}

View File

@ -41,7 +41,8 @@ public class ReportService : IReportService
{ {
var work = new WorkToCreateReport(idWell, idUser, request, progressHandler); var work = new WorkToCreateReport(idWell, idUser, request, progressHandler);
work.OnErrorAsync = (message, exception, token) => Task.Run(() => progressHandler.Invoke(new work.OnErrorAsync = (message, exception, token) => Task.Run(() => {
var state = new ProgressExceptionDto
{ {
Operation = "error", Operation = "error",
Progress = 100f, Progress = 100f,
@ -49,8 +50,9 @@ public class ReportService : IReportService
? exception.Message ? exception.Message
: message, : message,
Exception = exception, Exception = exception,
}, work.Id) };
, token); progressHandler.Invoke(state, work.Id);
}, token);
backgroundWorkerService.Enqueue(work); backgroundWorkerService.Enqueue(work);
@ -116,7 +118,6 @@ public class ReportService : IReportService
return dtos; return dtos;
} }
public async Task CreateReportAsync( public async Task CreateReportAsync(
string workId, string workId,
int idWell, int idWell,