namespace ZB.MOM.WW.OtOpcUa.Commons.Engines; /// /// Abstraction over the scripted-alarm predicate engine. Production binds this to a /// wrapper around ScriptedAlarmEngine from Core.ScriptedAlarms; default /// binding is which keeps the alarm in its /// current state (so an unconfigured node never spuriously alarms). /// public interface IScriptedAlarmEvaluator { /// Evaluates an alarm predicate against the provided dependencies. /// The unique identifier of the alarm being evaluated. /// The predicate expression to evaluate. /// Read-only dictionary of variable names to values for predicate evaluation. /// Result containing success flag, alarm active state, and optional failure reason. ScriptedAlarmEvalResult Evaluate(string alarmId, string predicate, IReadOnlyDictionary dependencies); } /// Result of one alarm-predicate evaluation. Active is only meaningful when /// Success is true; on failure the caller should keep the prior state and log Reason. public sealed record ScriptedAlarmEvalResult(bool Success, bool Active, string? Reason) { /// Creates a successful alarm evaluation result with the given active state. /// Whether the alarm condition is active. /// A successful evaluation result. public static ScriptedAlarmEvalResult Ok(bool active) => new(true, active, null); /// Creates a failed alarm evaluation result with the given reason. /// Description of the evaluation failure cause. /// A failed evaluation result. public static ScriptedAlarmEvalResult Failure(string reason) => new(false, false, reason); } /// Default that always returns Active = false, Success = true. Safe no-op: /// no alarm fires when no real engine is bound. public sealed class NullScriptedAlarmEvaluator : IScriptedAlarmEvaluator { public static readonly NullScriptedAlarmEvaluator Instance = new(); private NullScriptedAlarmEvaluator() { } /// Returns an inactive alarm result for every evaluation (safe no-op behavior). /// The alarm identifier (ignored). /// The predicate expression (ignored). /// The variable dependencies (ignored). /// Always returns an inactive alarm result. public ScriptedAlarmEvalResult Evaluate(string alarmId, string predicate, IReadOnlyDictionary dependencies) => ScriptedAlarmEvalResult.Ok(active: false); }