a25593a9c6
Group all 69 projects into category subfolders under src/ and tests/ so the Rider Solution Explorer mirrors the module structure. Folders: Core, Server, Drivers (with a nested Driver CLIs subfolder), Client, Tooling. - Move every project folder on disk with git mv (history preserved as renames). - Recompute relative paths in 57 .csproj files: cross-category ProjectReferences, the lib/ HintPath+None refs in Driver.Historian.Wonderware, and the external mxaccessgw refs in Driver.Galaxy and its test project. - Rebuild ZB.MOM.WW.OtOpcUa.slnx with nested solution folders. - Re-prefix project paths in functional scripts (e2e, compliance, smoke SQL, integration, install). Build green (0 errors); unit tests pass. Docs left for a separate pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
57 lines
2.3 KiB
C#
57 lines
2.3 KiB
C#
using Opc.Ua;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Client.CLI.Helpers;
|
|
|
|
/// <summary>
|
|
/// Parses node ID strings into OPC UA <see cref="NodeId" /> objects.
|
|
/// Supports standard OPC UA format (e.g., "ns=2;s=MyNode", "i=85") and bare numeric IDs.
|
|
/// </summary>
|
|
public static class NodeIdParser
|
|
{
|
|
/// <summary>
|
|
/// Parses a string into a <see cref="NodeId" />. Returns <c>null</c> if the input is null or empty.
|
|
/// </summary>
|
|
/// <param name="nodeIdString">The node ID string to parse.</param>
|
|
/// <returns>A parsed <see cref="NodeId" />, or <c>null</c> if input is null/empty.</returns>
|
|
/// <exception cref="FormatException">Thrown when the string cannot be parsed as a valid NodeId.</exception>
|
|
public static NodeId? Parse(string? nodeIdString)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(nodeIdString))
|
|
return null;
|
|
|
|
var trimmed = nodeIdString.Trim();
|
|
|
|
// Standard OPC UA format: ns=X;s=..., ns=X;i=..., ns=X;g=..., ns=X;b=...
|
|
// Also: s=..., i=..., g=..., b=... (namespace 0 implied)
|
|
if (trimmed.Contains('='))
|
|
try
|
|
{
|
|
return NodeId.Parse(trimmed);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new FormatException($"Invalid node ID format: '{nodeIdString}'", ex);
|
|
}
|
|
|
|
// Bare numeric: treat as namespace 0, numeric identifier
|
|
if (uint.TryParse(trimmed, out var numericId)) return new NodeId(numericId);
|
|
|
|
throw new FormatException(
|
|
$"Invalid node ID format: '{nodeIdString}'. Expected format like 'ns=2;s=MyNode', 'i=85', or a numeric ID.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parses a string into a <see cref="NodeId" />, throwing if the input is null or empty.
|
|
/// </summary>
|
|
/// <param name="nodeIdString">The node ID string to parse.</param>
|
|
/// <returns>A parsed <see cref="NodeId" />.</returns>
|
|
/// <exception cref="ArgumentException">Thrown when the input is null or empty.</exception>
|
|
/// <exception cref="FormatException">Thrown when the string cannot be parsed as a valid NodeId.</exception>
|
|
public static NodeId ParseRequired(string? nodeIdString)
|
|
{
|
|
var result = Parse(nodeIdString);
|
|
if (result == null)
|
|
throw new ArgumentException("Node ID is required but was not provided.");
|
|
return result;
|
|
}
|
|
} |