diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Clients/AdminOperationsClient.cs b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Clients/AdminOperationsClient.cs new file mode 100644 index 0000000..b73503a --- /dev/null +++ b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Clients/AdminOperationsClient.cs @@ -0,0 +1,33 @@ +using Akka.Actor; +using Akka.Hosting; +using ZB.MOM.WW.OtOpcUa.Commons.Interfaces; +using ZB.MOM.WW.OtOpcUa.Commons.Messages.Admin; +using ZB.MOM.WW.OtOpcUa.Commons.Types; +using ZB.MOM.WW.OtOpcUa.ControlPlane; + +namespace ZB.MOM.WW.OtOpcUa.AdminUI.Clients; + +/// +/// backed by the cluster singleton registered in +/// AddOtOpcUaControlPlane. Resolves the singleton proxy from +/// at construction time; each call Asks the proxy with a 10s timeout. +/// +public sealed class AdminOperationsClient : IAdminOperationsClient +{ + private static readonly TimeSpan AskTimeout = TimeSpan.FromSeconds(10); + + private readonly IActorRef _proxy; + + public AdminOperationsClient(ActorRegistry registry) + { + _proxy = registry.Get(); + } + + public async Task StartDeploymentAsync(string createdBy, CancellationToken ct) + { + var msg = new StartDeployment(createdBy, CorrelationId.NewId()); + using var linked = CancellationTokenSource.CreateLinkedTokenSource(ct); + linked.CancelAfter(AskTimeout); + return await _proxy.Ask(msg, AskTimeout, linked.Token); + } +} diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Clients/ServiceCollectionExtensions.cs b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Clients/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..39c96c5 --- /dev/null +++ b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Clients/ServiceCollectionExtensions.cs @@ -0,0 +1,14 @@ +using Microsoft.Extensions.DependencyInjection; +using ZB.MOM.WW.OtOpcUa.Commons.Interfaces; + +namespace ZB.MOM.WW.OtOpcUa.AdminUI.Clients; + +public static class ServiceCollectionExtensions +{ + public static IServiceCollection AddOtOpcUaAdminClients(this IServiceCollection services) + { + services.AddScoped(); + services.AddScoped(); + return services; + } +}