added signar sync

master
Jan Beníček 2024-01-15 10:33:10 +01:00
parent 8597d5d0ba
commit ad784c21e0
5 changed files with 45 additions and 3 deletions

View File

@ -17,6 +17,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.SignalR.Core" Version="2.4.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.0" />
<PackageReference Include="NetTopologySuite.IO.GeoJSON" Version="4.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

View File

@ -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
{

37
Hubs/SyncHub.cs Normal file
View File

@ -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);
}
}
}

View File

@ -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<RTDDAService>();
builder.Services.AddSingleton<PointsService>();
@ -61,6 +63,8 @@ namespace API_SequentMicrosystems
app.Services.GetService<RTDDAService>();
app.Services.GetService<PointsService>();
app.MapHub<SyncHub>("/signalr/sync");
app.MapControllers();
app.Run();

View File

@ -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)