feat(cli): historyread --events reads event history over the wire (lmxopcua#776)
v2-ci / unit-tests (push) Has been cancelled

Item 1 of #776 (the B2 over-the-wire ask): Client.CLI had no way to issue a
HistoryReadEvents. `historyread --events` now sends ReadEventDetails to an
event notifier and prints one line per event in select-clause order.
--fields picks the select clauses (default EventId, EventType, Time,
SourceName, Severity, Message, ConditionName (on ConditionType), SourceNode);
--of-type adds an OfType where-clause. --events is exclusive with --modified /
--aggregate, and --fields / --of-type require it.

Client.Shared gains IOpcUaClientService/ISessionAdapter.HistoryReadEventsAsync
(default-implemented as NotSupported for other implementations) backed by the
real session adapter through HistoryReadPaging, so continuation points are
followed up to --max and a Bad node status is surfaced, not printed as empty.

Tests: CLI tests over the fake service (default filter, --fields/--of-type
filter, option conflicts); an over-the-wire test drives the shared client's
event read against the in-process server — the default fields come back
non-null, OfType filters, an invalid where-clause is BadEventFilterInvalid.
The other #776 items are decisions and are left open.

Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
Joseph Doherty
2026-11-09 16:07:11 -05:00
parent e790938f94
commit 380ec541c2
11 changed files with 369 additions and 4 deletions
@@ -178,6 +178,27 @@ internal sealed class DefaultSessionAdapter : ISessionAdapter
ToModifiedEntries, maxValues, nodeId, ct).ConfigureAwait(false);
}
/// <inheritdoc />
public async Task<IReadOnlyList<Models.HistoryEventEntry>> HistoryReadEventsAsync(
NodeId nodeId, DateTime startTime, DateTime endTime, int maxEvents, EventFilter filter, CancellationToken ct)
{
ArgumentNullException.ThrowIfNull(filter);
var details = new ReadEventDetails
{
StartTime = startTime,
EndTime = endTime,
NumValuesPerNode = (uint)maxEvents,
Filter = filter
};
return await HistoryReadPaging.ReadAllAsync(
(cp, release, token) => ReadHistoryPageAsync(details, nodeId, cp, release, TimestampsToReturn.Both, token),
result => result.HistoryData is ExtensionObject { Body: HistoryEvent historyEvent }
? historyEvent.Events.Select(e => new Models.HistoryEventEntry(e.EventFields?.ToArray() ?? []))
: [],
maxEvents, nodeId, ct).ConfigureAwait(false);
}
private static IEnumerable<Models.HistoryModifiedEntry> ToModifiedEntries(HistoryReadResult result)
{
if (result.HistoryData is not ExtensionObject { Body: HistoryModifiedData modified }) yield break;
@@ -194,7 +215,7 @@ internal sealed class DefaultSessionAdapter : ISessionAdapter
/// <summary>Issues one single-node HistoryRead (or a release of its continuation point).</summary>
private async Task<HistoryReadResult?> ReadHistoryPageAsync(
ReadRawModifiedDetails details, NodeId nodeId, byte[]? continuationPoint, bool release,
HistoryReadDetails details, NodeId nodeId, byte[]? continuationPoint, bool release,
TimestampsToReturn timestamps, CancellationToken ct)
{
var nodesToRead = new HistoryReadValueIdCollection
@@ -116,6 +116,21 @@ internal interface ISessionAdapter : IDisposable
DateTime endTime, int maxValues, CancellationToken ct = default) =>
throw new NotSupportedException("This session adapter does not support modified-value history reads.");
/// <summary>
/// Reads event history (Part 11 HistoryReadEvents) from an event notifier with the supplied event filter, following
/// continuation points.
/// </summary>
/// <param name="nodeId">The event notifier node.</param>
/// <param name="startTime">Window start.</param>
/// <param name="endTime">Window end.</param>
/// <param name="maxEvents">The maximum number of events to return.</param>
/// <param name="filter">The event filter: the select clauses to project and an optional where-clause.</param>
/// <param name="ct">The cancellation token.</param>
/// <returns>The events in server order.</returns>
Task<IReadOnlyList<Models.HistoryEventEntry>> HistoryReadEventsAsync(NodeId nodeId, DateTime startTime,
DateTime endTime, int maxEvents, EventFilter filter, CancellationToken ct = default) =>
throw new NotSupportedException("This session adapter does not support event history reads.");
/// <summary>
/// Sends a HistoryUpdate request for the supplied details.
/// </summary>