forked from ddrilling/AsbCloudServer
ProcessMapController Add SirnalR notifications on modification. MethodName = "ProcessMapChanged"
This commit is contained in:
parent
bf9a1d50f4
commit
85983e2870
@ -1,17 +1,17 @@
|
|||||||
using AsbCloudApp.Data.ProcessMap;
|
using AsbCloudApp.Data.ProcessMap;
|
||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudWebApi.SignalR;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// РТК
|
/// РТК
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -21,18 +21,23 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
public class ProcessMapController : CrudWellRelatedController<ProcessMapPlanDto, IProcessMapPlanRepository>
|
public class ProcessMapController : CrudWellRelatedController<ProcessMapPlanDto, IProcessMapPlanRepository>
|
||||||
{
|
{
|
||||||
private readonly ITelemetryService telemetryService;
|
private readonly ITelemetryService telemetryService;
|
||||||
|
private readonly IHubContext<TelemetryHub> telemetryHubContext;
|
||||||
private readonly IProcessMapReportMakerService processMapReportService;
|
private readonly IProcessMapReportMakerService processMapReportService;
|
||||||
private readonly IProcessMapReportService processMapService;
|
private readonly IProcessMapReportService processMapService;
|
||||||
|
|
||||||
|
private const string SirnalRMethodGetDataName = "ProcessMapChanged";
|
||||||
|
|
||||||
public ProcessMapController(
|
public ProcessMapController(
|
||||||
IWellService wellService,
|
IWellService wellService,
|
||||||
IProcessMapPlanRepository repository,
|
IProcessMapPlanRepository repository,
|
||||||
IProcessMapReportMakerService processMapReportService,
|
IProcessMapReportMakerService processMapReportService,
|
||||||
IProcessMapReportService processMapService,
|
IProcessMapReportService processMapService,
|
||||||
ITelemetryService telemetryService)
|
ITelemetryService telemetryService,
|
||||||
|
IHubContext<TelemetryHub> telemetryHubContext)
|
||||||
: base(wellService, repository)
|
: base(wellService, repository)
|
||||||
{
|
{
|
||||||
this.telemetryService = telemetryService;
|
this.telemetryService = telemetryService;
|
||||||
|
this.telemetryHubContext = telemetryHubContext;
|
||||||
this.processMapReportService = processMapReportService;
|
this.processMapReportService = processMapReportService;
|
||||||
this.processMapService = processMapService;
|
this.processMapService = processMapService;
|
||||||
|
|
||||||
@ -56,8 +61,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
if (idWell is null)
|
if (idWell is null)
|
||||||
return BadRequest($"Wrong uid {uid}");
|
return BadRequest($"Wrong uid {uid}");
|
||||||
|
|
||||||
var dto = Enumerable.Empty<ProcessMapPlanDto>();
|
throw new NotImplementedException();
|
||||||
return Ok(dto);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -136,7 +140,10 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
public override async Task<ActionResult<int>> InsertAsync([FromBody] ProcessMapPlanDto value, CancellationToken token)
|
public override async Task<ActionResult<int>> InsertAsync([FromBody] ProcessMapPlanDto value, CancellationToken token)
|
||||||
{
|
{
|
||||||
value.IdUser = User.GetUserId() ?? -1;
|
value.IdUser = User.GetUserId() ?? -1;
|
||||||
return await base.InsertAsync(value, token);
|
var result = await base.InsertAsync(value, token);
|
||||||
|
if (result.Value > 0)
|
||||||
|
await NotifyUsersBySignalR(value.IdWell, token);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -149,8 +156,17 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
public override async Task<ActionResult<int>> UpdateAsync([FromBody] ProcessMapPlanDto value, CancellationToken token)
|
public override async Task<ActionResult<int>> UpdateAsync([FromBody] ProcessMapPlanDto value, CancellationToken token)
|
||||||
{
|
{
|
||||||
value.IdUser = User.GetUserId() ?? -1;
|
value.IdUser = User.GetUserId() ?? -1;
|
||||||
return await base.UpdateAsync(value, token);
|
var result = await base.UpdateAsync(value, token);
|
||||||
|
if (result.Value > 0)
|
||||||
|
await NotifyUsersBySignalR(value.IdWell, token);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task NotifyUsersBySignalR(int idWell, CancellationToken token)
|
||||||
|
{
|
||||||
|
var dtos = await service.GetAllAsync(idWell, null, token);
|
||||||
|
_ = Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}")
|
||||||
|
.SendAsync(SirnalRMethodGetDataName, dtos), CancellationToken.None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user