Отправка данных об ошибке, если файл по какой-то причине не сформирован

This commit is contained in:
Оля Бизюкова 2024-05-27 15:37:33 +05:00
parent 82bcb509d3
commit 063096e236
3 changed files with 20 additions and 14 deletions

View File

@ -5,18 +5,8 @@ namespace AsbCloudApp.Data.Progress;
/// <summary>
/// DTO прогресса с ошибкой
/// </summary>
public class ProgressExceptionDto
public class ProgressExceptionDto : ProgressDto
{
/// <summary>
/// прогресс 0 - 100%
/// </summary>
public float Progress { get; set; }
/// <summary>
/// название текущей операции генерации
/// </summary>
public string? Operation { get; set; }
/// <summary>
/// Отображаемый текст ошибки
/// </summary>

View File

@ -8,5 +8,5 @@ public class ReportProgressFinalDto : ReportProgressDto
/// <summary>
/// файл
/// </summary>
public FileInfoDto? file { get; set; }
public FileInfoDto file { get; set; } = null!;
}

View File

@ -54,13 +54,15 @@ public class ReportService : IReportService
progressHandler.Invoke(state, work.Id);
}, token);
backgroundWorkerService.Enqueue(work);
progressHandler.Invoke(new ReportProgressDto
{
Operation = "Ожидает начала в очереди.",
Progress = 0f,
}, work.Id);
backgroundWorkerService.Enqueue(work);
return work.Id;
}
@ -153,6 +155,20 @@ public class ReportService : IReportService
var fileInfo = (await fileService.MoveAsync(idWell, idUser, ReportCategoryId, reportFileName, reportFileName, token))!;
if (fileInfo == null)
{
var state = new ProgressExceptionDto
{
Operation = "error",
Progress = 0f,
Message = "Не удалось сгенерировать файл отчёта",
Exception = new FileNotFoundException(),
};
progressHandler(state, workId);
return;
}
progressHandler(new ReportProgressFinalDto()
{
Operation = "done",