FF-1718: new flow element variable exists

This commit is contained in:
John Andrews
2024-08-12 07:47:31 +12:00
parent abba7a001c
commit d7642182f1
4 changed files with 57 additions and 1 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ public class FileExists: Node
/// <inheritdoc />
public override FlowElementType Type => FlowElementType.Logic;
/// <inheritdoc />
public override string Icon => "fas fa-question-circle";
public override string Icon => "fas fa-question";
/// <inheritdoc />
public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/file-exists";
/// <inheritdoc />
+56
View File
@@ -0,0 +1,56 @@
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
namespace FileFlows.BasicNodes.File;
/// <summary>
/// Checks if a file exists
/// </summary>
public class VariableExists: Node
{
/// <inheritdoc />
public override int Inputs => 1;
/// <inheritdoc />
public override int Outputs => 2;
/// <inheritdoc />
public override FlowElementType Type => FlowElementType.Logic;
/// <inheritdoc />
public override string Icon => "fas fa-question";
/// <inheritdoc />
public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/variable-exists";
/// <inheritdoc />
public override bool NoEditorOnAdd => true;
/// <summary>
/// Gets or sets the name of the variable to check
/// </summary>
[Text(1)]
public string Variable { get; set; }
/// <inheritdoc />
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 does not exist");
return 2;
}
if (value == null)
{
args.Logger?.ILog("Variable exists but is null");
return 2;
}
args.Logger?.ILog("Variable exists and is not null");
return 1;
}
}
Binary file not shown.
Binary file not shown.