using System.Text.Json; using FileFlows.Plugin; namespace FileFlows.BasicNodes.Conditions; /// /// A flow element that test if a boolean is true /// public class IfBoolean: IfBase { /// /// Gets or sets the URL to the help page /// public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/conditions/if-boolean"; /// /// Checks the variable value /// /// the node parameters /// the variable value /// true if matches, otherwise false protected override int DoCheck(NodeParameters args, object value) { if (value == null) return 2; if (value is bool bValue) return bValue ? 1 : 2; if (value is string sValue) return sValue.ToLowerInvariant() == "true" || sValue.ToLowerInvariant() == "1" ? 1 : 2; if (value is JsonElement je) { if (je.ValueKind == JsonValueKind.False) return 2; if (je.ValueKind == JsonValueKind.True) return 1; if (je.ValueKind == JsonValueKind.Null) return 2; if (je.ValueKind == JsonValueKind.Number) return je.GetInt32() > 0 ? 1 : 2; if (je.ValueKind == JsonValueKind.String) return je.GetString().ToLowerInvariant() == "true" ? 1 : 2; } args?.Logger?.ILog("Value was an unexpected type: " + value.GetType().FullName); return 2; } }