docs: fill missing XML docs and strip tracking IDs from src comments
Clears CommentChecker findings in src/ (3,280 -> 209, the remainder being false positives like PLC-5/IEEE-754/M0.0) by adding missing summaries/params/returns, normalising inheritdoc usage, and removing Gitea/review tracking IDs while keeping the rationale they annotated. Comment-only: comment-stripped sources are identical to the parent commit.
This commit is contained in:
@@ -36,9 +36,9 @@ public sealed record MTConnectWriteOutcome(bool Accepted, string? AgentError);
|
||||
/// at all: it is an <see cref="HttpClient"/> over the Agent's three request paths, feeding
|
||||
/// hand-rolled <c>System.Xml.Linq</c> parsers (<c>MTConnectProbeParser</c> /
|
||||
/// <c>MTConnectStreamsParser</c>) plus a <c>multipart/x-mixed-replace</c> frame reader for the
|
||||
/// <c>/sample</c> long poll. (Task 0 planned to build on the TrakHound MTConnect.NET libraries;
|
||||
/// Tasks 6 and 7 proved they can neither parse a document nor frame the stream socket-free, and
|
||||
/// dropped the references — see the Task 0 CORRECTION block in the plan.) A fake for tests only
|
||||
/// <c>/sample</c> long poll. (An earlier plan was to build on the TrakHound MTConnect.NET libraries;
|
||||
/// Prototyping proved they can neither parse a document nor frame the stream socket-free, and
|
||||
/// dropped the references.) A fake for tests only
|
||||
/// needs to implement these four instance members; <see cref="IsSequenceGap"/> is a static
|
||||
/// protocol rule that lives here, rather than on the implementation, so a consumer written
|
||||
/// against this seam never has to reference the concrete client.
|
||||
@@ -73,6 +73,7 @@ public interface IMTConnectAgentClient : IDisposable
|
||||
/// browse tree, where each <see cref="MTConnectDataItem.Id"/> becomes a tag's FullName.
|
||||
/// </summary>
|
||||
/// <param name="ct">Cancellation token.</param>
|
||||
/// <returns>The parsed device hierarchy.</returns>
|
||||
Task<MTConnectProbeModel> ProbeAsync(CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
@@ -81,6 +82,7 @@ public interface IMTConnectAgentClient : IDisposable
|
||||
/// a detected sequence gap in <see cref="SampleAsync"/>.
|
||||
/// </summary>
|
||||
/// <param name="ct">Cancellation token.</param>
|
||||
/// <returns>The latest observation for every data item.</returns>
|
||||
Task<MTConnectStreamsResult> CurrentAsync(CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
@@ -94,7 +96,7 @@ public interface IMTConnectAgentClient : IDisposable
|
||||
/// writing its closing boundary, or the endpoint turning out not to stream at all —
|
||||
/// throws an <see cref="MTConnectStreamException"/> naming which. A consumer therefore
|
||||
/// never has to treat "the enumeration finished" as an ambiguous signal, and cannot
|
||||
/// silently lose its subscription to a data path that quietly stopped (#485). See
|
||||
/// silently lose its subscription to a data path that quietly stopped. See
|
||||
/// <see cref="MTConnectStreamEndedException"/> (transient — reconnect) and
|
||||
/// <see cref="MTConnectStreamNotSupportedException"/> (configuration — reconnecting will
|
||||
/// reproduce it forever).
|
||||
@@ -108,6 +110,7 @@ public interface IMTConnectAgentClient : IDisposable
|
||||
/// </remarks>
|
||||
/// <param name="from">The sequence number to resume streaming from.</param>
|
||||
/// <param name="ct">Cancellation token; cancelling is the contracted way to end the stream.</param>
|
||||
/// <returns>An asynchronous sequence of streams results, one per multipart chunk.</returns>
|
||||
IAsyncEnumerable<MTConnectStreamsResult> SampleAsync(long from, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// bounded by <see cref="MTConnectDriverOptions.RequestTimeoutMs"/>, while <c>/sample</c> is
|
||||
/// a long poll that is <i>supposed</i> to outlive that bound indefinitely. Raising the one
|
||||
/// timeout to suit the stream would un-bound the unary deadline — precisely what arch-review
|
||||
/// R2-01 says must never happen — so the streaming leg gets its own client with
|
||||
/// the arch review says must never happen — so the streaming leg gets its own client with
|
||||
/// <see cref="Timeout.InfiniteTimeSpan"/> and is bounded differently instead (below). In
|
||||
/// production each client owns its own handler and connection pool; in tests both are built
|
||||
/// over one injected handler, which the caller owns.
|
||||
@@ -42,7 +42,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// client can tell "quiet but alive" from "dead", so every body read is bounded by a
|
||||
/// two-missed-heartbeat window and a silent Agent surfaces as a
|
||||
/// <see cref="TimeoutException"/>. This is the exact shape of this repo's S7 frozen-peer
|
||||
/// production defect (arch-review R2-01) — an async read that ignores the socket deadline —
|
||||
/// production defect — an async read that ignores the socket deadline —
|
||||
/// and the watchdog is what closes it here.
|
||||
/// </para>
|
||||
/// <para>
|
||||
@@ -53,8 +53,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// surface as a parse failure that never names the offending config key.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Disposal is safe against an in-flight enumeration.</b> Task 9 re-initializes the
|
||||
/// driver by disposing and rebuilding this client, which can happen while a pump is still
|
||||
/// <b>Disposal is safe against an in-flight enumeration.</b> Re-initialization disposes and rebuilds this client, which can happen while a pump is still
|
||||
/// enumerating <see cref="SampleAsync"/>. Rather than letting the in-flight read fault with
|
||||
/// an unclassified <see cref="ObjectDisposedException"/> or <see cref="IOException"/> that no
|
||||
/// caller is written to expect, every request runs under a token linked to an internal
|
||||
@@ -65,7 +64,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// This class does not swallow failures into an empty model: an unreachable Agent, a non-2xx
|
||||
/// status, an unparseable body, and <b>the end of a <c>/sample</c> stream</b> all throw. See
|
||||
/// <see cref="MTConnectStreamException"/> for why the last of those is an exception rather
|
||||
/// than a normal end of enumeration. <c>InitializeAsync</c> (Task 9) is what catches these
|
||||
/// than a normal end of enumeration. <c>InitializeAsync</c> is what catches these
|
||||
/// and moves the driver to Faulted.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
@@ -88,7 +87,7 @@ public sealed class MTConnectAgentClient : IMTConnectAgentClient, IDisposable
|
||||
/// than a <c>bool</c> so the claim is an <see cref="Interlocked.Exchange(ref int, int)"/>:
|
||||
/// a check-then-set let two concurrent disposals both pass, and the loser then cancelled a
|
||||
/// <see cref="CancellationTokenSource"/> the winner had already disposed
|
||||
/// (Driver.MTConnect-007). Read with <c>Volatile.Read</c> at the request seams for the same
|
||||
/// Read with <c>Volatile.Read</c> at the request seams for the same
|
||||
/// reason.
|
||||
/// </summary>
|
||||
private int _disposed;
|
||||
@@ -116,6 +115,9 @@ public sealed class MTConnectAgentClient : IMTConnectAgentClient, IDisposable
|
||||
/// sends through the supplied handler so the request/response round trip can be exercised
|
||||
/// with no socket. The caller retains ownership of <paramref name="handler"/>.
|
||||
/// </summary>
|
||||
/// <param name="options">The driver options (agent endpoint, timeouts).</param>
|
||||
/// <param name="handler">The HTTP message handler to send through, or null for the default.</param>
|
||||
/// <param name="logger">The logger, or null for none.</param>
|
||||
internal MTConnectAgentClient(MTConnectDriverOptions options, HttpMessageHandler? handler, ILogger? logger = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(options);
|
||||
@@ -219,7 +221,7 @@ public sealed class MTConnectAgentClient : IMTConnectAgentClient, IDisposable
|
||||
// exactly this shape (text/xml under HTTP 200) and the Agent's own error text is far
|
||||
// more useful than ours — then report the misconfiguration. The parsed snapshot is
|
||||
// deliberately NOT yielded: one document followed by a healthy-looking finished stream
|
||||
// is how a dead data path disguises itself as a working one (#485).
|
||||
// is how a dead data path disguises itself as a working one.
|
||||
var single = await ReadWholeBodyAsync(body, uri, lifetime).ConfigureAwait(false);
|
||||
_ = MTConnectStreamsParser.Parse(single);
|
||||
|
||||
@@ -256,16 +258,14 @@ public sealed class MTConnectAgentClient : IMTConnectAgentClient, IDisposable
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// Issued on <c>_http</c>, the <b>unary</b> client — the write is a short request/response
|
||||
/// and must be bounded by <c>RequestTimeoutMs</c> like the other unary legs. Sending it on
|
||||
/// the streaming client would inherit that client's infinite timeout, and a frozen Agent
|
||||
/// would park a write forever with nothing to bound it (the streaming leg's heartbeat
|
||||
/// watchdog protects a multipart body, not a one-shot POST).
|
||||
/// </remarks>
|
||||
public async Task<MTConnectWriteOutcome> WriteObservationAsync(
|
||||
string deviceName, string dataItemId, string value, CancellationToken cancellationToken)
|
||||
{
|
||||
// Issued on _http, the unary client — the write is a short request/response
|
||||
// and must be bounded by RequestTimeoutMs like the other unary legs. Sending it on
|
||||
// the streaming client would inherit that client's infinite timeout, and a frozen Agent
|
||||
// would park a write forever with nothing to bound it (the streaming leg's heartbeat
|
||||
// watchdog protects a multipart body, not a one-shot POST).
|
||||
ObjectDisposedException.ThrowIf(Volatile.Read(ref _disposed) != 0, this);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(deviceName);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(dataItemId);
|
||||
@@ -379,11 +379,11 @@ public sealed class MTConnectAgentClient : IMTConnectAgentClient, IDisposable
|
||||
?? "The Agent answered with an MTConnectError document carrying no error detail.";
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <summary>Cancels in-flight reads and releases the HTTP clients.</summary>
|
||||
/// <remarks>
|
||||
/// Idempotent, including under a race: the teardown is claimed with a single atomic exchange,
|
||||
/// so a second concurrent caller returns rather than cancelling an already-disposed
|
||||
/// <see cref="CancellationTokenSource"/> (Driver.MTConnect-007).
|
||||
/// <see cref="CancellationTokenSource"/>.
|
||||
/// </remarks>
|
||||
public void Dispose()
|
||||
{
|
||||
@@ -589,8 +589,8 @@ public sealed class MTConnectAgentClient : IMTConnectAgentClient, IDisposable
|
||||
/// <b>Why hand-rolled.</b> ASP.NET Core's <c>MultipartReader</c> is not in this
|
||||
/// dependency set, and TrakHound's <c>MTConnectHttpClientStream</c> — the one candidate
|
||||
/// the plan left open — takes a URL and dials its own socket, so it can neither be fed an
|
||||
/// existing response stream nor be exercised without a listener. See the Task 0
|
||||
/// correction in the plan.
|
||||
/// existing response stream nor be exercised without a listener. See the plan
|
||||
/// correction.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Two framing paths, and the first one matters for latency.</b> When the part carries
|
||||
@@ -606,7 +606,7 @@ public sealed class MTConnectAgentClient : IMTConnectAgentClient, IDisposable
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Every read is watchdog-bounded.</b> A silent peer faults the stream rather than
|
||||
/// parking a task forever (arch-review R2-01), and the buffer is capped so a hostile or
|
||||
/// parking a task forever, and the buffer is capped so a hostile or
|
||||
/// malfunctioning Agent cannot grow it without limit.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
@@ -637,6 +637,8 @@ public sealed class MTConnectAgentClient : IMTConnectAgentClient, IDisposable
|
||||
/// which reads UTF-8 off a stream itself. Decoding here would materialise every chunk of
|
||||
/// a never-ending stream twice for a document that is parsed once and dropped.
|
||||
/// </remarks>
|
||||
/// <param name="ct">Cancels the read.</param>
|
||||
/// <returns>The next part's body bytes, or null when the stream has ended.</returns>
|
||||
public async Task<byte[]?> ReadNextPartBytesAsync(CancellationToken ct)
|
||||
{
|
||||
if (_finished)
|
||||
|
||||
@@ -4,7 +4,7 @@ using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
|
||||
/// <summary>
|
||||
/// What the server was last TOLD about one condition (#626): the last alarm statement it was given
|
||||
/// What the server was last TOLD about one condition: the last alarm statement it was given
|
||||
/// (active or Normal — never Unavailable) and whether its Quality is currently annotated Bad.
|
||||
/// </summary>
|
||||
/// <param name="Statement">The last statement delivered; <c>null</c> when only an Unavailable was ever seen.</param>
|
||||
@@ -12,7 +12,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
internal sealed record MTConnectToldCondition(MTConnectConditionState? Statement, bool QualityBad);
|
||||
|
||||
/// <summary>
|
||||
/// The MTConnect CONDITION → OPC UA Part 9 mapping (#626), as one pure function: given what the server was
|
||||
/// The MTConnect CONDITION → OPC UA Part 9 mapping, as one pure function: given what the server was
|
||||
/// last told about a condition and what the Agent says now, the single <see cref="AlarmEventArgs"/> to
|
||||
/// raise — or none — and what the server has then been told.
|
||||
/// </summary>
|
||||
@@ -27,7 +27,7 @@ internal sealed record MTConnectToldCondition(MTConnectConditionState? Statement
|
||||
/// <para>
|
||||
/// <b>Unavailable is comms loss one hop further out, not a return to normal.</b> A cppagent marks every
|
||||
/// DataItem of an adapter UNAVAILABLE when the adapter socket drops, so it is treated exactly like the
|
||||
/// host's own transport loss (#477/#481): an active condition STAYS active (and keeps its ack), only its
|
||||
/// host's own transport loss: an active condition STAYS active (and keeps its ack), only its
|
||||
/// Quality goes Bad, as a quality-only annotation (<see cref="AlarmEventArgs.IsQualityOnly"/>, no
|
||||
/// <c>/alerts</c> row). When data returns: the same statement ⇒ quality-only Good; Normal ⇒ Clear; a
|
||||
/// different active statement ⇒ Retrigger.
|
||||
@@ -45,7 +45,7 @@ internal sealed record MTConnectToldCondition(MTConnectConditionState? Statement
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Resync.</b> On a (re)subscribe an unchanged Bad quality is re-asserted, because the host
|
||||
/// re-annotates every condition Good when the driver reconnects (#477) and nothing else would put the
|
||||
/// re-annotates every condition Good when the driver reconnects and nothing else would put the
|
||||
/// per-condition Bad back.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
@@ -129,6 +129,7 @@ internal static class MTConnectConditionAlarmMapper
|
||||
|
||||
/// <summary>The Part 9 severity of an active level.</summary>
|
||||
/// <param name="level">An active level.</param>
|
||||
/// <returns>The Fault or Warning severity.</returns>
|
||||
internal static int SeverityOf(MTConnectConditionLevel level) =>
|
||||
level == MTConnectConditionLevel.Fault ? FaultSeverity : WarningSeverity;
|
||||
|
||||
@@ -138,6 +139,7 @@ internal static class MTConnectConditionAlarmMapper
|
||||
/// model has no slot for them, and an operator needs the native code to look the alarm up.
|
||||
/// </summary>
|
||||
/// <param name="state">The state to describe.</param>
|
||||
/// <returns>The alarm message text.</returns>
|
||||
internal static string MessageOf(MTConnectConditionState state)
|
||||
{
|
||||
var detail = state.Detail;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
|
||||
/// <summary>The four MTConnect CONDITION levels the alarm path distinguishes (#626).</summary>
|
||||
/// <summary>The four MTConnect CONDITION levels the alarm path distinguishes.</summary>
|
||||
internal enum MTConnectConditionLevel
|
||||
{
|
||||
/// <summary><c><Normal/></c> — nothing is active.</summary>
|
||||
@@ -17,7 +17,7 @@ internal enum MTConnectConditionLevel
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The derived state of ONE CONDITION DataItem as the alarm path sees it (#626): the most severe active
|
||||
/// The derived state of ONE CONDITION DataItem as the alarm path sees it: the most severe active
|
||||
/// condition when any is active, else Normal or Unavailable.
|
||||
/// </summary>
|
||||
/// <param name="Level">The derived level.</param>
|
||||
@@ -61,7 +61,7 @@ internal sealed record MTConnectConditionState(
|
||||
|
||||
/// <summary>
|
||||
/// Folds MTConnect CONDITION observations into per-DataItem alarm state with the protocol's own
|
||||
/// multi-condition semantics (#626) — the alarm path's analogue of <see cref="MTConnectObservationIndex"/>.
|
||||
/// multi-condition semantics — the alarm path's analogue of <see cref="MTConnectObservationIndex"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
@@ -137,6 +137,7 @@ internal sealed class MTConnectConditionTracker
|
||||
|
||||
/// <summary>The derived state of one DataItem, or <c>null</c> when it has never been observed as a condition.</summary>
|
||||
/// <param name="dataItemId">The DataItem id.</param>
|
||||
/// <returns>The derived state, or null when the item was never observed.</returns>
|
||||
public MTConnectConditionState? Get(string dataItemId)
|
||||
{
|
||||
lock (_lock)
|
||||
@@ -176,6 +177,7 @@ internal sealed class MTConnectConditionTracker
|
||||
|
||||
/// <summary>Maps a parsed condition state word onto a level (unknown vendor words ⇒ Warning).</summary>
|
||||
/// <param name="value">The observation's state word.</param>
|
||||
/// <returns>The mapped condition level.</returns>
|
||||
internal static MTConnectConditionLevel LevelOf(string? value) => value switch
|
||||
{
|
||||
UnavailableSentinel => MTConnectConditionLevel.Unavailable,
|
||||
|
||||
@@ -4,7 +4,7 @@ using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IAlarmSource"/> half of <see cref="MTConnectDriver"/> (#626): CONDITION data items as
|
||||
/// The <see cref="IAlarmSource"/> half of <see cref="MTConnectDriver"/>: CONDITION data items as
|
||||
/// native OPC UA Part 9 alarms.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
@@ -38,7 +38,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// <para>
|
||||
/// <b>Comms loss emits nothing here</b>, matching every other native source: a driver that cannot reach
|
||||
/// its Agent has nothing new to say, and the host annotates every condition it owns
|
||||
/// <c>BadNoCommunication</c> on the connectivity edge (#477), keeping each one's Active state. On recovery
|
||||
/// <c>BadNoCommunication</c> on the connectivity edge, keeping each one's Active state. On recovery
|
||||
/// the re-baselined <c>/current</c> is diffed like any other document.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
@@ -52,7 +52,7 @@ public sealed partial class MTConnectDriver : IAlarmSource
|
||||
/// re-subscribe with the SAME reference set (a reconnect) and lifecycle restarts — the server's condition
|
||||
/// nodes outlive both, and re-raising there would un-acknowledge. When the subscribed set changes (an
|
||||
/// alarm-bearing raw-tag delta, i.e. a full rebuild) only the entries that LEFT the set are dropped: the
|
||||
/// server carries every surviving condition's state across the rebuild (Gitea #641), so a survivor needs
|
||||
/// server carries every surviving condition's state across the rebuild, so a survivor needs
|
||||
/// no re-tell, while a condition that comes back later was materialised fresh and is told again.
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, MTConnectToldCondition> _deliveredConditions = new(StringComparer.Ordinal);
|
||||
@@ -75,13 +75,11 @@ public sealed partial class MTConnectDriver : IAlarmSource
|
||||
internal MTConnectConditionTracker ConditionTracker => Volatile.Read(ref _conditions);
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// Collapses to ONE live subscription (the latest), like the Galaxy and FOCAS sources: the owning
|
||||
/// <c>DriverInstanceActor</c> is the only caller and re-subscribes on every Connected entry. Starts the
|
||||
/// shared <c>/sample</c> pump when nothing else had (a driver whose only authored tags are alarms), and
|
||||
/// immediately delivers the current state of every subscribed condition that differs from what the server
|
||||
/// was last told — the re-establish step after a restart or a reconnect.
|
||||
/// </remarks>
|
||||
// Collapses to ONE live subscription (the latest), like the Galaxy and FOCAS sources: the owning
|
||||
// <c>DriverInstanceActor</c> is the only caller and re-subscribes on every Connected entry. Starts the
|
||||
// shared <c>/sample</c> pump when nothing else had (a driver whose only authored tags are alarms), and
|
||||
// immediately delivers the current state of every subscribed condition that differs from what the server
|
||||
// was last told — the re-establish step after a restart or a reconnect.
|
||||
public Task<IAlarmSubscriptionHandle> SubscribeAlarmsAsync(
|
||||
IReadOnlyList<string> sourceNodeIds, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -103,7 +101,7 @@ public sealed partial class MTConnectDriver : IAlarmSource
|
||||
|
||||
lock (_alarmLock)
|
||||
{
|
||||
// Forget only the conditions that LEFT the set (Gitea #641). A changed set is an alarm-bearing delta,
|
||||
// Forget only the conditions that LEFT the set. A changed set is an alarm-bearing delta,
|
||||
// which the server applies as a full rebuild — but the server carries every surviving condition's
|
||||
// state (acknowledgement included) across that rebuild, so re-raising a survivor would only
|
||||
// un-acknowledge it. A condition that left and later comes back was materialised fresh and has no
|
||||
@@ -124,7 +122,7 @@ public sealed partial class MTConnectDriver : IAlarmSource
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>An unknown or superseded handle is a no-op, matching <see cref="UnsubscribeAsync"/>.</remarks>
|
||||
// An unknown or superseded handle is a no-op, matching UnsubscribeAsync.
|
||||
public async Task UnsubscribeAlarmsAsync(IAlarmSubscriptionHandle handle, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(handle);
|
||||
@@ -149,11 +147,9 @@ public sealed partial class MTConnectDriver : IAlarmSource
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// MTConnect has no acknowledgement — an Agent's conditions clear when the machine says so. The Part 9
|
||||
/// Acknowledge (and AddComment) is applied server-side; this is the no-op success the host routes it to,
|
||||
/// so nothing is sent to the Agent and capability negotiation still succeeds. Same posture as FOCAS.
|
||||
/// </remarks>
|
||||
// MTConnect has no acknowledgement — an Agent's conditions clear when the machine says so. The Part 9
|
||||
// Acknowledge (and AddComment) is applied server-side; this is the no-op success the host routes it to,
|
||||
// so nothing is sent to the Agent and capability negotiation still succeeds. Same posture as FOCAS.
|
||||
public Task AcknowledgeAsync(
|
||||
IReadOnlyList<AlarmAcknowledgeRequest> acknowledgements, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <b>The constructor opens nothing and builds nothing.</b> It does not even call
|
||||
/// <c>agentClientFactory</c> — the Wave-0 universal discovery browser constructs a throwaway
|
||||
/// <c>agentClientFactory</c> — the universal discovery browser constructs a throwaway
|
||||
/// instance purely to ask whether the driver can browse, and a constructor that materialized
|
||||
/// a client would open a connection pool per browse probe against a possibly-unreachable
|
||||
/// Agent. Every connection is owned by <see cref="InitializeAsync"/>.
|
||||
@@ -25,21 +25,21 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// and <see cref="ReinitializeAsync"/> both take the document, and the contract is that the driver
|
||||
/// serves it — a driver that read only its constructor options would turn an in-place config
|
||||
/// change into a silent no-op. (The runtime itself now applies a config change by respawning,
|
||||
/// #516/#665.) This class therefore
|
||||
/// .) This class therefore
|
||||
/// re-parses the document (<see cref="ParseOptions"/>) whenever it carries a real body,
|
||||
/// matching S7/AbCip/TwinCAT/Galaxy rather than the Modbus/FOCAS/OpcUaClient drivers that
|
||||
/// ignore the argument. A blank / <c>{}</c> / <c>[]</c> document means "no config supplied"
|
||||
/// and keeps the constructor options, which is what unit tests and the factory path rely on.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Failure is never dressed as success (#485).</b> A failed initialize disposes whatever
|
||||
/// <b>Failure is never dressed as success.</b> A failed initialize disposes whatever
|
||||
/// client it built, drops the probe cache and the observation index, publishes
|
||||
/// <see cref="DriverState.Faulted"/> with the error text, and rethrows — the runtime's
|
||||
/// retry/backoff loop is the recovery path. In particular a <c>/probe</c> that succeeds while
|
||||
/// the priming <c>/current</c> fails is Faulted, not "Healthy with no data": the index IS the
|
||||
/// read surface, so serving that state would render every tag
|
||||
/// <c>BadWaitingForInitialData</c> indefinitely behind a green driver, and the
|
||||
/// <c>/sample</c> cursor (Task 11) only exists because <c>/current</c> reported a
|
||||
/// <c>/sample</c> cursor only exists because <c>/current</c> reported a
|
||||
/// <c>nextSequence</c>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
@@ -47,7 +47,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// <see cref="IWritable"/>, <see cref="ISubscribable"/>, <see cref="ITagDiscovery"/>,
|
||||
/// <see cref="IHostConnectivityProbe"/> and <see cref="IRediscoverable"/> — the last two
|
||||
/// built on state this class already caches (the Agent <c>instanceId</c> and the probe
|
||||
/// model) — plus <see cref="IAlarmSource"/> for CONDITION data items (#626, in
|
||||
/// model) — plus <see cref="IAlarmSource"/> for CONDITION data items (in
|
||||
/// <c>MTConnectDriver.Alarms.cs</c>).
|
||||
/// </para>
|
||||
/// <para>
|
||||
@@ -67,7 +67,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// <b>The read path never writes the shared observation index</b> — see
|
||||
/// <see cref="ReadAsync"/>. That index has exactly one writer: the <c>/sample</c> pump
|
||||
/// (<see cref="RunSampleStreamAsync"/>). The same single-writer discipline covers the two
|
||||
/// Task-13 fields: the <b>connectivity probe loop</b> is the sole writer of
|
||||
/// connectivity-probe fields: the <b>connectivity probe loop</b> is the sole writer of
|
||||
/// <see cref="HostState"/>, and it publishes <b>nothing</b> into
|
||||
/// <see cref="AgentSession.ProbeModel"/> (see <see cref="RunProbeLoopAsync"/>).
|
||||
/// </para>
|
||||
@@ -76,7 +76,7 @@ public sealed partial class MTConnectDriver
|
||||
: IDriver, IReadable, IWritable, ISubscribable, ITagDiscovery, IHostConnectivityProbe, IRediscoverable,
|
||||
ISkippedTagReporter
|
||||
{
|
||||
/// <summary>Authored tags this driver could not bind to an Agent DataItem (Gitea #541).</summary>
|
||||
/// <summary>Authored tags this driver could not bind to an Agent DataItem.</summary>
|
||||
private readonly SkippedTagLedger _skippedTags = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -93,7 +93,7 @@ public sealed partial class MTConnectDriver
|
||||
// ---- Write status codes ----
|
||||
//
|
||||
// NAMED constants, never inline literals: StatusCodeParityTests checks each against the pinned SDK
|
||||
// by reflection and can only see a named const (Gitea #497/#519). The names must match
|
||||
// by reflection and can only see a named const. The names must match
|
||||
// Opc.Ua.StatusCodes members exactly. Spelled WITHOUT the "Status" prefix MqttDriver uses, to match
|
||||
// the two this file already declares (the parity guard strips either spelling).
|
||||
|
||||
@@ -209,7 +209,7 @@ public sealed partial class MTConnectDriver
|
||||
/// no log line to diagnose it from.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>This is aimed squarely at the <c>/sample</c> pump (Task 11).</b> Its ring-buffer
|
||||
/// <b>This is aimed squarely at the <c>/sample</c> pump.</b> Its ring-buffer
|
||||
/// re-baseline ("on a sequence gap, re-<c>/current</c> and resume") is naturally written
|
||||
/// as "just call the existing re-init logic" — and
|
||||
/// <see cref="ReinitializeAsync"/>/<see cref="InitializeAsync"/> both take this
|
||||
@@ -223,7 +223,7 @@ public sealed partial class MTConnectDriver
|
||||
/// <para>
|
||||
/// The inverse direction is already safe: the lifecycle methods call
|
||||
/// <see cref="StopSampleStreamAsync"/> while holding this, so that method — and whatever
|
||||
/// Task 11 fills it with — must never re-enter the lifecycle either.
|
||||
/// the sample pump fills it with — must never re-enter the lifecycle either.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
private readonly SemaphoreSlim _lifecycle = new(1, 1);
|
||||
@@ -304,7 +304,7 @@ public sealed partial class MTConnectDriver
|
||||
/// takes this field BEFORE it takes <see cref="_binding"/> — which both <c>ReadAsync</c>
|
||||
/// and <c>WriteAsync</c> do — has the ordering that stops it judging a batch against the
|
||||
/// previous document's <c>Write.Enabled</c> / <c>RequestTimeoutMs</c> paired with the new
|
||||
/// tag table (Driver.MTConnect-005). Pinned by
|
||||
/// tag table. Pinned by
|
||||
/// <c>MTConnectOptionsPublicationTests</c>, which fails on any unfenced touch.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
@@ -329,7 +329,7 @@ public sealed partial class MTConnectDriver
|
||||
private Task? _pumpTask;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="_sessionGeneration"/> the running pump was started against (STAB-20), guarded by
|
||||
/// The <see cref="_sessionGeneration"/> the running pump was started against, guarded by
|
||||
/// <see cref="_subscriptionLock"/> like the rest of the control block. A pump whose generation is
|
||||
/// not the current one is bound to a client a lifecycle restart has retired.
|
||||
/// </summary>
|
||||
@@ -344,7 +344,7 @@ public sealed partial class MTConnectDriver
|
||||
|
||||
/// <summary>
|
||||
/// Pumps retired by <see cref="StartSampleStreamCore"/> because they were bound to a replaced
|
||||
/// session (STAB-20), kept so <see cref="StopSampleStreamAsync"/> can join them — a pump nobody
|
||||
/// session, kept so <see cref="StopSampleStreamAsync"/> can join them — a pump nobody
|
||||
/// awaits can still run its default-verdict arm (<c>Degrade</c>, the reconnect counter) after
|
||||
/// the new session has written Healthy. Guarded by <see cref="_subscriptionLock"/>.
|
||||
/// </summary>
|
||||
@@ -394,11 +394,11 @@ public sealed partial class MTConnectDriver
|
||||
/// <para>
|
||||
/// <b>Why one field instead of several.</b> These values are read <i>outside</i>
|
||||
/// <see cref="_lifecycle"/> — by <see cref="ReadAsync"/> and by
|
||||
/// <see cref="GetOrFetchProbeModelAsync"/> (Task 12's browse) — while every write
|
||||
/// <see cref="GetOrFetchProbeModelAsync"/> (the browse) — while every write
|
||||
/// happens under it. As separate fields they could be observed mid-update, pairing one
|
||||
/// initialize's client with the previous one's model. Packing them makes every
|
||||
/// observation internally consistent by construction, with no lock on the read path.
|
||||
/// (A third value, a cached data-item count, lived here until Gitea #525 deleted its
|
||||
/// (A third value, a cached data-item count, lived here until it was deleted when its
|
||||
/// only reader — <c>GetMemoryFootprint</c> — along with the rest of that dead surface.)
|
||||
/// </para>
|
||||
/// <para>
|
||||
@@ -459,7 +459,7 @@ public sealed partial class MTConnectDriver
|
||||
Volatile.Write(ref _options, options);
|
||||
_binding = BuildBinding(options, probeModel: null);
|
||||
|
||||
// Never null, so every consumer (Task 10's ReadAsync included) can ask it for a snapshot
|
||||
// Never null, so every consumer (ReadAsync included) can ask it for a snapshot
|
||||
// without a null check: an un-primed index answers BadWaitingForInitialData for an authored
|
||||
// tag and BadNodeIdUnknown otherwise, which is exactly the truth before Initialize runs.
|
||||
_index = new MTConnectObservationIndex(_binding.IndexTags);
|
||||
@@ -468,18 +468,16 @@ public sealed partial class MTConnectDriver
|
||||
/// <inheritdoc/>
|
||||
public string DriverInstanceId => _driverInstanceId;
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// Sourced from the <see cref="DriverTypeNames"/> constant rather than a literal — the
|
||||
/// repo-wide fix for the historical <c>TwinCat</c>/<c>Focas</c> drift, where a driver's own
|
||||
/// spelling diverged from the constant every dispatch map keys off.
|
||||
/// </remarks>
|
||||
/// <inheritdoc />
|
||||
// Sourced from the constant rather than a literal — the
|
||||
// repo-wide fix for the historical TwinCat/Focas drift, where a driver's own
|
||||
// spelling diverged from the constant every dispatch map keys off.
|
||||
public string DriverType => DriverTypeNames.MTConnect;
|
||||
|
||||
/// <summary>
|
||||
/// The live <c>dataItemId → snapshot</c> map that backs the <b>subscription</b> surface:
|
||||
/// primed by <see cref="InitializeAsync"/> and thereafter written only by the <c>/sample</c>
|
||||
/// pump (Task 11). Exposed to tests as the observable proof that initialize actually primed
|
||||
/// pump. Exposed to tests as the observable proof that initialize actually primed
|
||||
/// it — and, in <c>MTConnectReadTests</c>, that <see cref="ReadAsync"/> leaves it alone.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
@@ -498,7 +496,7 @@ public sealed partial class MTConnectDriver
|
||||
|
||||
/// <summary>
|
||||
/// The Agent's <c>instanceId</c> as of the last successful <c>/current</c> — including the
|
||||
/// re-baseline the <c>/sample</c> pump runs when it sees the id change mid-stream. Task 13
|
||||
/// re-baseline the <c>/sample</c> pump runs when it sees the id change mid-stream. The driver
|
||||
/// watches this for change to raise rediscovery (an Agent restart invalidates every cached
|
||||
/// id).
|
||||
/// </summary>
|
||||
@@ -546,15 +544,13 @@ public sealed partial class MTConnectDriver
|
||||
/// <summary>The options currently in force — the constructor's, or the last document applied.</summary>
|
||||
internal MTConnectDriverOptions EffectiveOptions => Volatile.Read(ref _options);
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// Builds the Agent client from the effective options, runs one deadline-bounded
|
||||
/// <c>/probe</c> (caching the device model and its data-item count), then one
|
||||
/// deadline-bounded <c>/current</c> to prime the observation index and record the Agent's
|
||||
/// <c>instanceId</c>. Publishes <see cref="DriverState.Healthy"/> on success; on any failure
|
||||
/// disposes the client, clears the caches, publishes <see cref="DriverState.Faulted"/> with
|
||||
/// the error text, and rethrows.
|
||||
/// </remarks>
|
||||
/// <inheritdoc />
|
||||
// Builds the Agent client from the effective options, runs one deadline-bounded
|
||||
// /probe (caching the device model and its data-item count), then one
|
||||
// deadline-bounded /current to prime the observation index and record the Agent's
|
||||
// instanceId. Publishes on success; on any failure
|
||||
// disposes the client, clears the caches, publishes with
|
||||
// the error text, and rethrows.
|
||||
public async Task InitializeAsync(string driverConfigJson, CancellationToken cancellationToken)
|
||||
{
|
||||
await _lifecycle.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
@@ -583,30 +579,22 @@ public sealed partial class MTConnectDriver
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Stops the <c>/sample</c> stream, then takes one of two paths depending on whether the
|
||||
/// new document changes anything the <see cref="IMTConnectAgentClient"/> reads at
|
||||
/// <b>construction</b>:
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Endpoint/transport changed</b> (<c>AgentUri</c>, <c>DeviceName</c>,
|
||||
/// <c>RequestTimeoutMs</c>, <c>HeartbeatMs</c>, <c>SampleIntervalMs</c>,
|
||||
/// <c>SampleCount</c>) ⇒ full teardown and rebuild. The plan names only the first two,
|
||||
/// but the other four are baked into the client's deadlines, its watchdog window, and its
|
||||
/// <c>/sample</c> query string, so keeping the old client because the URI happened not to
|
||||
/// change would silently discard the operator's edit — the same class of defect as
|
||||
/// ignoring the config document altogether.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Otherwise</b> ("config-only": authored tags, probe cadence, reconnect backoff) ⇒
|
||||
/// the live client and its connection pool are kept, and everything derived from config
|
||||
/// is rebuilt: the probe model is re-fetched, the observation index is recreated against
|
||||
/// the new tag types, and one <c>/current</c> re-primes it. Nothing config-derived
|
||||
/// survives, so a retyped tag cannot keep coercing to its old type.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <inheritdoc />
|
||||
// Stops the /sample stream, then takes one of two paths depending on whether the
|
||||
// new document changes anything the reads at
|
||||
// construction:
|
||||
// Endpoint/transport changed (AgentUri, DeviceName,
|
||||
// RequestTimeoutMs, HeartbeatMs, SampleIntervalMs,
|
||||
// SampleCount) ⇒ full teardown and rebuild. The plan names only the first two,
|
||||
// but the other four are baked into the client's deadlines, its watchdog window, and its
|
||||
// /sample query string, so keeping the old client because the URI happened not to
|
||||
// change would silently discard the operator's edit — the same class of defect as
|
||||
// ignoring the config document altogether.
|
||||
// Otherwise ("config-only": authored tags, probe cadence, reconnect backoff) ⇒
|
||||
// the live client and its connection pool are kept, and everything derived from config
|
||||
// is rebuilt: the probe model is re-fetched, the observation index is recreated against
|
||||
// the new tag types, and one /current re-primes it. Nothing config-derived
|
||||
// survives, so a retyped tag cannot keep coercing to its old type.
|
||||
public async Task ReinitializeAsync(string driverConfigJson, CancellationToken cancellationToken)
|
||||
{
|
||||
await _lifecycle.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
@@ -635,13 +623,11 @@ public sealed partial class MTConnectDriver
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// Stops the <c>/sample</c> stream, disposes the Agent client, and drops the probe cache and
|
||||
/// the observation index — values sourced from a torn-down connection must never keep
|
||||
/// reading Good. <c>LastSuccessfulRead</c> is retained because it is diagnostic ("when did
|
||||
/// this driver last hear from the Agent"), not served data. Idempotent.
|
||||
/// </remarks>
|
||||
/// <inheritdoc />
|
||||
// Stops the /sample stream, disposes the Agent client, and drops the probe cache and
|
||||
// the observation index — values sourced from a torn-down connection must never keep
|
||||
// reading Good. LastSuccessfulRead is retained because it is diagnostic ("when did
|
||||
// this driver last hear from the Agent"), not served data. Idempotent.
|
||||
public async Task ShutdownAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await _lifecycle.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
@@ -664,51 +650,39 @@ public sealed partial class MTConnectDriver
|
||||
/// <inheritdoc/>
|
||||
public DriverHealth GetHealth() => ReadHealth();
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <b>One <c>/current</c> per batch, whatever the batch size.</b> MTConnect's
|
||||
/// <c>/current</c> answers for the whole device (or the whole Agent), so N references
|
||||
/// cost one deadline-bounded round-trip and are answered out of that one document. There
|
||||
/// is no per-reference request to make and none is made.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>The response is indexed into a per-call snapshot, NOT into the driver's shared
|
||||
/// observation index.</b> That index is written by the <c>/sample</c> pump (Task 11) and
|
||||
/// is deliberately last-write-wins with no timestamp arbitration. A read that folded its
|
||||
/// <c>/current</c> into it would be a second writer racing the first, and the
|
||||
/// <c>/current</c> document is frequently the <i>older</i> of the two — the Agent
|
||||
/// composes it while the pump's newer delta is already in flight. Losing that race rolls
|
||||
/// a subscribed value backwards and <b>leaves it there until the data item next
|
||||
/// changes</b>, which for an EVENT such as <c>Execution</c> can be hours. Keeping the
|
||||
/// read path a pure function of (document, authored tags) costs one index construction
|
||||
/// per batch — negligible beside the HTTP round-trip that precedes it — and makes it
|
||||
/// impossible for a read to corrupt subscription state. The reference source-of-truth is
|
||||
/// unchanged either way: both paths coerce through the same
|
||||
/// <see cref="MTConnectObservationIndex"/> logic, so a read and a subscription report a
|
||||
/// given observation identically.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Nothing but genuine caller cancellation crosses this boundary.</b> An unreachable
|
||||
/// Agent, a blown deadline, an unusable answer — each fails the batch's <i>values</i>
|
||||
/// (every reference codes <see cref="BadCommunicationError"/>) rather than the batch: an
|
||||
/// exception here would also fail the references that were perfectly readable, and the
|
||||
/// node-manager cannot tell a thrown read from a broken driver. This is the opposite
|
||||
/// posture to <see cref="InitializeAsync"/>, which is specified to throw so the
|
||||
/// runtime's retry/backoff loop can own recovery.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The status-code distinctions the index draws — <c>BadWaitingForInitialData</c> for an
|
||||
/// authored-but-unreported id, <c>BadNodeIdUnknown</c> for an unknown one,
|
||||
/// <c>BadNoCommunication</c> for the Agent's <c>UNAVAILABLE</c> — are passed through
|
||||
/// unmodified. They tell an operator three different things.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <exception cref="ArgumentNullException">
|
||||
/// <paramref name="fullReferences"/> is <c>null</c> — a caller bug, not device data, and the
|
||||
/// one thing this method is loud about (matching <see cref="MTConnectObservationIndex"/>'s
|
||||
/// documented posture).
|
||||
/// </exception>
|
||||
/// <inheritdoc />
|
||||
// One /current per batch, whatever the batch size. MTConnect's
|
||||
// /current answers for the whole device (or the whole Agent), so N references
|
||||
// cost one deadline-bounded round-trip and are answered out of that one document. There
|
||||
// is no per-reference request to make and none is made.
|
||||
// The response is indexed into a per-call snapshot, NOT into the driver's shared
|
||||
// observation index. That index is written by the /sample pump and
|
||||
// is deliberately last-write-wins with no timestamp arbitration. A read that folded its
|
||||
// /current into it would be a second writer racing the first, and the
|
||||
// /current document is frequently the older of the two — the Agent
|
||||
// composes it while the pump's newer delta is already in flight. Losing that race rolls
|
||||
// a subscribed value backwards and leaves it there until the data item next
|
||||
// changes, which for an EVENT such as Execution can be hours. Keeping the
|
||||
// read path a pure function of (document, authored tags) costs one index construction
|
||||
// per batch — negligible beside the HTTP round-trip that precedes it — and makes it
|
||||
// impossible for a read to corrupt subscription state. The reference source-of-truth is
|
||||
// unchanged either way: both paths coerce through the same
|
||||
// logic, so a read and a subscription report a
|
||||
// given observation identically.
|
||||
// Nothing but genuine caller cancellation crosses this boundary. An unreachable
|
||||
// Agent, a blown deadline, an unusable answer — each fails the batch's values
|
||||
// (every reference codes ) rather than the batch: an
|
||||
// exception here would also fail the references that were perfectly readable, and the
|
||||
// node-manager cannot tell a thrown read from a broken driver. This is the opposite
|
||||
// posture to , which is specified to throw so the
|
||||
// runtime's retry/backoff loop can own recovery.
|
||||
// The status-code distinctions the index draws — BadWaitingForInitialData for an
|
||||
// authored-but-unreported id, BadNodeIdUnknown for an unknown one,
|
||||
// BadNoCommunication for the Agent's UNAVAILABLE — are passed through
|
||||
// unmodified. They tell an operator three different things.
|
||||
// is null — a caller bug, not device data, and the
|
||||
// one thing this method is loud about (matching 's
|
||||
// documented posture).
|
||||
public async Task<IReadOnlyList<DataValueSnapshot>> ReadAsync(
|
||||
IReadOnlyList<string> fullReferences, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -780,45 +754,34 @@ public sealed partial class MTConnectDriver
|
||||
|
||||
// ---- IWritable: observation injection through the Agent's AllowPut surface ----
|
||||
|
||||
/// <summary>
|
||||
/// Sets the Agent's reported observation for each requested reference, through its
|
||||
/// <c>AllowPut</c> surface. Returns one status per request, in request order.
|
||||
/// </summary>
|
||||
/// <param name="writes">The requested writes.</param>
|
||||
/// <param name="cancellationToken">Cancellation for the batch.</param>
|
||||
/// <returns>One <see cref="WriteResult"/> per request, in request order.</returns>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <b>This writes the Agent, not the machine</b> — see the class remarks. Good here means
|
||||
/// "the Agent took the observation", which is a stronger statement than MQTT's optimistic
|
||||
/// "published" (the Agent answers) and a weaker one than a device acknowledgement (no
|
||||
/// MTConnect Agent speaks for the machine). The next adapter update for that DataItem
|
||||
/// overwrites what was written, and the ordinary <c>/sample</c> ingest path is what
|
||||
/// corrects the node.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Never throws, and one bad slot never fails the batch</b> — matching
|
||||
/// <see cref="ReadAsync"/>. Failing the whole call would let one stale reference reject
|
||||
/// every other write in the same OPC UA request. Even cancellation returns a full-length
|
||||
/// batch rather than propagating, so the node-manager can tell which slots were attempted.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Refusal order is fixed, and each step answers a different operator question:</b>
|
||||
/// writing switched off ⇒ <c>BadNotWritable</c>; no live client ⇒ <c>BadNotConnected</c>
|
||||
/// (this driver is not running — <see cref="ReadAsync"/>'s convention); the reference
|
||||
/// resolves to no DataItem, or to one whose owning device cannot be named ⇒
|
||||
/// <c>BadNodeIdUnknown</c>; CONDITION category ⇒ <c>BadNotWritable</c>; no invariant string
|
||||
/// form ⇒ <c>BadTypeMismatch</c>; and only then the Agent, whose refusal <b>or</b> whose
|
||||
/// unreachability ⇒ <c>BadCommunicationError</c>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>The Agent's refusal text is logged, never stored.</b> It goes to a Warning line and
|
||||
/// nowhere near <see cref="DriverHealth.LastError"/>, which is type-only by repo-wide
|
||||
/// discipline — and a refused write is not evidence the read path degraded, so health is
|
||||
/// left exactly as it is (unlike <see cref="DegradeAfterReadFailure"/>).
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writes"/> is <c>null</c> — a caller bug.</exception>
|
||||
/// <inheritdoc />
|
||||
// Sets the Agent's reported observation for each requested reference, through its
|
||||
// AllowPut surface. Returns one status per request, in request order.
|
||||
// The requested writes.
|
||||
// Cancellation for the batch.
|
||||
// One per request, in request order.
|
||||
// This writes the Agent, not the machine — see the class remarks. Good here means
|
||||
// "the Agent took the observation", which is a stronger statement than MQTT's optimistic
|
||||
// "published" (the Agent answers) and a weaker one than a device acknowledgement (no
|
||||
// MTConnect Agent speaks for the machine). The next adapter update for that DataItem
|
||||
// overwrites what was written, and the ordinary /sample ingest path is what
|
||||
// corrects the node.
|
||||
// Never throws, and one bad slot never fails the batch — matching
|
||||
// . Failing the whole call would let one stale reference reject
|
||||
// every other write in the same OPC UA request. Even cancellation returns a full-length
|
||||
// batch rather than propagating, so the node-manager can tell which slots were attempted.
|
||||
// Refusal order is fixed, and each step answers a different operator question:
|
||||
// writing switched off ⇒ BadNotWritable; no live client ⇒ BadNotConnected
|
||||
// (this driver is not running — 's convention); the reference
|
||||
// resolves to no DataItem, or to one whose owning device cannot be named ⇒
|
||||
// BadNodeIdUnknown; CONDITION category ⇒ BadNotWritable; no invariant string
|
||||
// form ⇒ BadTypeMismatch; and only then the Agent, whose refusal or whose
|
||||
// unreachability ⇒ BadCommunicationError.
|
||||
// The Agent's refusal text is logged, never stored. It goes to a Warning line and
|
||||
// nowhere near , which is type-only by repo-wide
|
||||
// discipline — and a refused write is not evidence the read path degraded, so health is
|
||||
// left exactly as it is (unlike ).
|
||||
// is null — a caller bug.
|
||||
public async Task<IReadOnlyList<WriteResult>> WriteAsync(
|
||||
IReadOnlyList<WriteRequest> writes, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -941,7 +904,7 @@ public sealed partial class MTConnectDriver
|
||||
/// The guard is therefore written against that property itself rather than against
|
||||
/// <see cref="Array"/>, the one type it was first noticed on: an
|
||||
/// <c>Opc.Ua.ExtensionObject</c>, an <c>XmlElement</c> or a <c>List<T></c> from a
|
||||
/// non-SDK caller corrupts an observation in exactly the same way (Driver.MTConnect-006).
|
||||
/// non-SDK caller corrupts an observation in exactly the same way.
|
||||
/// <c>string</c>, <c>bool</c>, <see cref="DateTime"/> and every numeric type ARE
|
||||
/// <see cref="IConvertible"/>, so the accepted set is unchanged. TIME_SERIES / DATA_SET
|
||||
/// writes are out of scope for v1.
|
||||
@@ -1002,49 +965,37 @@ public sealed partial class MTConnectDriver
|
||||
|
||||
// ---- ISubscribable: ONE shared /sample long poll behind every handle ----
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <summary>Raised when a subscribed data item's value changes.</summary>
|
||||
public event EventHandler<DataChangeEventArgs>? OnDataChange;
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <b>Initial data comes from the primed <c>/current</c>, not from the wire.</b> Every
|
||||
/// subscribed reference gets one callback immediately (the OPC UA Part 4 convention),
|
||||
/// answered out of the observation index — including the references with no value yet,
|
||||
/// which report <c>BadWaitingForInitialData</c>. Waiting for the Agent's next chunk
|
||||
/// instead would leave a fresh subscription silent for up to a whole <c>heartbeat</c>,
|
||||
/// and permanently silent for any data item that simply is not changing.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Subscribe does not wait for the stream.</b> The first subscription starts the
|
||||
/// shared pump; the pump then opens <c>/sample</c> on its own task under its own
|
||||
/// cancellation token. This is deliberate on both counts. The opening handshake cannot
|
||||
/// be awaited inside the caller's Subscribe timeout in any useful sense — the first
|
||||
/// chunk may legitimately be a heartbeat away — and the long-lived poll must NOT run
|
||||
/// under the caller's token, which belongs to one Subscribe call and is disposed the
|
||||
/// moment it returns. What bounds the running stream is the client's own heartbeat
|
||||
/// watchdog, and what stops it is <see cref="UnsubscribeAsync"/> or the lifecycle.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b><paramref name="publishingInterval"/> is not honoured per subscription</b>, and
|
||||
/// cannot be: MTConnect's publish cadence is the Agent-side <c>interval</c> query
|
||||
/// parameter of the single shared <c>/sample</c> request
|
||||
/// (<see cref="MTConnectDriverOptions.SampleIntervalMs"/>), fixed when the client is
|
||||
/// built. Honouring a per-handle interval would mean one stream per subscription — the
|
||||
/// Agent load this driver exists to avoid — or client-side throttling that would drop
|
||||
/// transient EVENT values the Agent bothered to send. The parameter is accepted and
|
||||
/// ignored, which is also what the natively-subscribing sibling drivers do.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Subscribing before <see cref="InitializeAsync"/> is legal: the interest is recorded,
|
||||
/// every reference reports "no value yet", and the initialize that follows starts the
|
||||
/// pump for it. It does not throw and it does not dial an Agent that is not there yet.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <exception cref="ArgumentNullException">
|
||||
/// <paramref name="fullReferences"/> is <c>null</c> — a caller bug, and the only thing this
|
||||
/// method is loud about, matching <see cref="ReadAsync"/>'s posture.
|
||||
/// </exception>
|
||||
/// <inheritdoc />
|
||||
// Initial data comes from the primed /current, not from the wire. Every
|
||||
// subscribed reference gets one callback immediately (the OPC UA Part 4 convention),
|
||||
// answered out of the observation index — including the references with no value yet,
|
||||
// which report BadWaitingForInitialData. Waiting for the Agent's next chunk
|
||||
// instead would leave a fresh subscription silent for up to a whole heartbeat,
|
||||
// and permanently silent for any data item that simply is not changing.
|
||||
// Subscribe does not wait for the stream. The first subscription starts the
|
||||
// shared pump; the pump then opens /sample on its own task under its own
|
||||
// cancellation token. This is deliberate on both counts. The opening handshake cannot
|
||||
// be awaited inside the caller's Subscribe timeout in any useful sense — the first
|
||||
// chunk may legitimately be a heartbeat away — and the long-lived poll must NOT run
|
||||
// under the caller's token, which belongs to one Subscribe call and is disposed the
|
||||
// moment it returns. What bounds the running stream is the client's own heartbeat
|
||||
// watchdog, and what stops it is or the lifecycle.
|
||||
// is not honoured per subscription, and
|
||||
// cannot be: MTConnect's publish cadence is the Agent-side interval query
|
||||
// parameter of the single shared /sample request
|
||||
// (), fixed when the client is
|
||||
// built. Honouring a per-handle interval would mean one stream per subscription — the
|
||||
// Agent load this driver exists to avoid — or client-side throttling that would drop
|
||||
// transient EVENT values the Agent bothered to send. The parameter is accepted and
|
||||
// ignored, which is also what the natively-subscribing sibling drivers do.
|
||||
// Subscribing before is legal: the interest is recorded,
|
||||
// every reference reports "no value yet", and the initialize that follows starts the
|
||||
// pump for it. It does not throw and it does not dial an Agent that is not there yet.
|
||||
// is null — a caller bug, and the only thing this
|
||||
// method is loud about, matching 's posture.
|
||||
public Task<ISubscriptionHandle> SubscribeAsync(
|
||||
IReadOnlyList<string> fullReferences, TimeSpan publishingInterval, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -1088,14 +1039,12 @@ public sealed partial class MTConnectDriver
|
||||
return Task.FromResult<ISubscriptionHandle>(handle);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// Drops the handle's references and stops the shared stream when the last subscription
|
||||
/// goes. An unknown handle — already unsubscribed, or issued by a different driver — is a
|
||||
/// no-op rather than an error: this runs on teardown paths, including failure paths, where
|
||||
/// throwing would mask whatever prompted the teardown.
|
||||
/// </remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="handle"/> is <c>null</c>.</exception>
|
||||
/// <inheritdoc />
|
||||
// Drops the handle's references and stops the shared stream when the last subscription
|
||||
// goes. An unknown handle — already unsubscribed, or issued by a different driver — is a
|
||||
// no-op rather than an error: this runs on teardown paths, including failure paths, where
|
||||
// throwing would mask whatever prompted the teardown.
|
||||
// is null.
|
||||
public async Task UnsubscribeAsync(ISubscriptionHandle handle, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(handle);
|
||||
@@ -1132,112 +1081,88 @@ public sealed partial class MTConnectDriver
|
||||
|
||||
// ---- ITagDiscovery: the /probe device model, streamed as folders + variables ----
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// <b>This one member is the whole browse opt-in.</b> The Wave-0 universal
|
||||
/// <c>DiscoveryDriverBrowser</c> turns any driver that answers <c>true</c> here into a live
|
||||
/// address picker by capturing <see cref="DiscoverAsync"/> — so this driver ships no browser
|
||||
/// code, no per-driver picker component, and no entry in the browser's browse-patch table
|
||||
/// (its discovery is unconditional; there is no "enable browse" option to turn on first).
|
||||
/// It is answered on an <b>un-initialized</b> instance without dialling anything, because
|
||||
/// <c>CanBrowse</c> constructs a throwaway driver purely to read it — which is also why the
|
||||
/// constructor opens nothing.
|
||||
/// </remarks>
|
||||
/// <inheritdoc />
|
||||
// This one member is the whole browse opt-in. The universal
|
||||
// DiscoveryDriverBrowser turns any driver that answers true here into a live
|
||||
// address picker by capturing — so this driver ships no browser
|
||||
// code, no per-driver picker component, and no entry in the browser's browse-patch table
|
||||
// (its discovery is unconditional; there is no "enable browse" option to turn on first).
|
||||
// It is answered on an un-initialized instance without dialling anything, because
|
||||
// CanBrowse constructs a throwaway driver purely to read it — which is also why the
|
||||
// constructor opens nothing.
|
||||
public bool SupportsOnlineDiscovery => true;
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// <c>Once</c>, not the default <c>UntilStable</c>: <see cref="DiscoverAsync"/> streams the
|
||||
/// complete device model within the single call — <c>/probe</c> is one synchronous request
|
||||
/// that either answers with the whole hierarchy or fails — so nothing fills in asynchronously
|
||||
/// after connect and a settle loop would only re-fetch an identical answer. (The one thing
|
||||
/// that <i>does</i> change the model is an Agent restart, and that is
|
||||
/// <c>IRediscoverable</c>'s job in Task 13, not a retry cadence's.)
|
||||
/// </remarks>
|
||||
/// <inheritdoc />
|
||||
// Once, not the default UntilStable: streams the
|
||||
// complete device model within the single call — /probe is one synchronous request
|
||||
// that either answers with the whole hierarchy or fails — so nothing fills in asynchronously
|
||||
// after connect and a settle loop would only re-fetch an identical answer. (The one thing
|
||||
// that does change the model is an Agent restart, and that is
|
||||
// IRediscoverable's job, not a retry cadence's.)
|
||||
public DiscoveryRediscoverPolicy RediscoverPolicy => DiscoveryRediscoverPolicy.Once;
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Streams the Agent's <c>/probe</c> hierarchy verbatim: one folder per <c>Device</c>,
|
||||
/// one per nested <c>Component</c> to arbitrary depth, and one variable per
|
||||
/// <c>DataItem</c> under whichever container declares it — <b>including the data items a
|
||||
/// device declares directly</b>, outside any component (an availability item almost
|
||||
/// always lives there, and a walker that only recursed <c>Components</c> would silently
|
||||
/// drop it).
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b><see cref="DriverAttributeInfo.FullName"/> is the <c>DataItem@id</c>, never the
|
||||
/// browse name.</b> The universal browser commits a browsed leaf's <c>FullName</c>
|
||||
/// straight into <c>TagConfig.FullName</c>, and that is the key
|
||||
/// <see cref="ReadAsync"/> and the <c>/sample</c> pump resolve an observation against
|
||||
/// (<see cref="MTConnectObservationIndex"/> is keyed by <c>DataItem@id</c>). Committing
|
||||
/// the <c>name</c> instead would produce a picker that looks right and authors tags that
|
||||
/// can never report a value. The browse <i>name</i> — cosmetic — prefers the DataItem's
|
||||
/// <c>name</c> and falls back to its <c>id</c>, which for this protocol is the common
|
||||
/// case rather than an edge case.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>The type shape comes from <see cref="MTConnectDataTypeInference.Infer"/>'s returned
|
||||
/// record, in full</b> — <see cref="MTConnectInferredType.IsArray"/> and
|
||||
/// <see cref="MTConnectInferredType.ArrayDim"/> included. Recomputing the array shape
|
||||
/// locally from <c>representation</c>/<c>sampleCount</c> is the tempting shortcut and it
|
||||
/// is wrong: the inference also demotes <c>DATA_SET</c>/<c>TABLE</c> to
|
||||
/// <see cref="DriverDataType.String"/> even on a <c>SAMPLE</c>, and honours
|
||||
/// <c>TIME_SERIES</c> only on a <c>SAMPLE</c>. The AdminUI typed editor calls the same
|
||||
/// function, so any divergence here makes the picker and the editor disagree about one
|
||||
/// data item. The <c>type</c> attribute is passed <b>verbatim</b> for the same reason:
|
||||
/// the probe document spells it UPPER_SNAKE (<c>PART_COUNT</c>) where the streams
|
||||
/// document uses PascalCase, and the inference is separator-insensitive precisely to
|
||||
/// bridge the two — pre-normalising it here would defeat that.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b><see cref="DriverAttributeInfo.IsAlarm"/> is this seam's job</b>, deliberately not
|
||||
/// the inference's: a <c>CONDITION</c> data item is an alarm.
|
||||
/// <c>IVariableHandle.MarkAsAlarmCondition</c> is <i>not</i> called — that annotation
|
||||
/// needs the driver-side refs of an alarm's sibling attributes (in-alarm flag, priority,
|
||||
/// ack target), and an MTConnect condition has none: it is one text observation whose
|
||||
/// value is the state word. Core's generic node manager enriches on the flag alone.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>The model comes from <see cref="GetOrFetchProbeModelAsync"/>, never from
|
||||
/// <see cref="CachedProbeModel"/>.</b> <see cref="InvalidateProbeModel"/> may have
|
||||
/// dropped the cache after an Agent restart; reading the field directly would make such
|
||||
/// a driver browse as an Agent with no data items, permanently.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>This throws, and that is the opposite of <see cref="ReadAsync"/>'s posture on
|
||||
/// purpose.</b> A read has a per-reference Bad status code to report a failure in-band; a
|
||||
/// discovery stream has no such channel, so the only way to "fail quietly" would be to
|
||||
/// emit an empty tree — indistinguishable from an Agent that genuinely declares nothing,
|
||||
/// and read by an operator in the picker as a working connection to an empty machine
|
||||
/// (#485: empty is not an answer).
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>What the callers actually do with the throw</b> — worth stating precisely, because
|
||||
/// the reassuring version ("it is logged and retried") is not true here. The live
|
||||
/// consumer is the <c>/raw</c> browse-commit path
|
||||
/// (<c>DiscoveryDriverBrowser</c>/<c>BrowserSessionService</c>), which surfaces it to the
|
||||
/// operator as a <i>failed browse</i> — that is the case this posture is chosen for.
|
||||
/// <c>DriverInstanceActor.HandleRediscoverAsync</c> catches it, logs a Warning, and
|
||||
/// publishes an EMPTY node set; it does <b>not</b> reschedule, because retrying is a
|
||||
/// <see cref="DiscoveryRediscoverPolicy.UntilStable"/> behaviour and this driver is
|
||||
/// <see cref="DiscoveryRediscoverPolicy.Once"/>. And that publish currently reaches
|
||||
/// nothing: <c>DriverHostActor.HandleDiscoveredNodes</c> short-circuits unconditionally
|
||||
/// (discovered-node injection is dormant in v3 — raw tags are authored through
|
||||
/// browse-commit instead), so at that seam the throw-versus-empty choice has no runtime
|
||||
/// effect today. It is made for the browse path, and for whatever re-enables injection.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Nothing here writes the observation index.</b> Discovery is a pure read of the
|
||||
/// device model — the <c>/sample</c> pump remains its sole writer.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="builder"/> is <c>null</c>.</exception>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// The driver is not initialized, or it was torn down while the <c>/probe</c> fetch was in
|
||||
/// flight (see <see cref="GetOrFetchProbeModelAsync"/>).
|
||||
/// </exception>
|
||||
/// <inheritdoc />
|
||||
// Streams the Agent's /probe hierarchy verbatim: one folder per Device,
|
||||
// one per nested Component to arbitrary depth, and one variable per
|
||||
// DataItem under whichever container declares it — including the data items a
|
||||
// device declares directly, outside any component (an availability item almost
|
||||
// always lives there, and a walker that only recursed Components would silently
|
||||
// drop it).
|
||||
// is the DataItem@id, never the
|
||||
// browse name. The universal browser commits a browsed leaf's FullName
|
||||
// straight into TagConfig.FullName, and that is the key
|
||||
// and the /sample pump resolve an observation against
|
||||
// ( is keyed by DataItem@id). Committing
|
||||
// the name instead would produce a picker that looks right and authors tags that
|
||||
// can never report a value. The browse name — cosmetic — prefers the DataItem's
|
||||
// name and falls back to its id, which for this protocol is the common
|
||||
// case rather than an edge case.
|
||||
// The type shape comes from 's returned
|
||||
// record, in full — and
|
||||
// included. Recomputing the array shape
|
||||
// locally from representation/sampleCount is the tempting shortcut and it
|
||||
// is wrong: the inference also demotes DATA_SET/TABLE to
|
||||
// even on a SAMPLE, and honours
|
||||
// TIME_SERIES only on a SAMPLE. The AdminUI typed editor calls the same
|
||||
// function, so any divergence here makes the picker and the editor disagree about one
|
||||
// data item. The type attribute is passed verbatim for the same reason:
|
||||
// the probe document spells it UPPER_SNAKE (PART_COUNT) where the streams
|
||||
// document uses PascalCase, and the inference is separator-insensitive precisely to
|
||||
// bridge the two — pre-normalising it here would defeat that.
|
||||
// is this seam's job, deliberately not
|
||||
// the inference's: a CONDITION data item is an alarm.
|
||||
// IVariableHandle.MarkAsAlarmCondition is not called — that annotation
|
||||
// needs the driver-side refs of an alarm's sibling attributes (in-alarm flag, priority,
|
||||
// ack target), and an MTConnect condition has none: it is one text observation whose
|
||||
// value is the state word. Core's generic node manager enriches on the flag alone.
|
||||
// The model comes from , never from
|
||||
// . may have
|
||||
// dropped the cache after an Agent restart; reading the field directly would make such
|
||||
// a driver browse as an Agent with no data items, permanently.
|
||||
// This throws, and that is the opposite of 's posture on
|
||||
// purpose. A read has a per-reference Bad status code to report a failure in-band; a
|
||||
// discovery stream has no such channel, so the only way to "fail quietly" would be to
|
||||
// emit an empty tree — indistinguishable from an Agent that genuinely declares nothing,
|
||||
// and read by an operator in the picker as a working connection to an empty machine
|
||||
// (empty is not an answer).
|
||||
// What the callers actually do with the throw — worth stating precisely, because
|
||||
// the reassuring version ("it is logged and retried") is not true here. The live
|
||||
// consumer is the /raw browse-commit path
|
||||
// (DiscoveryDriverBrowser/BrowserSessionService), which surfaces it to the
|
||||
// operator as a failed browse — that is the case this posture is chosen for.
|
||||
// DriverInstanceActor.HandleRediscoverAsync catches it, logs a Warning, and
|
||||
// publishes an EMPTY node set; it does not reschedule, because retrying is a
|
||||
// behaviour and this driver is
|
||||
// . And that publish currently reaches
|
||||
// nothing: DriverHostActor.HandleDiscoveredNodes short-circuits unconditionally
|
||||
// (discovered-node injection is dormant in v3 — raw tags are authored through
|
||||
// browse-commit instead), so at that seam the throw-versus-empty choice has no runtime
|
||||
// effect today. It is made for the browse path, and for whatever re-enables injection.
|
||||
// Nothing here writes the observation index. Discovery is a pure read of the
|
||||
// device model — the /sample pump remains its sole writer.
|
||||
// is null.
|
||||
// The driver is not initialized, or it was torn down while the /probe fetch was in
|
||||
// flight (see ).
|
||||
public async Task DiscoverAsync(IAddressSpaceBuilder builder, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(builder);
|
||||
@@ -1453,7 +1378,7 @@ public sealed partial class MTConnectDriver
|
||||
|
||||
// ---- IHostConnectivityProbe: one host per Agent, on its own cheap tick ----
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <summary>Raised when the Agent host connectivity state changes.</summary>
|
||||
/// <remarks>
|
||||
/// <b>Raised from the probe loop's task, never under a lock and never under
|
||||
/// <see cref="_lifecycle"/>.</b> A handler is arbitrary caller code: one that blocks forever
|
||||
@@ -1470,14 +1395,12 @@ public sealed partial class MTConnectDriver
|
||||
/// </summary>
|
||||
public string HostName => Volatile.Read(ref _options).AgentUri;
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// One entry, always — an Agent is a single host, and the driver knows of it whether or not
|
||||
/// it has been reached. Before the first probe tick (and for the whole life of an instance
|
||||
/// with <c>Probe.Enabled = false</c>) that entry reads <see cref="HostState.Unknown"/>, which
|
||||
/// is the truth: nothing has measured it. See <see cref="_hostState"/> for why a successful
|
||||
/// initialize does not seed it <see cref="HostState.Running"/>.
|
||||
/// </remarks>
|
||||
/// <inheritdoc />
|
||||
// One entry, always — an Agent is a single host, and the driver knows of it whether or not
|
||||
// it has been reached. Before the first probe tick (and for the whole life of an instance
|
||||
// with Probe.Enabled = false) that entry reads , which
|
||||
// is the truth: nothing has measured it. See for why a successful
|
||||
// initialize does not seed it .
|
||||
public IReadOnlyList<HostConnectivityStatus> GetHostStatuses()
|
||||
{
|
||||
lock (_probeLock)
|
||||
@@ -1716,7 +1639,7 @@ public sealed partial class MTConnectDriver
|
||||
|
||||
// ---- IRediscoverable: the Agent instanceId watch ----
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <summary>Raised when the Agent instance id changes, so the host should rediscover.</summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <b>This event is what makes <see cref="RediscoverPolicy"/> =
|
||||
@@ -1795,7 +1718,7 @@ public sealed partial class MTConnectDriver
|
||||
/// than a courtesy: losing the race must not leave a model from a dead Agent installed.
|
||||
/// (The courtesy version, <c>FlushOptionalCachesAsync</c>, took the same lock-free
|
||||
/// approach but gave up on a lost race; it went with the rest of the unconsumed
|
||||
/// memory-pressure surface in Gitea #525.)
|
||||
/// memory-pressure surface.)
|
||||
/// </summary>
|
||||
internal void InvalidateProbeModel()
|
||||
{
|
||||
@@ -1863,7 +1786,7 @@ public sealed partial class MTConnectDriver
|
||||
return;
|
||||
}
|
||||
|
||||
// STAB-20: a Subscribe can land between StopSampleStreamAsync clearing the registry slots and
|
||||
// A Subscribe can land between StopSampleStreamAsync clearing the registry slots and
|
||||
// the teardown that retires the client — StopSampleStreamAsync is still awaiting the OLD pump
|
||||
// then — and starts a pump on the session about to be disposed. Treating that pump as "the
|
||||
// running stream" would leave the freshly-installed session with no live stream at all
|
||||
@@ -1894,7 +1817,7 @@ public sealed partial class MTConnectDriver
|
||||
// Unsubscribe-then-Subscribe with NO re-initialize, and the unsubscribe stops a stream
|
||||
// that is not running; without this, the resubscribe returns a handle, the caller is
|
||||
// told SubscriptionEstablished, and the next successful read reports a perfectly green
|
||||
// driver over a subscription that can never deliver a value (#485).
|
||||
// driver over a subscription that can never deliver a value.
|
||||
var agentUri = Volatile.Read(ref _options).AgentUri;
|
||||
|
||||
_streamDegraded = true;
|
||||
@@ -1983,7 +1906,7 @@ public sealed partial class MTConnectDriver
|
||||
{
|
||||
FanOut(SubscribedReferences(), ObservationIndex);
|
||||
|
||||
// #626: and the conditions, diffed against what the server was last told — so a restart
|
||||
// and the conditions, diffed against what the server was last told — so a restart
|
||||
// delivers what changed while the driver was down and re-raises nothing that did not.
|
||||
EmitConditionTransitions(touchedDataItemIds: null, resync: false);
|
||||
}
|
||||
@@ -2182,7 +2105,7 @@ public sealed partial class MTConnectDriver
|
||||
|
||||
// The seam contracts that cancellation is the ONLY way this enumeration ends quietly, so
|
||||
// a quiet end under a live token is a non-conforming client — reported as the lost
|
||||
// stream it is rather than treated as "the subscription is simply idle" (#485).
|
||||
// stream it is rather than treated as "the subscription is simply idle".
|
||||
return ct.IsCancellationRequested
|
||||
? new StreamOutcome(StreamVerdict.Cancelled, expected, instanceId, delivered, null)
|
||||
: new StreamOutcome(
|
||||
@@ -2339,7 +2262,7 @@ public sealed partial class MTConnectDriver
|
||||
var index = ObservationIndex;
|
||||
index.Apply(document, baseline);
|
||||
|
||||
// #626: CONDITION observations also feed the alarm path, which keeps its own multi-condition state
|
||||
// CONDITION observations also feed the alarm path, which keeps its own multi-condition state
|
||||
// (a /sample Normal for one nativeCode is not a return to normal while another code is active).
|
||||
var touchedConditions = ConditionTracker.Apply(document, baseline);
|
||||
EmitConditionTransitions(touchedConditions, resync: false);
|
||||
@@ -2520,7 +2443,7 @@ public sealed partial class MTConnectDriver
|
||||
/// </summary>
|
||||
private bool HasSubscribedReferencesCore()
|
||||
{
|
||||
// #626: a CONDITION alarm subscription needs the same stream — a driver whose only authored tags are
|
||||
// a CONDITION alarm subscription needs the same stream — a driver whose only authored tags are
|
||||
// alarms would otherwise never hear a condition change.
|
||||
if (HasAlarmReferencesCore())
|
||||
{
|
||||
@@ -2587,7 +2510,7 @@ public sealed partial class MTConnectDriver
|
||||
/// <summary>
|
||||
/// The <c>/probe</c> device model: the cached copy when warm, otherwise a fresh
|
||||
/// deadline-bounded <c>/probe</c> that re-populates the cache. This is the accessor every
|
||||
/// model consumer (Task 12's <c>DiscoverAsync</c>) must use, so that
|
||||
/// model consumer (<c>DiscoverAsync</c>) must use, so that
|
||||
/// <see cref="InvalidateProbeModel"/> can never leave browse permanently disabled.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
@@ -2644,7 +2567,7 @@ public sealed partial class MTConnectDriver
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Lives here rather than on the factory because the driver itself needs it: the runtime
|
||||
/// delivers config changes as JSON to a live instance (see the class remarks). Task 15's
|
||||
/// delivers config changes as JSON to a live instance (see the class remarks). The
|
||||
/// <c>MTConnectDriverFactoryExtensions.CreateInstance</c> should <b>delegate to this method</b>
|
||||
/// rather than deserializing a second DTO — two parsers for one document drift.
|
||||
/// </remarks>
|
||||
@@ -2744,7 +2667,7 @@ public sealed partial class MTConnectDriver
|
||||
RequirePositive(options.SampleIntervalMs, nameof(MTConnectDriverOptions.SampleIntervalMs));
|
||||
RequirePositive(options.SampleCount, nameof(MTConnectDriverOptions.SampleCount));
|
||||
|
||||
// Same 01/S-6 guard for Task 13's two knobs, gated on the feature that reads them. A 0
|
||||
// Same guard for the probe's two knobs, gated on the feature that reads them. A 0
|
||||
// interval turns the "periodic" probe into an unthrottled hot loop against the Agent, and
|
||||
// a 0 (or negative) timeout cancels every probe before it can be answered — pinning the
|
||||
// host to Stopped forever and reporting an outage that does not exist. Checked only when
|
||||
@@ -2804,7 +2727,7 @@ public sealed partial class MTConnectDriver
|
||||
index.Apply(current, baseline: true);
|
||||
Volatile.Write(ref _index, index);
|
||||
|
||||
// #626: the CONDITION tracker is per-session state like the index. Nothing is RAISED here — the
|
||||
// the CONDITION tracker is per-session state like the index. Nothing is RAISED here — the
|
||||
// lifecycle semaphore is held; the restarted pump delivers the diff as its first act.
|
||||
var conditions = new MTConnectConditionTracker();
|
||||
conditions.Apply(current, baseline: true);
|
||||
@@ -2841,7 +2764,7 @@ public sealed partial class MTConnectDriver
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Gitea #517 — land Faulted BEFORE anything is disposed, not after.
|
||||
// land Faulted BEFORE anything is disposed, not after.
|
||||
//
|
||||
// A successful connect writes Healthy above, and the steps that follow it (stream start, probe
|
||||
// loop) can still throw. Without this first write the driver would report Healthy for the whole
|
||||
@@ -3019,7 +2942,7 @@ public sealed partial class MTConnectDriver
|
||||
// Nothing to be degraded about once the stream is gone — UNLESS the endpoint is latched as
|
||||
// unable to stream at all, in which case there is no prospect of one coming back, and
|
||||
// clearing this would let the next successful read report a green driver over a subscription
|
||||
// that can never deliver (#485). See StartSampleStreamCore.
|
||||
// that can never deliver. See StartSampleStreamCore.
|
||||
lock (_subscriptionLock)
|
||||
{
|
||||
if (!_streamUnsupported)
|
||||
@@ -3153,7 +3076,7 @@ public sealed partial class MTConnectDriver
|
||||
/// Runs one unary agent call under a deadline linked to the caller's token. Belt-and-braces
|
||||
/// over the production client's own per-call deadline: the seam does not oblige an
|
||||
/// implementation to bound itself, and an unbounded initialize would wedge the driver-host
|
||||
/// actor (arch-review R2-01).
|
||||
/// actor.
|
||||
/// </summary>
|
||||
private async Task<T> BoundedAsync<T>(
|
||||
Func<CancellationToken, Task<T>> call, string request, int timeoutMs, CancellationToken ct)
|
||||
@@ -3193,7 +3116,7 @@ public sealed partial class MTConnectDriver
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Routes a read failure to the health surface (05/STAB-9's fleet-wide shape): log it and
|
||||
/// Routes a read failure to the health surface (the fleet-wide shape): log it and
|
||||
/// degrade, preserving <c>LastSuccessfulRead</c> — the "when did this driver last hear from
|
||||
/// the Agent" diagnostic. Never downgrades <see cref="DriverState.Faulted"/>, which is a
|
||||
/// stronger, config-level signal that a transient read failure must not paper over.
|
||||
@@ -3364,7 +3287,7 @@ public sealed partial class MTConnectDriver
|
||||
|
||||
/// <summary>
|
||||
/// Names the distinct, non-blank <see cref="RawTagEntry.DeviceName"/> values when there are two or
|
||||
/// more, else <c>null</c> (#613). The driver never routes by that field — one instance owns one
|
||||
/// more, else <c>null</c>. The driver never routes by that field — one instance owns one
|
||||
/// Agent client — so differing values mean the author expects a split the driver silently does
|
||||
/// not perform. A single value is NOT reported: it is the <c>/raw</c> Device's own name, which
|
||||
/// routinely differs from the Agent's device name and would make the warning noise.
|
||||
@@ -3410,12 +3333,12 @@ public sealed partial class MTConnectDriver
|
||||
/// The MTConnect branch of <c>RawBrowseCommitMapper.BuildTagConfig</c> emits a whole
|
||||
/// <c>MTConnectTagConfigModel</c>, whose <c>ToJson</c> unconditionally writes
|
||||
/// <c>"dataType"</c> — always a non-blank authored type, so step 1 always wins. Since
|
||||
/// Gitea #560 the value it writes is the browsed leaf's own inferred
|
||||
/// the value it writes is the browsed leaf's own inferred
|
||||
/// <see cref="DriverDataType"/>, i.e. what this step would have computed, so it agrees
|
||||
/// with the raw-tag node's OPC UA type (taken from the same inference by
|
||||
/// <c>RawBrowseCommitMapper.MapLeaf</c>). Historically it wrote the model's
|
||||
/// <see cref="DriverDataType.String"/> default instead, and every browse-committed tag
|
||||
/// coerced to text inside a <c>Double</c>/<c>Int64</c> node — <c>Driver.MTConnect-003</c>.
|
||||
/// coerced to text inside a <c>Double</c>/<c>Int64</c> node.
|
||||
/// The step remains the rescue for a blob authored by hand, by CSV or by API that states
|
||||
/// no type at all.
|
||||
/// </para>
|
||||
@@ -3853,12 +3776,19 @@ public sealed partial class MTConnectDriver
|
||||
/// </summary>
|
||||
private sealed class MTConnectDriverConfigDto
|
||||
{
|
||||
/// <summary>The Agent base URI.</summary>
|
||||
public string? AgentUri { get; init; }
|
||||
/// <summary>The Agent device name to bind.</summary>
|
||||
public string? DeviceName { get; init; }
|
||||
/// <summary>Per-request timeout in milliseconds.</summary>
|
||||
public int? RequestTimeoutMs { get; init; }
|
||||
/// <summary>The /sample interval in milliseconds.</summary>
|
||||
public int? SampleIntervalMs { get; init; }
|
||||
/// <summary>The /sample count per request.</summary>
|
||||
public int? SampleCount { get; init; }
|
||||
/// <summary>The /sample heartbeat in milliseconds.</summary>
|
||||
public int? HeartbeatMs { get; init; }
|
||||
/// <summary>The authored tags.</summary>
|
||||
public List<MTConnectTagDto>? Tags { get; init; }
|
||||
|
||||
/// <summary>
|
||||
@@ -3867,43 +3797,61 @@ public sealed partial class MTConnectDriver
|
||||
/// collection a deployed instance's data plane is keyed by.
|
||||
/// </summary>
|
||||
public List<RawTagEntry>? RawTags { get; init; }
|
||||
/// <summary>Connectivity-probe settings.</summary>
|
||||
public MTConnectProbeDto? Probe { get; init; }
|
||||
/// <summary>Reconnect-backoff settings.</summary>
|
||||
public MTConnectReconnectDto? Reconnect { get; init; }
|
||||
/// <summary>Write-back settings.</summary>
|
||||
public MTConnectWriteDto? Write { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>One authored tag. <c>DriverDataType</c> stays a string — see <see cref="ParseEnum{T}"/>.</summary>
|
||||
private sealed class MTConnectTagDto
|
||||
{
|
||||
/// <summary>The tag's full name.</summary>
|
||||
public string? FullName { get; init; }
|
||||
/// <summary>The coercion type name.</summary>
|
||||
public string? DriverDataType { get; init; }
|
||||
/// <summary>Whether the tag is an array.</summary>
|
||||
public bool? IsArray { get; init; }
|
||||
/// <summary>The array length when <c>IsArray</c> is set.</summary>
|
||||
public int? ArrayDim { get; init; }
|
||||
/// <summary>The MTConnect DataItem category.</summary>
|
||||
public string? MtCategory { get; init; }
|
||||
/// <summary>The MTConnect DataItem type.</summary>
|
||||
public string? MtType { get; init; }
|
||||
/// <summary>The MTConnect DataItem sub-type.</summary>
|
||||
public string? MtSubType { get; init; }
|
||||
/// <summary>The engineering units.</summary>
|
||||
public string? Units { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>Background connectivity-probe knobs (Task 13 consumes them).</summary>
|
||||
/// <summary>Background connectivity-probe knobs (consumed by the probe loop).</summary>
|
||||
private sealed class MTConnectProbeDto
|
||||
{
|
||||
/// <summary>Whether the probe loop runs.</summary>
|
||||
public bool? Enabled { get; init; }
|
||||
/// <summary>Probe interval in milliseconds.</summary>
|
||||
public int? IntervalMs { get; init; }
|
||||
/// <summary>Probe timeout in milliseconds.</summary>
|
||||
public int? TimeoutMs { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>Reconnect-backoff knobs (Task 11's pump consumes them).</summary>
|
||||
/// <summary>Reconnect-backoff knobs (consumed by the /sample pump).</summary>
|
||||
private sealed class MTConnectReconnectDto
|
||||
{
|
||||
/// <summary>Minimum reconnect backoff in milliseconds.</summary>
|
||||
public int? MinBackoffMs { get; init; }
|
||||
/// <summary>Maximum reconnect backoff in milliseconds.</summary>
|
||||
public int? MaxBackoffMs { get; init; }
|
||||
/// <summary>Backoff growth multiplier.</summary>
|
||||
public double? BackoffMultiplier { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>Write-back knobs — the driver-side half of the two-layer opt-in on observation injection.</summary>
|
||||
private sealed class MTConnectWriteDto
|
||||
{
|
||||
/// <summary>Whether write-back to the Agent is enabled.</summary>
|
||||
public bool? Enabled { get; init; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// being applied differently by the two paths — or not at all.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Construction opens nothing.</b> The Wave-0 universal discovery browser builds a
|
||||
/// <b>Construction opens nothing.</b> The universal discovery browser builds a
|
||||
/// throwaway instance through this factory purely to read
|
||||
/// <c>ITagDiscovery.SupportsOnlineDiscovery</c>, and never initializes it — so a factory
|
||||
/// that dialled the Agent (or that pre-built an <see cref="IMTConnectAgentClient"/>) would
|
||||
|
||||
@@ -20,8 +20,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// URL, so this type parses its own minimal DTO — a config that is invalid for the driver (bad
|
||||
/// tag, bad data type) can still be reachability-tested, matching the AdminUI's "does the
|
||||
/// endpoint answer" intent for Test Connect. It also avoids a compile-time dependency on the
|
||||
/// factory DTO shape (<c>MTConnectDriverFactoryExtensions</c>), which is authored separately
|
||||
/// (Task 15).
|
||||
/// factory DTO shape (<c>MTConnectDriverFactoryExtensions</c>), which is authored separately.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>The minimal DTO is "everything in the URL", not "agentUri".</b> It reads
|
||||
@@ -50,7 +49,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// lifts the Agent's own error text into the thrown exception's message; re-parsing by hand
|
||||
/// here would either duplicate that logic or under-validate (accepting any 200 response as
|
||||
/// healthy, which is precisely the "empty-but-successful" defect class this codebase has hit
|
||||
/// before, #485). The one-off cost of a full probe-document parse is negligible next to that
|
||||
/// before). The one-off cost of a full probe-document parse is negligible next to that
|
||||
/// risk.
|
||||
/// </para>
|
||||
/// <para>
|
||||
@@ -110,22 +109,22 @@ public sealed class MTConnectDriverProbe : IDriverProbe
|
||||
}
|
||||
|
||||
/// <summary>Test seam constructor — see <see cref="_handler"/>.</summary>
|
||||
/// <param name="handler">Stub handler for the agent client, or <see langword="null"/> for real sockets.</param>
|
||||
internal MTConnectDriverProbe(HttpMessageHandler? handler)
|
||||
{
|
||||
_handler = handler;
|
||||
}
|
||||
|
||||
// Sourced from the DriverTypeNames constant, not a literal — the probe is
|
||||
// looked up by AdminOperationsActor under this key, so a drift from the constant
|
||||
// silently disables the Test Connect button rather than failing anything at build time.
|
||||
/// <inheritdoc />
|
||||
/// <remarks>
|
||||
/// Sourced from the <see cref="DriverTypeNames"/> constant, not a literal — the probe is
|
||||
/// looked up by <c>AdminOperationsActor</c> under this key, so a drift from the constant
|
||||
/// silently disables the Test Connect button rather than failing anything at build time.
|
||||
/// </remarks>
|
||||
public string DriverType => DriverTypeNames.MTConnect;
|
||||
|
||||
/// <summary>Minimal probe-only config shape. Deliberately independent of the factory DTO — see the type remarks.</summary>
|
||||
private sealed class MTConnectProbeConfigDto
|
||||
{
|
||||
/// <summary>The MTConnect Agent base URI to probe.</summary>
|
||||
public string? AgentUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -160,7 +160,7 @@ public sealed record MTConnectStreamsResult(
|
||||
/// </param>
|
||||
/// <param name="SampleCount">
|
||||
/// The observation's own <c>sampleCount</c> attribute — the number of values a <c>TIME_SERIES</c>
|
||||
/// vector claims to carry (#627). The index checks the parsed vector against it. <c>null</c> when absent.
|
||||
/// vector claims to carry. The index checks the parsed vector against it. <c>null</c> when absent.
|
||||
/// </param>
|
||||
/// <param name="SampleRate">
|
||||
/// The observation's own <c>sampleRate</c> attribute (samples per second) on a <c>TIME_SERIES</c>
|
||||
@@ -168,7 +168,7 @@ public sealed record MTConnectStreamsResult(
|
||||
/// docs/drivers/MTConnect.md). <c>null</c> when absent.
|
||||
/// </param>
|
||||
/// <param name="Entries">
|
||||
/// The parsed <c><Entry key="…"></c> children of a <c>DATA_SET</c> / <c>TABLE</c> observation (#650), in
|
||||
/// The parsed <c><Entry key="…"></c> children of a <c>DATA_SET</c> / <c>TABLE</c> observation, in
|
||||
/// document order, or <c>null</c> when the observation had none. A <c>TABLE</c> entry carries
|
||||
/// <see cref="MTConnectDataSetEntry.Cells"/>. The observation index folds these into a JSON String — see
|
||||
/// <see cref="MTConnectObservationIndex"/>. <see cref="IsStructured"/> stays <c>true</c> beside them: it is the
|
||||
@@ -185,7 +185,7 @@ public sealed record MTConnectStreamsResult(
|
||||
/// an absent value; <c>resetTriggered</c> also appears on ordinary accumulating SAMPLEs and must not matter there.
|
||||
/// </param>
|
||||
/// <param name="Condition">
|
||||
/// The CONDITION-only detail (#626) — set exactly when the observation came from a
|
||||
/// The CONDITION-only detail — set exactly when the observation came from a
|
||||
/// <c><Condition></c> container, <c>null</c> for every Sample/Event. Its presence is what marks an
|
||||
/// observation as a condition for the alarm path; <see cref="Value"/> still carries the state word.
|
||||
/// </param>
|
||||
@@ -201,11 +201,11 @@ public sealed record MTConnectObservation(
|
||||
bool ResetTriggered = false,
|
||||
bool IsDataSet = false);
|
||||
|
||||
/// <summary>One <c><Cell key="…"></c> of a <c>TABLE</c> row (#650).</summary>
|
||||
/// <summary>One <c><Cell key="…"></c> of a <c>TABLE</c> row.</summary>
|
||||
public sealed record MTConnectDataSetCell(string Key, string Value);
|
||||
|
||||
/// <summary>
|
||||
/// One <c><Entry key="…"></c> of a <c>DATA_SET</c> / <c>TABLE</c> observation (#650).
|
||||
/// One <c><Entry key="…"></c> of a <c>DATA_SET</c> / <c>TABLE</c> observation.
|
||||
/// </summary>
|
||||
/// <param name="Key">The entry's <c>key</c> attribute, verbatim.</param>
|
||||
/// <param name="Value">A <c>DATA_SET</c> entry's trimmed text; <c>null</c> for a <c>TABLE</c> row or a removed entry.</param>
|
||||
@@ -218,7 +218,7 @@ public sealed record MTConnectDataSetEntry(
|
||||
IReadOnlyList<MTConnectDataSetCell>? Cells = null);
|
||||
|
||||
/// <summary>
|
||||
/// What an MTConnect CONDITION observation says beyond its state word (#626). Every field is the
|
||||
/// What an MTConnect CONDITION observation says beyond its state word. Every field is the
|
||||
/// Agent's own text, trimmed, or <c>null</c> when absent or blank — none is interpreted at this layer.
|
||||
/// </summary>
|
||||
/// <param name="Text">The element's text content: the operator-facing condition message.</param>
|
||||
@@ -244,6 +244,7 @@ public static class MTConnectComponentTreeExtensions
|
||||
/// own data items first, then each child component's data items in turn.
|
||||
/// </summary>
|
||||
/// <param name="container">The device or component to walk.</param>
|
||||
/// <returns>The container's data items followed by those of every nested component.</returns>
|
||||
public static IEnumerable<MTConnectDataItem> AllDataItems(this IMTConnectComponentContainer container)
|
||||
{
|
||||
foreach (var dataItem in container.DataItems)
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// <para>
|
||||
/// <b>Shapes this build does not represent</b> are coded <c>BadNotSupported</c> with a null
|
||||
/// value rather than approximated: a non-Float64 array tag and a <c>DATA_SET</c> / <c>TABLE</c>
|
||||
/// observation whose children are not <c><Entry></c> elements (a Float64 <c>TIME_SERIES</c> vector is served as <c>double[]</c>, #627). The latter carries its
|
||||
/// observation whose children are not <c><Entry></c> elements (a Float64 <c>TIME_SERIES</c> vector is served as <c>double[]</c>). The latter carries its
|
||||
/// real content in <c><Entry key=…></c> child elements, which reach a text-valued
|
||||
/// observation concatenated with the keys discarded — a two-entry set reads as the single
|
||||
/// token <c>"12"</c> — and because the type inference correctly demotes those
|
||||
@@ -115,7 +115,7 @@ internal sealed class MTConnectObservationIndex
|
||||
|
||||
private readonly ConcurrentDictionary<string, DataValueSnapshot> _snapshots = new(StringComparer.Ordinal);
|
||||
|
||||
// #650: the accumulated DATA_SET / TABLE content per dataItemId. A /sample chunk carries only the entries
|
||||
// the accumulated DATA_SET / TABLE content per dataItemId. A /sample chunk carries only the entries
|
||||
// that changed, so the served JSON is the merge of the baseline and every delta since. Row value is the
|
||||
// entry's text (DATA_SET) or its cell map (TABLE). Only the single pump (or a one-shot snapshot) calls
|
||||
// Apply, but the lock keeps a concurrent one-shot read-through from corrupting a shared index.
|
||||
@@ -247,7 +247,7 @@ internal sealed class MTConnectObservationIndex
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DATA_SET / TABLE (#650). Folds an observation's <c><Entry></c> children into the accumulated set for
|
||||
/// DATA_SET / TABLE. Folds an observation's <c><Entry></c> children into the accumulated set for
|
||||
/// its dataItemId and returns a plain String observation carrying the merged JSON; any other observation is
|
||||
/// returned untouched, except that an <c>UNAVAILABLE</c> one drops the accumulated set (a later delta must not
|
||||
/// resurrect pre-outage entries).
|
||||
@@ -437,7 +437,7 @@ internal sealed class MTConnectObservationIndex
|
||||
|
||||
_tags.TryGetValue(observation.DataItemId, out var tag);
|
||||
|
||||
// TIME_SERIES vectors arrive as one whitespace-separated string (#627). Checked AFTER the
|
||||
// TIME_SERIES vectors arrive as one whitespace-separated string. Checked AFTER the
|
||||
// sentinel so an unavailable array tag still reports the truthful no-comms.
|
||||
if (tag is { IsArray: true })
|
||||
{
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <b>Why hand-rolled rather than TrakHound.</b> The TrakHound packages Task 0 pinned
|
||||
/// (<c>MTConnect.NET-Common</c> + <c>-HTTP</c> 6.9.0.2 — both dropped in Task 7) contain <b>no</b>
|
||||
/// <b>Why hand-rolled rather than TrakHound.</b> The TrakHound packages originally pinned
|
||||
/// (<c>MTConnect.NET-Common</c> + <c>-HTTP</c> 6.9.0.2 — both dropped) contain <b>no</b>
|
||||
/// <c>IResponseDocumentFormatter</c> implementation — the XML formatter ships in the
|
||||
/// separate, unreferenced <c>MTConnect.NET-XML</c> package — so
|
||||
/// <c>ResponseDocumentFormatter.CreateDevicesResponseDocument("xml", stream)</c> answers
|
||||
@@ -46,7 +46,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// <b>Failure posture.</b> Anything that is not a well-formed MTConnect device model throws
|
||||
/// <see cref="InvalidDataException"/>. It never degrades to an empty-but-successful model:
|
||||
/// an empty device model that looks successful is precisely the defect class that has bitten
|
||||
/// this codebase before (#485), and here it would tear the driver's browse tree down to
|
||||
/// this codebase before, and here it would tear the driver's browse tree down to
|
||||
/// nothing while reporting healthy.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
@@ -64,6 +64,7 @@ internal static class MTConnectProbeParser
|
||||
|
||||
/// <summary>Parses a <c>/probe</c> response held as a string.</summary>
|
||||
/// <param name="xml">The raw <c>MTConnectDevices</c> XML document.</param>
|
||||
/// <returns>The parsed probe model.</returns>
|
||||
/// <exception cref="InvalidDataException">
|
||||
/// The payload is empty, not well-formed XML, not an <c>MTConnectDevices</c> document (an
|
||||
/// Agent <c>MTConnectError</c> document included — Agents answer a bad device path with one
|
||||
@@ -91,6 +92,7 @@ internal static class MTConnectProbeParser
|
||||
|
||||
/// <summary>Parses a <c>/probe</c> response read from a stream.</summary>
|
||||
/// <param name="stream">A stream positioned at the start of the XML document.</param>
|
||||
/// <returns>The parsed probe model.</returns>
|
||||
/// <exception cref="InvalidDataException">As for <see cref="Parse(string)"/>.</exception>
|
||||
public static MTConnectProbeModel Parse(Stream stream)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// completion — it would either drop the subscription silently or hot-loop reconnecting on
|
||||
/// an enumerator that ends immediately. Returning normally would make "the data path
|
||||
/// stopped" indistinguishable from "the data path is idle", which is the
|
||||
/// quiet-successful-looking-termination shape that produced this repo's #485 defect. Every
|
||||
/// quiet-successful-looking-termination shape that produced an earlier defect in this repo. Every
|
||||
/// non-cancellation end is therefore loud, typed, and carries the Agent URI.
|
||||
/// </para>
|
||||
/// <para>
|
||||
|
||||
@@ -16,9 +16,9 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect;
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <b>Why hand-rolled rather than TrakHound.</b> Same finding as
|
||||
/// <see cref="MTConnectProbeParser"/>: the packages pinned by Task 0 ship no XML document
|
||||
/// <see cref="MTConnectProbeParser"/>: the packages originally pinned ship no XML document
|
||||
/// formatter, and TrakHound's streaming client offers no socket-free entry point. Both
|
||||
/// package references were dropped in Task 7; the driver depends only on the BCL.
|
||||
/// package references were dropped; the driver depends only on the BCL.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>The Streams document is shaped nothing like the Devices document</b>, and three
|
||||
@@ -139,6 +139,7 @@ internal static class MTConnectStreamsParser
|
||||
|
||||
/// <summary>Parses a <c>/current</c> response, or one <c>/sample</c> chunk, held as a string.</summary>
|
||||
/// <param name="xml">The raw <c>MTConnectStreams</c> XML document.</param>
|
||||
/// <returns>The parsed header and observations.</returns>
|
||||
/// <exception cref="InvalidDataException">
|
||||
/// The payload is empty, not well-formed XML, not an <c>MTConnectStreams</c> document (an
|
||||
/// Agent <c>MTConnectError</c> included — Agents answer a bad request with one under HTTP
|
||||
@@ -172,6 +173,7 @@ internal static class MTConnectStreamsParser
|
||||
/// copies.
|
||||
/// </remarks>
|
||||
/// <param name="xml">The chunk's raw bytes; a UTF-8 BOM and surrounding framing whitespace are tolerated.</param>
|
||||
/// <returns>The parsed header and observations.</returns>
|
||||
/// <exception cref="InvalidDataException">As for <see cref="Parse(string)"/>.</exception>
|
||||
public static MTConnectStreamsResult Parse(ReadOnlyMemory<byte> xml)
|
||||
{
|
||||
@@ -189,6 +191,7 @@ internal static class MTConnectStreamsParser
|
||||
|
||||
/// <summary>Parses a <c>/current</c> response read from a stream.</summary>
|
||||
/// <param name="stream">A stream positioned at the start of the XML document.</param>
|
||||
/// <returns>The parsed header and observations.</returns>
|
||||
/// <exception cref="InvalidDataException">As for <see cref="Parse(string)"/>.</exception>
|
||||
public static MTConnectStreamsResult Parse(Stream stream)
|
||||
{
|
||||
@@ -363,7 +366,7 @@ internal static class MTConnectStreamsParser
|
||||
/// <c>null</c> when there is none. Text found anywhere below an observation belongs to it —
|
||||
/// that is what <c>XElement.Value</c> meant.
|
||||
/// </param>
|
||||
/// <param name="entryCollector">The enclosing observation's DATA_SET / TABLE entry list (#650), or <c>null</c> outside one.</param>
|
||||
/// <param name="entryCollector">The enclosing observation's DATA_SET / TABLE entry list, or <c>null</c> outside one.</param>
|
||||
private static void ReadElement(
|
||||
XmlReader reader,
|
||||
ContainerKind parent,
|
||||
@@ -393,7 +396,7 @@ internal static class MTConnectStreamsParser
|
||||
timestampUtc = ReadTimestampUtc(reader, dataItemId);
|
||||
conditionState = isCondition ? ConditionState(name) : null;
|
||||
|
||||
// #626: a condition's alarm identity rides the element's attributes — read here, before the
|
||||
// A condition's alarm identity rides the element's attributes — read here, before the
|
||||
// subtree walk moves the reader off them. Verbatim (trimmed), never interpreted.
|
||||
if (isCondition)
|
||||
{
|
||||
@@ -433,7 +436,7 @@ internal static class MTConnectStreamsParser
|
||||
observations.Add(null!);
|
||||
}
|
||||
|
||||
// A CONDITION's VALUE is its element NAME, so its text never becomes the value — but since #626
|
||||
// A CONDITION's VALUE is its element NAME, so its text never becomes the value — but
|
||||
// the text is still collected, into a sink of its own, because it is the condition's
|
||||
// operator-facing MESSAGE (the alarm path's Message). It is deliberately not appended to an
|
||||
// enclosing observation's sink: a condition is never nested inside a text-valued observation.
|
||||
@@ -512,7 +515,7 @@ internal static class MTConnectStreamsParser
|
||||
case XmlNodeType.Element:
|
||||
hasElements = true;
|
||||
|
||||
// #650: an <Entry> directly under a non-condition observation is DATA_SET / TABLE
|
||||
// An <Entry> directly under a non-condition observation is DATA_SET / TABLE
|
||||
// content, captured structurally rather than as concatenated text.
|
||||
if (entries is not null && kind == ContainerKind.None && MTConnectXml.IsNamed(reader, "Entry"))
|
||||
{
|
||||
@@ -672,6 +675,8 @@ internal static class MTConnectStreamsParser
|
||||
/// <summary>Everything appended so far, untrimmed — <c>XElement.Value</c>'s concatenation.</summary>
|
||||
public string Value => _builder?.ToString() ?? _single ?? string.Empty;
|
||||
|
||||
/// <summary>Appends a text fragment to the sink.</summary>
|
||||
/// <param name="text">The fragment to append.</param>
|
||||
public void Append(string text)
|
||||
{
|
||||
if (_builder is not null)
|
||||
|
||||
@@ -31,6 +31,7 @@ internal static class MTConnectXml
|
||||
/// <summary>Does <paramref name="element"/> have the given local name, whatever its namespace?</summary>
|
||||
/// <param name="element">The element to test.</param>
|
||||
/// <param name="localName">The unqualified name to match.</param>
|
||||
/// <returns><see langword="true"/> if the element has the given local name.</returns>
|
||||
public static bool IsNamed(XElement element, string localName) =>
|
||||
string.Equals(element.Name.LocalName, localName, StringComparison.Ordinal);
|
||||
|
||||
@@ -48,12 +49,14 @@ internal static class MTConnectXml
|
||||
/// </remarks>
|
||||
/// <param name="reader">A reader positioned on an element.</param>
|
||||
/// <param name="localName">The unqualified name to match.</param>
|
||||
/// <returns><see langword="true"/> if the current element has the given local name.</returns>
|
||||
public static bool IsNamed(XmlReader reader, string localName) =>
|
||||
string.Equals(reader.LocalName, localName, StringComparison.Ordinal);
|
||||
|
||||
/// <summary>Direct element children of <paramref name="parent"/> with the given local name.</summary>
|
||||
/// <param name="parent">The element whose children to filter.</param>
|
||||
/// <param name="localName">The unqualified name to match.</param>
|
||||
/// <returns>The matching child elements.</returns>
|
||||
public static IEnumerable<XElement> ChildrenNamed(XElement parent, string localName) =>
|
||||
parent.Elements().Where(child => IsNamed(child, localName));
|
||||
|
||||
@@ -63,6 +66,7 @@ internal static class MTConnectXml
|
||||
/// </summary>
|
||||
/// <param name="element">The element carrying the attribute.</param>
|
||||
/// <param name="name">The unqualified attribute name.</param>
|
||||
/// <returns>The attribute value, or <see langword="null"/> when absent or blank.</returns>
|
||||
public static string? OptionalAttribute(XElement element, string name)
|
||||
{
|
||||
var value = element.Attribute(name)?.Value;
|
||||
@@ -83,6 +87,7 @@ internal static class MTConnectXml
|
||||
/// </remarks>
|
||||
/// <param name="reader">A reader positioned on an element.</param>
|
||||
/// <param name="name">The unqualified attribute name.</param>
|
||||
/// <returns>The attribute value, or <see langword="null"/> when absent or blank.</returns>
|
||||
public static string? OptionalAttribute(XmlReader reader, string name)
|
||||
{
|
||||
var value = reader.GetAttribute(name);
|
||||
@@ -95,6 +100,7 @@ internal static class MTConnectXml
|
||||
/// <param name="name">The unqualified attribute name.</param>
|
||||
/// <param name="owner">How to describe the element in the error message.</param>
|
||||
/// <param name="subject">How to describe the document in the error message (e.g. "/probe response").</param>
|
||||
/// <returns>The attribute value.</returns>
|
||||
/// <exception cref="InvalidDataException">The attribute is absent or blank.</exception>
|
||||
public static string RequiredAttribute(XElement element, string name, string owner, string subject) =>
|
||||
OptionalAttribute(element, name) ?? throw MissingAttribute(name, owner, subject);
|
||||
@@ -107,6 +113,7 @@ internal static class MTConnectXml
|
||||
/// <param name="name">The unqualified attribute name.</param>
|
||||
/// <param name="owner">How to describe the element in the error message.</param>
|
||||
/// <param name="subject">How to describe the document in the error message.</param>
|
||||
/// <returns>The attribute value.</returns>
|
||||
/// <exception cref="InvalidDataException">The attribute is absent or blank.</exception>
|
||||
public static string RequiredAttribute(XmlReader reader, string name, string owner, string subject) =>
|
||||
OptionalAttribute(reader, name) ?? throw MissingAttribute(name, owner, subject);
|
||||
@@ -116,6 +123,7 @@ internal static class MTConnectXml
|
||||
/// <param name="name">The unqualified attribute name.</param>
|
||||
/// <param name="owner">How to describe the element in the error message.</param>
|
||||
/// <param name="subject">How to describe the document in the error message.</param>
|
||||
/// <returns>The parsed integer, or <see langword="null"/> when the attribute is absent or blank.</returns>
|
||||
/// <exception cref="InvalidDataException">The attribute is present but not an integer.</exception>
|
||||
public static int? OptionalIntAttribute(XElement element, string name, string owner, string subject)
|
||||
{
|
||||
@@ -139,6 +147,7 @@ internal static class MTConnectXml
|
||||
/// <param name="name">The unqualified attribute name.</param>
|
||||
/// <param name="owner">How to describe the element in the error message.</param>
|
||||
/// <param name="subject">How to describe the document in the error message.</param>
|
||||
/// <returns>The parsed long value.</returns>
|
||||
/// <exception cref="InvalidDataException">The attribute is absent, blank, or not an integer.</exception>
|
||||
public static long RequiredLongAttribute(XElement element, string name, string owner, string subject) =>
|
||||
AsLong(RequiredAttribute(element, name, owner, subject), name, owner, subject);
|
||||
@@ -151,6 +160,7 @@ internal static class MTConnectXml
|
||||
/// <param name="name">The unqualified attribute name.</param>
|
||||
/// <param name="owner">How to describe the element in the error message.</param>
|
||||
/// <param name="subject">How to describe the document in the error message.</param>
|
||||
/// <returns>The parsed long value.</returns>
|
||||
/// <exception cref="InvalidDataException">The attribute is absent, blank, or not an integer.</exception>
|
||||
public static long RequiredLongAttribute(XmlReader reader, string name, string owner, string subject) =>
|
||||
AsLong(RequiredAttribute(reader, name, owner, subject), name, owner, subject);
|
||||
@@ -180,6 +190,7 @@ internal static class MTConnectXml
|
||||
/// <param name="root">The document's actual root element.</param>
|
||||
/// <param name="expectedRootName">The root element name the caller required.</param>
|
||||
/// <param name="subject">How to describe the document in the error message.</param>
|
||||
/// <returns>The error message describing the unexpected root.</returns>
|
||||
public static string DescribeUnexpectedRoot(XElement root, string expectedRootName, string subject)
|
||||
{
|
||||
var message =
|
||||
@@ -220,6 +231,7 @@ internal static class MTConnectXml
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <param name="root">The <c>MTConnectError</c> document's root element.</param>
|
||||
/// <returns>The Agent's error text, or <see langword="null"/> when no readable detail is present.</returns>
|
||||
public static string? ExtractErrorText(XElement root)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(root);
|
||||
|
||||
Reference in New Issue
Block a user