Improve IfElse scope

This commit is contained in:
Sipke Schoorstra 2021-01-12 13:42:48 +01:00
parent 8613133add
commit e2c8cfe795
2 changed files with 21 additions and 24 deletions

View file

@ -1,3 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Elsa.ActivityResults;
using Elsa.Attributes;
using Elsa.Services;
@ -19,7 +21,7 @@ namespace Elsa.Activities.ControlFlow
[ActivityProperty(Hint = "The condition to evaluate.")]
public bool Condition { get; set; }
private bool EnteredScope
{
get => GetState<bool>();
@ -28,17 +30,20 @@ namespace Elsa.Activities.ControlFlow
protected override IActivityExecutionResult OnExecute(ActivityExecutionContext context)
{
if (!EnteredScope)
if (!context.WorkflowInstance.Scopes.Contains(Id))
{
context.WorkflowInstance.Scopes.Push(Id);
EnteredScope = true;
if (!EnteredScope)
{
context.WorkflowInstance.Scopes.Push(Id);
EnteredScope = true;
}
else
{
EnteredScope = false;
return Done();
}
}
else
{
EnteredScope = false;
return Done();
}
var outcome = Condition ? True : False;
return Outcome(outcome);
}

View file

@ -19,21 +19,13 @@ namespace Elsa.Samples.IfElseConsole
workflow
.WriteLine("--POND OF HAPPINESS--")
.WriteLine("Throw some Rupees in and your wishes will surely come true.")
.WriteLine("Do you want to throw Rupees?").WithName("Start")
.WriteLine("Do you want to throw Rupees?")
.ReadLine()
.IfElse(context => IsYes(context.Input),
ifElse =>
{
ifElse
.When(OutcomeNames.True)
.WriteLine(GetCurse)
.WriteLine("...")
.Then("Start");
ifElse
.When(OutcomeNames.False)
.WriteLine("Keep your rupees.");
})
.While(context => IsYes(context.Input), iteration => iteration
.WriteLine(GetCurse)
.WriteLine("...")
.WriteLine("Do you want to throw Rupees?")
.ReadLine())
.WriteLine("--END--");
}