using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
namespace FileFlows.BasicNodes.File;
///
/// Checks if a file exists
///
public class VariableExists: Node
{
///
public override int Inputs => 1;
///
public override int Outputs => 2;
///
public override FlowElementType Type => FlowElementType.Logic;
///
public override string Icon => "fas fa-question";
///
public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/variable-exists";
///
public override bool FailureNode => true;
///
/// Gets or sets the name of the variable to check
///
[Text(1)]
public string Variable { get; set; }
///
public override int Execute(NodeParameters args)
{
string variable = Variable;
if(string.IsNullOrWhiteSpace(variable))
{
args.FailureReason = "Variable not set";
args.Logger?.ELog(args.FailureReason);
return -1;
}
if (args.Variables.TryGetValue(variable, out var value) == false)
{
args.Logger?.ILog($"Variable '{variable}' does not exist");
return 2;
}
if (value == null)
{
args.Logger?.ILog($"Variable '{variable}' exists but is null");
return 2;
}
args.Logger?.ILog($"Variable '{variable}' exists and is not null");
return 1;
}
}