Files
ScadaBridge/src/ZB.MOM.WW.ScadaBridge.StoreAndForward/StoreAndForwardOptionsValidator.cs
T

36 lines
1.8 KiB
C#

using ZB.MOM.WW.Configuration;
namespace ZB.MOM.WW.ScadaBridge.StoreAndForward;
/// <summary>
/// Validates <see cref="StoreAndForwardOptions"/> at startup. The retry intervals
/// feed the background sweep timer (a zero/negative period trips
/// <see cref="ArgumentOutOfRangeException"/> in the timer constructor) and the
/// SQLite path is opened for the S&amp;F buffer; an empty path yields an opaque
/// connection failure at first enqueue. Registered with <c>ValidateOnStart()</c>
/// so a bad <c>ScadaBridge:StoreAndForward</c> section fails fast at boot with a
/// clear, key-naming message.
/// </summary>
public sealed class StoreAndForwardOptionsValidator : OptionsValidatorBase<StoreAndForwardOptions>
{
/// <inheritdoc />
protected override void Validate(ValidationBuilder builder, StoreAndForwardOptions options)
{
builder.RequireThat(!string.IsNullOrWhiteSpace(options.SqliteDbPath),
"ScadaBridge:StoreAndForward:SqliteDbPath must be a non-empty path; " +
"it is the SQLite file backing the store-and-forward buffer.");
builder.RequireThat(options.DefaultRetryInterval > TimeSpan.Zero,
$"ScadaBridge:StoreAndForward:DefaultRetryInterval must be a positive duration " +
$"(was {options.DefaultRetryInterval}); it is the default per-message retry interval.");
builder.RequireThat(options.RetryTimerInterval > TimeSpan.Zero,
$"ScadaBridge:StoreAndForward:RetryTimerInterval must be a positive duration " +
$"(was {options.RetryTimerInterval}); it is the background retry-sweep timer period.");
builder.RequireThat(options.DefaultMaxRetries >= 0,
$"ScadaBridge:StoreAndForward:DefaultMaxRetries must be >= 0 " +
$"(was {options.DefaultMaxRetries}).");
}
}