| | | 1 | | using System.Runtime.CompilerServices; |
| | | 2 | | using Elsa.Expressions.Models; |
| | | 3 | | using Elsa.Workflows.Activities.Flowchart.Attributes; |
| | | 4 | | using Elsa.Workflows.Attributes; |
| | | 5 | | using Elsa.Workflows.Models; |
| | | 6 | | using Elsa.Workflows.UIHints; |
| | | 7 | | using JetBrains.Annotations; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Workflows.Activities.Flowchart.Activities; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Performs a boolean condition and returns an outcome based on the result. |
| | | 13 | | /// </summary> |
| | | 14 | | [FlowNode("True", "False")] |
| | | 15 | | [Activity("Elsa", "Branching", "Evaluate a Boolean condition to determine which path to execute next.", DisplayName = "D |
| | | 16 | | [PublicAPI] |
| | | 17 | | public class FlowDecision : Activity |
| | | 18 | | { |
| | | 19 | | /// <inheritdoc /> |
| | 33 | 20 | | public FlowDecision([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line |
| | | 21 | | { |
| | 33 | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <inheritdoc /> |
| | 32 | 25 | | public FlowDecision(Func<ExpressionExecutionContext, bool> condition, [CallerFilePath] string? source = null, [Calle |
| | | 26 | | { |
| | 32 | 27 | | Condition = new(condition); |
| | 32 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | 0 | 31 | | public FlowDecision(Func<ExpressionExecutionContext, ValueTask<bool>> condition, [CallerFilePath] string? source = n |
| | | 32 | | { |
| | 0 | 33 | | Condition = new(condition); |
| | 0 | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// The condition to evaluate. |
| | | 38 | | /// </summary> |
| | | 39 | | [Input(UIHint = InputUIHints.SingleLine)] |
| | 156 | 40 | | public Input<bool> Condition { get; set; } = new(new Literal<bool>(false)); |
| | | 41 | | |
| | | 42 | | /// <inheritdoc /> |
| | | 43 | | protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) |
| | | 44 | | { |
| | 29 | 45 | | var result = context.Get(Condition); |
| | 29 | 46 | | var outcome = result ? "True" : "False"; |
| | | 47 | | |
| | 29 | 48 | | await context.CompleteActivityWithOutcomesAsync(outcome); |
| | 29 | 49 | | } |
| | | 50 | | } |