diff --git a/AsbCloudApp/IntegrationEvents/Events/IIntegrationEvent.cs b/AsbCloudApp/IntegrationEvents/Events/IIntegrationEvent.cs
new file mode 100644
index 00000000..c44d83a0
--- /dev/null
+++ b/AsbCloudApp/IntegrationEvents/Events/IIntegrationEvent.cs
@@ -0,0 +1,6 @@
+namespace AsbCloudApp.IntegrationEvents.Events;
+
+///
+/// Интерфейс маркер для доменных событий
+///
+public interface IIntegrationEvent { }
\ No newline at end of file
diff --git a/AsbCloudApp/IntegrationEvents/Events/WellInfoUpdaterEvent.cs b/AsbCloudApp/IntegrationEvents/Events/WellInfoUpdaterEvent.cs
new file mode 100644
index 00000000..6e95e72e
--- /dev/null
+++ b/AsbCloudApp/IntegrationEvents/Events/WellInfoUpdaterEvent.cs
@@ -0,0 +1,7 @@
+namespace AsbCloudApp.IntegrationEvents.Events;
+
+///
+/// Обновление информации о скважине
+///
+///
+public record WellInfoUpdaterEvent(int IdWell) : IIntegrationEvent;
\ No newline at end of file
diff --git a/AsbCloudApp/IntegrationEvents/IIntegrationEventHandler.cs b/AsbCloudApp/IntegrationEvents/IIntegrationEventHandler.cs
new file mode 100644
index 00000000..1fec260a
--- /dev/null
+++ b/AsbCloudApp/IntegrationEvents/IIntegrationEventHandler.cs
@@ -0,0 +1,20 @@
+using System.Threading;
+using System.Threading.Tasks;
+using AsbCloudApp.IntegrationEvents.Events;
+
+namespace AsbCloudApp.IntegrationEvents;
+
+///
+/// Обработчик событий
+///
+///
+public interface IIntegrationEventHandler where T: IIntegrationEvent
+{
+ ///
+ /// Метод обработки события
+ ///
+ ///
+ ///
+ ///
+ Task HandleAsync(T integrationEvent, CancellationToken cancellationToken);
+}
\ No newline at end of file
diff --git a/AsbCloudInfrastructure/Services/WellInfoService.cs b/AsbCloudInfrastructure/Services/WellInfoService.cs
index 7066ef22..c05b51a2 100644
--- a/AsbCloudInfrastructure/Services/WellInfoService.cs
+++ b/AsbCloudInfrastructure/Services/WellInfoService.cs
@@ -16,6 +16,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using AsbCloudApp.IntegrationEvents;
+using AsbCloudApp.IntegrationEvents.Events;
namespace AsbCloudInfrastructure.Services
{
@@ -36,7 +38,7 @@ namespace AsbCloudInfrastructure.Services
private readonly IWitsRecordRepository witsRecord1Repository;
private readonly IGtrRepository gtrRepository;
private static IEnumerable WellMapInfo = Enumerable.Empty();
-
+
public WellInfoService(
TelemetryDataCache telemetryDataSaubCache,
TelemetryDataCache telemetryDataSpinCache,
@@ -69,6 +71,7 @@ namespace AsbCloudInfrastructure.Services
var processMapRepository = serviceProvider.GetRequiredService();
var subsystemOperationTimeService = serviceProvider.GetRequiredService();
var telemetryDataSaubCache = serviceProvider.GetRequiredService>();
+ var messageHub = serviceProvider.GetRequiredService>();
var activeWells = await wellService.GetAsync(new() {IdState = 1}, token);
@@ -167,6 +170,11 @@ namespace AsbCloudInfrastructure.Services
return wellMapInfo;
}).ToArray();
+
+ foreach (var idWell in activeWellsIds)
+ {
+ await messageHub.HandleAsync(new WellInfoUpdaterEvent(idWell), token);
+ }
}
private WellMapInfoWithTelemetryStat Convert(WellMapInfoWithComanies wellInfo)
diff --git a/AsbCloudWebApi/DependencyInjection.cs b/AsbCloudWebApi/DependencyInjection.cs
index 7477f745..a0a6ab24 100644
--- a/AsbCloudWebApi/DependencyInjection.cs
+++ b/AsbCloudWebApi/DependencyInjection.cs
@@ -3,7 +3,6 @@ using AsbCloudApp.Repositories;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services;
using Microsoft.AspNetCore.Authentication.JwtBearer;
-using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
@@ -12,8 +11,12 @@ using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
+using AsbCloudApp.IntegrationEvents;
+using AsbCloudApp.IntegrationEvents.Events;
using AsbCloudApp.Services.Notifications;
+using AsbCloudWebApi.SignalR;
using AsbCloudWebApi.SignalR.Services;
+using Microsoft.AspNetCore.Mvc;
using Microsoft.OpenApi.Any;
namespace AsbCloudWebApi
@@ -140,5 +143,8 @@ namespace AsbCloudWebApi
{
services.AddTransient();
}
+
+ public static void AddIntegrationEvents(this IServiceCollection services) => services
+ .AddTransient, WellInfoUpdaterHub>();
}
}
diff --git a/AsbCloudWebApi/SignalR/WellInfoUpdaterHub.cs b/AsbCloudWebApi/SignalR/WellInfoUpdaterHub.cs
new file mode 100644
index 00000000..9490df4d
--- /dev/null
+++ b/AsbCloudWebApi/SignalR/WellInfoUpdaterHub.cs
@@ -0,0 +1,49 @@
+using System.Text.Json;
+using System.Threading;
+using System.Threading.Tasks;
+using AsbCloudApp.IntegrationEvents;
+using AsbCloudApp.IntegrationEvents.Events;
+using AsbCloudInfrastructure.Services;
+using Microsoft.AspNetCore.SignalR;
+
+namespace AsbCloudWebApi.SignalR;
+
+public class WellInfoUpdaterHub : Hub, IIntegrationEventHandler
+{
+ private const string groupTemplate = "system_operation_updater_well_{0}";
+
+ private readonly IHubContext hubContext;
+ private readonly WellInfoService wellInfoService;
+
+ public WellInfoUpdaterHub(IHubContext hubContext,
+ WellInfoService wellInfoService)
+ {
+ this.hubContext = hubContext;
+ this.wellInfoService = wellInfoService;
+ }
+
+ public async Task OnConnectedAsync(int idWell)
+ {
+ await base.OnConnectedAsync();
+
+ await Groups.AddToGroupAsync(Context.ConnectionId, string.Format(groupTemplate, idWell));
+
+ await HandleAsync(new WellInfoUpdaterEvent(idWell), CancellationToken.None);
+ }
+
+ public async Task HandleAsync(WellInfoUpdaterEvent integrationEvent, CancellationToken cancellationToken)
+ {
+ const string method = "well_info_update";
+
+ var wellInfo = wellInfoService.FirstOrDefault(w => w.Id == integrationEvent.IdWell);
+
+ if (wellInfo != null)
+ {
+ var serializedObject = JsonSerializer.Serialize(wellInfo);
+
+ await hubContext.Clients.Group(string.Format(groupTemplate, integrationEvent.IdWell))
+ .SendCoreAsync(method, new object[] { serializedObject }, cancellationToken);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/AsbCloudWebApi/Startup.cs b/AsbCloudWebApi/Startup.cs
index 0fb3ba87..aadaf829 100644
--- a/AsbCloudWebApi/Startup.cs
+++ b/AsbCloudWebApi/Startup.cs
@@ -45,6 +45,8 @@ namespace AsbCloudWebApi
services.AddNotificationTransportServices();
+ services.AddIntegrationEvents();
+
services.AddJWTAuthentication();
services.AddSignalR()
@@ -151,6 +153,7 @@ namespace AsbCloudWebApi
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
+ endpoints.MapHub("/hubs/limitingParameters");
endpoints.MapHub("/hubs/notifications");
endpoints.MapHub("/hubs/telemetry");
endpoints.MapHub("/hubs/reports");
diff --git a/SignalRTestClient/Program.cs b/SignalRTestClient/Program.cs
index 487f1253..9ae72e04 100644
--- a/SignalRTestClient/Program.cs
+++ b/SignalRTestClient/Program.cs
@@ -10,7 +10,7 @@ internal class Program
{
var connectionBuilder = new HubConnectionBuilder();
var connection = connectionBuilder
- .WithUrl("http://localhost:5000/hubs/notifications", connectionOptions => {
+ .WithUrl("http://localhost:5000/hubs/limitingParameters", connectionOptions => {
connectionOptions.AccessTokenProvider = AccessTokenProvider;
})
.WithAutomaticReconnect()
@@ -26,9 +26,9 @@ internal class Program
connection.StartAsync().Wait();
//Console.WriteLine("OnConnected");
- //connection.SendCoreAsync("OnConnected", new object[] { }, CancellationToken.None).Wait();
+ connection.SendCoreAsync("OnConnectedAsync", new object[] { 1 }, CancellationToken.None).Wait();
- var subsction = connection.On