fix(r2-02): range-validation warnings on the resilience override form (01/S-6 authoring layer)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers;
|
||||
|
||||
@@ -39,6 +40,38 @@ public sealed class ResilienceFormModel
|
||||
public bool IsEmpty => TimeoutSeconds is null && RetryCount is null && BreakerFailureThreshold is null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Range-validate the per-capability overrides against <see cref="ResiliencePolicyRanges"/> and return
|
||||
/// one human-readable message per violation (naming capability + field + legal range). This is
|
||||
/// authoring-time <b>feedback</b>, not the enforcement layer — the parser's clamp is the authoritative
|
||||
/// guard, so the form still emits. Mirrors the driver tag editors' <c>Validate()</c> idiom (01/S-6).
|
||||
/// </summary>
|
||||
/// <returns>A list of range-violation messages; empty when every override is in range or blank.</returns>
|
||||
public IReadOnlyList<string> Validate()
|
||||
{
|
||||
var msgs = new List<string>();
|
||||
foreach (var (cap, row) in Policies)
|
||||
{
|
||||
if (row.TimeoutSeconds is { } t &&
|
||||
(t < ResiliencePolicyRanges.MinTimeoutSeconds || t > ResiliencePolicyRanges.MaxTimeoutSeconds))
|
||||
msgs.Add($"{cap} timeout must be between {ResiliencePolicyRanges.MinTimeoutSeconds} and " +
|
||||
$"{ResiliencePolicyRanges.MaxTimeoutSeconds} seconds (got {t}).");
|
||||
|
||||
if (row.RetryCount is { } r &&
|
||||
(r < ResiliencePolicyRanges.MinRetryCount || r > ResiliencePolicyRanges.MaxRetryCount))
|
||||
msgs.Add($"{cap} retries must be between {ResiliencePolicyRanges.MinRetryCount} and " +
|
||||
$"{ResiliencePolicyRanges.MaxRetryCount} (got {r}).");
|
||||
|
||||
if (row.BreakerFailureThreshold is { } b &&
|
||||
(b < ResiliencePolicyRanges.MinBreakerFailureThreshold || b == 1 ||
|
||||
b > ResiliencePolicyRanges.MaxBreakerFailureThreshold))
|
||||
msgs.Add($"{cap} breaker threshold must be 0 (off) or between " +
|
||||
$"{ResiliencePolicyRanges.MinEnabledBreakerFailureThreshold} and " +
|
||||
$"{ResiliencePolicyRanges.MaxBreakerFailureThreshold} (got {b}).");
|
||||
}
|
||||
return msgs;
|
||||
}
|
||||
|
||||
private static readonly JsonSerializerOptions ReadOpts = new() { PropertyNameCaseInsensitive = true };
|
||||
private static readonly JsonSerializerOptions WriteOpts = new()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user