feat(historian): materialise historized vars with Historizing + HistoryRead bit + NodeId->tagname map
This commit is contained in:
@@ -59,8 +59,10 @@ public sealed class DeferredAddressSpaceSink : IOpcUaAddressSpaceSink
|
||||
/// <param name="displayName">The display name of the variable.</param>
|
||||
/// <param name="dataType">The OPC UA data type of the variable.</param>
|
||||
/// <param name="writable">When true the node is created read/write; otherwise read-only.</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable)
|
||||
=> _inner.EnsureVariable(variableNodeId, parentFolderNodeId, displayName, dataType, writable);
|
||||
/// <param name="historianTagname">null ⇒ not historized; non-null ⇒ create Historizing with the
|
||||
/// HistoryRead access bit and register the historian tagname.</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null)
|
||||
=> _inner.EnsureVariable(variableNodeId, parentFolderNodeId, displayName, dataType, writable, historianTagname);
|
||||
|
||||
/// <summary>Rebuilds the address space through the inner sink.</summary>
|
||||
public void RebuildAddressSpace() => _inner.RebuildAddressSpace();
|
||||
|
||||
@@ -65,7 +65,10 @@ public interface IOpcUaAddressSpaceSink
|
||||
/// <param name="writable">When true the node is created <c>CurrentReadWrite</c> (an authored
|
||||
/// ReadWrite equipment tag); when false it stays <c>CurrentRead</c> (read-only). Non-equipment-tag
|
||||
/// variables (folders' children, alarm placeholders) always pass <c>false</c>.</param>
|
||||
void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable);
|
||||
/// <param name="historianTagname">null ⇒ the variable is not historized; non-null ⇒ create it
|
||||
/// Historizing with the HistoryRead access bit and register the (already default-resolved)
|
||||
/// historian tagname.</param>
|
||||
void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null);
|
||||
|
||||
/// <summary>
|
||||
/// Tear down + repopulate the address space. Called by <c>OpcUaPublishActor</c> after a
|
||||
@@ -98,7 +101,7 @@ public sealed class NullOpcUaAddressSpaceSink : IOpcUaAddressSpaceSink
|
||||
public void EnsureFolder(string folderNodeId, string? parentNodeId, string displayName) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable) { }
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RebuildAddressSpace() { }
|
||||
|
||||
@@ -30,6 +30,11 @@ public sealed class OtOpcUaNodeManager : CustomNodeManager2
|
||||
private readonly ConcurrentDictionary<string, BaseDataVariableState> _variables = new(StringComparer.Ordinal);
|
||||
private readonly ConcurrentDictionary<string, FolderState> _folders = new(StringComparer.Ordinal);
|
||||
private readonly ConcurrentDictionary<string, AlarmConditionState> _alarmConditions = new(StringComparer.Ordinal);
|
||||
/// <summary>Phase C: NodeId → resolved historian tagname for every variable materialised
|
||||
/// Historizing. Populated by <see cref="EnsureVariable"/> when a historian tagname is supplied; the
|
||||
/// (later) HistoryRead override resolves a HistoryRead request's NodeId against this map. Cleared on
|
||||
/// <see cref="RebuildAddressSpace"/>.</summary>
|
||||
private readonly ConcurrentDictionary<string, string> _historizedTagnames = new(StringComparer.Ordinal);
|
||||
/// <summary>Folders we have already promoted to event-notifiers + registered as root notifiers,
|
||||
/// so repeated <see cref="MaterialiseAlarmCondition"/> calls don't double-add (idempotent guard).
|
||||
/// Keyed by NodeId → the actual <see cref="FolderState"/> so <see cref="RebuildAddressSpace"/> can
|
||||
@@ -113,6 +118,26 @@ public sealed class OtOpcUaNodeManager : CustomNodeManager2
|
||||
public AlarmConditionState? TryGetAlarmCondition(string alarmNodeId) =>
|
||||
_alarmConditions.TryGetValue(alarmNodeId, out var condition) ? condition : null;
|
||||
|
||||
/// <summary>Phase C: look up the resolved historian tagname registered for a historized variable
|
||||
/// node, or null when the node is not historized. The (later) HistoryRead override resolves an
|
||||
/// inbound HistoryRead request's NodeId against this map. Exposed for tests + the override.</summary>
|
||||
/// <param name="nodeId">The variable node identifier.</param>
|
||||
/// <param name="tagname">The resolved historian tagname when historized; otherwise null.</param>
|
||||
/// <returns>True when the node is registered as historized; otherwise false.</returns>
|
||||
public bool TryGetHistorizedTagname(string nodeId, out string? tagname)
|
||||
{
|
||||
if (_historizedTagnames.TryGetValue(nodeId, out var t)) { tagname = t; return true; }
|
||||
tagname = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Look up a materialised variable node by its NodeId string, or null if not present.
|
||||
/// Exposed for tests so they can assert the SDK node's Historizing / AccessLevel attributes.</summary>
|
||||
/// <param name="nodeId">The variable node identifier.</param>
|
||||
/// <returns>The cached <see cref="BaseDataVariableState"/>, or null when none is registered.</returns>
|
||||
internal BaseDataVariableState? TryGetVariable(string nodeId) =>
|
||||
_variables.TryGetValue(nodeId, out var variable) ? variable : null;
|
||||
|
||||
/// <summary>
|
||||
/// Apply a value write from <see cref="IOpcUaAddressSpaceSink.WriteValue"/>. Creates the
|
||||
/// variable node on first call; subsequent calls update Value + StatusCode +
|
||||
@@ -817,7 +842,12 @@ public sealed class OtOpcUaNodeManager : CustomNodeManager2
|
||||
/// ReadWrite equipment tag) and the inbound-write handler <see cref="OnEquipmentTagWrite"/> is attached
|
||||
/// to its <c>OnWriteValue</c> (Task 11) so a client write gates on the <c>WriteOperate</c> role + routes
|
||||
/// to the backing driver; when false it stays <c>CurrentRead</c> (read-only) with no write handler.</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable)
|
||||
/// <param name="historianTagname">Phase C: null ⇒ the node is NOT historized (Historizing=false, no
|
||||
/// HistoryRead bit, not registered). Non-null ⇒ the node is created <c>Historizing</c> with the
|
||||
/// <c>HistoryRead</c> access bit OR-ed into both <c>AccessLevel</c> and <c>UserAccessLevel</c>, and the
|
||||
/// (already default-resolved) tagname is registered in the NodeId→tagname map the HistoryRead override
|
||||
/// resolves against.</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrEmpty(variableNodeId);
|
||||
ArgumentException.ThrowIfNullOrEmpty(displayName);
|
||||
@@ -830,6 +860,13 @@ public sealed class OtOpcUaNodeManager : CustomNodeManager2
|
||||
if (_variables.ContainsKey(variableNodeId)) return;
|
||||
|
||||
var parent = ResolveParentFolder(parentFolderNodeId);
|
||||
// Phase C: a non-null historian tagname makes the node Historizing and grants the HistoryRead
|
||||
// access bit (on top of the writable composite) so clients can browse + HistoryRead it.
|
||||
var historized = historianTagname is not null;
|
||||
// The SDK exposes the flags separately (no CurrentReadWrite composite): ReadWrite is
|
||||
// CurrentRead | CurrentWrite. OR-ing two byte constants promotes to int, so cast back.
|
||||
byte access = writable ? (byte)(AccessLevels.CurrentRead | AccessLevels.CurrentWrite) : AccessLevels.CurrentRead;
|
||||
if (historized) access = (byte)(access | AccessLevels.HistoryRead);
|
||||
var variable = new BaseDataVariableState(parent)
|
||||
{
|
||||
NodeId = new NodeId(variableNodeId, NamespaceIndex),
|
||||
@@ -839,11 +876,9 @@ public sealed class OtOpcUaNodeManager : CustomNodeManager2
|
||||
ReferenceTypeId = ReferenceTypeIds.Organizes,
|
||||
DataType = ResolveBuiltInDataType(dataType),
|
||||
ValueRank = ValueRanks.Scalar,
|
||||
// The SDK exposes the flags separately (no CurrentReadWrite composite): ReadWrite is
|
||||
// CurrentRead | CurrentWrite. OR-ing two byte constants promotes to int, so cast back.
|
||||
AccessLevel = writable ? (byte)(AccessLevels.CurrentRead | AccessLevels.CurrentWrite) : AccessLevels.CurrentRead,
|
||||
UserAccessLevel = writable ? (byte)(AccessLevels.CurrentRead | AccessLevels.CurrentWrite) : AccessLevels.CurrentRead,
|
||||
Historizing = false,
|
||||
AccessLevel = access,
|
||||
UserAccessLevel = access,
|
||||
Historizing = historized,
|
||||
Value = null,
|
||||
StatusCode = StatusCodes.BadWaitingForInitialData,
|
||||
Timestamp = DateTime.MinValue,
|
||||
@@ -859,6 +894,9 @@ public sealed class OtOpcUaNodeManager : CustomNodeManager2
|
||||
parent.AddChild(variable);
|
||||
AddPredefinedNode(SystemContext, variable);
|
||||
_variables[variableNodeId] = variable;
|
||||
// Phase C: register the resolved historian tagname so the HistoryRead override can map this
|
||||
// NodeId back to its Aveva/historian source.
|
||||
if (historized) _historizedTagnames[variableNodeId] = historianTagname!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -896,6 +934,8 @@ public sealed class OtOpcUaNodeManager : CustomNodeManager2
|
||||
PredefinedNodes?.Remove(v.NodeId);
|
||||
}
|
||||
_variables.Clear();
|
||||
// Phase C: drop the NodeId→historian-tagname registrations alongside the variables they map.
|
||||
_historizedTagnames.Clear();
|
||||
|
||||
foreach (var alarm in _alarmConditions.Values)
|
||||
{
|
||||
|
||||
@@ -197,7 +197,13 @@ public sealed class Phase7Applier
|
||||
}
|
||||
else
|
||||
{
|
||||
SafeEnsureVariable(nodeId, parent, tag.Name, tag.DataType, tag.Writable);
|
||||
// Phase C: a historized tag materialises Historizing + HistoryRead. Resolve the effective
|
||||
// historian tagname HERE (default-vs-override): a null/blank override falls back to the
|
||||
// driver-side FullName; null means the tag is not historized at all.
|
||||
string? historianTagname = tag.IsHistorized
|
||||
? (string.IsNullOrWhiteSpace(tag.HistorianTagname) ? tag.FullName : tag.HistorianTagname)
|
||||
: null;
|
||||
SafeEnsureVariable(nodeId, parent, tag.Name, tag.DataType, tag.Writable, historianTagname);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,9 +297,9 @@ public sealed class Phase7Applier
|
||||
catch (Exception ex) { _logger.LogWarning(ex, "Phase7Applier: EnsureFolder threw for {Node}", nodeId); }
|
||||
}
|
||||
|
||||
private void SafeEnsureVariable(string nodeId, string? parentNodeId, string displayName, string dataType, bool writable)
|
||||
private void SafeEnsureVariable(string nodeId, string? parentNodeId, string displayName, string dataType, bool writable, string? historianTagname = null)
|
||||
{
|
||||
try { _sink.EnsureVariable(nodeId, parentNodeId, displayName, dataType, writable); }
|
||||
try { _sink.EnsureVariable(nodeId, parentNodeId, displayName, dataType, writable, historianTagname); }
|
||||
catch (Exception ex) { _logger.LogWarning(ex, "Phase7Applier: EnsureVariable threw for {Node}", nodeId); }
|
||||
}
|
||||
|
||||
|
||||
@@ -57,8 +57,10 @@ public sealed class SdkAddressSpaceSink : IOpcUaAddressSpaceSink
|
||||
/// <param name="displayName">The display name for the variable.</param>
|
||||
/// <param name="dataType">The OPC UA data type.</param>
|
||||
/// <param name="writable">When true the node is created read/write; otherwise read-only.</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable)
|
||||
=> _nodeManager.EnsureVariable(variableNodeId, parentFolderNodeId, displayName, dataType, writable);
|
||||
/// <param name="historianTagname">null ⇒ not historized; non-null ⇒ create Historizing with the
|
||||
/// HistoryRead access bit and register the historian tagname.</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null)
|
||||
=> _nodeManager.EnsureVariable(variableNodeId, parentFolderNodeId, displayName, dataType, writable, historianTagname);
|
||||
|
||||
/// <summary>Rebuilds the entire OPC UA address space.</summary>
|
||||
public void RebuildAddressSpace() => _nodeManager.RebuildAddressSpace();
|
||||
|
||||
@@ -93,7 +93,7 @@ public sealed class DeferredAddressSpaceSinkTests
|
||||
public void EnsureFolder(string folderNodeId, string? parentNodeId, string displayName)
|
||||
=> CallQueue.Enqueue($"EF:{folderNodeId}");
|
||||
/// <inheritdoc />
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable)
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null)
|
||||
=> CallQueue.Enqueue($"EV:{variableNodeId}");
|
||||
/// <inheritdoc />
|
||||
public void RebuildAddressSpace() => CallQueue.Enqueue("RB");
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Opc.Ua;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Phase C Task 2 — node-manager materialisation honours the historize intent. Boot a real
|
||||
/// <see cref="OtOpcUaSdkServer"/> through <see cref="OpcUaApplicationHost"/> (the same harness
|
||||
/// <see cref="SdkAddressSpaceSinkTests"/> uses), drive <see cref="OtOpcUaNodeManager.EnsureVariable"/>
|
||||
/// with / without a historian tagname, and assert the created <see cref="BaseDataVariableState"/>'s
|
||||
/// <c>Historizing</c> flag + <c>HistoryRead</c> access bit + the NodeId→tagname registration.
|
||||
/// </summary>
|
||||
public sealed class NodeManagerHistorizeTests : IDisposable
|
||||
{
|
||||
private static CancellationToken Ct => TestContext.Current.CancellationToken;
|
||||
|
||||
private readonly string _pkiRoot = Path.Combine(
|
||||
Path.GetTempPath(),
|
||||
$"otopcua-historize-{Guid.NewGuid():N}");
|
||||
|
||||
/// <summary>A historized variable is created Historizing, gains the HistoryRead access bit in BOTH
|
||||
/// AccessLevel and UserAccessLevel, and its NodeId→tagname registration is queryable.</summary>
|
||||
[Fact]
|
||||
public async Task EnsureVariable_with_historian_tagname_sets_historizing_and_history_read_bit()
|
||||
{
|
||||
var (host, server) = await BootAsync();
|
||||
var nm = server.NodeManager!;
|
||||
|
||||
nm.EnsureVariable("eq-1/temp", parentFolderNodeId: null, displayName: "Temp", dataType: "Float",
|
||||
writable: false, historianTagname: "WW.Tag");
|
||||
|
||||
var variable = nm.TryGetVariable("eq-1/temp");
|
||||
variable.ShouldNotBeNull();
|
||||
variable!.Historizing.ShouldBeTrue();
|
||||
(variable.AccessLevel & AccessLevels.HistoryRead).ShouldNotBe((byte)0);
|
||||
(variable.UserAccessLevel & AccessLevels.HistoryRead).ShouldNotBe((byte)0);
|
||||
// Read-only historized node still grants CurrentRead.
|
||||
(variable.AccessLevel & AccessLevels.CurrentRead).ShouldNotBe((byte)0);
|
||||
|
||||
// The NodeId→resolved-tagname registration is queryable for the (later) HistoryRead override.
|
||||
nm.TryGetHistorizedTagname("eq-1/temp", out var tagname).ShouldBeTrue();
|
||||
tagname.ShouldBe("WW.Tag");
|
||||
|
||||
await host.DisposeAsync();
|
||||
}
|
||||
|
||||
/// <summary>A non-historized variable (tagname null / omitted) stays Historizing=false, has no
|
||||
/// HistoryRead bit, and is NOT registered in the NodeId→tagname map.</summary>
|
||||
[Fact]
|
||||
public async Task EnsureVariable_without_historian_tagname_is_not_historized()
|
||||
{
|
||||
var (host, server) = await BootAsync();
|
||||
var nm = server.NodeManager!;
|
||||
|
||||
// Explicit null and the defaulted-param form both mean "not historized".
|
||||
nm.EnsureVariable("eq-1/plain", parentFolderNodeId: null, displayName: "Plain", dataType: "Int32",
|
||||
writable: false, historianTagname: null);
|
||||
nm.EnsureVariable("eq-1/plain2", parentFolderNodeId: null, displayName: "Plain2", dataType: "Int32",
|
||||
writable: false);
|
||||
|
||||
foreach (var nodeId in new[] { "eq-1/plain", "eq-1/plain2" })
|
||||
{
|
||||
var variable = nm.TryGetVariable(nodeId);
|
||||
variable.ShouldNotBeNull();
|
||||
variable!.Historizing.ShouldBeFalse();
|
||||
(variable.AccessLevel & AccessLevels.HistoryRead).ShouldBe((byte)0);
|
||||
(variable.UserAccessLevel & AccessLevels.HistoryRead).ShouldBe((byte)0);
|
||||
nm.TryGetHistorizedTagname(nodeId, out var tagname).ShouldBeFalse();
|
||||
tagname.ShouldBeNull();
|
||||
}
|
||||
|
||||
await host.DisposeAsync();
|
||||
}
|
||||
|
||||
/// <summary>A historized AND writable node keeps the CurrentRead|CurrentWrite composite AND gains the
|
||||
/// HistoryRead bit (the three bits are OR-ed, not replaced).</summary>
|
||||
[Fact]
|
||||
public async Task EnsureVariable_historized_and_writable_keeps_read_write_and_adds_history_read()
|
||||
{
|
||||
var (host, server) = await BootAsync();
|
||||
var nm = server.NodeManager!;
|
||||
|
||||
nm.EnsureVariable("eq-1/setpoint", parentFolderNodeId: null, displayName: "Setpoint", dataType: "Float",
|
||||
writable: true, historianTagname: "WW.Setpoint");
|
||||
|
||||
var variable = nm.TryGetVariable("eq-1/setpoint");
|
||||
variable.ShouldNotBeNull();
|
||||
variable!.Historizing.ShouldBeTrue();
|
||||
(variable.AccessLevel & AccessLevels.CurrentRead).ShouldNotBe((byte)0);
|
||||
(variable.AccessLevel & AccessLevels.CurrentWrite).ShouldNotBe((byte)0);
|
||||
(variable.AccessLevel & AccessLevels.HistoryRead).ShouldNotBe((byte)0);
|
||||
// The composite is exactly CurrentRead | CurrentWrite | HistoryRead.
|
||||
variable.AccessLevel.ShouldBe((byte)(AccessLevels.CurrentRead | AccessLevels.CurrentWrite | AccessLevels.HistoryRead));
|
||||
variable.UserAccessLevel.ShouldBe(variable.AccessLevel);
|
||||
|
||||
nm.TryGetHistorizedTagname("eq-1/setpoint", out var tagname).ShouldBeTrue();
|
||||
tagname.ShouldBe("WW.Setpoint");
|
||||
|
||||
await host.DisposeAsync();
|
||||
}
|
||||
|
||||
/// <summary>RebuildAddressSpace drops the NodeId→tagname registrations alongside the variables.</summary>
|
||||
[Fact]
|
||||
public async Task RebuildAddressSpace_clears_historized_tagname_registrations()
|
||||
{
|
||||
var (host, server) = await BootAsync();
|
||||
var nm = server.NodeManager!;
|
||||
|
||||
nm.EnsureVariable("eq-1/temp", parentFolderNodeId: null, displayName: "Temp", dataType: "Float",
|
||||
writable: false, historianTagname: "WW.Tag");
|
||||
nm.TryGetHistorizedTagname("eq-1/temp", out _).ShouldBeTrue();
|
||||
|
||||
nm.RebuildAddressSpace();
|
||||
|
||||
nm.TryGetHistorizedTagname("eq-1/temp", out var tagname).ShouldBeFalse();
|
||||
tagname.ShouldBeNull();
|
||||
|
||||
await host.DisposeAsync();
|
||||
}
|
||||
|
||||
private async Task<(OpcUaApplicationHost Host, OtOpcUaSdkServer Server)> BootAsync()
|
||||
{
|
||||
var host = new OpcUaApplicationHost(
|
||||
new OpcUaApplicationHostOptions
|
||||
{
|
||||
ApplicationName = "OtOpcUa.HistorizeTest",
|
||||
ApplicationUri = $"urn:OtOpcUa.HistorizeTest:{Guid.NewGuid():N}",
|
||||
OpcUaPort = AllocateFreePort(),
|
||||
PublicHostname = "localhost",
|
||||
PkiStoreRoot = _pkiRoot,
|
||||
},
|
||||
NullLogger<OpcUaApplicationHost>.Instance);
|
||||
|
||||
var server = new OtOpcUaSdkServer();
|
||||
await host.StartAsync(server, Ct);
|
||||
return (host, server);
|
||||
}
|
||||
|
||||
private static int AllocateFreePort()
|
||||
{
|
||||
using var listener = new System.Net.Sockets.TcpListener(System.Net.IPAddress.Loopback, 0);
|
||||
listener.Start();
|
||||
var port = ((System.Net.IPEndPoint)listener.LocalEndpoint).Port;
|
||||
listener.Stop();
|
||||
return port;
|
||||
}
|
||||
|
||||
/// <summary>Cleans up the PKI root directory.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (Directory.Exists(_pkiRoot))
|
||||
{
|
||||
try { Directory.Delete(_pkiRoot, recursive: true); }
|
||||
catch { /* best-effort cleanup */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -265,7 +265,8 @@ public sealed class Phase7ApplierHierarchyTests : IDisposable
|
||||
/// <param name="displayName">The display name of the variable.</param>
|
||||
/// <param name="dataType">The OPC UA built-in type name.</param>
|
||||
/// <param name="writable">Whether the node is created read/write.</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable) { }
|
||||
/// <param name="historianTagname">The resolved historian tagname (null ⇒ not historized).</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null) { }
|
||||
/// <summary>Rebuilds the address space (stub implementation for testing).</summary>
|
||||
public void RebuildAddressSpace() { }
|
||||
}
|
||||
|
||||
@@ -262,6 +262,65 @@ public sealed class Phase7ApplierTests
|
||||
sink.VariableCalls.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>Phase C Task 2 — the applier resolves the historian tagname per value tag and threads it
|
||||
/// to <c>EnsureVariable</c>: a historized tag with NO override falls back to its <c>FullName</c>; a
|
||||
/// historized tag WITH an override passes the override verbatim; a non-historized tag passes null.</summary>
|
||||
[Fact]
|
||||
public void MaterialiseEquipmentTags_resolves_historian_tagname_default_override_and_null()
|
||||
{
|
||||
var sink = new RecordingSink();
|
||||
var applier = new Phase7Applier(sink, NullLogger<Phase7Applier>.Instance);
|
||||
|
||||
var composition = new Phase7CompositionResult(
|
||||
Array.Empty<EquipmentNode>(), Array.Empty<DriverInstancePlan>(), Array.Empty<ScriptedAlarmPlan>())
|
||||
{
|
||||
EquipmentTags = new[]
|
||||
{
|
||||
// Historized, no override ⇒ tagname defaults to FullName ("T.A").
|
||||
new EquipmentTagPlan("tag-def", "eq-1", "drv", FolderPath: "", Name: "ADefault", DataType: "Float",
|
||||
FullName: "T.A", Writable: false, Alarm: null, IsHistorized: true, HistorianTagname: null),
|
||||
// Historized, override ⇒ tagname is the override ("WW.Override"), NOT FullName.
|
||||
new EquipmentTagPlan("tag-ovr", "eq-1", "drv", FolderPath: "", Name: "BOverride", DataType: "Float",
|
||||
FullName: "T.B", Writable: false, Alarm: null, IsHistorized: true, HistorianTagname: "WW.Override"),
|
||||
// Not historized ⇒ tagname is null.
|
||||
new EquipmentTagPlan("tag-no", "eq-1", "drv", FolderPath: "", Name: "CPlain", DataType: "Float",
|
||||
FullName: "T.C", Writable: false, Alarm: null, IsHistorized: false, HistorianTagname: null),
|
||||
},
|
||||
};
|
||||
|
||||
applier.MaterialiseEquipmentTags(composition);
|
||||
|
||||
var byNode = sink.HistorianCalls.ToDictionary(c => c.NodeId, c => c.HistorianTagname);
|
||||
byNode[EquipmentNodeIds.Variable("eq-1", "", "ADefault")].ShouldBe("T.A"); // default ⇒ FullName
|
||||
byNode[EquipmentNodeIds.Variable("eq-1", "", "BOverride")].ShouldBe("WW.Override"); // override verbatim
|
||||
byNode[EquipmentNodeIds.Variable("eq-1", "", "CPlain")].ShouldBeNull(); // not historized ⇒ null
|
||||
}
|
||||
|
||||
/// <summary>Phase C Task 2 — a historized tag whose override is blank/whitespace still falls back to
|
||||
/// <c>FullName</c> (the resolve uses <c>string.IsNullOrWhiteSpace</c>, not just null).</summary>
|
||||
[Fact]
|
||||
public void MaterialiseEquipmentTags_blank_override_falls_back_to_full_name()
|
||||
{
|
||||
var sink = new RecordingSink();
|
||||
var applier = new Phase7Applier(sink, NullLogger<Phase7Applier>.Instance);
|
||||
|
||||
var composition = new Phase7CompositionResult(
|
||||
Array.Empty<EquipmentNode>(), Array.Empty<DriverInstancePlan>(), Array.Empty<ScriptedAlarmPlan>())
|
||||
{
|
||||
EquipmentTags = new[]
|
||||
{
|
||||
new EquipmentTagPlan("tag-blank", "eq-1", "drv", FolderPath: "", Name: "Speed", DataType: "Float",
|
||||
FullName: "40001", Writable: false, Alarm: null, IsHistorized: true, HistorianTagname: " "),
|
||||
},
|
||||
};
|
||||
|
||||
applier.MaterialiseEquipmentTags(composition);
|
||||
|
||||
var call = sink.HistorianCalls.ShouldHaveSingleItem();
|
||||
call.NodeId.ShouldBe(EquipmentNodeIds.Variable("eq-1", "", "Speed"));
|
||||
call.HistorianTagname.ShouldBe("40001");
|
||||
}
|
||||
|
||||
/// <summary>Verifies MaterialiseEquipmentVirtualTags creates one Variable per VirtualTag directly
|
||||
/// under its existing equipment folder, with a folder-scoped NodeId (EquipmentId/Name — NOT the
|
||||
/// VirtualTagId or Expression), parent == EquipmentId, displayName == Name, and does NOT re-create
|
||||
@@ -463,6 +522,9 @@ public sealed class Phase7ApplierTests
|
||||
public ConcurrentQueue<(string NodeId, string? Parent, string DisplayName)> FolderQueue { get; } = new();
|
||||
/// <summary>Gets the queue of variable creation calls.</summary>
|
||||
public ConcurrentQueue<(string NodeId, string? Parent, string DisplayName, string DataType, bool Writable)> VariableQueue { get; } = new();
|
||||
/// <summary>Gets the queue of the historian-tagname arg captured per <c>EnsureVariable</c> call,
|
||||
/// keyed by NodeId (null ⇒ that call passed not-historized).</summary>
|
||||
public ConcurrentQueue<(string NodeId, string? HistorianTagname)> HistorianQueue { get; } = new();
|
||||
/// <summary>Gets the queue of alarm-condition materialise calls.</summary>
|
||||
public ConcurrentQueue<(string AlarmNodeId, string EquipmentNodeId, string DisplayName, string AlarmType, int Severity)> AlarmConditionQueue { get; } = new();
|
||||
/// <summary>Gets the number of rebuild calls made on this sink.</summary>
|
||||
@@ -474,6 +536,8 @@ public sealed class Phase7ApplierTests
|
||||
public List<(string NodeId, string? Parent, string DisplayName)> FolderCalls => FolderQueue.ToList();
|
||||
/// <summary>Gets the list of recorded variable creation calls.</summary>
|
||||
public List<(string NodeId, string? Parent, string DisplayName, string DataType, bool Writable)> VariableCalls => VariableQueue.ToList();
|
||||
/// <summary>Gets the list of recorded (NodeId, historian-tagname) pairs captured per EnsureVariable call.</summary>
|
||||
public List<(string NodeId, string? HistorianTagname)> HistorianCalls => HistorianQueue.ToList();
|
||||
/// <summary>Gets the list of recorded alarm-condition materialise calls.</summary>
|
||||
public List<(string AlarmNodeId, string EquipmentNodeId, string DisplayName, string AlarmType, int Severity)> AlarmConditionCalls => AlarmConditionQueue.ToList();
|
||||
|
||||
@@ -509,8 +573,12 @@ public sealed class Phase7ApplierTests
|
||||
/// <param name="displayName">The display name for the variable.</param>
|
||||
/// <param name="dataType">The OPC UA built-in type name.</param>
|
||||
/// <param name="writable">Whether the node is created read/write.</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable)
|
||||
=> VariableQueue.Enqueue((variableNodeId, parentFolderNodeId, displayName, dataType, writable));
|
||||
/// <param name="historianTagname">The resolved historian tagname (null ⇒ not historized).</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null)
|
||||
{
|
||||
VariableQueue.Enqueue((variableNodeId, parentFolderNodeId, displayName, dataType, writable));
|
||||
HistorianQueue.Enqueue((variableNodeId, historianTagname));
|
||||
}
|
||||
/// <summary>Records a rebuild address space call.</summary>
|
||||
public void RebuildAddressSpace() => Interlocked.Increment(ref RebuildCalls);
|
||||
}
|
||||
@@ -555,7 +623,8 @@ public sealed class Phase7ApplierTests
|
||||
/// <param name="displayName">The display name for the variable.</param>
|
||||
/// <param name="dataType">The OPC UA built-in type name.</param>
|
||||
/// <param name="writable">Whether the node is created read/write.</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable) { }
|
||||
/// <param name="historianTagname">The resolved historian tagname (null ⇒ not historized).</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null) { }
|
||||
/// <summary>No-op rebuild address space call.</summary>
|
||||
public void RebuildAddressSpace() { }
|
||||
}
|
||||
|
||||
+2
-1
@@ -218,7 +218,8 @@ public sealed class OtOpcUaTelemetryHookTests : RuntimeActorTestBase
|
||||
/// <param name="displayName">The display name for the variable.</param>
|
||||
/// <param name="dataType">The OPC UA built-in type name.</param>
|
||||
/// <param name="writable">Whether the node is created read/write.</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable) { }
|
||||
/// <param name="historianTagname">The resolved historian tagname (null ⇒ not historized).</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null) { }
|
||||
/// <summary>Rebuilds address space (recorded via span).</summary>
|
||||
public void RebuildAddressSpace() { /* recorded via span */ }
|
||||
}
|
||||
|
||||
@@ -288,7 +288,8 @@ public sealed class OpcUaPublishActorRebuildTests : RuntimeActorTestBase
|
||||
/// <param name="displayName">The display name of the variable.</param>
|
||||
/// <param name="dataType">The OPC UA built-in type name.</param>
|
||||
/// <param name="writable">Whether the node is created read/write.</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable)
|
||||
/// <param name="historianTagname">The resolved historian tagname (null ⇒ not historized).</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null)
|
||||
=> Calls.Enqueue($"EV:{variableNodeId}");
|
||||
/// <summary>Records a rebuild address space call.</summary>
|
||||
public void RebuildAddressSpace() => Interlocked.Increment(ref RebuildCalls);
|
||||
|
||||
@@ -209,7 +209,8 @@ public sealed class OpcUaPublishActorTests : RuntimeActorTestBase
|
||||
/// <param name="displayName">The display name of the variable.</param>
|
||||
/// <param name="dataType">The OPC UA built-in type name.</param>
|
||||
/// <param name="writable">Whether the node is created read/write.</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable) { }
|
||||
/// <param name="historianTagname">The resolved historian tagname (null ⇒ not historized).</param>
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null) { }
|
||||
|
||||
/// <summary>Records a rebuild call.</summary>
|
||||
public void RebuildAddressSpace() => Interlocked.Increment(ref RebuildCalls);
|
||||
|
||||
Reference in New Issue
Block a user