From 2dc584fac7aa1dcf344b84ae05ba3b0852ceae58 Mon Sep 17 00:00:00 2001 From: MariusVuscanNx <96233009+MariusVuscanNx@users.noreply.github.com> Date: Thu, 7 Dec 2023 23:29:05 +0200 Subject: [PATCH] Implemeted FlowFork activity (#4684) --- .../Flowchart/Activities/FlowFork.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/FlowFork.cs diff --git a/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/FlowFork.cs b/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/FlowFork.cs new file mode 100644 index 000000000..f155020b3 --- /dev/null +++ b/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/FlowFork.cs @@ -0,0 +1,37 @@ +using Elsa.Extensions; +using Elsa.Workflows.Core.Attributes; +using Elsa.Workflows.Core.Models; +using JetBrains.Annotations; +using System.Runtime.CompilerServices; + +namespace Elsa.Workflows.Core.Activities.Flowchart.Activities; + +/// +/// Branch execution into multiple branches that will be executed in parallel. +/// +[Activity("Elsa", "Branching", "Branch execution into multiple branches that will be executed in parallel.", DisplayName = "Fork (flow)")] +[PublicAPI] +public class FlowFork : Activity +{ + /// + public FlowFork([CallerFilePath] string? source = default, [CallerLineNumber] int? line = default) : base(source, line) + { + } + + /// + /// A list of expected outcomes to handle. + /// + [Input( + Description = "A list of expected outcomes to handle.", + UIHint = InputUIHints.DynamicOutcomes + )] + public Input> Branches { get; set; } = default!; + + /// + protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) + { + var outcomes = Branches.GetOrDefault(context)?.ToArray() ?? new[] { "Done" }; + + await context.ScheduleOutcomesAsync(outcomes); + } +}