Incremental work on composite activity completion
This commit is contained in:
parent
e40b987446
commit
03eba3f6ad
|
|
@ -1,7 +1,9 @@
|
|||
using System.ComponentModel;
|
||||
using Elsa.Expressions.Models;
|
||||
using Elsa.Workflows.Core.Attributes;
|
||||
using Elsa.Workflows.Core.Models;
|
||||
using Elsa.Workflows.Core.Services;
|
||||
using Elsa.Workflows.Core.Signals;
|
||||
|
||||
namespace Elsa.Workflows.Core.Activities;
|
||||
|
||||
|
|
@ -15,6 +17,7 @@ public class Composite : ActivityBase
|
|||
/// The activity to schedule when this activity executes.
|
||||
/// </summary>
|
||||
[Port]
|
||||
[Browsable(false)]
|
||||
public IActivity Root { get; set; } = new Sequence();
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -62,10 +65,16 @@ public class Composite : ActivityBase
|
|||
/// </summary>
|
||||
public class Composite<T> : ActivityBase<T>
|
||||
{
|
||||
public Composite()
|
||||
{
|
||||
OnSignalReceived<CompleteCompositeSignal>(OnCompleteCompositeSignal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The activity to schedule when this activity executes.
|
||||
/// </summary>
|
||||
[Port]
|
||||
[Browsable(false)]
|
||||
public IActivity Root { get; protected set; } = new Sequence();
|
||||
|
||||
protected override void Execute(ActivityExecutionContext context)
|
||||
|
|
@ -105,4 +114,10 @@ public class Composite<T> : ActivityBase<T>
|
|||
protected static Inline<TResult> From<TResult>(Func<ValueTask<TResult>> activity, MemoryBlockReference? output = default) => new(activity, output);
|
||||
protected static Inline<TResult> From<TResult>(Func<ActivityExecutionContext, TResult> activity, MemoryBlockReference? output = default) => new(activity, output);
|
||||
protected static Inline<TResult> From<TResult>(Func<TResult> activity, MemoryBlockReference? output = default) => new(activity, output);
|
||||
|
||||
private async ValueTask OnCompleteCompositeSignal(CompleteCompositeSignal signal, SignalContext context)
|
||||
{
|
||||
await context.ReceiverActivityExecutionContext.CompleteActivityAsync(signal.Result);
|
||||
context.StopPropagation();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
namespace Elsa.Workflows.Core.Signals;
|
||||
|
||||
/// <summary>
|
||||
/// Sent by child activities to notify their composite root that it should complete.
|
||||
/// </summary>
|
||||
public record CompleteCompositeSignal(object? Result = default);
|
||||
|
|
@ -46,7 +46,8 @@ public class ActivityDescriber : IActivityDescriber
|
|||
from prop in activityType.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
||||
where typeof(IActivity).IsAssignableFrom(prop.PropertyType) || typeof(IEnumerable<IActivity>).IsAssignableFrom(prop.PropertyType)
|
||||
let portAttr = prop.GetCustomAttribute<PortAttribute>()
|
||||
where portAttr != null
|
||||
let portBrowsableAttr = prop.GetCustomAttribute<BrowsableAttribute>()
|
||||
where portAttr != null && (portBrowsableAttr == null || portBrowsableAttr.Browsable)
|
||||
select new Port
|
||||
{
|
||||
Name = portAttr.Name ?? prop.Name,
|
||||
|
|
@ -62,25 +63,6 @@ public class ActivityDescriber : IActivityDescriber
|
|||
DisplayName = x
|
||||
}).ToDictionary(x => x.Name) ?? new Dictionary<string, Port>();
|
||||
|
||||
if (flowNodeAttr != null)
|
||||
{
|
||||
var portProperties = activityType.GetProperties().Where(p => typeof(IActivity).IsAssignableFrom(p.PropertyType) && p.GetCustomAttribute<PortAttribute>() != null).ToList();
|
||||
|
||||
foreach (var portProperty in portProperties)
|
||||
{
|
||||
var portAttr = portProperty.GetCustomAttribute<PortAttribute>();
|
||||
|
||||
var port = new Port
|
||||
{
|
||||
Mode = PortMode.Port,
|
||||
Name = portAttr?.Name ?? portProperty.Name,
|
||||
DisplayName = portAttr?.DisplayName ?? portProperty.Name
|
||||
};
|
||||
|
||||
flowPorts[port.Name] = port;
|
||||
}
|
||||
}
|
||||
|
||||
var allPorts = embeddedPorts.Concat(flowPorts.Values);
|
||||
var properties = activityType.GetProperties();
|
||||
var inputProperties = properties.Where(x => typeof(Input).IsAssignableFrom(x.PropertyType) || x.GetCustomAttribute<InputAttribute>() != null).ToList();
|
||||
|
|
|
|||
22
src/samples/aspnet/Elsa.Samples.TelnyxIntegration/GetAge.cs
Normal file
22
src/samples/aspnet/Elsa.Samples.TelnyxIntegration/GetAge.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using Elsa.Workflows.Core;
|
||||
using Elsa.Workflows.Core.Activities;
|
||||
using Elsa.Workflows.Core.Activities.Flowchart.Attributes;
|
||||
using Elsa.Workflows.Core.Activities.Flowchart.Models;
|
||||
using Elsa.Workflows.Core.Signals;
|
||||
|
||||
namespace Elsa.Samples.TelnyxIntegration;
|
||||
|
||||
[FlowNode("Over 18", "Under 18")]
|
||||
public class GetAge : Composite<int>
|
||||
{
|
||||
public GetAge()
|
||||
{
|
||||
Root = new Inline(async context =>
|
||||
{
|
||||
var random = new Random();
|
||||
var n = random.Next(2);
|
||||
var outcome = n == 0 ? "Under 18" : "Over 18";
|
||||
await context.SendSignalAsync(new CompleteCompositeSignal(new Outcomes(outcome)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -58,6 +58,7 @@ services
|
|||
.AddActivity<Switch>()
|
||||
.AddActivity<RunJavaScript>()
|
||||
.AddActivity<Event>()
|
||||
.AddActivitiesFrom<Program>()
|
||||
)
|
||||
.Use<IdentityFeature>(identity =>
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue