protected override Decimal Execute(CodeActivityContext context) { Decimal result = 0; switch (ShipVia.Get(context)) { case "normal": if (OrderTotal.Get(context) >= _freeThreshold) { _isFreeShipping = true; } else { result = (Weight.Get(context) * _normalRate); } break; case "express": result = (Weight.Get(context) * _expressRate); break; } if ((result < _minimum) && (!_isFreeShipping)) { result = _minimum; } return(result); }
protected override IAsyncResult BeginExecute( AsyncCodeActivityContext context, AsyncCallback callback, object state) { CalcShippingAsyncArgs parameters = new CalcShippingAsyncArgs { Weight = Weight.Get(context), OrderTotal = OrderTotal.Get(context), ShipVia = ShipVia.Get(context), }; Func <CalcShippingAsyncArgs, Decimal> asyncWork = a => Calculate(a); context.UserState = asyncWork; return(asyncWork.BeginInvoke(parameters, callback, state)); }
private Activity BuildImplementation() { Variable <Boolean> isFreeShipping = new Variable <Boolean> { Name = "IsFreeShipping" }; Variable <Decimal> normalRate = new Variable <Decimal> { Name = "NormalRate", Default = 1.95M }; Variable <Decimal> expressRate = new Variable <Decimal> { Name = "ExpressRate", Default = 3.50M }; Variable <Decimal> minimum = new Variable <Decimal> { Name = "Minimum", Default = 12.95M }; Variable <Decimal> freeThreshold = new Variable <Decimal> { Name = "FreeThreshold", Default = 75.00M }; return(new Sequence { Variables = { isFreeShipping, normalRate, expressRate, minimum, freeThreshold }, Activities = { new Switch <String> { //public InArgument(Expression<Func<ActivityContext, T>> expression); Expression = new InArgument <String>( ac => ShipVia.Get(ac)), Cases = { { "normal", new If { Condition = new InArgument <Boolean>(ac => OrderTotal.Get(ac) >= freeThreshold.Get(ac)), Then = new Assign <Boolean> { //public OutArgument(Expression<Func<ActivityContext, T>> expression); To = new OutArgument <Boolean>(ac => isFreeShipping.Get(ac)), Value = true }, Else = new Assign <Decimal> { To = new OutArgument <Decimal>(ac => this.Result.Get(ac)), Value = new InArgument <Decimal>(ac => Weight.Get(ac) * normalRate.Get(ac)) } } }, { "express", new Assign <Decimal> { To = new OutArgument <Decimal>(ac => this.Result.Get(ac)), Value = new InArgument <Decimal>(ac => Weight.Get(ac) * expressRate.Get(ac)) } } } }, new If { Condition = new InArgument <bool>(ac => Result.Get(ac) < minimum.Get(ac) && (!isFreeShipping.Get(ac))), Then = new Assign { To = new OutArgument <Decimal>(ac => Result.Get(ac)), Value = new InArgument <Decimal>(ac => minimum.Get(ac)) } } } }); //new Sequence }