fix(triggers): bound expression evaluation, align AlarmActor error handling, dedupe config parsing

This commit is contained in:
Joseph Doherty
2026-05-16 05:43:18 -04:00
parent 41c3fa3d84
commit 78b10d00d8
4 changed files with 80 additions and 45 deletions

View File

@@ -1,3 +1,5 @@
using System.Text.Json;
namespace ScadaLink.SiteRuntime.Scripts;
/// <summary>
@@ -11,6 +13,29 @@ namespace ScadaLink.SiteRuntime.Scripts;
/// </summary>
public sealed class TriggerExpressionGlobals
{
/// <summary>
/// Extracts the <c>"expression"</c> field from an Expression-trigger config
/// JSON document. Returns <c>null</c> for a missing, blank, or malformed
/// config — the single parsing idiom shared by InstanceActor, ScriptActor,
/// and AlarmActor.
/// </summary>
public static string? ExtractExpression(string? triggerConfigJson)
{
if (string.IsNullOrEmpty(triggerConfigJson)) return null;
try
{
using var doc = JsonDocument.Parse(triggerConfigJson);
var expr = doc.RootElement.TryGetProperty("expression", out var e)
? e.GetString()
: null;
return string.IsNullOrWhiteSpace(expr) ? null : expr;
}
catch (JsonException)
{
return null;
}
}
private readonly IReadOnlyDictionary<string, object?> _snapshot;
public TriggerExpressionGlobals(IReadOnlyDictionary<string, object?> snapshot)