forked from ddrilling/AsbCloudServer
Рефактор: один экшн, который передается в качестве параметра в метод CreateReportAsync. Внутри экшна вызываются 2 метода: onProgress и progressHandler.
This commit is contained in:
parent
38ef2941c4
commit
1d3294e799
@ -5,6 +5,11 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ReportProgressDto
|
public class ReportProgressDto
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// файл
|
||||||
|
/// </summary>
|
||||||
|
public FileInfoDto file { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// прогресс 0 - 100%
|
/// прогресс 0 - 100%
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -27,13 +27,14 @@ namespace AsbCloudApp.Services
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Создание отчета
|
/// Создание отчета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="workId"></param>
|
||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
/// <param name="idUser"></param>
|
/// <param name="idUser"></param>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="progressHandler"></param>
|
/// <param name="progressHandler"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task CreateReportAsync(int idWell, int idUser, ReportParametersRequest request, Action<object, string> progressHandler, CancellationToken token);
|
Task CreateReportAsync(string workId, int idWell, int idUser, ReportParametersRequest request, Action<ReportProgressDto, string> progressHandler, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить предполагаемый список страниц рапорта
|
/// Получить предполагаемый список страниц рапорта
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using System;
|
using System;
|
||||||
@ -23,13 +24,20 @@ namespace AsbCloudInfrastructure.Background
|
|||||||
this.idUser = idUser;
|
this.idUser = idUser;
|
||||||
this.request = request;
|
this.request = request;
|
||||||
this.progressHandler = progressHandler;
|
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)
|
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>();
|
||||||
await reportService.CreateReportAsync(idWell, idUser, request, progressHandler, token);
|
Action<ReportProgressDto, 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,13 +117,13 @@ public class ReportService : IReportService
|
|||||||
|
|
||||||
|
|
||||||
public async Task CreateReportAsync(
|
public async Task CreateReportAsync(
|
||||||
|
string workId,
|
||||||
int idWell,
|
int idWell,
|
||||||
int idUser,
|
int idUser,
|
||||||
ReportParametersRequest request,
|
ReportParametersRequest request,
|
||||||
Action<object, string> progressHandler,
|
Action<ReportProgressDto, string> progressHandler,
|
||||||
CancellationToken token)
|
CancellationToken token)
|
||||||
{
|
{
|
||||||
var workId = $"create report by wellid:{idWell} for userid:{idUser} requested at {DateTime.Now}";
|
|
||||||
var timezoneOffset = wellService.GetTimezone(idWell).Hours;
|
var timezoneOffset = wellService.GetTimezone(idWell).Hours;
|
||||||
var beginRemote = request.Begin.ToTimeZoneOffsetHours(timezoneOffset);
|
var beginRemote = request.Begin.ToTimeZoneOffsetHours(timezoneOffset);
|
||||||
var endRemote = request.End.ToTimeZoneOffsetHours(timezoneOffset);
|
var endRemote = request.End.ToTimeZoneOffsetHours(timezoneOffset);
|
||||||
@ -150,7 +150,7 @@ public class ReportService : IReportService
|
|||||||
|
|
||||||
var fileInfo = (await fileService.MoveAsync(idWell, idUser, ReportCategoryId, reportFileName, reportFileName, token))!;
|
var fileInfo = (await fileService.MoveAsync(idWell, idUser, ReportCategoryId, reportFileName, reportFileName, token))!;
|
||||||
|
|
||||||
progressHandler(new
|
progressHandler(new ReportProgressDto()
|
||||||
{
|
{
|
||||||
Operation = "done",
|
Operation = "done",
|
||||||
Progress = 100f,
|
Progress = 100f,
|
||||||
|
Loading…
Reference in New Issue
Block a user