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; /// Initializes a new instance of the AdminOperationsClient. /// The actor registry to resolve the admin operations singleton 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); } /// public async Task AcknowledgeAlarmAsync( string alarmId, string user, string? comment, CancellationToken ct) { var msg = new AcknowledgeAlarmCommand(alarmId, user, comment, CorrelationId.NewId()); using var linked = CancellationTokenSource.CreateLinkedTokenSource(ct); linked.CancelAfter(AskTimeout); return await _proxy.Ask(msg, AskTimeout, linked.Token); } /// public async Task ShelveAlarmAsync( string alarmId, string user, ShelveKind kind, DateTime? unshelveAtUtc, string? comment, CancellationToken ct) { var msg = new ShelveAlarmCommand(alarmId, user, kind, unshelveAtUtc, comment, CorrelationId.NewId()); using var linked = CancellationTokenSource.CreateLinkedTokenSource(ct); linked.CancelAfter(AskTimeout); return await _proxy.Ask(msg, AskTimeout, linked.Token); } /// public Task AskAsync(object message, CancellationToken ct) => _proxy.Ask(message, cancellationToken: ct); }