bool ExecuteSingleNode(NativeActivityContext context, FlowNode node, out FlowNode nextNode)
        {
            Fx.Assert(node != null, "caller should validate");
            FlowStep step = node as FlowStep;

            if (step != null)
            {
                if (this.onStepCompleted == null)
                {
                    this.onStepCompleted = new CompletionCallback(this.OnStepCompleted);
                }

                return(step.Execute(context, this.onStepCompleted, out nextNode));
            }

            nextNode = null;
            FlowDecision decision = node as FlowDecision;

            if (decision != null)
            {
                if (this.onDecisionCompleted == null)
                {
                    this.onDecisionCompleted = new CompletionCallback <bool>(this.OnDecisionCompleted);
                }

                return(decision.Execute(context, this.onDecisionCompleted));
            }

            IFlowSwitch switchNode = node as IFlowSwitch;

            Fx.Assert(switchNode != null, "unrecognized FlowNode");

            return(switchNode.Execute(context, this));
        }
예제 #2
0
        private void OnDecisionCompleted(NativeActivityContext context, System.Activities.ActivityInstance completedInstance, bool result)
        {
            FlowDecision currentNode = this.GetCurrentNode(context) as FlowDecision;
            FlowNode     node        = result ? currentNode.True : currentNode.False;

            this.ExecuteNodeChain(context, node, completedInstance);
        }
예제 #3
0
        private bool ExecuteSingleNode(NativeActivityContext context, FlowNode node, out FlowNode nextNode)
        {
            FlowStep step = node as FlowStep;

            if (step != null)
            {
                if (this.onStepCompleted == null)
                {
                    this.onStepCompleted = new CompletionCallback(this.OnStepCompleted);
                }
                return(step.Execute(context, this.onStepCompleted, out nextNode));
            }
            nextNode = null;
            FlowDecision decision = node as FlowDecision;

            if (decision != null)
            {
                if (this.onDecisionCompleted == null)
                {
                    this.onDecisionCompleted = new CompletionCallback <bool>(this.OnDecisionCompleted);
                }
                return(decision.Execute(context, this.onDecisionCompleted));
            }
            IFlowSwitch switch2 = node as IFlowSwitch;

            return(switch2.Execute(context, this));
        }
예제 #4
0
        private void OnDecisionCompleted(NativeActivityContext context, ActivityInstance completedInstance, bool result)
        {
            FlowDecision decision = this.GetCurrentNode(context) as FlowDecision;

            Fx.Assert(decision != null, "corrupt internal state");
            FlowNode next = result ? decision.True : decision.False;

            this.ExecuteNodeChain(context, next, completedInstance);
        }
예제 #5
0
        protected override void BuildDataList()
        {
            BuildShapeAndTestData();
            var decisionActivity = new DsfFlowDecisionActivity();
            Dev2DecisionMode mode;
            ScenarioContext.Current.TryGetValue("mode", out mode);

            var decisionModels =
                ScenarioContext.Current.Get<List<Tuple<string, enDecisionType, string, string>>>("decisionModels");
            var dds = new Dev2DecisionStack { TheStack = new List<Dev2Decision>(), Mode = mode, TrueArmText = "YES", FalseArmText = "NO" };

            foreach(var dm in decisionModels)
            {
                var dev2Decision = new Dev2Decision
                    {
                        Col1 = dm.Item1 ?? string.Empty,
                        EvaluationFn = dm.Item2,
                        Col2 = dm.Item3 ?? string.Empty,
                        Col3 = dm.Item4 ?? string.Empty
                    };

                dds.AddModelItem(dev2Decision);
            }

            string modelData = dds.ToVBPersistableModel();
            ScenarioContext.Current.Add("modelData", modelData);

            decisionActivity.ExpressionText = string.Join("", GlobalConstants.InjectedDecisionHandler, "(\"", modelData,
                                                          "\",", GlobalConstants.InjectedDecisionDataListVariable, ")");

            List<Tuple<string, string>> variableList;
            ScenarioContext.Current.TryGetValue("variableList", out variableList);

            if(variableList == null)
            {
                variableList = new List<Tuple<string, string>>();
                ScenarioContext.Current.Add("variableList", variableList);
            }


            var multiAssign = new DsfMultiAssignActivity();
            int row = 1;
            foreach(var variable in variableList)
            {
                multiAssign.FieldsCollection.Add(new ActivityDTO(variable.Item1, variable.Item2, row, true));
                row++;
            }
            FlowDecision x = new FlowDecision();
            x.Condition=decisionActivity;
            TestStartNode = new FlowStep
                {
                    Action = multiAssign,
                    Next = x
                };
            ScenarioContext.Current.Add("activity", decisionActivity);
        }
예제 #6
0
        private static Activity CreateFlowchartWithFaults(string promoCode, int numKids)
        {
            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 = ExpressionServices.Convert<bool>((ctx) => discount.Get(ctx) > 0),
                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>(0)
                                            }
                                         }
                                     }
                             }
                         }
                    }
                },
                Next = flowDecision
            };

            FlowStep discountDefault = new FlowStep
            {
                Action = new Assign<double>
                {
                    DisplayName = "Default discount assignment: discount = 0",
                    To = discount,
                    Value = new InArgument<double>(0)
                },
                Next = flowDecision
            };

            FlowSwitch<string> promoCodeSwitch = new FlowSwitch<string>
            {
                Expression = 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;
        }
 IEnumerable<IDev2Activity> ParseDecision(FlowDecision decision, List<IDev2Activity> seenActivities)
 {
     
     var activity = decision.Condition as DsfFlowDecisionActivity;
     if(activity != null)
     {
         if( seenActivities.Contains(activity))
         {
             return new List<IDev2Activity> { activity};
         }
         var rawText = activity.ExpressionText;
         // ReSharper disable MaximumChainedReferences
         var activityTextjson = rawText.Substring(rawText.IndexOf("{", StringComparison.Ordinal)).Replace(@""",AmbientDataList)","").Replace("\"","!");
         // ReSharper restore MaximumChainedReferences
         var activityText = Dev2DecisionStack.FromVBPersitableModelToJSON(activityTextjson);
         var decisionStack =  JsonConvert.DeserializeObject<Dev2DecisionStack>(activityText);
         var dec = new DsfDecision(activity);
         if (!seenActivities.Contains(activity))
         {
             seenActivities.Add( dec);
         }
         dec.TrueArm = ParseTools(decision.True, seenActivities);
         dec.FalseArm = ParseTools(decision.False, seenActivities);
         dec.Conditions = decisionStack;
         dec.And = decisionStack.Mode == Dev2DecisionMode.AND;
         
         
         return new List<IDev2Activity>
         { dec};
     }
     throw new Exception("Invalid activity");
 }