-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added parameters function and workflow parameters config
- Loading branch information
1 parent
5282445
commit d505842
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...mateMockUp/ExpressionParser/Functions/Implementations/Miscellaneous/ParametersFunction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Linq; | ||
using Microsoft.Extensions.Options; | ||
using Parser.ExpressionParser.Functions.Base; | ||
using Parser.ExpressionParser.Functions.CustomException; | ||
|
||
namespace Parser.ExpressionParser.Functions.Implementations.Miscellaneous | ||
{ | ||
public class ParametersFunction : Function | ||
{ | ||
private readonly WorkflowParameters _flowParameters; | ||
|
||
public ParametersFunction(IOptions<WorkflowParameters> flowParameters) : base("parameters") | ||
{ | ||
_flowParameters = flowParameters?.Value; | ||
} | ||
|
||
public override ValueContainer ExecuteFunction(params ValueContainer[] parameters) | ||
{ | ||
var paramKey = parameters.FirstOrDefault(); | ||
|
||
if (paramKey == null || paramKey.Type() != ValueContainer.ValueType.String) | ||
{ | ||
throw new ArgumentError("The parameters functions is expected to have one argument of type string"); | ||
} | ||
|
||
if (_flowParameters?.Parameters == null) | ||
{ | ||
return paramKey; | ||
} | ||
|
||
if (_flowParameters.Parameters.ContainsKey(paramKey.GetValue<string>())) | ||
{ | ||
return _flowParameters.Parameters[paramKey.GetValue<string>()]; | ||
} | ||
|
||
throw InvalidTemplateException.BuildInvalidLanguageFunction("ActionName", "parameters"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Collections.Generic; | ||
using Parser.ExpressionParser; | ||
|
||
namespace Parser | ||
{ | ||
public class WorkflowParameters | ||
{ | ||
public Dictionary<string, ValueContainer> Parameters { get; set; } | ||
} | ||
} |