diff --git a/BasicNodes/Functions/FailFlow.cs b/BasicNodes/Functions/FailFlow.cs
index 75a6c278..5bc3997a 100644
--- a/BasicNodes/Functions/FailFlow.cs
+++ b/BasicNodes/Functions/FailFlow.cs
@@ -4,7 +4,7 @@ using FileFlows.Plugin.Attributes;
namespace FileFlows.BasicNodes.Functions;
///
-/// A node that simply fails a flow
+/// A flow element that simply fails a flow
///
public class FailFlow : Node
{
diff --git a/BasicNodes/Functions/SetVariable.cs b/BasicNodes/Functions/SetVariable.cs
new file mode 100644
index 00000000..f63a9f6c
--- /dev/null
+++ b/BasicNodes/Functions/SetVariable.cs
@@ -0,0 +1,90 @@
+using System.Text.RegularExpressions;
+using FileFlows.Plugin;
+using FileFlows.Plugin.Attributes;
+
+namespace FileFlows.BasicNodes.Functions;
+
+///
+/// A flow element that sets a variable in the flow
+///
+public class SetVariable : Node
+{
+ ///
+ public override int Inputs => 1;
+ ///
+ public override int Outputs => 1;
+ ///
+ public override FlowElementType Type => FlowElementType.Logic;
+ ///
+ public override string Icon => "fas fa-at";
+ ///
+ public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/set-variable";
+
+ ///
+ /// Gets or sets the name of the variable to set
+ ///
+ [TextVariable(1)]
+ public string Variable { get; set; }
+ ///
+ /// Gets or sets the value to set
+ ///
+ [TextVariable(2)]
+ public string Value { get; set; }
+
+ ///
+ public override int Execute(NodeParameters args)
+ {
+ string variable = args.ReplaceVariables(Variable, stripMissing: true);
+ if (string.IsNullOrWhiteSpace(variable))
+ {
+ args.FailureReason = "No variable name defined";
+ args.Logger?.ELog(args.FailureReason);
+ return -1;
+ }
+
+ if (Regex.IsMatch(variable, "^[a-zA-Z_][a-zA-Z0-9_]*$") == false)
+ {
+ args.FailureReason = "Invalid variable name: " + variable;
+ args.Logger?.ELog(args.FailureReason);
+ return -1;
+ }
+
+ string value = args.ReplaceVariables(Value, stripMissing: true);
+ object valueToUse;
+ string lowerValue = value?.ToLowerInvariant()?.Trim() ?? string.Empty;
+ if (lowerValue == "true")
+ {
+ args.Logger?.ILog($"Boolean detected, setting variable '{variable}' to: True");
+ valueToUse = (object)true;
+ }
+ else if (lowerValue == "false")
+ {
+ args.Logger?.ILog($"Boolean detected, setting variable '{variable}' to: False");
+ valueToUse = (object)false;
+ }
+ else if (Regex.IsMatch(lowerValue, "^[\\d]+$") && int.TryParse(lowerValue, out int iValue))
+ {
+ args.Logger?.ILog($"Integer detected, setting variable '{variable}' to: " + iValue);
+ valueToUse = (object)iValue;
+ }
+ else if (Regex.IsMatch(lowerValue, "^[\\d]+\\.[\\d]+$") && float.TryParse(lowerValue, out float fValue))
+ {
+ args.Logger?.ILog($"Float detected, setting variable '{variable}' to: " + fValue);
+ valueToUse = (object)fValue;
+ }
+ else if (Value == null || value == null)
+ {
+ args.Logger?.ILog($"Null detected, setting variable '{variable}' to: null");
+ valueToUse = null;
+ }
+ else
+ {
+ args.Logger?.ILog($"String detected, setting variable '{variable}' to: " + Value);
+ valueToUse = value;
+ }
+
+ args.Variables[variable] = valueToUse;
+
+ return 1;
+ }
+}
\ No newline at end of file
diff --git a/BasicNodes/i18n/de.json b/BasicNodes/i18n/de.json
index 98489bb8..f69203ed 100644
--- a/BasicNodes/i18n/de.json
+++ b/BasicNodes/i18n/de.json
@@ -287,6 +287,19 @@
"CsvFile-Help": "Der ursprüngliche Name und die umbenannte Datei werden an diese Datei angehängt. Nützlich, wenn Sie „Nur protokollieren“ verwenden, um den Renamer zu testen, bevor Sie Dateien ändern. Symbol „Von der Community überprüft“"
}
},
+ "SetVariable": {
+ "Label": "Variable setzen",
+ "Description": "Setzt eine Variable im Flow.",
+ "Outputs": {
+ "1": "Variable gesetzt"
+ },
+ "Fields": {
+ "Variable": "Variable",
+ "Variable-Help": "Der Name der zu setzenden Variable",
+ "Value": "Wert",
+ "Value-Help": "Der Wert der zu setzenden Variable"
+ }
+ },
"Sleep": {
"Description": "Unterbricht den Flow",
"Outputs": {
diff --git a/BasicNodes/i18n/en.json b/BasicNodes/i18n/en.json
index 696b3c04..79cf6904 100644
--- a/BasicNodes/i18n/en.json
+++ b/BasicNodes/i18n/en.json
@@ -316,6 +316,19 @@
"CsvFile-Help": "Will append to this file the original name and the renamed file. Useful when using ''Log Only'' to test the renamer before changing files."
}
},
+ "SetVariable": {
+ "Label": "Set Variable",
+ "Description": "Sets a variable in the flow.",
+ "Outputs": {
+ "1": "Variable set"
+ },
+ "Fields": {
+ "Variable": "Variable",
+ "Variable-Help": "The name of the variable to set",
+ "Value": "Value",
+ "Value-Help": "The value of the variable to set."
+ }
+ },
"Sleep": {
"Description": "Pauses the flow",
"Outputs": {