diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Commons/OpcUa/DeferredAddressSpaceSink.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Commons/OpcUa/DeferredAddressSpaceSink.cs
index ab57b959..a52f8fe0 100644
--- a/src/Core/ZB.MOM.WW.OtOpcUa.Commons/OpcUa/DeferredAddressSpaceSink.cs
+++ b/src/Core/ZB.MOM.WW.OtOpcUa.Commons/OpcUa/DeferredAddressSpaceSink.cs
@@ -59,8 +59,10 @@ public sealed class DeferredAddressSpaceSink : IOpcUaAddressSpaceSink
/// The display name of the variable.
/// The OPC UA data type of the variable.
/// When true the node is created read/write; otherwise read-only.
- public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable)
- => _inner.EnsureVariable(variableNodeId, parentFolderNodeId, displayName, dataType, writable);
+ /// null ⇒ not historized; non-null ⇒ create Historizing with the
+ /// HistoryRead access bit and register the historian tagname.
+ public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null)
+ => _inner.EnsureVariable(variableNodeId, parentFolderNodeId, displayName, dataType, writable, historianTagname);
/// Rebuilds the address space through the inner sink.
public void RebuildAddressSpace() => _inner.RebuildAddressSpace();
diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Commons/OpcUa/IOpcUaAddressSpaceSink.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Commons/OpcUa/IOpcUaAddressSpaceSink.cs
index 8357fe38..2b45fd8a 100644
--- a/src/Core/ZB.MOM.WW.OtOpcUa.Commons/OpcUa/IOpcUaAddressSpaceSink.cs
+++ b/src/Core/ZB.MOM.WW.OtOpcUa.Commons/OpcUa/IOpcUaAddressSpaceSink.cs
@@ -65,7 +65,10 @@ public interface IOpcUaAddressSpaceSink
/// When true the node is created CurrentReadWrite (an authored
/// ReadWrite equipment tag); when false it stays CurrentRead (read-only). Non-equipment-tag
/// variables (folders' children, alarm placeholders) always pass false.
- void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable);
+ /// null ⇒ the variable is not historized; non-null ⇒ create it
+ /// Historizing with the HistoryRead access bit and register the (already default-resolved)
+ /// historian tagname.
+ void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null);
///
/// Tear down + repopulate the address space. Called by OpcUaPublishActor after a
@@ -98,7 +101,7 @@ public sealed class NullOpcUaAddressSpaceSink : IOpcUaAddressSpaceSink
public void EnsureFolder(string folderNodeId, string? parentNodeId, string displayName) { }
///
- 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) { }
///
public void RebuildAddressSpace() { }
diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/OtOpcUaNodeManager.cs b/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/OtOpcUaNodeManager.cs
index d5d1446d..9e700438 100644
--- a/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/OtOpcUaNodeManager.cs
+++ b/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/OtOpcUaNodeManager.cs
@@ -30,6 +30,11 @@ public sealed class OtOpcUaNodeManager : CustomNodeManager2
private readonly ConcurrentDictionary _variables = new(StringComparer.Ordinal);
private readonly ConcurrentDictionary _folders = new(StringComparer.Ordinal);
private readonly ConcurrentDictionary _alarmConditions = new(StringComparer.Ordinal);
+ /// Phase C: NodeId → resolved historian tagname for every variable materialised
+ /// Historizing. Populated by when a historian tagname is supplied; the
+ /// (later) HistoryRead override resolves a HistoryRead request's NodeId against this map. Cleared on
+ /// .
+ private readonly ConcurrentDictionary _historizedTagnames = new(StringComparer.Ordinal);
/// Folders we have already promoted to event-notifiers + registered as root notifiers,
/// so repeated calls don't double-add (idempotent guard).
/// Keyed by NodeId → the actual so can
@@ -113,6 +118,26 @@ public sealed class OtOpcUaNodeManager : CustomNodeManager2
public AlarmConditionState? TryGetAlarmCondition(string alarmNodeId) =>
_alarmConditions.TryGetValue(alarmNodeId, out var condition) ? condition : null;
+ /// 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.
+ /// The variable node identifier.
+ /// The resolved historian tagname when historized; otherwise null.
+ /// True when the node is registered as historized; otherwise false.
+ public bool TryGetHistorizedTagname(string nodeId, out string? tagname)
+ {
+ if (_historizedTagnames.TryGetValue(nodeId, out var t)) { tagname = t; return true; }
+ tagname = null;
+ return false;
+ }
+
+ /// 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.
+ /// The variable node identifier.
+ /// The cached , or null when none is registered.
+ internal BaseDataVariableState? TryGetVariable(string nodeId) =>
+ _variables.TryGetValue(nodeId, out var variable) ? variable : null;
+
///
/// Apply a value write from . 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 is attached
/// to its OnWriteValue (Task 11) so a client write gates on the WriteOperate role + routes
/// to the backing driver; when false it stays CurrentRead (read-only) with no write handler.
- public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable)
+ /// Phase C: null ⇒ the node is NOT historized (Historizing=false, no
+ /// HistoryRead bit, not registered). Non-null ⇒ the node is created Historizing with the
+ /// HistoryRead access bit OR-ed into both AccessLevel and UserAccessLevel, and the
+ /// (already default-resolved) tagname is registered in the NodeId→tagname map the HistoryRead override
+ /// resolves against.
+ 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)
{
diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/Phase7Applier.cs b/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/Phase7Applier.cs
index ccb2eb85..bda644cd 100644
--- a/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/Phase7Applier.cs
+++ b/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/Phase7Applier.cs
@@ -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); }
}
diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/SdkAddressSpaceSink.cs b/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/SdkAddressSpaceSink.cs
index c92682a3..474155cf 100644
--- a/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/SdkAddressSpaceSink.cs
+++ b/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/SdkAddressSpaceSink.cs
@@ -57,8 +57,10 @@ public sealed class SdkAddressSpaceSink : IOpcUaAddressSpaceSink
/// The display name for the variable.
/// The OPC UA data type.
/// When true the node is created read/write; otherwise read-only.
- public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable)
- => _nodeManager.EnsureVariable(variableNodeId, parentFolderNodeId, displayName, dataType, writable);
+ /// null ⇒ not historized; non-null ⇒ create Historizing with the
+ /// HistoryRead access bit and register the historian tagname.
+ public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null)
+ => _nodeManager.EnsureVariable(variableNodeId, parentFolderNodeId, displayName, dataType, writable, historianTagname);
/// Rebuilds the entire OPC UA address space.
public void RebuildAddressSpace() => _nodeManager.RebuildAddressSpace();
diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/DeferredAddressSpaceSinkTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/DeferredAddressSpaceSinkTests.cs
index bd35324d..76d03ab2 100644
--- a/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/DeferredAddressSpaceSinkTests.cs
+++ b/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/DeferredAddressSpaceSinkTests.cs
@@ -93,7 +93,7 @@ public sealed class DeferredAddressSpaceSinkTests
public void EnsureFolder(string folderNodeId, string? parentNodeId, string displayName)
=> CallQueue.Enqueue($"EF:{folderNodeId}");
///
- 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}");
///
public void RebuildAddressSpace() => CallQueue.Enqueue("RB");
diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/NodeManagerHistorizeTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/NodeManagerHistorizeTests.cs
new file mode 100644
index 00000000..d4e4f8a1
--- /dev/null
+++ b/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/NodeManagerHistorizeTests.cs
@@ -0,0 +1,159 @@
+using Microsoft.Extensions.Logging.Abstractions;
+using Opc.Ua;
+using Shouldly;
+using Xunit;
+
+namespace ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests;
+
+///
+/// Phase C Task 2 — node-manager materialisation honours the historize intent. Boot a real
+/// through (the same harness
+/// uses), drive
+/// with / without a historian tagname, and assert the created 's
+/// Historizing flag + HistoryRead access bit + the NodeId→tagname registration.
+///
+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}");
+
+ /// A historized variable is created Historizing, gains the HistoryRead access bit in BOTH
+ /// AccessLevel and UserAccessLevel, and its NodeId→tagname registration is queryable.
+ [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();
+ }
+
+ /// A non-historized variable (tagname null / omitted) stays Historizing=false, has no
+ /// HistoryRead bit, and is NOT registered in the NodeId→tagname map.
+ [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();
+ }
+
+ /// A historized AND writable node keeps the CurrentRead|CurrentWrite composite AND gains the
+ /// HistoryRead bit (the three bits are OR-ed, not replaced).
+ [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();
+ }
+
+ /// RebuildAddressSpace drops the NodeId→tagname registrations alongside the variables.
+ [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.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;
+ }
+
+ /// Cleans up the PKI root directory.
+ public void Dispose()
+ {
+ if (Directory.Exists(_pkiRoot))
+ {
+ try { Directory.Delete(_pkiRoot, recursive: true); }
+ catch { /* best-effort cleanup */ }
+ }
+ }
+}
diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/Phase7ApplierHierarchyTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/Phase7ApplierHierarchyTests.cs
index 085612c0..15a12123 100644
--- a/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/Phase7ApplierHierarchyTests.cs
+++ b/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/Phase7ApplierHierarchyTests.cs
@@ -265,7 +265,8 @@ public sealed class Phase7ApplierHierarchyTests : IDisposable
/// The display name of the variable.
/// The OPC UA built-in type name.
/// Whether the node is created read/write.
- public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable) { }
+ /// The resolved historian tagname (null ⇒ not historized).
+ public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null) { }
/// Rebuilds the address space (stub implementation for testing).
public void RebuildAddressSpace() { }
}
diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/Phase7ApplierTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/Phase7ApplierTests.cs
index d14992ae..b30c6403 100644
--- a/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/Phase7ApplierTests.cs
+++ b/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/Phase7ApplierTests.cs
@@ -262,6 +262,65 @@ public sealed class Phase7ApplierTests
sink.VariableCalls.ShouldBeEmpty();
}
+ /// Phase C Task 2 — the applier resolves the historian tagname per value tag and threads it
+ /// to EnsureVariable: a historized tag with NO override falls back to its FullName; a
+ /// historized tag WITH an override passes the override verbatim; a non-historized tag passes null.
+ [Fact]
+ public void MaterialiseEquipmentTags_resolves_historian_tagname_default_override_and_null()
+ {
+ var sink = new RecordingSink();
+ var applier = new Phase7Applier(sink, NullLogger.Instance);
+
+ var composition = new Phase7CompositionResult(
+ Array.Empty(), Array.Empty(), Array.Empty())
+ {
+ 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
+ }
+
+ /// Phase C Task 2 — a historized tag whose override is blank/whitespace still falls back to
+ /// FullName (the resolve uses string.IsNullOrWhiteSpace, not just null).
+ [Fact]
+ public void MaterialiseEquipmentTags_blank_override_falls_back_to_full_name()
+ {
+ var sink = new RecordingSink();
+ var applier = new Phase7Applier(sink, NullLogger.Instance);
+
+ var composition = new Phase7CompositionResult(
+ Array.Empty(), Array.Empty(), Array.Empty())
+ {
+ 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");
+ }
+
/// 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();
/// Gets the queue of variable creation calls.
public ConcurrentQueue<(string NodeId, string? Parent, string DisplayName, string DataType, bool Writable)> VariableQueue { get; } = new();
+ /// Gets the queue of the historian-tagname arg captured per EnsureVariable call,
+ /// keyed by NodeId (null ⇒ that call passed not-historized).
+ public ConcurrentQueue<(string NodeId, string? HistorianTagname)> HistorianQueue { get; } = new();
/// Gets the queue of alarm-condition materialise calls.
public ConcurrentQueue<(string AlarmNodeId, string EquipmentNodeId, string DisplayName, string AlarmType, int Severity)> AlarmConditionQueue { get; } = new();
/// Gets the number of rebuild calls made on this sink.
@@ -474,6 +536,8 @@ public sealed class Phase7ApplierTests
public List<(string NodeId, string? Parent, string DisplayName)> FolderCalls => FolderQueue.ToList();
/// Gets the list of recorded variable creation calls.
public List<(string NodeId, string? Parent, string DisplayName, string DataType, bool Writable)> VariableCalls => VariableQueue.ToList();
+ /// Gets the list of recorded (NodeId, historian-tagname) pairs captured per EnsureVariable call.
+ public List<(string NodeId, string? HistorianTagname)> HistorianCalls => HistorianQueue.ToList();
/// Gets the list of recorded alarm-condition materialise calls.
public List<(string AlarmNodeId, string EquipmentNodeId, string DisplayName, string AlarmType, int Severity)> AlarmConditionCalls => AlarmConditionQueue.ToList();
@@ -509,8 +573,12 @@ public sealed class Phase7ApplierTests
/// The display name for the variable.
/// The OPC UA built-in type name.
/// Whether the node is created read/write.
- public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable)
- => VariableQueue.Enqueue((variableNodeId, parentFolderNodeId, displayName, dataType, writable));
+ /// The resolved historian tagname (null ⇒ not historized).
+ 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));
+ }
/// Records a rebuild address space call.
public void RebuildAddressSpace() => Interlocked.Increment(ref RebuildCalls);
}
@@ -555,7 +623,8 @@ public sealed class Phase7ApplierTests
/// The display name for the variable.
/// The OPC UA built-in type name.
/// Whether the node is created read/write.
- public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable) { }
+ /// The resolved historian tagname (null ⇒ not historized).
+ public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null) { }
/// No-op rebuild address space call.
public void RebuildAddressSpace() { }
}
diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Observability/OtOpcUaTelemetryHookTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Observability/OtOpcUaTelemetryHookTests.cs
index d58d17f2..74ca4a5a 100644
--- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Observability/OtOpcUaTelemetryHookTests.cs
+++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Observability/OtOpcUaTelemetryHookTests.cs
@@ -218,7 +218,8 @@ public sealed class OtOpcUaTelemetryHookTests : RuntimeActorTestBase
/// The display name for the variable.
/// The OPC UA built-in type name.
/// Whether the node is created read/write.
- public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable) { }
+ /// The resolved historian tagname (null ⇒ not historized).
+ public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null) { }
/// Rebuilds address space (recorded via span).
public void RebuildAddressSpace() { /* recorded via span */ }
}
diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/OpcUa/OpcUaPublishActorRebuildTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/OpcUa/OpcUaPublishActorRebuildTests.cs
index 6e3e85ba..6329d183 100644
--- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/OpcUa/OpcUaPublishActorRebuildTests.cs
+++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/OpcUa/OpcUaPublishActorRebuildTests.cs
@@ -288,7 +288,8 @@ public sealed class OpcUaPublishActorRebuildTests : RuntimeActorTestBase
/// The display name of the variable.
/// The OPC UA built-in type name.
/// Whether the node is created read/write.
- public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable)
+ /// The resolved historian tagname (null ⇒ not historized).
+ public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null)
=> Calls.Enqueue($"EV:{variableNodeId}");
/// Records a rebuild address space call.
public void RebuildAddressSpace() => Interlocked.Increment(ref RebuildCalls);
diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/OpcUa/OpcUaPublishActorTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/OpcUa/OpcUaPublishActorTests.cs
index 34d98e73..19ce2d73 100644
--- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/OpcUa/OpcUaPublishActorTests.cs
+++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/OpcUa/OpcUaPublishActorTests.cs
@@ -209,7 +209,8 @@ public sealed class OpcUaPublishActorTests : RuntimeActorTestBase
/// The display name of the variable.
/// The OPC UA built-in type name.
/// Whether the node is created read/write.
- public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable) { }
+ /// The resolved historian tagname (null ⇒ not historized).
+ public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, string? historianTagname = null) { }
/// Records a rebuild call.
public void RebuildAddressSpace() => Interlocked.Increment(ref RebuildCalls);