using Opc.Ua; using ZB.MOM.WW.OtOpcUa.Client.Shared.Models; using BrowseResult = ZB.MOM.WW.OtOpcUa.Client.Shared.Models.BrowseResult; namespace ZB.MOM.WW.OtOpcUa.Client.Shared; /// /// Shared OPC UA client service contract for CLI and UI consumers. /// public interface IOpcUaClientService : IDisposable { /// /// Gets a value indicating whether the client is currently connected to an OPC UA endpoint. /// bool IsConnected { get; } /// /// Gets the current connection metadata shown to CLI and UI operators after a successful connect or failover. /// ConnectionInfo? CurrentConnectionInfo { get; } /// /// Connects the client to the configured OPC UA endpoint set, including failover-capable endpoints when provided. /// /// The endpoint, security, and authentication settings used to establish the session. /// The cancellation token that aborts the connect workflow. Task ConnectAsync(ConnectionSettings settings, CancellationToken ct = default); /// /// Disconnects from the active OPC UA endpoint and tears down subscriptions owned by the client. /// /// The cancellation token that aborts disconnect cleanup. Task DisconnectAsync(CancellationToken ct = default); /// /// Reads the current value of an OPC UA node. /// /// The node whose value should be retrieved. /// The cancellation token that aborts the read request. Task ReadValueAsync(NodeId nodeId, CancellationToken ct = default); /// /// Writes an operator-supplied value to an OPC UA node after applying client-side type conversion when needed. /// /// The node whose value should be updated. /// The raw value supplied by the CLI or UI workflow. /// The cancellation token that aborts the write request. Task WriteValueAsync(NodeId nodeId, object value, CancellationToken ct = default); /// /// Browses the children of a node so the client can build an address-space tree for operators. /// /// The node to browse, or when omitted. /// The cancellation token that aborts the browse request. Task> BrowseAsync(NodeId? parentNodeId = null, CancellationToken ct = default); /// /// Subscribes to live data changes for a node. /// /// The node whose value changes should be monitored. /// The monitored-item sampling and publishing interval in milliseconds. /// The cancellation token that aborts subscription creation. Task SubscribeAsync(NodeId nodeId, int intervalMs = 1000, CancellationToken ct = default); /// /// Removes a previously created live-data subscription for a node. /// /// The node whose live-data subscription should be removed. /// The cancellation token that aborts the unsubscribe request. Task UnsubscribeAsync(NodeId nodeId, CancellationToken ct = default); /// /// Subscribes to OPC UA alarm and condition events for a source node or the server root. /// /// The event source to monitor, or the server object when omitted. /// The publishing interval in milliseconds for the alarm subscription. /// The cancellation token that aborts alarm subscription creation. Task SubscribeAlarmsAsync(NodeId? sourceNodeId = null, int intervalMs = 1000, CancellationToken ct = default); /// /// Removes the active alarm subscription. /// /// The cancellation token that aborts alarm subscription cleanup. Task UnsubscribeAlarmsAsync(CancellationToken ct = default); /// /// Requests retained alarm conditions again so a client can repopulate its alarm list after reconnecting. /// /// The cancellation token that aborts the condition refresh request. Task RequestConditionRefreshAsync(CancellationToken ct = default); /// /// Acknowledges an active condition using the event identifier returned by an alarm notification. /// /// The condition node associated with the alarm event being acknowledged. /// The event identifier returned by the OPC UA server for the alarm event. /// The operator acknowledgment comment to write with the method call. /// The cancellation token that aborts the acknowledgment request. Task AcknowledgeAlarmAsync(string conditionNodeId, byte[] eventId, string comment, CancellationToken ct = default); /// /// Reads raw historical samples for a historized node. /// /// The historized node whose samples should be read. /// The inclusive start of the requested history range. /// The inclusive end of the requested history range. /// The maximum number of raw values to return. /// The cancellation token that aborts the history read. Task> HistoryReadRawAsync(NodeId nodeId, DateTime startTime, DateTime endTime, int maxValues = 1000, CancellationToken ct = default); /// /// Reads aggregate historical values for a historized node using an OPC UA aggregate function. /// /// The historized node whose processed values should be read. /// The inclusive start of the requested processed-history range. /// The inclusive end of the requested processed-history range. /// The aggregate function the operator selected for processed history. /// The processing interval, in milliseconds, for each aggregate bucket. /// The cancellation token that aborts the processed history request. Task> HistoryReadAggregateAsync(NodeId nodeId, DateTime startTime, DateTime endTime, AggregateType aggregate, double intervalMs = 3600000, CancellationToken ct = default); /// /// Reads redundancy status data such as redundancy mode, service level, and partner endpoint URIs. /// /// The cancellation token that aborts redundancy inspection. Task GetRedundancyInfoAsync(CancellationToken ct = default); /// /// Raised when a subscribed node produces a new live data value. /// event EventHandler? DataChanged; /// /// Raised when an alarm or condition event is received from the server. /// event EventHandler? AlarmEvent; /// /// Raised when the client changes connection state during connect, disconnect, or failover. /// event EventHandler? ConnectionStateChanged; }