Improve IfElse scope
This commit is contained in:
parent
8613133add
commit
e2c8cfe795
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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--");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue