Renames all 11 projects (5 src + 6 tests), the .slnx solution file, all source-file namespaces, all axaml namespace references, and all v1 documentation references in CLAUDE.md and docs/*.md (excluding docs/v2/ which is already in OtOpcUa form). Also updates the TopShelf service registration name from "LmxOpcUa" to "OtOpcUa" per Phase 0 Task 0.6.
Preserves runtime identifiers per Phase 0 Out-of-Scope rules to avoid breaking v1/v2 client trust during coexistence: OPC UA `ApplicationUri` defaults (`urn:{GalaxyName}:LmxOpcUa`), server `EndpointPath` (`/LmxOpcUa`), `ServerName` default (feeds cert subject CN), `MxAccessConfiguration.ClientName` default (defensive — stays "LmxOpcUa" for MxAccess audit-trail consistency), client OPC UA identifiers (`ApplicationName = "LmxOpcUaClient"`, `ApplicationUri = "urn:localhost:LmxOpcUaClient"`, cert directory `%LocalAppData%\LmxOpcUaClient\pki\`), and the `LmxOpcUaServer` class name (class rename out of Phase 0 scope per Task 0.5 sed pattern; happens in Phase 1 alongside `LmxNodeManager → GenericDriverNodeManager` Core extraction). 23 LmxOpcUa references retained, all enumerated and justified in `docs/v2/implementation/exit-gate-phase-0.md`.
Build clean: 0 errors, 30 warnings (lower than baseline 167). Tests at strict improvement over baseline: 821 passing / 1 failing vs baseline 820 / 2 (one flaky pre-existing failure passed this run; the other still fails — both pre-existing and unrelated to the rename). `Client.UI.Tests`, `Historian.Aveva.Tests`, `Client.Shared.Tests`, `IntegrationTests` all match baseline exactly. Exit gate compliance results recorded in `docs/v2/implementation/exit-gate-phase-0.md` with all 7 checks PASS or DEFERRED-to-PR-review (#7 service install verification needs Windows service permissions on the reviewer's box).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
132 lines
5.7 KiB
C#
132 lines
5.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using ZB.MOM.WW.OtOpcUa.Host.Domain;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Host.OpcUa
|
|
{
|
|
/// <summary>
|
|
/// Computes the set of changed Galaxy object IDs between two snapshots of hierarchy and attributes.
|
|
/// </summary>
|
|
public static class AddressSpaceDiff
|
|
{
|
|
/// <summary>
|
|
/// Compares old and new hierarchy+attributes and returns the set of gobject IDs that have any difference.
|
|
/// </summary>
|
|
/// <param name="oldHierarchy">The previously published Galaxy object hierarchy snapshot.</param>
|
|
/// <param name="oldAttributes">The previously published Galaxy attribute snapshot keyed to the old hierarchy.</param>
|
|
/// <param name="newHierarchy">The latest Galaxy object hierarchy snapshot pulled from the repository.</param>
|
|
/// <param name="newAttributes">The latest Galaxy attribute snapshot that should be reflected in the OPC UA namespace.</param>
|
|
public static HashSet<int> FindChangedGobjectIds(
|
|
List<GalaxyObjectInfo> oldHierarchy, List<GalaxyAttributeInfo> oldAttributes,
|
|
List<GalaxyObjectInfo> newHierarchy, List<GalaxyAttributeInfo> newAttributes)
|
|
{
|
|
var changed = new HashSet<int>();
|
|
|
|
var oldObjects = oldHierarchy.ToDictionary(h => h.GobjectId);
|
|
var newObjects = newHierarchy.ToDictionary(h => h.GobjectId);
|
|
|
|
// Added objects
|
|
foreach (var id in newObjects.Keys)
|
|
if (!oldObjects.ContainsKey(id))
|
|
changed.Add(id);
|
|
|
|
// Removed objects
|
|
foreach (var id in oldObjects.Keys)
|
|
if (!newObjects.ContainsKey(id))
|
|
changed.Add(id);
|
|
|
|
// Modified objects
|
|
foreach (var kvp in newObjects)
|
|
if (oldObjects.TryGetValue(kvp.Key, out var oldObj) && !ObjectsEqual(oldObj, kvp.Value))
|
|
changed.Add(kvp.Key);
|
|
|
|
// Attribute changes — group by gobject_id and compare
|
|
var oldAttrsByObj = oldAttributes.GroupBy(a => a.GobjectId)
|
|
.ToDictionary(g => g.Key, g => g.ToList());
|
|
var newAttrsByObj = newAttributes.GroupBy(a => a.GobjectId)
|
|
.ToDictionary(g => g.Key, g => g.ToList());
|
|
|
|
// All gobject_ids that have attributes in either old or new
|
|
var allAttrGobjectIds = new HashSet<int>(oldAttrsByObj.Keys);
|
|
allAttrGobjectIds.UnionWith(newAttrsByObj.Keys);
|
|
|
|
foreach (var id in allAttrGobjectIds)
|
|
{
|
|
if (changed.Contains(id))
|
|
continue;
|
|
|
|
oldAttrsByObj.TryGetValue(id, out var oldAttrs);
|
|
newAttrsByObj.TryGetValue(id, out var newAttrs);
|
|
|
|
if (!AttributeSetsEqual(oldAttrs, newAttrs))
|
|
changed.Add(id);
|
|
}
|
|
|
|
return changed;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Expands a set of changed gobject IDs to include all descendant gobject IDs in the hierarchy.
|
|
/// </summary>
|
|
/// <param name="changed">The root Galaxy objects that were detected as changed between snapshots.</param>
|
|
/// <param name="hierarchy">The hierarchy used to include descendant objects whose OPC UA nodes must also be rebuilt.</param>
|
|
public static HashSet<int> ExpandToSubtrees(HashSet<int> changed, List<GalaxyObjectInfo> hierarchy)
|
|
{
|
|
var childrenByParent = hierarchy.GroupBy(h => h.ParentGobjectId)
|
|
.ToDictionary(g => g.Key, g => g.Select(h => h.GobjectId).ToList());
|
|
|
|
var expanded = new HashSet<int>(changed);
|
|
var queue = new Queue<int>(changed);
|
|
|
|
while (queue.Count > 0)
|
|
{
|
|
var id = queue.Dequeue();
|
|
if (childrenByParent.TryGetValue(id, out var children))
|
|
foreach (var childId in children)
|
|
if (expanded.Add(childId))
|
|
queue.Enqueue(childId);
|
|
}
|
|
|
|
return expanded;
|
|
}
|
|
|
|
private static bool ObjectsEqual(GalaxyObjectInfo a, GalaxyObjectInfo b)
|
|
{
|
|
return a.TagName == b.TagName
|
|
&& a.BrowseName == b.BrowseName
|
|
&& a.ContainedName == b.ContainedName
|
|
&& a.ParentGobjectId == b.ParentGobjectId
|
|
&& a.IsArea == b.IsArea;
|
|
}
|
|
|
|
private static bool AttributeSetsEqual(List<GalaxyAttributeInfo>? a, List<GalaxyAttributeInfo>? b)
|
|
{
|
|
if (a == null && b == null) return true;
|
|
if (a == null || b == null) return false;
|
|
if (a.Count != b.Count) return false;
|
|
|
|
// Sort by a stable key and compare pairwise
|
|
var sortedA = a.OrderBy(x => x.FullTagReference).ThenBy(x => x.PrimitiveName).ToList();
|
|
var sortedB = b.OrderBy(x => x.FullTagReference).ThenBy(x => x.PrimitiveName).ToList();
|
|
|
|
for (var i = 0; i < sortedA.Count; i++)
|
|
if (!AttributesEqual(sortedA[i], sortedB[i]))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
private static bool AttributesEqual(GalaxyAttributeInfo a, GalaxyAttributeInfo b)
|
|
{
|
|
return a.AttributeName == b.AttributeName
|
|
&& a.FullTagReference == b.FullTagReference
|
|
&& a.MxDataType == b.MxDataType
|
|
&& a.IsArray == b.IsArray
|
|
&& a.ArrayDimension == b.ArrayDimension
|
|
&& a.PrimitiveName == b.PrimitiveName
|
|
&& a.SecurityClassification == b.SecurityClassification
|
|
&& a.IsHistorized == b.IsHistorized
|
|
&& a.IsAlarm == b.IsAlarm;
|
|
}
|
|
}
|
|
} |