namespace ZB.MOM.WW.OtOpcUa.Core.Abstractions; /// /// Driver capability for historical-data reads (OPC UA HistoryRead). Optional — /// only drivers whose backends carry historian data implement this. Currently: /// Galaxy (Wonderware Historian via the optional plugin), OPC UA Client (forward /// to upstream server). /// public interface IHistoryProvider { /// /// Read raw historical samples for a single attribute over a time range. /// The Core wraps this with continuation-point handling. /// Task ReadRawAsync( string fullReference, DateTime startUtc, DateTime endUtc, uint maxValuesPerNode, CancellationToken cancellationToken); /// /// Read processed (aggregated) samples — interval-bucketed average / min / max / etc. /// Optional — drivers that only support raw history can throw . /// Task ReadProcessedAsync( string fullReference, DateTime startUtc, DateTime endUtc, TimeSpan interval, HistoryAggregateType aggregate, CancellationToken cancellationToken); /// /// Read one sample per requested timestamp — OPC UA HistoryReadAtTime service. The /// driver interpolates (or returns the prior-boundary sample) when no exact match /// exists. Optional; drivers that can't interpolate throw . /// /// /// Default implementation throws. Drivers opt in by overriding; keeps existing /// IHistoryProvider implementations compiling without forcing a ReadAtTime path /// they may not have a backend for. /// Task ReadAtTimeAsync( string fullReference, IReadOnlyList timestampsUtc, CancellationToken cancellationToken) => throw new NotSupportedException( $"{GetType().Name} does not implement ReadAtTimeAsync. " + "Drivers whose backends support at-time reads override this method."); /// /// Read historical alarm/event records — OPC UA HistoryReadEvents service. Distinct /// from the live event stream — historical rows come from an event historian (Galaxy's /// Alarm Provider history log, etc.) rather than the driver's active subscription. /// /// /// Optional filter: null means "all sources", otherwise restrict to events from that /// source-object name. Drivers may ignore the filter if the backend doesn't support it. /// /// Inclusive lower bound on EventTimeUtc. /// Exclusive upper bound on EventTimeUtc. /// Upper cap on returned events — the driver's backend enforces this. /// Request cancellation. /// /// Default implementation throws. Only drivers with an event historian (Galaxy via the /// Wonderware Alarm & Events log) override. Modbus / the OPC UA Client driver stay /// with the default and let callers see BadHistoryOperationUnsupported. /// Task ReadEventsAsync( string? sourceName, DateTime startUtc, DateTime endUtc, int maxEvents, CancellationToken cancellationToken) => throw new NotSupportedException( $"{GetType().Name} does not implement ReadEventsAsync. " + "Drivers whose backends have an event historian override this method."); } /// Result of a HistoryRead call. /// Returned samples in chronological order. /// Opaque token for the next call when more samples are available; null when complete. public sealed record HistoryReadResult( IReadOnlyList Samples, byte[]? ContinuationPoint); /// Aggregate function for processed history reads. Mirrors OPC UA Part 13 standard aggregates. public enum HistoryAggregateType { Average, Minimum, Maximum, Total, Count, } /// /// One row returned by — a historical /// alarm/event record, not the OPC UA live-event stream. Fields match the minimum set the /// Server needs to populate a HistoryEventFieldList for HistoryReadEvents responses. /// /// Stable unique id for the event — driver-specific format. /// Source object that emitted the event. May differ from the sourceName filter the caller passed (fuzzy matches). /// Process-side timestamp — when the event actually occurred. /// Historian-side timestamp — when the historian persisted the row; may lag by the historian's buffer flush cadence. /// Human-readable message text. /// OPC UA severity (1-1000). Drivers map their native priority scale onto this range. public sealed record HistoricalEvent( string EventId, string? SourceName, DateTime EventTimeUtc, DateTime ReceivedTimeUtc, string? Message, ushort Severity); /// Result of a call. /// Events in chronological order by EventTimeUtc. /// Opaque token for the next call when more events are available; null when complete. public sealed record HistoricalEventsResult( IReadOnlyList Events, byte[]? ContinuationPoint);