added pattern node, add some tests

This commit is contained in:
reven
2021-11-22 15:31:31 +13:00
parent 54a1957e9b
commit a55c5df49f
14 changed files with 248 additions and 11 deletions

View File

@@ -25,9 +25,16 @@ namespace FileFlows.BasicNodes.Functions
delegate void LogDelegate(params object[] values);
public override int Execute(NodeParameters args)
{
args.Logger.DLog("Code: ", Environment.NewLine + new string('=', 40) + Environment.NewLine + Code + Environment.NewLine + new string('=', 40));
if (string.IsNullOrEmpty(Code))
return base.Execute(args); // no code, means will run fine... i think... maybe... depends what i do
return -1; // no code, flow cannot continue doesnt know what to do
args.Logger.DLog("Code: ", Environment.NewLine + new string('=', 40) + Environment.NewLine + Code + Environment.NewLine + new string('=', 40));
long fileSize = 0;
var fileInfo = new FileInfo(args.WorkingFile);
if(fileInfo.Exists)
fileSize = fileInfo.Length;
var sb = new StringBuilder();
var log = new
@@ -43,15 +50,19 @@ namespace FileFlows.BasicNodes.Functions
options.MaxStatements(100);
})
.SetValue("Logger", args.Logger)
.SetValue("FileSize", new FileInfo(args.WorkingFile).Length)
//.SetValue("ILog", log.ILog)
.SetValue("FileSize", fileSize)
;
var result = engine.Evaluate(Code).ToObject();
if (result as bool? != true)
args.Result = NodeResult.Failure;
return base.Execute(args);
try
{
var result = int.Parse(engine.Evaluate(Code).ToObject().ToString());
return result;
}
catch (Exception ex)
{
args.Logger.ELog("Failed executing function: " + ex.Message);
return -1;
}
}
}
}

View File

@@ -0,0 +1,38 @@
namespace FileFlows.BasicNodes.Functions
{
using System.ComponentModel;
using System.Text.RegularExpressions;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
public class PatternMatch : Node
{
public override int Inputs => 1;
public override int Outputs => 2;
public override FlowElementType Type => FlowElementType.Logic;
public override string Icon => "fas fa-equals";
[DefaultValue(".*?")]
[RegularExpression(2)]
public string Pattern { get; set; }
delegate void LogDelegate(params object[] values);
public override int Execute(NodeParameters args)
{
if (string.IsNullOrEmpty(Pattern))
return 1; // no pattern, matches everything
try
{
var rgx = new Regex(Pattern);
if (rgx.IsMatch(args.WorkingFile) || rgx.IsMatch(args.FileName))
return 1;
return 0;
}
catch (Exception ex)
{
args.Logger?.ELog("Pattern error: " + ex.Message);
return -1;
}
}
}
}