From 4c97c6459414cb653b54f9a7123270165d62c994 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Wed, 27 Dec 2023 13:07:41 +0500 Subject: [PATCH] =?UTF-8?q?Report*=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/Progress/ProgressDto.cs | 25 +++++---- .../Data/Progress/ProgressExceptionDto.cs | 29 ++++++++++ .../Data/Progress/ReportProgressDto.cs | 17 +++--- .../Data/Progress/ReportProgressFinalDto.cs | 25 +++++---- .../Background/WorkToCreateReport.cs | 54 +++++++++---------- .../Services/ReportService.cs | 19 +++---- 6 files changed, 97 insertions(+), 72 deletions(-) create mode 100644 AsbCloudApp/Data/Progress/ProgressExceptionDto.cs diff --git a/AsbCloudApp/Data/Progress/ProgressDto.cs b/AsbCloudApp/Data/Progress/ProgressDto.cs index 601268ca..3ad2c50a 100644 --- a/AsbCloudApp/Data/Progress/ProgressDto.cs +++ b/AsbCloudApp/Data/Progress/ProgressDto.cs @@ -1,19 +1,18 @@ -namespace AsbCloudApp.Data.Progress +namespace AsbCloudApp.Data.Progress; + +/// +/// DTO прогресса +/// +public class ProgressDto { /// - /// DTO прогресса + /// прогресс 0 - 100% /// - public class ProgressDto - { - /// - /// прогресс 0 - 100% - /// - public float Progress { get; set; } + public float Progress { get; set; } - /// - /// название текущей операции генерации - /// - public string? Operation { get; set; } + /// + /// название текущей операции генерации + /// + public string? Operation { get; set; } - } } diff --git a/AsbCloudApp/Data/Progress/ProgressExceptionDto.cs b/AsbCloudApp/Data/Progress/ProgressExceptionDto.cs new file mode 100644 index 00000000..cb264178 --- /dev/null +++ b/AsbCloudApp/Data/Progress/ProgressExceptionDto.cs @@ -0,0 +1,29 @@ +using System; + +namespace AsbCloudApp.Data.Progress; + +/// +/// DTO прогресса с ошибкой +/// +public class ProgressExceptionDto +{ + /// + /// прогресс 0 - 100% + /// + public float Progress { get; set; } + + /// + /// название текущей операции генерации + /// + public string? Operation { get; set; } + + /// + /// Отображаемый текст ошибки + /// + public string Message { get; set; } = null!; + + /// + /// Инфо об исключении + /// + public Exception Exception { get; set; } = null!; +} \ No newline at end of file diff --git a/AsbCloudApp/Data/Progress/ReportProgressDto.cs b/AsbCloudApp/Data/Progress/ReportProgressDto.cs index 00db12a8..b14166e9 100644 --- a/AsbCloudApp/Data/Progress/ReportProgressDto.cs +++ b/AsbCloudApp/Data/Progress/ReportProgressDto.cs @@ -1,13 +1,12 @@ -namespace AsbCloudApp.Data.Progress +namespace AsbCloudApp.Data.Progress; + +/// +/// DTO завершенного прогресса генерации рапорта-диаграммы +/// +public class ReportProgressFinalDto : ReportProgressDto { /// - /// DTO завершенного прогресса генерации рапорта-диаграммы + /// файл /// - public class ReportProgressFinalDto : ReportProgressDto - { - /// - /// файл - /// - public FileInfoDto file { get; set; } - } + public FileInfoDto file { get; set; } } diff --git a/AsbCloudApp/Data/Progress/ReportProgressFinalDto.cs b/AsbCloudApp/Data/Progress/ReportProgressFinalDto.cs index 29956546..b5ce965a 100644 --- a/AsbCloudApp/Data/Progress/ReportProgressFinalDto.cs +++ b/AsbCloudApp/Data/Progress/ReportProgressFinalDto.cs @@ -1,18 +1,17 @@ -namespace AsbCloudApp.Data.Progress +namespace AsbCloudApp.Data.Progress; + +/// +/// DTO прогресса генерации рапорта-диаграммы +/// +public class ReportProgressDto : ProgressDto { /// - /// DTO прогресса генерации рапорта-диаграммы + /// номер текущей страницы /// - public class ReportProgressDto : ProgressDto - { - /// - /// номер текущей страницы - /// - public int CurrentPage { get; set; } + public int CurrentPage { get; set; } - /// - /// предполагаемое суммарное количество страниц - /// - public int TotalPages { get; set; } - } + /// + /// предполагаемое суммарное количество страниц + /// + public int TotalPages { get; set; } } diff --git a/AsbCloudInfrastructure/Background/WorkToCreateReport.cs b/AsbCloudInfrastructure/Background/WorkToCreateReport.cs index 3381f033..f07e7f85 100644 --- a/AsbCloudInfrastructure/Background/WorkToCreateReport.cs +++ b/AsbCloudInfrastructure/Background/WorkToCreateReport.cs @@ -6,38 +6,36 @@ using System; using System.Threading; using System.Threading.Tasks; -namespace AsbCloudInfrastructure.Background +namespace AsbCloudInfrastructure.Background; + +/// +/// Класс для создания отчета +/// +internal class WorkToCreateReport : Work { - /// - /// Класс для создания отчета - /// - 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("") { - private int idWell; - private int idUser; - private ReportParametersRequest request; - private Action progressHandler; + this.idWell = idWell; + this.idUser = idUser; + this.request = request; + this.progressHandler = progressHandler; - public WorkToCreateReport(int idWell, int idUser, ReportParametersRequest request, Action 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 onProgress, CancellationToken token) + { + var reportService = services.GetRequiredService(); + void handler(ProgressDto state, string workId) { - 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(); - Action handler = (state, workId) => - { - onProgress?.Invoke(state.Operation ?? string.Empty, state.Progress); - progressHandler?.Invoke(state, workId); - }; - await reportService.CreateReportAsync(Id, idWell, idUser, request, handler, token); + onProgress(state.Operation ?? string.Empty, state.Progress); + progressHandler(state, workId); } + await reportService.CreateReportAsync(Id, idWell, idUser, request, handler, token); } } diff --git a/AsbCloudInfrastructure/Services/ReportService.cs b/AsbCloudInfrastructure/Services/ReportService.cs index 59fd97ea..3b7199a9 100644 --- a/AsbCloudInfrastructure/Services/ReportService.cs +++ b/AsbCloudInfrastructure/Services/ReportService.cs @@ -41,16 +41,18 @@ public class ReportService : IReportService { var work = new WorkToCreateReport(idWell, idUser, request, progressHandler); - work.OnErrorAsync = (message, exception, token) => Task.Run(() => progressHandler.Invoke(new - { - Operation = "error", - Progress = 100f, - Message = string.IsNullOrEmpty(message) + work.OnErrorAsync = (message, exception, token) => Task.Run(() => { + var state = new ProgressExceptionDto + { + Operation = "error", + Progress = 100f, + Message = string.IsNullOrEmpty(message) ? exception.Message : message, - Exception = exception, - }, work.Id) - , token); + Exception = exception, + }; + progressHandler.Invoke(state, work.Id); + }, token); backgroundWorkerService.Enqueue(work); @@ -116,7 +118,6 @@ public class ReportService : IReportService return dtos; } - public async Task CreateReportAsync( string workId, int idWell,