FF-1578: Fixed duplicate key issue in Pattern Match flow element

This commit is contained in:
John Andrews
2024-05-30 07:54:17 +12:00
parent d6069e6b19
commit 96d2b660d3
3 changed files with 22 additions and 4 deletions

View File

@@ -1,20 +1,34 @@
namespace FileFlows.BasicNodes.Functions;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
namespace FileFlows.BasicNodes.Functions;
/// <summary>
/// Flow element that matches the working file or the original file against a regular expression pattern
/// </summary>
public class PatternMatch : 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-equals";
/// <inheritdoc />
public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/pattern-match";
private Dictionary<string, object> _Variables;
/// <inheritdoc />
public override Dictionary<string, object> Variables => _Variables;
/// <summary>
/// Constructs a new instance of the Pattern Match object
/// </summary>
public PatternMatch()
{
_Variables = new Dictionary<string, object>()
@@ -23,11 +37,15 @@ public class PatternMatch : Node
};
}
/// <summary>
/// Gets or sets the pattern to match against
/// </summary>
[DefaultValue("")]
[Text(1)]
[Required]
public string Pattern { get; set; }
/// <inheritdoc />
public override int Execute(NodeParameters args)
{
if (string.IsNullOrEmpty(Pattern))
@@ -38,12 +56,12 @@ public class PatternMatch : Node
var rgx = new Regex(Pattern, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (rgx.IsMatch(args.WorkingFile))
{
args.Variables.Add("PatternMatch", rgx.Match(args.WorkingFile).Value);
args.Variables["PatternMatch"] = rgx.Match(args.WorkingFile).Value;
return 1;
}
if (rgx.IsMatch(args.FileName))
{
args.Variables.Add("PatternMatch", rgx.Match(args.FileName).Value);
args.Variables["PatternMatch"] = rgx.Match(args.FileName).Value;
return 1;
}
return 2;

Binary file not shown.

Binary file not shown.