using ZB.MOM.WW.Configuration; namespace ZB.MOM.WW.ScadaBridge.ExternalSystemGateway; /// /// Validates at startup. /// bounds each outbound call, /// is fed into /// SocketsHttpHandler.MaxConnectionsPerServer (a non-positive value throws in the handler /// constructor), and caps buffered /// response bodies. Registered with ValidateOnStart() so a bad /// ScadaBridge:ExternalSystemGateway section fails fast at boot with a clear, key-naming /// message rather than crashing the HTTP client factory or silently disabling the gateway. /// public sealed class ExternalSystemGatewayOptionsValidator : OptionsValidatorBase { /// protected override void Validate(ValidationBuilder builder, ExternalSystemGatewayOptions options) { builder.RequireThat(options.DefaultHttpTimeout > TimeSpan.Zero, $"ScadaBridge:ExternalSystemGateway:DefaultHttpTimeout must be a positive duration " + $"(was {options.DefaultHttpTimeout}); it bounds each outbound external-system HTTP call."); builder.RequireThat(options.MaxConcurrentConnectionsPerSystem > 0, $"ScadaBridge:ExternalSystemGateway:MaxConcurrentConnectionsPerSystem must be greater than zero " + $"(was {options.MaxConcurrentConnectionsPerSystem}); it is fed into " + "SocketsHttpHandler.MaxConnectionsPerServer, which rejects non-positive values."); builder.RequireThat(options.MaxResponseBodyBytes > 0, $"ScadaBridge:ExternalSystemGateway:MaxResponseBodyBytes must be greater than zero " + $"(was {options.MaxResponseBodyBytes}); it caps the outbound response body buffered into memory."); builder.RequireThat(options.DefinitionCacheTtl >= TimeSpan.Zero, $"ScadaBridge:ExternalSystemGateway:DefinitionCacheTtl must not be negative " + $"(was {options.DefinitionCacheTtl}); use 00:00:00 to disable the definition cache."); } }