Various API enhancements
This commit is contained in:
parent
ceed1ff1fe
commit
bd48f113cc
|
|
@ -8,7 +8,7 @@ namespace Elsa.Activities.ControlFlow;
|
|||
|
||||
public class Fork : Activity
|
||||
{
|
||||
[Input] public Input<JoinMode> JoinMode { get; set; } = new(ControlFlow.JoinMode.WaitAny);
|
||||
[Input] public JoinMode JoinMode { get; set; } = JoinMode.WaitAny;
|
||||
[Outbound] public ICollection<IActivity> Branches { get; set; } = new List<IActivity>();
|
||||
|
||||
protected override void Execute(ActivityExecutionContext context) => context.PostActivities(Branches.Reverse(), CompleteChildAsync);
|
||||
|
|
@ -32,17 +32,17 @@ public class Fork : Activity
|
|||
});
|
||||
|
||||
var allChildActivityIds = Branches.Select(x => x.Id).ToImmutableHashSet();
|
||||
var joinMode = context.Get(JoinMode);
|
||||
var joinMode = JoinMode;
|
||||
|
||||
switch (joinMode)
|
||||
{
|
||||
case ControlFlow.JoinMode.WaitAny:
|
||||
case JoinMode.WaitAny:
|
||||
{
|
||||
// Remove any and all bookmarks from other branches.
|
||||
RemoveBookmarks(context);
|
||||
}
|
||||
break;
|
||||
case ControlFlow.JoinMode.WaitAll:
|
||||
case JoinMode.WaitAll:
|
||||
{
|
||||
var allSet = allChildActivityIds.All(x => completedActivityIds.Contains(x));
|
||||
|
||||
|
|
|
|||
|
|
@ -6,28 +6,29 @@ namespace Elsa.Activities.ControlFlow;
|
|||
|
||||
public class While : Activity
|
||||
{
|
||||
public While()
|
||||
public While(IActivity? body = default)
|
||||
{
|
||||
Body = body!;
|
||||
}
|
||||
|
||||
public While(Input<bool> condition)
|
||||
public While(Input<bool> condition, IActivity? body = default) : this(body)
|
||||
{
|
||||
Condition = condition;
|
||||
}
|
||||
|
||||
public While(Func<ExpressionExecutionContext, ValueTask<bool>> condition) : this(new Input<bool>(condition))
|
||||
public While(Func<ExpressionExecutionContext, ValueTask<bool>> condition, IActivity? body = default) : this(new Input<bool>(condition), body)
|
||||
{
|
||||
}
|
||||
|
||||
public While(Func<ExpressionExecutionContext, bool> condition) : this(new Input<bool>(condition))
|
||||
public While(Func<ExpressionExecutionContext, bool> condition, IActivity? body = default) : this(new Input<bool>(condition), body)
|
||||
{
|
||||
}
|
||||
|
||||
public While(Func<ValueTask<bool>> condition) : this(new Input<bool>(condition))
|
||||
public While(Func<ValueTask<bool>> condition, IActivity? body = default) : this(new Input<bool>(condition), body)
|
||||
{
|
||||
}
|
||||
|
||||
public While(Func<bool> condition) : this(new Input<bool>(condition))
|
||||
public While(Func<bool> condition, IActivity? body = default) : this(new Input<bool>(condition), body)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class Inline<T> : Activity<T>
|
|||
public Inline(Func<ActivityExecutionContext, ValueTask<T>> activity, RegisterLocationReference? output = default)
|
||||
{
|
||||
_activity = activity;
|
||||
if (output != null) Result = new Output(output);
|
||||
if (output != null) Result = new Output<T>(output);
|
||||
}
|
||||
|
||||
public Inline(Func<ValueTask<T>> activity, RegisterLocationReference? output = default) : this(_ => activity(), output)
|
||||
|
|
|
|||
9
src/core/Elsa.Core/Extensions/InputExtensions.cs
Normal file
9
src/core/Elsa.Core/Extensions/InputExtensions.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using Elsa.Models;
|
||||
|
||||
namespace Elsa.Extensions;
|
||||
|
||||
public static class InputExtensions
|
||||
{
|
||||
public static T? Get<T>(this Input<T> input, ActivityExecutionContext context) => context.Get(input);
|
||||
public static T? Get<T>(this Input<T> input, ExpressionExecutionContext context) => context.Get(input);
|
||||
}
|
||||
|
|
@ -36,5 +36,6 @@ public class Variable<T> : Variable
|
|||
{
|
||||
}
|
||||
|
||||
public new T? Get(ActivityExecutionContext context) => (T?)base.Get(context);
|
||||
public new T? Get(ExpressionExecutionContext context) => (T?)base.Get(context);
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@ public class ForkedHttpWorkflow : IWorkflow
|
|||
},
|
||||
new Fork
|
||||
{
|
||||
JoinMode = new Input<JoinMode>(JoinMode.WaitAll),
|
||||
JoinMode = JoinMode.WaitAll,
|
||||
Branches =
|
||||
{
|
||||
new Sequence
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public static class ForkedWorkflow
|
|||
new WriteLine("Forking..."),
|
||||
new Fork
|
||||
{
|
||||
JoinMode = new Input<JoinMode>(JoinMode.WaitAll),
|
||||
JoinMode = JoinMode.WaitAll,
|
||||
Branches =
|
||||
{
|
||||
new Sequence(
|
||||
|
|
|
|||
Loading…
Reference in a new issue