public
sealed
class
FlowChartActivity : Activity
{
public
string
promoCode {
get
;
set
; }
public
int
numKids {
get
;
set
; }
public
FlowChartActivity(
string
promoCode,
int
numKids)
{
this
.promoCode
=
promoCode;
this
.numKids
=
numKids;
base
.Implementation
=
new
Func
<
Activity
>
(CreateBody);
}
Activity CreateBody()
{
Variable
<
string
>
promo
=
new
Variable
<
string
>
{ Default
=
promoCode};
Variable
<
int
>
numberOfKids
=
new
Variable
<
int
>
{ Default
=
numKids };
Variable
<
double
>
discount
=
new
Variable
<
double
>
();
DelegateInArgument
<
DivideByZeroException
>
ex
=
new
DelegateInArgument
<
DivideByZeroException
>
();
FlowStep discountNotApplied
=
new
FlowStep
{
Action
=
new
WriteLine
{
DisplayName
=
"
WriteLine: Discount not applied
"
,
Text
=
"
Discount not applied
"
},
Next
=
null
};
FlowStep discountApplied
=
new
FlowStep
{
Action
=
new
WriteLine
{
DisplayName
=
"
WriteLine: Discount applied
"
,
Text
=
"
Discount applied
"
},
Next
=
null
};
FlowDecision flowDecision
=
new
FlowDecision
{
Condition
=
ExssionServices.Convert
<
bool
>
((ctx)
=>
discount.Get(ctx)
>
),
True
=
discountApplied,
False
=
discountNotApplied
};
FlowStep singleStep
=
new
FlowStep
{
Action
=
new
Assign
{
DisplayName
=
"
discount = 10.0
"
,
To
=
new
OutArgument
<
double
>
(discount),
Value
=
new
InArgument
<
double
>
(
10.0
)
},
Next
=
flowDecision
};
FlowStep mnkStep
=
new
FlowStep
{
Action
=
new
Assign
{
DisplayName
=
"
discount = 15.0
"
,
To
=
new
OutArgument
<
double
>
(discount),
Value
=
new
InArgument
<
double
>
(
15.0
)
},
Next
=
flowDecision
};
FlowStep mwkStep
=
new
FlowStep
{
Action
=
new
TryCatch
{
DisplayName
=
"
Try/Catch for Divide By Zero Exception
"
,
Try
=
new
Assign
{
DisplayName
=
"
discount = 15 + (1 - 1/numberOfKids)*10
"
,
To
=
new
OutArgument
<
double
>
(discount),
Value
=
new
InArgument
<
double
>
((ctx)
=>
(
15
+
(
1
-
1
/
numberOfKids.Get(ctx))
*
10
))
},
Catches
=
{
new
Catch
<
System.DivideByZeroException
>
{
Action
=
new
ActivityAction
<
System.DivideByZeroException
>
{
Argument
=
ex,
DisplayName
=
"
ActivityAction - DivideByZeroException
"
,
Handler
=
new
Sequence
{
DisplayName
=
"
Divide by Zero Exception Workflow
"
,
Activities
=
{
new
WriteLine()
{
DisplayName
=
"
WriteLine: DivideByZeroException
"
,
Text
=
"
DivideByZeroException: Promo code is MWK - but number of kids = 0
"
},
new
Assign
<
double
>
{
DisplayName
=
"
Exception - discount = 0
"
,
To
=
discount,
Value
=
new
InArgument
<
double
>
(
)
}
}
}
}
}
}
},
Next
=
flowDecision
};
FlowStep discountDefault
=
new
FlowStep
{
Action
=
new
Assign
<
double
>
{
DisplayName
=
"
Default discount assignment: discount = 0
"
,
To
=
discount,
Value
=
new
InArgument
<
double
>
(
)
},
Next
=
flowDecision
};
FlowSwitch
<
string
>
promoCodeSwitch
=
new
FlowSwitch
<
string
>
{
Exssion
=
promo,
Cases
=
{
{
"
Single
"
, singleStep },
{
"
MNK
"
, mnkStep },
{
"
MWK
"
, mwkStep }
},
Default
=
discountDefault
};
Flowchart flowChart
=
new
Flowchart
{
DisplayName
=
"
Promotional Discount Calculation
"
,
Variables
=
{ discount, promo, numberOfKids },
StartNode
=
promoCodeSwitch,
Nodes
=
{
promoCodeSwitch,
singleStep,
mnkStep,
mwkStep,
discountDefault,
flowDecision,
discountApplied,
discountNotApplied
}
};
return
flowChart;
}
}