-
Notifications
You must be signed in to change notification settings - Fork 1
/
PermitIssueWorkflow.cs
51 lines (41 loc) · 2.24 KB
/
PermitIssueWorkflow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// /Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root folder for license information.
using Guflow.Decider;
namespace ServerlessManualApproval.Workflows
{
/// <summary>
/// This workflow start three parallel branches and wait for the signals in each of them. When everyone approve the permit application permit is approved otherwise it is rejected.
/// </summary>
[WorkflowDescription("1.1", DefaultChildPolicy = ChildPolicy.Terminate,
DefaultExecutionStartToCloseTimeoutInSeconds = 10000, DefaultTaskListName = "manualapproval",
DefaultTaskStartToCloseTimeoutInSeconds = 20, DefaultLambdaRole = LambdaRole.Name)]
public class PermitIssueWorkflow : Workflow
{
public PermitIssueWorkflow()
{
ScheduleLambda("ApplyToCouncil").WithInput(_ => new {Id})
.OnCompletion(e => e.WaitForAnySignal("CApproved", "CRejected"));
ScheduleLambda("ApplyToFireDept").WithInput(_ => new { Id })
.OnCompletion(e => e.WaitForAnySignal("FApproved", "FRejected"));
ScheduleLambda("ApplyToForestDept").WithInput(_ => new { Id })
.OnCompletion(e => e.WaitForAnySignal("FrApproved", "FrRejected"));
ScheduleLambda("IssuePermit").AfterLambda("ApplyToCouncil").AfterLambda("ApplyToFireDept")
.AfterLambda("ApplyToForestDept")
.When(EveryOneAgree);
ScheduleLambda("RejectPermit").AfterLambda("ApplyToCouncil").AfterLambda("ApplyToFireDept")
.AfterLambda("ApplyToForestDept")
.When(AnyOneDisagree);
}
private bool AnyOneDisagree(ILambdaItem arg)
{
return arg.ParentLambda("ApplyToCouncil").IsSignalled("CRejected")
|| arg.ParentLambda("ApplyToFireDept").IsSignalled("FRejected")
|| arg.ParentLambda("ApplyToForestDept").IsSignalled("FrRejected");
}
private bool EveryOneAgree(ILambdaItem arg)
{
return arg.ParentLambda("ApplyToCouncil").IsSignalled("CApproved")
&& arg.ParentLambda("ApplyToFireDept").IsSignalled("FApproved")
&& arg.ParentLambda("ApplyToForestDept").IsSignalled("FrApproved");
}
}
}