forked from ddrilling/AsbCloudServer
Report* форматирование
This commit is contained in:
parent
2526fc0bb5
commit
4c97c64594
@ -1,19 +1,18 @@
|
||||
namespace AsbCloudApp.Data.Progress
|
||||
namespace AsbCloudApp.Data.Progress;
|
||||
|
||||
/// <summary>
|
||||
/// DTO прогресса
|
||||
/// </summary>
|
||||
public class ProgressDto
|
||||
{
|
||||
/// <summary>
|
||||
/// DTO прогресса
|
||||
/// прогресс 0 - 100%
|
||||
/// </summary>
|
||||
public class ProgressDto
|
||||
{
|
||||
/// <summary>
|
||||
/// прогресс 0 - 100%
|
||||
/// </summary>
|
||||
public float Progress { get; set; }
|
||||
public float Progress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// название текущей операции генерации
|
||||
/// </summary>
|
||||
public string? Operation { get; set; }
|
||||
/// <summary>
|
||||
/// название текущей операции генерации
|
||||
/// </summary>
|
||||
public string? Operation { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
29
AsbCloudApp/Data/Progress/ProgressExceptionDto.cs
Normal file
29
AsbCloudApp/Data/Progress/ProgressExceptionDto.cs
Normal 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!;
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
namespace AsbCloudApp.Data.Progress
|
||||
namespace AsbCloudApp.Data.Progress;
|
||||
|
||||
/// <summary>
|
||||
/// DTO завершенного прогресса генерации рапорта-диаграммы
|
||||
/// </summary>
|
||||
public class ReportProgressFinalDto : ReportProgressDto
|
||||
{
|
||||
/// <summary>
|
||||
/// DTO завершенного прогресса генерации рапорта-диаграммы
|
||||
/// файл
|
||||
/// </summary>
|
||||
public class ReportProgressFinalDto : ReportProgressDto
|
||||
{
|
||||
/// <summary>
|
||||
/// файл
|
||||
/// </summary>
|
||||
public FileInfoDto file { get; set; }
|
||||
}
|
||||
public FileInfoDto file { get; set; }
|
||||
}
|
||||
|
@ -1,18 +1,17 @@
|
||||
namespace AsbCloudApp.Data.Progress
|
||||
namespace AsbCloudApp.Data.Progress;
|
||||
|
||||
/// <summary>
|
||||
/// DTO прогресса генерации рапорта-диаграммы
|
||||
/// </summary>
|
||||
public class ReportProgressDto : ProgressDto
|
||||
{
|
||||
/// <summary>
|
||||
/// DTO прогресса генерации рапорта-диаграммы
|
||||
/// номер текущей страницы
|
||||
/// </summary>
|
||||
public class ReportProgressDto : ProgressDto
|
||||
{
|
||||
/// <summary>
|
||||
/// номер текущей страницы
|
||||
/// </summary>
|
||||
public int CurrentPage { get; set; }
|
||||
public int CurrentPage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// предполагаемое суммарное количество страниц
|
||||
/// </summary>
|
||||
public int TotalPages { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// предполагаемое суммарное количество страниц
|
||||
/// </summary>
|
||||
public int TotalPages { get; set; }
|
||||
}
|
||||
|
@ -6,38 +6,36 @@ using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Background
|
||||
namespace AsbCloudInfrastructure.Background;
|
||||
|
||||
/// <summary>
|
||||
/// Класс для создания отчета
|
||||
/// </summary>
|
||||
internal class WorkToCreateReport : Work
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для создания отчета
|
||||
/// </summary>
|
||||
internal class WorkToCreateReport : Work
|
||||
private readonly int idWell;
|
||||
private readonly int idUser;
|
||||
private readonly ReportParametersRequest request;
|
||||
private readonly Action<object, string> progressHandler;
|
||||
|
||||
public WorkToCreateReport(int idWell, int idUser, ReportParametersRequest request, Action<object, string> progressHandler) : base("")
|
||||
{
|
||||
private int idWell;
|
||||
private int idUser;
|
||||
private ReportParametersRequest request;
|
||||
private Action<object, string> progressHandler;
|
||||
this.idWell = idWell;
|
||||
this.idUser = idUser;
|
||||
this.request = request;
|
||||
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;
|
||||
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>();
|
||||
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);
|
||||
onProgress(state.Operation ?? string.Empty, state.Progress);
|
||||
progressHandler(state, workId);
|
||||
}
|
||||
await reportService.CreateReportAsync(Id, idWell, idUser, request, handler, token);
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user