From ad784c21e0725c32c48694705f11333eebfd4f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ben=C3=AD=C4=8Dek?= Date: Mon, 15 Jan 2024 10:33:10 +0100 Subject: [PATCH] added signar sync --- API_SequentMicrosystems.csproj | 1 + Controllers/PointsController.cs | 2 +- Hubs/SyncHub.cs | 37 +++++++++++++++++++++++++++++++++ Program.cs | 4 ++++ Services/PointsService.cs | 4 ++-- 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 Hubs/SyncHub.cs diff --git a/API_SequentMicrosystems.csproj b/API_SequentMicrosystems.csproj index 0dcdebb..5cfc633 100644 --- a/API_SequentMicrosystems.csproj +++ b/API_SequentMicrosystems.csproj @@ -17,6 +17,7 @@ + diff --git a/Controllers/PointsController.cs b/Controllers/PointsController.cs index 6dd2399..46bc470 100644 --- a/Controllers/PointsController.cs +++ b/Controllers/PointsController.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Mvc; namespace API_SequentMicrosystems.Controllers { [Tags("Internal Saving Points (Recommended use only \"Actual\" endpoint for read all data at once. Saving points is not recomended)")] - [Route("Points")] + [Route("api/Points")] [ApiController] public class PointsController : ControllerBase { diff --git a/Hubs/SyncHub.cs b/Hubs/SyncHub.cs new file mode 100644 index 0000000..4ca5063 --- /dev/null +++ b/Hubs/SyncHub.cs @@ -0,0 +1,37 @@ +using Microsoft.AspNetCore.SignalR; + +namespace API_SequentMicrosystems.Hubs +{ + public class SyncHub : Hub + { + + public async Task SyncClients() + { + await Clients.All.SendAsync("ClientsRequest"); + } + + public async Task SyncClientResponse(string clientID) + { + await Clients.All.SendAsync("ClientsResponse", clientID); + } + + public async Task SyncRequest(string clientID) + { + await Clients.All.SendAsync("SyncRequested", clientID); + } + + public async Task SyncPoints(string clientID, object o) + { + await Clients.All.SendAsync("SyncPointsData", clientID, o); + } + + public async Task SyncRTD8TMChart(string clientID, object o) + { + await Clients.All.SendAsync("SyncRTD8TMChartData", clientID, o); + } + + + + + } +} diff --git a/Program.cs b/Program.cs index 38db06a..c3adb9b 100644 --- a/Program.cs +++ b/Program.cs @@ -1,3 +1,4 @@ +using API_SequentMicrosystems.Hubs; using API_SequentMicrosystems.Services; using Microsoft.OpenApi.Models; using System.Reflection; @@ -15,6 +16,7 @@ namespace API_SequentMicrosystems // Add services to the container. builder.Services.AddControllers().AddNewtonsoftJson(); + builder.Services.AddSignalR(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); @@ -61,6 +63,8 @@ namespace API_SequentMicrosystems app.Services.GetService(); app.Services.GetService(); + app.MapHub("/signalr/sync"); + app.MapControllers(); app.Run(); diff --git a/Services/PointsService.cs b/Services/PointsService.cs index b01d3f2..66618ba 100644 --- a/Services/PointsService.cs +++ b/Services/PointsService.cs @@ -6,9 +6,9 @@ namespace API_SequentMicrosystems.Services { public class PointsService { - private System.Timers.Timer _SaveTimer; + private System.Timers.Timer _SaveTimer; //timer for saving Points to file private bool _SavePoints; - private System.Timers.Timer? _timer; + private System.Timers.Timer? _timer; //Timer for creating new points private RTDDAService _RTDDAService; public PointsService(IConfiguration conf, RTDDAService _RTDDAS)