added sleep node

This commit is contained in:
John Andrews
2022-06-29 14:35:06 +12:00
parent b1b1f09d1b
commit 99cd71dfb2
17 changed files with 112 additions and 70 deletions

View File

@@ -1,51 +1,48 @@
namespace FileFlows.BasicNodes.Functions
using System.ComponentModel;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
using System.ComponentModel.DataAnnotations;
namespace FileFlows.BasicNodes.Functions;
public class Function : Node
{
using System.ComponentModel;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using System.Text.Json;
public override int Inputs => 1;
public override FlowElementType Type => FlowElementType.Logic;
public override string Icon => "fas fa-code";
public override bool FailureNode => true;
public class Function : Node
public override string HelpUrl => "https://docs.fileflows.com/plugins/basic-nodes/function";
[DefaultValue(1)]
[NumberInt(1)]
public new int Outputs { get; set; }
[Required]
[DefaultValue("// Custom javascript code that you can run against the flow file.\n// Flow contains helper functions for the Flow.\n// Variables contain variables available to this node from previous nodes.\n// Logger lets you log messages to the flow output.\n\n// return 0 to complete the flow.\n// return -1 to signal an error in the flow\n// return 1+ to select which output node will be processed next\n\nif(Variables.file.Size === 0)\n\treturn -1;\n\nreturn 1;")]
[Code(2)]
public string Code { get; set; }
delegate void LogDelegate(params object[] values);
public override int Execute(NodeParameters args)
{
public override int Inputs => 1;
public override FlowElementType Type => FlowElementType.Logic;
public override string Icon => "fas fa-code";
public override bool FailureNode => true;
if (string.IsNullOrEmpty(Code))
return -1; // no code, flow cannot continue doesnt know what to do
public override string HelpUrl => "https://docs.fileflows.com/plugins/basic-nodes/function";
[DefaultValue(1)]
[NumberInt(1)]
public new int Outputs { get; set; }
[Required]
[DefaultValue("// Custom javascript code that you can run against the flow file.\n// Flow contains helper functions for the Flow.\n// Variables contain variables available to this node from previous nodes.\n// Logger lets you log messages to the flow output.\n\n// return 0 to complete the flow.\n// return -1 to signal an error in the flow\n// return 1+ to select which output node will be processed next\n\nif(Variables.file.Size === 0)\n\treturn -1;\n\nreturn 0;")]
[Code(2)]
public string Code { get; set; }
delegate void LogDelegate(params object[] values);
public override int Execute(NodeParameters args)
try
{
if (string.IsNullOrEmpty(Code))
return -1; // no code, flow cannot continue doesnt know what to do
try
return args.ScriptExecutor.Execute(new FileFlows.Plugin.Models.ScriptExecutionArgs
{
return args.ScriptExecutor.Execute(new FileFlows.Plugin.Models.ScriptExecutionArgs
{
Args = args,
Code = Code
});
}
catch (Exception ex)
{
args.Logger?.ELog("Failed executing function: " + ex.Message + Environment.NewLine + ex.StackTrace);
return -1;
}
Args = args,
Code = Code
});
}
catch (Exception ex)
{
args.Logger?.ELog("Failed executing function: " + ex.Message + Environment.NewLine + ex.StackTrace);
return -1;
}
}
}
}

View File

@@ -0,0 +1,35 @@
namespace FileFlows.BasicNodes.Functions;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
/// <summary>
/// Node that sleeps for a given time
/// </summary>
public class Sleep : Node
{
public override int Inputs => 1;
public override int Outputs => 1;
public override FlowElementType Type => FlowElementType.Logic;
public override string Icon => "fas fa-clock";
public override string HelpUrl => "https://docs.fileflows.com/plugins/basic-nodes/sleep";
[NumberInt(1)]
[Range(1, 3_600_000)]
[DefaultValue(1000)]
public int Milliseconds{ get; set; }
public override int Execute(NodeParameters args)
{
if (Milliseconds < 1 || Milliseconds > 3_600_000)
{
args.Logger.ELog("Milliseconds must be between 1 and 3,600,000");
return -1;
}
Thread.Sleep(Milliseconds);
return 1;
}
}