diff --git a/AsbCloudApp/Services/IBackgroundQueue.cs b/AsbCloudApp/Services/IBackgroundQueue.cs index ae99317b..b4394cc9 100644 --- a/AsbCloudApp/Services/IBackgroundQueue.cs +++ b/AsbCloudApp/Services/IBackgroundQueue.cs @@ -4,8 +4,8 @@ namespace AsbCloudApp.Services { public interface IBackgroundQueue { - int EnqueueTask(Action action); + int EnqueueTask(Action action); - bool TryDequeue(out (Action action, int id) item); + bool TryDequeue(out (Action action, int id) item); } } diff --git a/AsbCloudApp/Services/IReportService.cs b/AsbCloudApp/Services/IReportService.cs index 0110e5ff..df6c2102 100644 --- a/AsbCloudApp/Services/IReportService.cs +++ b/AsbCloudApp/Services/IReportService.cs @@ -7,7 +7,7 @@ namespace AsbCloudApp.Services { string RootPath { get; } int CreateReport(int wellId, int stepSeconds, int format, DateTime begin, DateTime end, - EventHandler<(float progress, string operation)> handleReportProgress); + Action handleReportProgress); int GetReportPagesCount(int wellId, DateTime begin, DateTime end, int stepSeconds, int format); DatesRangeDto GetReportsDatesRange(int wellId); } diff --git a/AsbCloudInfrastructure/Services/BackgroundQueue.cs b/AsbCloudInfrastructure/Services/BackgroundQueue.cs index f44de1a6..7cd5286f 100644 --- a/AsbCloudInfrastructure/Services/BackgroundQueue.cs +++ b/AsbCloudInfrastructure/Services/BackgroundQueue.cs @@ -6,12 +6,12 @@ namespace AsbCloudInfrastructure.Services { class BackgroundQueue : IBackgroundQueue { - private readonly ConcurrentQueue<(Action action, int id)> tasks = - new ConcurrentQueue<(Action action, int id)>(); + private readonly ConcurrentQueue<(Action action, int id)> tasks = + new ConcurrentQueue<(Action action, int id)>(); private int id = 0; - public int EnqueueTask(Action action) + public int EnqueueTask(Action action) { if (action == null) throw new ArgumentNullException(nameof(action)); @@ -20,7 +20,7 @@ namespace AsbCloudInfrastructure.Services return id; } - public bool TryDequeue(out (Action action, int id) item) + public bool TryDequeue(out (Action action, int id) item) => tasks.TryDequeue(out item); } } diff --git a/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs b/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs index 4c40f398..876d7635 100644 --- a/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs +++ b/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs @@ -21,7 +21,7 @@ namespace AsbCloudInfrastructure.Services while (!token.IsCancellationRequested) { if (tasksQueue.TryDequeue(out var item)) - await Task.Run(item.action, token); + await Task.Run(()=>item.action(item.id), token); else await Task.Delay(100, token); } diff --git a/AsbCloudInfrastructure/Services/ReportService.cs b/AsbCloudInfrastructure/Services/ReportService.cs index 05e91dc3..735ad2a0 100644 --- a/AsbCloudInfrastructure/Services/ReportService.cs +++ b/AsbCloudInfrastructure/Services/ReportService.cs @@ -28,9 +28,9 @@ namespace AsbCloudInfrastructure.Services public string RootPath { get ; private set; } public int CreateReport(int wellId, int stepSeconds, int format, DateTime begin, - DateTime end, EventHandler<(float progress, string operation)> progressHandler) + DateTime end, Action progressHandler) { - var newReportId = queue.EnqueueTask(() => + var newReportId = queue.EnqueueTask((id) => { var optionsBuilder = new DbContextOptionsBuilder(); optionsBuilder.UseNpgsql(configuration.GetConnectionString("DefaultConnection")); @@ -38,7 +38,7 @@ namespace AsbCloudInfrastructure.Services using (var context = new AsbCloudDbContext(optionsBuilder.Options)) { var generator = GetReportGenerator(wellId, begin, end, stepSeconds, format, context); - generator.OnProgress += progressHandler; + generator.OnProgress += (s,e)=>progressHandler.Invoke(e.progress, e.operation, id); generator.Make(); } }); diff --git a/AsbCloudWebApi/Controllers/ReportController.cs b/AsbCloudWebApi/Controllers/ReportController.cs index 600162d2..7635ce32 100644 --- a/AsbCloudWebApi/Controllers/ReportController.cs +++ b/AsbCloudWebApi/Controllers/ReportController.cs @@ -28,10 +28,9 @@ namespace AsbCloudWebApi.Controllers private string signalRConnectionId = "0"; - private void HandleReportProgress(object sender, (float progress, string operation) e) - { - reportsHubContext.Clients.Client(signalRConnectionId).SendAsync("GetReportProgress", e.progress); - } + private void HandleReportProgress (float progress, string operation, int id) => + reportsHubContext.Clients.Group($"Report{id}").SendAsync("GetReportProgress", progress); + /// /// Создает отчет по скважине с указанными параметрами