forked from ddrilling/AsbCloudServer
CS2-3: Добавлен SignalR ReportHub и его применение в ReportController
This commit is contained in:
parent
75ea100186
commit
4507b26581
@ -6,7 +6,8 @@ namespace AsbCloudApp.Services
|
|||||||
public interface IReportService
|
public interface IReportService
|
||||||
{
|
{
|
||||||
string RootPath { get; }
|
string RootPath { get; }
|
||||||
int CreateReport(int wellId, int stepSeconds, int format, DateTime begin, DateTime end);
|
int CreateReport(int wellId, int stepSeconds, int format, DateTime begin, DateTime end,
|
||||||
|
EventHandler<(float progress, string operation)> handleReportProgress);
|
||||||
int GetReportPagesCount(int wellId, DateTime begin, DateTime end, int stepSeconds, int format);
|
int GetReportPagesCount(int wellId, DateTime begin, DateTime end, int stepSeconds, int format);
|
||||||
DatesRangeDto GetReportsDatesRange(int wellId);
|
DatesRangeDto GetReportsDatesRange(int wellId);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public string RootPath { get ; private set; }
|
public string RootPath { get ; private set; }
|
||||||
|
|
||||||
public int CreateReport(int wellId, int stepSeconds, int format, DateTime begin, DateTime end)
|
public int CreateReport(int wellId, int stepSeconds, int format, DateTime begin,
|
||||||
|
DateTime end, EventHandler<(float progress, string operation)> progressHandler)
|
||||||
{
|
{
|
||||||
var newReportId = queue.EnqueueTask(() =>
|
var newReportId = queue.EnqueueTask(() =>
|
||||||
{
|
{
|
||||||
@ -37,6 +38,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
using (var context = new AsbCloudDbContext(optionsBuilder.Options))
|
using (var context = new AsbCloudDbContext(optionsBuilder.Options))
|
||||||
{
|
{
|
||||||
var generator = GetReportGenerator(wellId, begin, end, stepSeconds, format, context);
|
var generator = GetReportGenerator(wellId, begin, end, stepSeconds, format, context);
|
||||||
|
generator.OnProgress += progressHandler;
|
||||||
generator.Make();
|
generator.Make();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -3,8 +3,8 @@ using System.IO;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudWebApi.SignalR;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -17,27 +17,40 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
{
|
{
|
||||||
private readonly IReportService reportService;
|
private readonly IReportService reportService;
|
||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
|
private readonly IHubContext<ReportsHub> reportsHubContext;
|
||||||
|
|
||||||
public ReportController(IReportService reportService, IWellService wellService)
|
public ReportController(IReportService reportService, IWellService wellService, IHubContext<ReportsHub> reportsHubContext)
|
||||||
{
|
{
|
||||||
this.reportService = reportService;
|
this.reportService = reportService;
|
||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
|
this.reportsHubContext = reportsHubContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string signalRConnectionId = "0";
|
||||||
|
|
||||||
|
private void HandleReportProgress(object sender, (float progress, string operation) e)
|
||||||
|
{
|
||||||
|
reportsHubContext.Clients.Client(signalRConnectionId).SendAsync("GetReportProgress", e.progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Создает отчет по скважине с указанными параметрами
|
/// Создает отчет по скважине с указанными параметрами
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="wellId">id скважины</param>
|
/// <param name="wellId">id скважины</param>
|
||||||
/// <param name="begin">дата начала интервала</param>
|
|
||||||
/// <param name="end">дата окончания интервала</param>
|
|
||||||
/// <param name="stepSeconds">шаг интервала</param>
|
/// <param name="stepSeconds">шаг интервала</param>
|
||||||
/// <param name="format">формат отчета (0-PDF, 1-LASS)</param>
|
/// <param name="format">формат отчета (0-PDF, 1-LASS)</param>
|
||||||
|
/// <param name="signalRConnectionId">SignalR id подключения клиента</param>
|
||||||
|
/// <param name="begin">дата начала интервала</param>
|
||||||
|
/// <param name="end">дата окончания интервала</param>
|
||||||
/// <returns>id фоновой задачи формирования отчета</returns>
|
/// <returns>id фоновой задачи формирования отчета</returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("{wellId}/report")]
|
[Route("{wellId}/report")]
|
||||||
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult CreateReport(int wellId, int stepSeconds, int format, DateTime begin = default, DateTime end = default)
|
public IActionResult CreateReport(int wellId, int stepSeconds, int format, string signalRConnectionId,
|
||||||
|
DateTime begin = default, DateTime end = default)
|
||||||
{
|
{
|
||||||
|
this.signalRConnectionId = signalRConnectionId;
|
||||||
|
|
||||||
int? idCustomer = User.GetCustomerId();
|
int? idCustomer = User.GetCustomerId();
|
||||||
|
|
||||||
if (idCustomer is null)
|
if (idCustomer is null)
|
||||||
@ -46,7 +59,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
|
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var id = reportService.CreateReport(wellId, stepSeconds, format, begin, end);
|
var id = reportService.CreateReport(wellId, stepSeconds, format, begin, end, HandleReportProgress);
|
||||||
|
|
||||||
return Ok(id);
|
return Ok(id);
|
||||||
}
|
}
|
||||||
|
7
AsbCloudWebApi/SignalR/IReportHubClient.cs
Normal file
7
AsbCloudWebApi/SignalR/IReportHubClient.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace AsbCloudWebApi.SignalR
|
||||||
|
{
|
||||||
|
public interface IReportHubClient
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
14
AsbCloudWebApi/SignalR/ReportsHub.cs
Normal file
14
AsbCloudWebApi/SignalR/ReportsHub.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.SignalR
|
||||||
|
{
|
||||||
|
// SignalR manual:
|
||||||
|
// https://docs.microsoft.com/ru-ru/aspnet/core/signalr/introduction?view=aspnetcore-5.0
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
public class ReportsHub : Hub<IReportHubClient>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -67,6 +67,7 @@ namespace AsbCloudWebApi
|
|||||||
{
|
{
|
||||||
endpoints.MapControllers();
|
endpoints.MapControllers();
|
||||||
endpoints.MapHub<TelemetryHub>("/hubs/telemetry");
|
endpoints.MapHub<TelemetryHub>("/hubs/telemetry");
|
||||||
|
endpoints.MapHub<ReportsHub>("/hubs/reports");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user