perf(worker): batch frames skip per-frame TCS; stream the alarm-poll XML (mxaccessgw#177)
R21-K12: WorkerFrameWriter.WriteBatchAsync allocated a TaskCompletionSource (plus its Task) per frame on the event drain hot path. PendingFrame now holds its terminal state itself (Interlocked pending/succeeded/faulted/canceled) and only single-frame WriteAsync frames, which race their completion against the write lock, get a TCS. A batch caller reads each frame's outcome after its own drain pass: every frame a pass claims is terminal before that pass releases the lock, so nothing is left to await. First-failure-in-batch-order, tombstoning, claim/cancel interlock and flush coalescing are unchanged. R21-K13: WnWrapAlarmConsumer.ParseSnapshotXml streams the GetXmlCurrentAlarms2 payload with an XmlTextReader (same defaults XmlDocument.LoadXml uses: Normalization off, DTDs parsed, no resolver; Significant whitespace only) instead of building a full XmlDocument every 500 ms poll. Behaviour is pinned by new tests: batch first-failure ordering (own drain and drained by another lock holder), batch cancellation tombstoning, batch flush failure, and a differential test running the replaced XmlDocument parser as an oracle over a 48-payload corpus (CRLF, CDATA, entities, DTD, namespaces, nesting, malformed). Mutation checks on windev: 8 of 8 injected regressions (whitespace, normalization, DTD, namespace, CDATA, batch last-failure, batch ignored failures, ignored tombstone) fail the new tests. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -27,14 +27,37 @@ public sealed class WorkerFrameWriter
|
||||
{
|
||||
private sealed class PendingFrame
|
||||
{
|
||||
private const int StatePending = 0;
|
||||
private const int StateSucceeded = 1;
|
||||
private const int StateFaulted = 2;
|
||||
private const int StateCanceled = 3;
|
||||
|
||||
// A single-frame caller awaits its frame — racing that completion against the write lock —
|
||||
// so it needs a Task and gets a TaskCompletionSource. A WriteBatchAsync frame never does: the
|
||||
// batch caller holds the write lock for its own drain pass, and every frame a pass claims
|
||||
// reaches a terminal state before that pass releases the lock, so once the caller's drain
|
||||
// returns it only has to read each frame's outcome. Skipping the per-frame TCS (plus its
|
||||
// Task) on the event drain loop's hot path is the batch allocation saving (#177). The
|
||||
// terminal state lives in _state either way, so both kinds share one claim/tombstone/
|
||||
// complete protocol and DequeueNext, FailAllQueued, and the drain pass treat them alike.
|
||||
private readonly TaskCompletionSource<bool>? _completion;
|
||||
private int _state;
|
||||
private Exception? _fault;
|
||||
|
||||
/// <summary>Initializes a new instance of the PendingFrame class.</summary>
|
||||
/// <param name="envelope">Worker envelope awaiting write.</param>
|
||||
/// <param name="priority">Priority class the frame was queued at.</param>
|
||||
public PendingFrame(WorkerEnvelope envelope, WorkerFrameWritePriority priority)
|
||||
/// <param name="awaitable">
|
||||
/// <see langword="true"/> for a frame whose caller awaits <see cref="Completion"/>;
|
||||
/// <see langword="false"/> for a batch frame whose caller reads <see cref="TryGetFault"/>.
|
||||
/// </param>
|
||||
public PendingFrame(WorkerEnvelope envelope, WorkerFrameWritePriority priority, bool awaitable)
|
||||
{
|
||||
Envelope = envelope;
|
||||
IsControl = priority != WorkerFrameWritePriority.Event;
|
||||
Completion = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
_completion = awaitable
|
||||
? new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously)
|
||||
: null;
|
||||
}
|
||||
|
||||
/// <summary>Gets the worker envelope awaiting write.</summary>
|
||||
@@ -48,8 +71,21 @@ public sealed class WorkerFrameWriter
|
||||
/// </summary>
|
||||
public bool IsControl { get; }
|
||||
|
||||
/// <summary>Gets the completion source signaled once the frame has been written or has failed.</summary>
|
||||
public TaskCompletionSource<bool> Completion { get; }
|
||||
/// <summary>
|
||||
/// Gets the task signaled once the frame has been written or has failed. Only an awaitable
|
||||
/// (single-frame) frame has one; reading it on a batch frame is a programming error.
|
||||
/// </summary>
|
||||
public Task Completion => _completion?.Task
|
||||
?? throw new InvalidOperationException("A batch frame has no awaitable completion.");
|
||||
|
||||
/// <summary>Gets a value indicating whether the frame has an awaitable <see cref="Completion"/>.</summary>
|
||||
public bool HasCompletion => _completion is not null;
|
||||
|
||||
/// <summary>Gets a value indicating whether a cancelled caller tombstoned this frame.</summary>
|
||||
public bool IsCanceled => Volatile.Read(ref _state) == StateCanceled;
|
||||
|
||||
/// <summary>Gets a value indicating whether the frame has reached a terminal state.</summary>
|
||||
public bool IsCompleted => Volatile.Read(ref _state) != StatePending;
|
||||
|
||||
/// <summary>
|
||||
/// Set to <c>true</c> by <see cref="DequeueNext"/> — under <c>_gate</c> — at the instant the
|
||||
@@ -60,6 +96,63 @@ public sealed class WorkerFrameWriter
|
||||
/// Mutated only under <c>_gate</c>.
|
||||
/// </summary>
|
||||
public bool Claimed;
|
||||
|
||||
/// <summary>Marks the frame written and flushed; a no-op once terminal.</summary>
|
||||
public void TrySetResult()
|
||||
{
|
||||
if (TryTransition(StateSucceeded))
|
||||
{
|
||||
_completion?.TrySetResult(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Marks the frame failed; a no-op once terminal.</summary>
|
||||
/// <param name="exception">Failure to surface to the frame's caller.</param>
|
||||
public void TrySetException(Exception exception)
|
||||
{
|
||||
// _fault is published before the state flips, so a reader that observes StateFaulted
|
||||
// (through the Interlocked fence) also observes the exception.
|
||||
if (Volatile.Read(ref _state) != StatePending)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Exception? previous = Interlocked.CompareExchange(ref _fault, exception, null);
|
||||
if (previous is not null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryTransition(StateFaulted))
|
||||
{
|
||||
_completion?.TrySetException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Tombstones the frame; a no-op once terminal.</summary>
|
||||
/// <param name="cancellationToken">Token whose cancellation tombstoned the frame.</param>
|
||||
public void TrySetCanceled(CancellationToken cancellationToken)
|
||||
{
|
||||
if (TryTransition(StateCanceled))
|
||||
{
|
||||
_completion?.TrySetCanceled(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the failure a terminal batch frame ended with, or <see langword="null"/> when it
|
||||
/// succeeded or was tombstoned.
|
||||
/// </summary>
|
||||
/// <returns>The frame's failure, or <see langword="null"/>.</returns>
|
||||
public Exception? TryGetFault()
|
||||
{
|
||||
return Volatile.Read(ref _state) == StateFaulted ? Volatile.Read(ref _fault) : null;
|
||||
}
|
||||
|
||||
private bool TryTransition(int terminalState)
|
||||
{
|
||||
return Interlocked.CompareExchange(ref _state, terminalState, StatePending) == StatePending;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly WorkerFrameProtocolOptions _options;
|
||||
@@ -132,7 +225,7 @@ public sealed class WorkerFrameWriter
|
||||
throw new ArgumentNullException(nameof(envelope));
|
||||
}
|
||||
|
||||
PendingFrame frame = new PendingFrame(envelope, priority);
|
||||
PendingFrame frame = new PendingFrame(envelope, priority, awaitable: true);
|
||||
lock (_gate)
|
||||
{
|
||||
if (priority == WorkerFrameWritePriority.Event)
|
||||
@@ -153,7 +246,7 @@ public sealed class WorkerFrameWriter
|
||||
// the winner's release; the acquisition it then walks away from is detached, never dropped, so
|
||||
// no drain responsibility leaves with it.
|
||||
Task lockWait = _writeLock.WaitAsync(cancellationToken);
|
||||
Task completion = frame.Completion.Task;
|
||||
Task completion = frame.Completion;
|
||||
await Task.WhenAny(completion, lockWait).ConfigureAwait(false);
|
||||
|
||||
if (lockWait.Status != TaskStatus.RanToCompletion)
|
||||
@@ -253,7 +346,7 @@ public sealed class WorkerFrameWriter
|
||||
{
|
||||
WorkerEnvelope envelope = envelopes[index]
|
||||
?? throw new ArgumentException("Batch envelopes must not contain null.", nameof(envelopes));
|
||||
frames[index] = new PendingFrame(envelope, priority);
|
||||
frames[index] = new PendingFrame(envelope, priority, awaitable: false);
|
||||
}
|
||||
|
||||
lock (_gate)
|
||||
@@ -284,19 +377,21 @@ public sealed class WorkerFrameWriter
|
||||
_writeLock.Release();
|
||||
}
|
||||
|
||||
// Await every completion so no per-frame rejection faults unobserved, but surface the first
|
||||
// failure (in batch order) to the caller — the drain loop maps it back to the offending event.
|
||||
// Surface the first failure (in batch order) to the caller — the drain loop maps it back to
|
||||
// the offending event. Every batch frame is terminal here without waiting: this caller's own
|
||||
// pass drained whatever of the batch was still queued, and any frame an earlier lock-holder
|
||||
// claimed was completed or failed inside that holder's pass, before it released the lock this
|
||||
// caller then acquired. Batch frames carry no Task, so there is nothing left to observe.
|
||||
Exception? firstFailure = null;
|
||||
foreach (PendingFrame frame in frames)
|
||||
{
|
||||
try
|
||||
if (!frame.IsCompleted)
|
||||
{
|
||||
await frame.Completion.Task.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
firstFailure ??= exception;
|
||||
throw new InvalidOperationException(
|
||||
"A batch frame was still pending after its caller's drain pass released the write lock.");
|
||||
}
|
||||
|
||||
firstFailure ??= frame.TryGetFault();
|
||||
}
|
||||
|
||||
if (firstFailure is not null)
|
||||
@@ -311,7 +406,7 @@ public sealed class WorkerFrameWriter
|
||||
{
|
||||
if (!frame.Claimed)
|
||||
{
|
||||
frame.Completion.TrySetCanceled(cancellationToken);
|
||||
frame.TrySetCanceled(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,7 +421,7 @@ public sealed class WorkerFrameWriter
|
||||
{
|
||||
if (!frame.Claimed)
|
||||
{
|
||||
frame.Completion.TrySetCanceled(cancellationToken);
|
||||
frame.TrySetCanceled(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -349,7 +444,11 @@ public sealed class WorkerFrameWriter
|
||||
/// <param name="frame">Frame whose completion may fault without an awaiter.</param>
|
||||
private static void ObserveAbandonedFault(PendingFrame frame)
|
||||
{
|
||||
ObserveFault(frame.Completion.Task);
|
||||
// A batch frame has no Task, so a later failure has nothing to go unobserved on.
|
||||
if (frame.HasCompletion)
|
||||
{
|
||||
ObserveFault(frame.Completion);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -497,7 +596,7 @@ public sealed class WorkerFrameWriter
|
||||
// flush that guarantees delivery failed, so the pipe is broken. Fail the frame just
|
||||
// claimed (it is out of its queue and nothing else will ever complete it), every
|
||||
// written-but-unflushed frame, and everything still queued, then stop draining.
|
||||
frame.Completion.TrySetException(exception);
|
||||
frame.TrySetException(exception);
|
||||
FailFrames(written, exception);
|
||||
FailAllQueued(exception);
|
||||
return;
|
||||
@@ -520,14 +619,14 @@ public sealed class WorkerFrameWriter
|
||||
// Validation, empty-payload, and oversized-frame errors are specific to this frame and
|
||||
// do not damage the stream; fail only this frame and keep draining the rest. Nothing was
|
||||
// written for it, so it needs no flush.
|
||||
frame.Completion.TrySetException(exception);
|
||||
frame.TrySetException(exception);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// A stream write failure means the pipe is broken; fail this frame, every frame already
|
||||
// written this batch but not yet flushed, and every frame still queued so no caller
|
||||
// awaits forever, then stop draining.
|
||||
frame.Completion.TrySetException(exception);
|
||||
frame.TrySetException(exception);
|
||||
FailFrames(written, exception);
|
||||
FailAllQueued(exception);
|
||||
return;
|
||||
@@ -560,7 +659,7 @@ public sealed class WorkerFrameWriter
|
||||
{
|
||||
foreach (PendingFrame frame in frames)
|
||||
{
|
||||
frame.Completion.TrySetResult(true);
|
||||
frame.TrySetResult();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -568,7 +667,7 @@ public sealed class WorkerFrameWriter
|
||||
{
|
||||
foreach (PendingFrame frame in frames)
|
||||
{
|
||||
frame.Completion.TrySetException(exception);
|
||||
frame.TrySetException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -591,7 +690,7 @@ public sealed class WorkerFrameWriter
|
||||
while (_controlFrames.Count > 0)
|
||||
{
|
||||
PendingFrame frame = _controlFrames.Dequeue();
|
||||
if (frame.Completion.Task.IsCanceled)
|
||||
if (frame.IsCanceled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -603,7 +702,7 @@ public sealed class WorkerFrameWriter
|
||||
while (_eventFrames.Count > 0)
|
||||
{
|
||||
PendingFrame frame = _eventFrames.Dequeue();
|
||||
if (frame.Completion.Task.IsCanceled)
|
||||
if (frame.IsCanceled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -622,12 +721,12 @@ public sealed class WorkerFrameWriter
|
||||
{
|
||||
while (_controlFrames.Count > 0)
|
||||
{
|
||||
_controlFrames.Dequeue().Completion.TrySetException(exception);
|
||||
_controlFrames.Dequeue().TrySetException(exception);
|
||||
}
|
||||
|
||||
while (_eventFrames.Count > 0)
|
||||
{
|
||||
_eventFrames.Dequeue().Completion.TrySetException(exception);
|
||||
_eventFrames.Dequeue().TrySetException(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using WNWRAPCONSUMERLib;
|
||||
using ZB.MOM.WW.MxGateway.Contracts;
|
||||
@@ -73,7 +75,7 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
|
||||
/// Ceiling on the resolved per-fetch cap. Mirrors the gateway-side
|
||||
/// <c>MxGateway:Alarms:MaxAlarmsPerFetch</c> maximum. The worker is a
|
||||
/// 32-bit process: every poll materializes the whole reply as one BSTR
|
||||
/// and then a full <see cref="XmlDocument"/> over it, so an unbounded
|
||||
/// and then streams it into one record per alarm, so an unbounded
|
||||
/// cap (<see cref="int.MaxValue"/> passed startup validation before
|
||||
/// this existed) is an out-of-memory fault on the STA, not a slow poll.
|
||||
/// </summary>
|
||||
@@ -685,22 +687,58 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
|
||||
|
||||
if (string.IsNullOrWhiteSpace(xml)) return records;
|
||||
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.LoadXml(xml);
|
||||
XmlNodeList? alarmNodes = doc.SelectNodes("/ALARM_RECORDS/ALARM");
|
||||
if (alarmNodes is null) return records;
|
||||
|
||||
alarmRecordCount = alarmNodes.Count;
|
||||
|
||||
foreach (XmlNode alarmNode in alarmNodes)
|
||||
// Streamed with a forward-only XmlTextReader instead of materializing a
|
||||
// full XmlDocument: the poll runs every 500 ms on the STA and at the
|
||||
// per-fetch cap the DOM was the dominant steady allocation (#177).
|
||||
//
|
||||
// Parity with the XmlDocument + XPath reading this replaces, which the
|
||||
// differential tests in WnWrapAlarmConsumerXmlTests pin against a copy
|
||||
// of the old code:
|
||||
// * XmlDocument.LoadXml reads through an XmlTextReader with its
|
||||
// defaults (DTDs parsed, Normalization off — so CRLF inside a
|
||||
// comment field survives — and no character checking); this reader
|
||||
// keeps those defaults and only nulls the resolver, which
|
||||
// XmlDocument also leaves unset. The whole document is read to its
|
||||
// end, so a malformed payload still throws XmlException rather than
|
||||
// returning the records before the fault.
|
||||
// * "/ALARM_RECORDS/ALARM" is an unprefixed XPath name test: local
|
||||
// name match in the empty namespace, document element then its
|
||||
// direct children only.
|
||||
// * XmlDocument (PreserveWhitespace off) drops insignificant
|
||||
// whitespace nodes and keeps significant ones; WhitespaceHandling
|
||||
// .Significant makes the reader do the same, so InnerText
|
||||
// concatenation below sees the same text nodes the DOM held.
|
||||
using StringReader textReader = new StringReader(xml);
|
||||
using XmlTextReader reader = new XmlTextReader(textReader)
|
||||
{
|
||||
XmlResolver = null,
|
||||
DtdProcessing = DtdProcessing.Parse,
|
||||
EntityHandling = EntityHandling.ExpandEntities,
|
||||
WhitespaceHandling = WhitespaceHandling.Significant,
|
||||
};
|
||||
|
||||
bool rootIsAlarmRecords = false;
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader.NodeType != XmlNodeType.Element) continue;
|
||||
|
||||
if (reader.Depth == 0)
|
||||
{
|
||||
rootIsAlarmRecords = IsUnqualified(reader, "ALARM_RECORDS");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!rootIsAlarmRecords || reader.Depth != 1 || !IsUnqualified(reader, "ALARM")) continue;
|
||||
|
||||
alarmRecordCount++;
|
||||
|
||||
// One pass over the child elements instead of 17 SelectSingleNode
|
||||
// XPath evaluations per record. At the 1024-record cap that is the
|
||||
// difference between ~17k XPath expression compilations plus child
|
||||
// walks and one walk per record, on the STA that also serves reads
|
||||
// and writes.
|
||||
//
|
||||
// Parity with the XPath it replaces: SelectSingleNode(name) picks
|
||||
// Parity with the XPath this replaced: SelectSingleNode(name) picks
|
||||
// the FIRST child ELEMENT of that name (ordinal, case-sensitive)
|
||||
// and yields its InnerText; an absent child yields string.Empty,
|
||||
// and so does a present-but-empty one. Hence: element nodes only,
|
||||
@@ -708,12 +746,14 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
|
||||
// coalesce to string.Empty at the end — which keeps the absent and
|
||||
// empty cases indistinguishable exactly as before.
|
||||
//
|
||||
// One theoretical divergence: XmlNode.Name is the QName, so a child
|
||||
// carrying its own default-namespace declaration (<GUID xmlns="...">)
|
||||
// matches here where the unprefixed XPath name test would not. It is
|
||||
// theoretical — wnwrap emits no namespaces, and a namespaced ALARM
|
||||
// wrapper makes the outer SelectNodes return nothing either way — and
|
||||
// it errs permissive (field populated rather than silently dropped).
|
||||
// One theoretical divergence from that XPath, kept from the DOM
|
||||
// walk that preceded this reader: reader.Name is the QName, so a
|
||||
// child carrying its own default-namespace declaration
|
||||
// (<GUID xmlns="...">) matches here where the unprefixed XPath
|
||||
// name test would not. It is theoretical — wnwrap emits no
|
||||
// namespaces, and a namespaced ALARM wrapper is skipped either
|
||||
// way — and it errs permissive (field populated rather than
|
||||
// silently dropped).
|
||||
string? guidHex = null;
|
||||
string? xmlDate = null;
|
||||
string? xmlTime = null;
|
||||
@@ -736,33 +776,40 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
|
||||
string? ackOperatorDomain = null;
|
||||
string? ackOperatorNode = null;
|
||||
|
||||
foreach (XmlNode child in alarmNode.ChildNodes)
|
||||
if (!reader.IsEmptyElement)
|
||||
{
|
||||
if (child.NodeType != XmlNodeType.Element) continue;
|
||||
|
||||
switch (child.Name)
|
||||
while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && reader.Depth == 1))
|
||||
{
|
||||
case "GUID": guidHex ??= child.InnerText; break;
|
||||
case "DATE": xmlDate ??= child.InnerText; break;
|
||||
case "TIME": xmlTime ??= child.InnerText; break;
|
||||
case "GMTOFFSET": gmtOffset ??= child.InnerText; break;
|
||||
case "DSTADJUST": dstAdjust ??= child.InnerText; break;
|
||||
case "PROVIDER_NODE": providerNode ??= child.InnerText; break;
|
||||
case "PROVIDER_NAME": providerName ??= child.InnerText; break;
|
||||
case "GROUP": group ??= child.InnerText; break;
|
||||
case "TAGNAME": tagName ??= child.InnerText; break;
|
||||
case "TYPE": type ??= child.InnerText; break;
|
||||
case "VALUE": value ??= child.InnerText; break;
|
||||
case "LIMIT": limit ??= child.InnerText; break;
|
||||
case "PRIORITY": priority ??= child.InnerText; break;
|
||||
case "STATE": state ??= child.InnerText; break;
|
||||
case "OPERATOR_NODE": operatorNode ??= child.InnerText; break;
|
||||
case "OPERATOR_NAME": operatorName ??= child.InnerText; break;
|
||||
case "ALARM_COMMENT": alarmComment ??= child.InnerText; break;
|
||||
case "ACK_COMMENT": ackComment ??= child.InnerText; break;
|
||||
case "ACK_OPERATOR_NAME": ackOperatorName ??= child.InnerText; break;
|
||||
case "ACK_DOMAIN_NAME": ackOperatorDomain ??= child.InnerText; break;
|
||||
case "ACK_OPERATOR_NODE": ackOperatorNode ??= child.InnerText; break;
|
||||
if (reader.NodeType != XmlNodeType.Element || reader.Depth != 2) continue;
|
||||
|
||||
// Read the name before the text: reading the text moves the
|
||||
// reader to the element's end tag.
|
||||
string name = reader.Name;
|
||||
string text = ReadElementInnerText(reader);
|
||||
switch (name)
|
||||
{
|
||||
case "GUID": guidHex ??= text; break;
|
||||
case "DATE": xmlDate ??= text; break;
|
||||
case "TIME": xmlTime ??= text; break;
|
||||
case "GMTOFFSET": gmtOffset ??= text; break;
|
||||
case "DSTADJUST": dstAdjust ??= text; break;
|
||||
case "PROVIDER_NODE": providerNode ??= text; break;
|
||||
case "PROVIDER_NAME": providerName ??= text; break;
|
||||
case "GROUP": group ??= text; break;
|
||||
case "TAGNAME": tagName ??= text; break;
|
||||
case "TYPE": type ??= text; break;
|
||||
case "VALUE": value ??= text; break;
|
||||
case "LIMIT": limit ??= text; break;
|
||||
case "PRIORITY": priority ??= text; break;
|
||||
case "STATE": state ??= text; break;
|
||||
case "OPERATOR_NODE": operatorNode ??= text; break;
|
||||
case "OPERATOR_NAME": operatorName ??= text; break;
|
||||
case "ALARM_COMMENT": alarmComment ??= text; break;
|
||||
case "ACK_COMMENT": ackComment ??= text; break;
|
||||
case "ACK_OPERATOR_NAME": ackOperatorName ??= text; break;
|
||||
case "ACK_DOMAIN_NAME": ackOperatorDomain ??= text; break;
|
||||
case "ACK_OPERATOR_NODE": ackOperatorNode ??= text; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -799,6 +846,55 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
|
||||
return records;
|
||||
}
|
||||
|
||||
private static bool IsUnqualified(XmlReader reader, string localName)
|
||||
{
|
||||
return reader.NamespaceURI.Length == 0
|
||||
&& string.Equals(reader.LocalName, localName, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns what <see cref="XmlNode.InnerText"/> returned for the
|
||||
/// element the reader is on — every text, CDATA and significant
|
||||
/// whitespace node in its subtree, concatenated in document order,
|
||||
/// comments and processing instructions excluded — and leaves the
|
||||
/// reader on the element's end tag (or on the element itself when it
|
||||
/// is empty). The single-text-node case, which is every wnwrap field,
|
||||
/// returns the reader's string without a builder.
|
||||
/// </summary>
|
||||
/// <param name="reader">Reader positioned on an element start tag.</param>
|
||||
/// <returns>The concatenated inner text, or <see cref="string.Empty"/>.</returns>
|
||||
private static string ReadElementInnerText(XmlReader reader)
|
||||
{
|
||||
if (reader.IsEmptyElement) return string.Empty;
|
||||
|
||||
int depth = reader.Depth;
|
||||
string? first = null;
|
||||
StringBuilder? builder = null;
|
||||
while (reader.Read())
|
||||
{
|
||||
XmlNodeType nodeType = reader.NodeType;
|
||||
if (nodeType == XmlNodeType.EndElement && reader.Depth == depth) break;
|
||||
|
||||
if (nodeType is XmlNodeType.Text
|
||||
or XmlNodeType.CDATA
|
||||
or XmlNodeType.Whitespace
|
||||
or XmlNodeType.SignificantWhitespace)
|
||||
{
|
||||
if (first is null)
|
||||
{
|
||||
first = reader.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
builder ??= new StringBuilder(first);
|
||||
builder.Append(reader.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return builder?.ToString() ?? first ?? string.Empty;
|
||||
}
|
||||
|
||||
private static int ParseInt(string text)
|
||||
{
|
||||
return int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out int n)
|
||||
|
||||
Reference in New Issue
Block a user