forked from elsa-workflows/elsa-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Bulk Dispatch Workflow activity (elsa-workflows#4683)
* Initial version of BulkDispatchWorkflow * Update comments * Refactor options models for running workflows and add Properties * Fix resumption * Add ability to provide arguments when evaluating expressions * Update args syntax for JS * Fix ProtoActor Runtime Properties mapping * Use default constructor * Provide completed workflow instance ID as input to BulkDispatchWorkflows * Implement ChildFaulted port * Switch to Publish to make Memory service bus work * Update input evaluation and activity output retrieval Refined the input evaluation process to only consider inputs with AutoEvaluate set to true. Added a comment to clarify the purpose of the GetActivitiesWithOutputs method. Removed the unnecessary check for AutoEvaluate from the EvaluateInputPropertyAsync method.
- Loading branch information
1 parent
0146a8a
commit 683f0ee
Showing
94 changed files
with
1,375 additions
and
584 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
45 changes: 45 additions & 0 deletions
45
src/modules/Elsa.CSharp/Handlers/GenerateArgumentAccessors.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,45 @@ | ||
using System.Text; | ||
using Elsa.CSharp.Notifications; | ||
using Elsa.Expressions.Models; | ||
using Elsa.Extensions; | ||
using Elsa.Mediator.Contracts; | ||
using JetBrains.Annotations; | ||
|
||
namespace Elsa.CSharp.Handlers; | ||
|
||
/// <summary> | ||
/// Configures the C# evaluator with methods to access workflow variables. | ||
/// </summary> | ||
[UsedImplicitly] | ||
public class GenerateArgumentAccessors : INotificationHandler<EvaluatingCSharp> | ||
{ | ||
/// <inheritdoc /> | ||
public Task HandleAsync(EvaluatingCSharp notification, CancellationToken cancellationToken) | ||
{ | ||
var arguments = notification.Options.Arguments; | ||
var sb = new StringBuilder(); | ||
sb.AppendLine("public partial class ArgumentsProxy {"); | ||
sb.AppendLine("\tpublic ArgumentsProxy(IDictionary<string, object> arguments) => Arguments = arguments;"); | ||
sb.AppendLine("\tpublic IDictionary<string, object> Arguments { get; }"); | ||
sb.AppendLine(); | ||
sb.AppendLine("\tpublic T? Get<T>(string name) => Arguments.TryGetValue(name, out var v) ? (T?)v : default;"); | ||
sb.AppendLine(); | ||
foreach (var argument in arguments) | ||
{ | ||
// var d = new Dictionary<string, object>(); | ||
// d.TryGetValue("", out var f); | ||
var argumentName = argument.Key; | ||
var variableType = argument.Value.GetType(); | ||
var friendlyTypeName = variableType.GetFriendlyTypeName(Brackets.Angle); | ||
sb.AppendLine($"\tpublic {friendlyTypeName} {argumentName}"); | ||
sb.AppendLine("\t{"); | ||
sb.AppendLine($"\t\tget => Get<{friendlyTypeName}>(\"{argumentName}\");"); | ||
sb.AppendLine("\t}"); | ||
} | ||
|
||
sb.AppendLine("}"); | ||
sb.AppendLine("var Args = new ArgumentsProxy(Arguments);"); | ||
notification.AppendScript(sb.ToString()); | ||
return Task.CompletedTask; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/modules/Elsa.CSharp/Handlers/GenerateWorkflowInputAccessors.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,47 @@ | ||
using System.Text; | ||
using Elsa.CSharp.Notifications; | ||
using Elsa.Expressions.Models; | ||
using Elsa.Extensions; | ||
using Elsa.Mediator.Contracts; | ||
using Humanizer; | ||
using JetBrains.Annotations; | ||
|
||
namespace Elsa.CSharp.Handlers; | ||
|
||
/// <summary> | ||
/// Configures the C# evaluator with methods to access workflow variables. | ||
/// </summary> | ||
[UsedImplicitly] | ||
public class GenerateWorkflowInputAccessors : INotificationHandler<EvaluatingCSharp> | ||
{ | ||
/// <inheritdoc /> | ||
public Task HandleAsync(EvaluatingCSharp notification, CancellationToken cancellationToken) | ||
{ | ||
var expressionExecutionContext = notification.Context; | ||
var workflowInputs = expressionExecutionContext.GetWorkflowInputs().ToList(); | ||
var workflow = expressionExecutionContext.GetWorkflowExecutionContext().Workflow; | ||
var inputDefinitions = workflow.Inputs.ToList(); | ||
var sb = new StringBuilder(); | ||
sb.AppendLine("public partial class WorkflowInputsProxy {"); | ||
sb.AppendLine("\tpublic WorkflowInputsProxy(ExecutionContextProxy executionContext) => ExecutionContext = executionContext;"); | ||
sb.AppendLine("\tpublic ExecutionContextProxy ExecutionContext { get; }"); | ||
sb.AppendLine(); | ||
sb.AppendLine("\tpublic T? Get<T>(string name) => ExecutionContext.GetInput<T>(name);"); | ||
sb.AppendLine(); | ||
foreach (var inputDefinition in inputDefinitions) | ||
{ | ||
var inputName = inputDefinition.Name; | ||
var variableType = inputDefinition.Type; | ||
var friendlyTypeName = variableType.GetFriendlyTypeName(Brackets.Angle); | ||
sb.AppendLine($"\tpublic {friendlyTypeName} {inputName}"); | ||
sb.AppendLine("\t{"); | ||
sb.AppendLine($"\t\tget => Get<{friendlyTypeName}>(\"{inputName}\");"); | ||
sb.AppendLine("\t}"); | ||
} | ||
|
||
sb.AppendLine("}"); | ||
sb.AppendLine("var Inputs = new WorkflowInputsProxy(ExecutionContext);"); | ||
notification.AppendScript(sb.ToString()); | ||
return Task.CompletedTask; | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
12 changes: 12 additions & 0 deletions
12
src/modules/Elsa.Expressions/Models/ExpressionEvaluatorOptions.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,12 @@ | ||
namespace Elsa.Expressions.Models; | ||
|
||
/// <summary> | ||
/// Contains additional options for the expression evaluator. | ||
/// </summary> | ||
public class ExpressionEvaluatorOptions | ||
{ | ||
/// <summary> | ||
/// An extra set of variables to add to the expression context. | ||
/// </summary> | ||
public IDictionary<string, object> Arguments { get; set; } = new Dictionary<string, object>(); | ||
} |
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
Oops, something went wrong.