using ZB.MOM.WW.HistorianGateway.Contracts.Grpc; using ZB.MOM.WW.OtOpcUa.Core.Abstractions; namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway.Mapping; /// /// Maps the driver-agnostic (OPC UA Part 13 aggregate) onto the /// gateway's native . /// /// /// /// Average/Minimum/Maximum line up with the legacy Wonderware client's aggregate mapping. The two /// remaining members are now served by native gateway retrieval modes: /// → and /// → . /// /// /// This replaces the Wonderware-era client-side workarounds (Total derived as Average × interval, /// Count approximated from a value count): no client-side scaling is performed any more, so the /// gateway path is a strict improvement. /// /// internal static class AggregateModeMapper { /// Maps an aggregate function to the gateway retrieval mode. /// The driver-agnostic aggregate function. /// The matching gateway . /// A defined member the gateway has no retrieval mode for. /// An undefined enum value. public static RetrievalMode ToRetrievalMode(HistoryAggregateType aggregate) => aggregate switch { HistoryAggregateType.Average => RetrievalMode.TimeWeightedAverage, HistoryAggregateType.Minimum => RetrievalMode.MinimumWithTime, HistoryAggregateType.Maximum => RetrievalMode.MaximumWithTime, HistoryAggregateType.Total => RetrievalMode.Integral, HistoryAggregateType.Count => RetrievalMode.Counter, // Part 13 aggregates the gateway has no retrieval mode for (#285) — an UNDEFINED enum value is a // programming error, but a defined-yet-unserved member is a normal client request the server // answers with BadAggregateNotSupported. _ when Enum.IsDefined(aggregate) => throw new HistoryAggregateNotSupportedException(aggregate), _ => throw new ArgumentOutOfRangeException( nameof(aggregate), aggregate, "Unmapped HistoryAggregateType — add a RetrievalMode mapping."), }; }