namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Scripts; /// /// WP3.2 (site_events volume policy — docs/plans/2026-08-15-site-events-policy-design.md): /// decides whether an instance script run should emit the legacy per-run Started/Completed /// Info site events, or stay silent and let 's interval /// aggregate carry the signal instead. Pure and side-effect-free — no DI, no actor context — /// so the three opt-in shapes (global switch, exact per-script match, per-instance wildcard) /// are unit-testable in isolation and reusable from without /// dragging config plumbing into the run body. /// public static class ScriptRunEventPolicy { /// /// True when per-run Started/Completed Info events should be emitted for this run. /// /// /// The effective snapshot for this run (the caller reads /// IOptionsMonitor<SiteRuntimeOptions>.CurrentValue per run so this stays /// hot-togglable — see ). /// /// The owning instance's name. /// The script's name. /// /// true if is set, or if /// contains an exact /// "{instanceName}/{scriptName}" entry or an "{instanceName}/*" wildcard /// entry for this instance; otherwise false. /// public static bool ShouldEmitPerRun(SiteRuntimeOptions options, string instanceName, string scriptName) { ArgumentNullException.ThrowIfNull(options); if (options.PerRunScriptEvents) return true; var scripts = options.PerRunScriptEventScripts; if (scripts is not { Count: > 0 }) return false; var exact = $"{instanceName}/{scriptName}"; var wildcard = $"{instanceName}/*"; foreach (var entry in scripts) { if (string.Equals(entry, exact, StringComparison.Ordinal) || string.Equals(entry, wildcard, StringComparison.Ordinal)) { return true; } } return false; } }