35 lines
1.6 KiB
C#
35 lines
1.6 KiB
C#
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Runtime.DataConnections;
|
|
|
|
/// <summary>Live process provenance and implemented capability limits, independent of any mount.</summary>
|
|
public sealed class DataCapabilitiesProvider
|
|
{
|
|
private readonly Func<ServingIdentity> _serving;
|
|
private readonly Func<bool> _ready;
|
|
public DataCapabilitiesProvider(string clusterId, Func<ServingIdentity> serving, Func<bool> ready, DataLimits limits)
|
|
{
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(clusterId);
|
|
ClusterId = clusterId;
|
|
_serving = serving ?? throw new ArgumentNullException(nameof(serving));
|
|
_ready = ready ?? throw new ArgumentNullException(nameof(ready));
|
|
Limits = limits ?? throw new ArgumentNullException(nameof(limits));
|
|
limits.Validate();
|
|
}
|
|
public string ClusterId { get; }
|
|
public DataLimits Limits { get; }
|
|
public ServingIdentity Serving => _serving();
|
|
public bool IsReady => _ready();
|
|
internal DataCapabilities Get(DataOperations operations, DataLimits limits)
|
|
{
|
|
var serving = Serving;
|
|
var ready = IsReady;
|
|
serving.Validate(requireEpochs: ready);
|
|
if (!string.Equals(serving.Role, "Primary", StringComparison.OrdinalIgnoreCase)) operations &= ~DataOperations.Write;
|
|
return new(1, 0, serving, ready ? DataReadiness.Ready : DataReadiness.Unavailable,
|
|
ready ? operations : DataOperations.None,
|
|
Enum.GetValues<DataValueKind>().Where(x => x != DataValueKind.Unspecified).ToHashSet(),
|
|
limits, true, 1, ClusterId);
|
|
}
|
|
}
|