feat(commons): add correlation/execution/node/deployment/revisionhash types
This commit is contained in:
13
src/Core/ZB.MOM.WW.OtOpcUa.Commons/Types/CorrelationId.cs
Normal file
13
src/Core/ZB.MOM.WW.OtOpcUa.Commons/Types/CorrelationId.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace ZB.MOM.WW.OtOpcUa.Commons.Types;
|
||||
|
||||
public readonly record struct CorrelationId(Guid Value)
|
||||
{
|
||||
public static CorrelationId NewId() => new(Guid.NewGuid());
|
||||
public override string ToString() => Value.ToString("N");
|
||||
public static CorrelationId Parse(string s) => new(Guid.ParseExact(s, "N"));
|
||||
public static bool TryParse(string? s, out CorrelationId id)
|
||||
{
|
||||
if (Guid.TryParseExact(s, "N", out var g)) { id = new CorrelationId(g); return true; }
|
||||
id = default; return false;
|
||||
}
|
||||
}
|
||||
13
src/Core/ZB.MOM.WW.OtOpcUa.Commons/Types/DeploymentId.cs
Normal file
13
src/Core/ZB.MOM.WW.OtOpcUa.Commons/Types/DeploymentId.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace ZB.MOM.WW.OtOpcUa.Commons.Types;
|
||||
|
||||
public readonly record struct DeploymentId(Guid Value)
|
||||
{
|
||||
public static DeploymentId NewId() => new(Guid.NewGuid());
|
||||
public override string ToString() => Value.ToString("N");
|
||||
public static DeploymentId Parse(string s) => new(Guid.ParseExact(s, "N"));
|
||||
public static bool TryParse(string? s, out DeploymentId id)
|
||||
{
|
||||
if (Guid.TryParseExact(s, "N", out var g)) { id = new DeploymentId(g); return true; }
|
||||
id = default; return false;
|
||||
}
|
||||
}
|
||||
13
src/Core/ZB.MOM.WW.OtOpcUa.Commons/Types/ExecutionId.cs
Normal file
13
src/Core/ZB.MOM.WW.OtOpcUa.Commons/Types/ExecutionId.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace ZB.MOM.WW.OtOpcUa.Commons.Types;
|
||||
|
||||
public readonly record struct ExecutionId(Guid Value)
|
||||
{
|
||||
public static ExecutionId NewId() => new(Guid.NewGuid());
|
||||
public override string ToString() => Value.ToString("N");
|
||||
public static ExecutionId Parse(string s) => new(Guid.ParseExact(s, "N"));
|
||||
public static bool TryParse(string? s, out ExecutionId id)
|
||||
{
|
||||
if (Guid.TryParseExact(s, "N", out var g)) { id = new ExecutionId(g); return true; }
|
||||
id = default; return false;
|
||||
}
|
||||
}
|
||||
20
src/Core/ZB.MOM.WW.OtOpcUa.Commons/Types/NodeId.cs
Normal file
20
src/Core/ZB.MOM.WW.OtOpcUa.Commons/Types/NodeId.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace ZB.MOM.WW.OtOpcUa.Commons.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Logical cluster node identifier — typically the host name configured on a fused
|
||||
/// <c>OtOpcUa.Host</c> instance. NOT to be confused with OPC UA <c>NodeId</c> from the
|
||||
/// Opc.Ua.Core stack.
|
||||
/// </summary>
|
||||
public readonly record struct NodeId(string Value)
|
||||
{
|
||||
public override string ToString() => Value;
|
||||
public static NodeId Parse(string s) =>
|
||||
string.IsNullOrWhiteSpace(s)
|
||||
? throw new ArgumentException("NodeId value cannot be empty.", nameof(s))
|
||||
: new NodeId(s);
|
||||
public static bool TryParse(string? s, out NodeId id)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(s)) { id = new NodeId(s); return true; }
|
||||
id = default; return false;
|
||||
}
|
||||
}
|
||||
19
src/Core/ZB.MOM.WW.OtOpcUa.Commons/Types/RevisionHash.cs
Normal file
19
src/Core/ZB.MOM.WW.OtOpcUa.Commons/Types/RevisionHash.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace ZB.MOM.WW.OtOpcUa.Commons.Types;
|
||||
|
||||
/// <summary>
|
||||
/// SHA-256 hex digest identifying a config snapshot revision. Storage form is lowercase
|
||||
/// 64-char hex (no <c>0x</c> prefix). Empty hash is invalid.
|
||||
/// </summary>
|
||||
public readonly record struct RevisionHash(string Value)
|
||||
{
|
||||
public override string ToString() => Value;
|
||||
public static RevisionHash Parse(string s) =>
|
||||
string.IsNullOrWhiteSpace(s)
|
||||
? throw new ArgumentException("RevisionHash value cannot be empty.", nameof(s))
|
||||
: new RevisionHash(s);
|
||||
public static bool TryParse(string? s, out RevisionHash hash)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(s)) { hash = new RevisionHash(s); return true; }
|
||||
hash = default; return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user