elsa-core/src/samples/Sample25/DataProcessingWorkflow.cs
Craig Fowler f22fadaac1
Resolve #548 - improperly connected activity
The activity I removed would never have been executed, because it is
not connected from either of the IfElse branches.
Since this is Elsa 1.x, I've fixed it using the cheapest/quickest possible
solution which is to just remove the misleading part of the sample.
2021-03-04 19:35:10 +00:00

57 lines
2.4 KiB
C#

using Elsa;
using Elsa.Activities.Console.Activities;
using Elsa.Activities.ControlFlow.Activities;
using Elsa.Expressions;
using Elsa.Scripting.JavaScript;
using Elsa.Services;
using Elsa.Services.Models;
using Sample25.Activities;
namespace Sample25
{
public class DataProcessingWorkflow : IWorkflow
{
public void Build(IWorkflowBuilder builder)
{
builder
.StartWith<WriteLine>(x => x.TextExpression = new LiteralExpression("Waiting for sensor input."))
// Fork execution into two branches to wait for external stimuli from the two channels in parallel.
.Then<Fork>(
fork => fork.Branches = new[] { "Channel 1", "Channel 2" },
fork =>
{
fork
.When("Channel 1")
.Then<Channel>(x => x.SensorId = "Sensor1").WithName("Channel1")
.Then("Subtract"); // Connect to Subtract activity.
fork
.When("Channel 2")
.Then<Channel>(x => x.SensorId = "Sensor2").WithName("Channel2")
.Then("Subtract"); // Connect to Subtract activity.
})
// Subtract the specified values.
.Then<Subtract>(x => x.Values = new JavaScriptExpression<double[]>("[Channel1.Value, Channel2.Value]")).WithName("Subtract")
// Calculate the absolute value of the subtraction.
.Then<Absolute>(x => x.ValueExpression = new JavaScriptExpression<double>("(Subtract.Result)")).WithName("Absolute")
// Compare the absolute value against a constant threshold, and write the appropriate output.
.Then<IfElse>(
x => x.ConditionExpression = new JavaScriptExpression<bool>("(Absolute.Result) > 0.5"),
ifElse =>
{
ifElse
.When(OutcomeNames.False)
.Then<WriteLine>(x => x.TextExpression = new LiteralExpression("Data does not exceed threshold (FALSE)"));
ifElse
.When(OutcomeNames.True)
.Then<WriteLine>(x => x.TextExpression = new LiteralExpression("Data exceeds threshold (TRUE)"));
});
}
}
}