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. /// The connection metadata for the newly established session. 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. /// A task that represents the asynchronous operation. 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. /// The current data value of the node. 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. /// The status code returned by the server for the write. 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. /// The child nodes discovered under . 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. /// A task that represents the asynchronous operation. 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. /// A task that represents the asynchronous operation. 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. /// A task that represents the asynchronous operation. Task SubscribeAlarmsAsync(NodeId? sourceNodeId = null, int intervalMs = 1000, CancellationToken ct = default); /// /// Removes the active alarm subscription. /// /// The cancellation token that aborts alarm subscription cleanup. /// A task that represents the asynchronous operation. 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. /// A task that represents the asynchronous operation. 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. /// /// on success, or the server's bad /// (from the underlying ) when the acknowledge call /// returns a bad result. Other transport-level failures still surface as exceptions. /// Task AcknowledgeAlarmAsync(string conditionNodeId, byte[] eventId, string comment, CancellationToken ct = default); /// /// Confirms an acknowledged condition (Part 9 two-stage acknowledgment) using the event identifier returned by an alarm notification. /// /// The condition node associated with the alarm event being confirmed. /// The event identifier returned by the OPC UA server for the alarm event. /// The operator confirmation comment to write with the method call. /// The cancellation token that aborts the confirmation request. /// /// on success, or the server's bad /// (from the underlying ) when the confirm call /// returns a bad result. Other transport-level failures still surface as exceptions. /// Task ConfirmAlarmAsync(string conditionNodeId, byte[] eventId, string comment, CancellationToken ct = default); /// /// Attaches an operator comment to a condition (Part 9 AddComment) using the event identifier of an alarm notification. /// /// The condition node the comment is attached to. /// The event identifier returned by the OPC UA server for the alarm event. /// The operator comment. /// The cancellation token that aborts the request. /// on success, or the server's bad when the call is refused. Task AddCommentAsync(string conditionNodeId, byte[] eventId, string comment, CancellationToken ct = default); /// /// Shelves or unshelves an active alarm condition (OPC UA Part 9 ShelvedStateMachine). /// /// The condition node associated with the alarm being shelved. /// The shelve operation: OneShot, Timed, or Unshelve. /// /// For Timed shelving: the shelving duration in seconds (must be > 0). /// This value is converted to milliseconds when passed to the OPC UA TimedShelve method /// (Duration is milliseconds per OPC UA Part 9). Ignored for OneShot and Unshelve. /// /// The cancellation token that aborts the shelve request. /// /// on success, or the server's bad /// (from the underlying ) when the shelve call /// returns a bad result. Other transport-level failures still surface as exceptions. /// Task ShelveAlarmAsync(string conditionNodeId, ShelveKind kind, double shelvingTimeSeconds = 0, CancellationToken ct = default); /// /// Enables an alarm condition by invoking the OPC UA Part 9 ConditionType Enable method /// (the H4 client-driven path). The method takes no input arguments. /// /// The condition node associated with the alarm being enabled. /// The cancellation token that aborts the enable request. /// /// on success, or the server's bad /// (from the underlying ) when the enable call /// returns a bad result. Other transport-level failures still surface as exceptions. /// Task EnableAsync(string conditionNodeId, CancellationToken ct = default); /// /// Disables an alarm condition by invoking the OPC UA Part 9 ConditionType Disable method /// (the H4 client-driven path). The method takes no input arguments. /// /// The condition node associated with the alarm being disabled. /// The cancellation token that aborts the disable request. /// /// on success, or the server's bad /// (from the underlying ) when the disable call /// returns a bad result. Other transport-level failures still surface as exceptions. /// Task DisableAsync(string conditionNodeId, 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. /// The raw historical samples in the requested range, up to . 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. /// The aggregated historical values for each processing interval in the requested range. 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. /// The current redundancy status of the connected server. 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; }