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

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

View File

@ -1,19 +1,18 @@
namespace AsbCloudApp.Data.Progress namespace AsbCloudApp.Data.Progress;
/// <summary>
/// DTO прогресса
/// </summary>
public class ProgressDto
{ {
/// <summary> /// <summary>
/// DTO прогресса /// прогресс 0 - 100%
/// </summary> /// </summary>
public class ProgressDto public float Progress { get; set; }
{
/// <summary>
/// прогресс 0 - 100%
/// </summary>
public float Progress { get; set; }
/// <summary> /// <summary>
/// название текущей операции генерации /// название текущей операции генерации
/// </summary> /// </summary>
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,13 +1,12 @@
namespace AsbCloudApp.Data.Progress namespace AsbCloudApp.Data.Progress;
/// <summary>
/// DTO завершенного прогресса генерации рапорта-диаграммы
/// </summary>
public class ReportProgressFinalDto : ReportProgressDto
{ {
/// <summary> /// <summary>
/// DTO завершенного прогресса генерации рапорта-диаграммы /// файл
/// </summary> /// </summary>
public class ReportProgressFinalDto : ReportProgressDto public FileInfoDto file { get; set; }
{
/// <summary>
/// файл
/// </summary>
public FileInfoDto file { get; set; }
}
} }

View File

@ -1,18 +1,17 @@
namespace AsbCloudApp.Data.Progress namespace AsbCloudApp.Data.Progress;
/// <summary>
/// DTO прогресса генерации рапорта-диаграммы
/// </summary>
public class ReportProgressDto : ProgressDto
{ {
/// <summary> /// <summary>
/// DTO прогресса генерации рапорта-диаграммы /// номер текущей страницы
/// </summary> /// </summary>
public class ReportProgressDto : ProgressDto public int CurrentPage { get; set; }
{
/// <summary>
/// номер текущей страницы
/// </summary>
public int CurrentPage { get; set; }
/// <summary> /// <summary>
/// предполагаемое суммарное количество страниц /// предполагаемое суммарное количество страниц
/// </summary> /// </summary>
public int TotalPages { get; set; } public int TotalPages { get; set; }
}
} }

View File

@ -6,38 +6,36 @@ using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Background namespace AsbCloudInfrastructure.Background;
/// <summary>
/// Класс для создания отчета
/// </summary>
internal class WorkToCreateReport : Work
{ {
/// <summary> private readonly int idWell;
/// Класс для создания отчета private readonly int idUser;
/// </summary> private readonly ReportParametersRequest request;
internal class WorkToCreateReport : Work private readonly Action<object, string> progressHandler;
public WorkToCreateReport(int idWell, int idUser, ReportParametersRequest request, Action<object, string> progressHandler) : base("")
{ {
private int idWell; this.idWell = idWell;
private int idUser; this.idUser = idUser;
private ReportParametersRequest request; this.request = request;
private Action<object, string> progressHandler; this.progressHandler = progressHandler;
public WorkToCreateReport(int idWell, int idUser, ReportParametersRequest request, Action<object, string> progressHandler) : base("") 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>();
void handler(ProgressDto state, string workId)
{ {
this.idWell = idWell; onProgress(state.Operation ?? string.Empty, state.Progress);
this.idUser = idUser; progressHandler(state, workId);
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>();
Action<ProgressDto, 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);
} }
await reportService.CreateReportAsync(Id, idWell, idUser, request, handler, token);
} }
} }

View File

@ -41,16 +41,18 @@ 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", {
Progress = 100f, Operation = "error",
Message = string.IsNullOrEmpty(message) Progress = 100f,
Message = string.IsNullOrEmpty(message)
? 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,