コード例 #1
0
ファイル: DecisionSteps.cs プロジェクト: kapiya/Warewolf
        protected override void BuildDataList()
        {
            BuildShapeAndTestData();
            var decisionActivity = new DsfFlowDecisionActivity();

            scenarioContext.TryGetValue("mode", out Dev2DecisionMode mode);

            var decisionModels =
                scenarioContext.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);
            }

            var modelData = dds.ToVBPersistableModel();

            scenarioContext.Add("modelData", modelData);

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

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

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


            var multiAssign = new DsfMultiAssignActivity();
            var row         = 1;

            foreach (var variable in variableList)
            {
                multiAssign.FieldsCollection.Add(new ActivityDTO(variable.Item1, variable.Item2, row, true));
                row++;
            }
            var x = new FlowDecision();

            x.Condition   = decisionActivity;
            TestStartNode = new FlowStep
            {
                Action = multiAssign,
                Next   = x
            };
            scenarioContext.Add("activity", decisionActivity);
        }
コード例 #2
0
ファイル: Constraints.cs プロジェクト: sunxiaotianmg/CoreWF
        public void ComplexScenario()
        {
            //TestFlowchart OM makes it difficult to construct such invalid flowchart, hence using product and wrapping it in TestFlowchart
            TestFlowchart flowchart = new TestFlowchart();

            Act.Flowchart prod = flowchart.ProductActivity as Act.Flowchart;

            FlowStep            A = new FlowStep();
            FlowSwitch <object> B = new FlowSwitch <object>();
            FlowStep            C = new FlowStep()
            {
                Action = new WriteLine {
                    Text = "Dummy"
                }
            };
            FlowDecision D = new FlowDecision();

            //A->B->C->D, StartNode = B, Nodes = {A, A, A}
            A.Next    = B;
            B.Default = C;
            C.Next    = D;

            prod.StartNode = B;

            prod.Nodes.Add(A);
            prod.Nodes.Add(A);
            prod.Nodes.Add(A);

            List <string> errors = new List <string>();

            errors.Add(string.Format(ErrorStrings.FlowSwitchRequiresExpression, prod.DisplayName));
            errors.Add(string.Format(ErrorStrings.FlowDecisionRequiresCondition, prod.DisplayName));

            Validate(flowchart, errors);
        }
コード例 #3
0
        IEnumerable <IDev2Activity> ParseTools(FlowNode startNode, List <IDev2Activity> seenActivities)
        {
            if (startNode == null)
            {
                return(null);
            }
            FlowStep step = startNode as FlowStep;

            if (step != null)
            {
                return(ParseFlowStep(step, seenActivities));
                // ReSharper disable RedundantIfElseBlock
            }
            else
            {
                FlowDecision node = startNode as FlowDecision;
                if (node != null)
                {
                    return(ParseDecision(node, seenActivities));
                }
                else
                {
                    FlowSwitch <string> @switch = startNode as FlowSwitch <string>;
                    if (@switch != null)
                    {
                        return(ParseSwitch(@switch, seenActivities));
                    }
                }
            }
            return(null);
            // ReSharper restore RedundantIfElseBlock
        }
コード例 #4
0
ファイル: Workflow.cs プロジェクト: kapiya/Warewolf
        private IWorkflowNode CalculateFlowDecision(FlowDecision node)
        {
            var wfTree = WorkflowNodeFrom(node.Condition as IDev2Activity);

            if (wfTree != null)
            {
                if (IsFlowStep(node.True))
                {
                    var activityTrue = ((FlowStep)node.True).Action as IDev2Activity;
                    wfTree.Add(WorkflowNodeFrom(activityTrue));
                }

                if (!IsFlowStep(node.True))
                {
                    wfTree.Add(GetWorkflowNodeFrom(node.True));
                }

                if (IsFlowStep(node.False))
                {
                    var activityFalse = ((FlowStep)node.False).Action as IDev2Activity;
                    wfTree.Add(WorkflowNodeFrom(activityFalse));
                }

                if (!IsFlowStep(node.False))
                {
                    wfTree.Add(GetWorkflowNodeFrom(node.False));
                }
            }

            return(wfTree);
        }
コード例 #5
0
 public TestFlowConditional(params HintTrueFalse[] thenOrElseHint)
 {
     _productFlowConditional = new FlowDecision();
     if (thenOrElseHint != null)
     {
         _trueOrFalse = new List <HintTrueFalse>(thenOrElseHint);
     }
 }
コード例 #6
0
        private static void CreateFlowchartUpdateMap()
        {
            ActivityBuilder wf = StartUpdate("FlowchartNumberGuessWorkflow.xaml");

            // Get a reference to the root Flowchart activity.
            Flowchart fc = wf.Implementation as Flowchart;

            // Update the Text of the two WriteLine activities that write the
            // results of the user's guess. They are contained in the workflow as the
            // True and False action of the "Guess < Target" FlowDecision, which is
            // Nodes[4].
            FlowDecision guessLow = fc.Nodes[4] as FlowDecision;

            // Update the "too low" message.
            FlowStep  trueStep = guessLow.True as FlowStep;
            WriteLine tooLow   = trueStep.Action as WriteLine;

            tooLow.Text = new CSharpValue <string>("Guess.ToString() + \" is too low.\"");

            // Update the "too high" message.
            FlowStep  falseStep = guessLow.False as FlowStep;
            WriteLine tooHigh   = falseStep.Action as WriteLine;

            tooHigh.Text = new CSharpValue <string>("Guess.ToString() + \" is too high.\"");

            // Add the new WriteLine that displays the closing message.
            WriteLine wl = new WriteLine
            {
                Text = new CSharpValue <string>("Guess.ToString() + \" is correct. You guessed it in \" + Turns.ToString() + \" turns.\"")
            };

            // Create a FlowStep to hold the WriteLine.
            FlowStep closingStep = new FlowStep
            {
                Action = wl
            };

            // Add this new FlowStep to the True action of the
            // "Guess == Guess" FlowDecision
            FlowDecision guessCorrect = fc.Nodes[3] as FlowDecision;

            guessCorrect.True = closingStep;

            // Add the new FlowStep to the Nodes collection.
            // If closingStep was replacing an existing node then
            // we would need to remove that Step from the collection.
            // In this example there was no existing True step to remove.
            fc.Nodes.Add(closingStep);

            // Create the update map.
            CreateUpdateMaps(wf, "FlowchartNumberGuessWorkflow.map");

            //  Save the updated workflow definition.
            SaveUpdatedDefinition(wf, "FlowchartNumberGuessWorkflow_du.xaml");
        }
コード例 #7
0
        private static bool IsBranchTrue(FlowDecision <string> .Branch branch, Engine engine)
        {
            var isBranchTrue =
                branch.Targets?
                .Any(t => (bool)engine
                     .Execute(t)
                     .GetCompletionValue()
                     .ToObject());

            return(isBranchTrue.GetValueOrDefault());
        }
コード例 #8
0
        public void Should_map_ok()
        {
            var flowStep     = new FlowStep();
            var flowDecision = new FlowDecision {
                False = flowStep, True = flowStep
            };

            flowStep.Next = flowDecision;
            var source = new FlowChart {
                Nodes = new FlowNode[] { flowStep, flowDecision }
            };
            var dest = Map <FlowChartModel>(source);
        }
        //This method updates the clone of currentFlowElement to reference cloned FlowElements.
        void UpdateCloneReferences(FlowNode currentFlowElement, Dictionary <FlowNode, FlowNode> clonedFlowElements)
        {
            if (typeof(FlowStep).IsAssignableFrom(currentFlowElement.GetType()))
            {
                FlowStep currentFlowStep = (FlowStep)currentFlowElement;
                FlowStep clonedFlowStep  = (FlowStep)clonedFlowElements[currentFlowElement];
                FlowNode nextFlowElement = currentFlowStep.Next;
                if (nextFlowElement != null && clonedFlowElements.ContainsKey(nextFlowElement))
                {
                    clonedFlowStep.Next = clonedFlowElements[nextFlowElement];
                }
                else
                {
                    clonedFlowStep.Next = null;
                }
            }
            else if (typeof(FlowDecision).IsAssignableFrom(currentFlowElement.GetType()))
            {
                FlowDecision currentFlowDecision = (FlowDecision)currentFlowElement;
                FlowDecision clonedFlowDecision  = (FlowDecision)clonedFlowElements[currentFlowElement];
                FlowNode     trueElement         = currentFlowDecision.True;
                FlowNode     falseElement        = currentFlowDecision.False;

                if (trueElement != null && clonedFlowElements.ContainsKey(trueElement))
                {
                    clonedFlowDecision.True = clonedFlowElements[trueElement];
                }
                else
                {
                    clonedFlowDecision.True = null;
                }

                if (falseElement != null && clonedFlowElements.ContainsKey(falseElement))
                {
                    clonedFlowDecision.False = clonedFlowElements[falseElement];
                }
                else
                {
                    clonedFlowDecision.False = null;
                }
            }
            else if (GenericFlowSwitchHelper.IsGenericFlowSwitch(currentFlowElement.GetType()))
            {
                GenericFlowSwitchHelper.Copy(currentFlowElement.GetType().GetGenericArguments()[0], currentFlowElement, clonedFlowElements);
            }
            else
            {
                Debug.Fail("Unknown FlowNode");
            }
        }
コード例 #10
0
ファイル: Constraints.cs プロジェクト: sunxiaotianmg/CoreWF
        public void FlowDecisionConditionMustBeSet()
        {
            TestFlowchart flowchart = new TestFlowchart();

            Act.Flowchart prod = flowchart.ProductActivity as Act.Flowchart;

            FlowStep     step;
            FlowDecision decision = new FlowDecision {
                True = step = new FlowStep {
                    Action = new WriteLine {
                        Text = "Dummy"
                    }
                }
            };

            prod.StartNode = decision;
            prod.Nodes.Add(step);

            List <string> errors = new List <string>();

            errors.Add(string.Format(ErrorStrings.FlowDecisionRequiresCondition, prod.DisplayName));

            Validate(flowchart, errors);
        }
コード例 #11
0
        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");
        }
コード例 #12
0
ファイル: program.cs プロジェクト: mconnew/dotnet-api-docs
        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
            };
//<Snippet3>
            FlowDecision flowDecision = new FlowDecision
            {
                Condition = ExpressionServices.Convert <bool>((ctx) => discount.Get(ctx) > 0),
                True      = discountApplied,
                False     = discountNotApplied
            };
//</Snippet3>
//<Snippet4>
            FlowStep singleStep = new FlowStep
            {
                Action = new Assign
                {
                    DisplayName = "discount = 10.0",
                    To          = new OutArgument <double> (discount),
                    Value       = new InArgument <double> (10.0)
                },
                Next = flowDecision
            };
//</Snippet4>

            FlowStep mnkStep = new FlowStep
            {
                Action = new Assign
                {
                    DisplayName = "discount = 15.0",
                    To          = new OutArgument <double> (discount),
                    Value       = new InArgument <double> (15.0)
                },
                Next = flowDecision
            };

//<Snippet1>
            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
            };
//</Snippet1>

            FlowStep discountDefault = new FlowStep
            {
                Action = new Assign <double>
                {
                    DisplayName = "Default discount assignment: discount = 0",
                    To          = discount,
                    Value       = new InArgument <double>(0)
                },
                Next = flowDecision
            };
//<Snippet5>
            FlowSwitch <string> promoCodeSwitch = new FlowSwitch <string>
            {
                Expression = promo,
                Cases      =
                {
                    { "Single", singleStep },
                    { "MNK",    mnkStep    },
                    { "MWK",    mwkStep    }
                },
                Default = discountDefault
            };
//</Snippet5>
//<Snippet2>
            Flowchart flowChart = new Flowchart
            {
                DisplayName = "Promotional Discount Calculation",
                Variables   = { discount, promo, numberOfKids },
                StartNode   = promoCodeSwitch,
                Nodes       =
                {
                    promoCodeSwitch,
                    singleStep,
                    mnkStep,
                    mwkStep,
                    discountDefault,
                    flowDecision,
                    discountApplied,
                    discountNotApplied
                }
            };

//</Snippet2>
            return(flowChart);
        }
コード例 #13
0
 private void btnDecision_Click(object sender, EventArgs e)
 {
     CreatedObject = new FlowDecision();
     this.Close();
 }
コード例 #14
0
        private Activity GetImplementation()
        {
            Variable <double> discount     = new Variable <double>();
            Variable <string> discountCode = new Variable <string>();
            Variable <bool>   isStudent    = new Variable <bool>()
            {
                Default = _isStudent
            };
            Variable <bool> isMarried = new Variable <bool> {
                Default = _isMarried
            };
            Variable <bool> haveChild = new Variable <bool> {
                Default = _haveChild
            };

            FlowStep returnDiscountCode = new FlowStep
            {
                Action = new Assign <string>
                {
                    DisplayName = "Return Discount Code",
                    To          = new OutArgument <string>((ctx) => DiscountCode.Get(ctx)),
                    Value       = new InArgument <string>(discountCode)
                },
                Next = null
            };

            FlowStep printDiscount = new FlowStep
            {
                Action = new WriteLine
                {
                    DisplayName = "WriteLine: Discount Applied",
                    Text        = discountCode
                },
                Next = returnDiscountCode
            };

            FlowStep applyDefaultDiscount = new FlowStep
            {
                Action = new Assign <double>
                {
                    DisplayName = "Default Discount is 0%",
                    To          = discount,
                    Value       = new InArgument <double>(0)
                },
                Next = printDiscount
            };

            FlowStep applyBaseDiscount = new FlowStep
            {
                Action = new Assign <double>
                {
                    DisplayName = "Base Discount is 5%",
                    To          = discount,
                    Value       = new InArgument <double>(5)
                },
                Next = printDiscount
            };

            FlowStep applyStandardDiscount = new FlowStep
            {
                Action = new Assign <double>
                {
                    DisplayName = "Standard Discount is 10%",
                    To          = discount,
                    Value       = new InArgument <double>(10)
                },
                Next = printDiscount
            };

            FlowStep applyPremiumDiscount = new FlowStep
            {
                Action = new Assign <double>
                {
                    DisplayName = "Standard Discount is 15%",
                    To          = discount,
                    Value       = new InArgument <double>(15)
                },
                Next = printDiscount
            };

            FlowSwitch <string> discountCodeSwitch = new FlowSwitch <string>
            {
                Expression = discountCode,
                Cases      =
                {
                    { "STD", applyBaseDiscount     },
                    { "MNC", applyStandardDiscount },
                    { "MWC", applyPremiumDiscount  },
                },
                Default = applyDefaultDiscount
            };

            FlowStep noDiscount = new FlowStep
            {
                Action = new Assign <string>
                {
                    DisplayName = "No Discount",
                    To          = discountCode,
                    Value       = new InArgument <string>("NONE")
                },
                Next = discountCodeSwitch
            };

            FlowStep studentDiscount = new FlowStep
            {
                Action = new Assign <string>
                {
                    DisplayName = "Student Discount is appplied",
                    To          = discountCode,
                    Value       = new InArgument <string>("STD")
                },
                Next = discountCodeSwitch
            };

            FlowStep marriedWithNoChildDiscount = new FlowStep
            {
                Action = new Assign <string>
                {
                    DisplayName = "Married with no child Discount is applied",
                    To          = discountCode,
                    Value       = new InArgument <string>("MNC")
                },
                Next = discountCodeSwitch
            };

            FlowStep marriedWithChildDiscount = new FlowStep
            {
                Action = new Assign <string>
                {
                    DisplayName = "Married with child Discount is 15%",
                    To          = discountCode,
                    Value       = new InArgument <string>("MWC")
                },
                Next = discountCodeSwitch
            };


            FlowDecision singleFlowDecision = new FlowDecision
            {
                Condition = ExpressionServices.Convert <bool>((ctx) => isStudent.Get(ctx)),
                True      = studentDiscount,
                False     = noDiscount,
            };

            FlowDecision marriedFlowDecision = new FlowDecision
            {
                Condition = ExpressionServices.Convert <bool>((ctx) => haveChild.Get(ctx)),
                True      = marriedWithChildDiscount,
                False     = marriedWithNoChildDiscount,
            };

            FlowDecision startNode = new FlowDecision
            {
                Condition = ExpressionServices.Convert <bool>((ctx) => isMarried.Get(ctx)),
                True      = marriedFlowDecision,
                False     = singleFlowDecision
            };

            return(new Flowchart()
            {
                DisplayName = "Auto insurance discount calculation",
                Variables = { discount, isMarried, isStudent, haveChild, discountCode },

                StartNode = startNode,
                Nodes =
                {
                    startNode,
                    marriedFlowDecision,
                    singleFlowDecision,
                    marriedWithChildDiscount,
                    marriedWithNoChildDiscount,
                    studentDiscount,
                    noDiscount,
                    discountCodeSwitch,
                    applyBaseDiscount,
                    applyDefaultDiscount,
                    applyPremiumDiscount,
                    applyStandardDiscount,
                    printDiscount,
                    returnDiscountCode
                }
            });
        }
コード例 #15
0
        // The logic is similar to UpdateCloneReferences.
        // the difference is in this function, we need to set reference by Property.
        void UpdateCloneReferenceByModelItem(FlowNode currentFlowElement,
                                             Dictionary <FlowNode, ModelItem> modelItems, Dictionary <FlowNode, FlowNode> clonedFlowElements)
        {
            if (typeof(FlowStep).IsAssignableFrom(currentFlowElement.GetType()))
            {
                FlowStep  currentFlowStep = (FlowStep)currentFlowElement;
                FlowStep  clonedFlowStep  = (FlowStep)clonedFlowElements[currentFlowElement];
                ModelItem modelItem       = modelItems[clonedFlowStep];
                FlowNode  nextFlowElement = currentFlowStep.Next;
                if (nextFlowElement != null && clonedFlowElements.ContainsKey(nextFlowElement))
                {
                    modelItem.Properties["Next"].SetValue(clonedFlowElements[nextFlowElement]);
                }
                else
                {
                    modelItem.Properties["Next"].SetValue(null);
                }
            }
            else if (typeof(FlowDecision).IsAssignableFrom(currentFlowElement.GetType()))
            {
                if (!modelItems.ContainsKey(currentFlowElement))
                {
                    Fx.Assert("Should not happen.");
                }
                FlowDecision currentFlowDecision = (FlowDecision)currentFlowElement;
                FlowDecision clonedFlowDecision  = (FlowDecision)clonedFlowElements[currentFlowElement];
                Fx.Assert(currentFlowDecision == clonedFlowDecision, "should not happen");
                ModelItem modelItem = modelItems[currentFlowElement];
                Fx.Assert(modelItem != null, "should not happen");
                FlowNode trueElement  = currentFlowDecision.True;
                FlowNode falseElement = currentFlowDecision.False;

                if (trueElement != null && clonedFlowElements.ContainsKey(trueElement))
                {
                    modelItem.Properties["True"].SetValue(clonedFlowElements[trueElement]);
                }
                else
                {
                    modelItem.Properties["True"].SetValue(null);
                }

                if (falseElement != null && clonedFlowElements.ContainsKey(falseElement))
                {
                    modelItem.Properties["False"].SetValue(clonedFlowElements[falseElement]);
                }
                else
                {
                    modelItem.Properties["False"].SetValue(null);
                }
            }
            else if (GenericFlowSwitchHelper.IsGenericFlowSwitch(currentFlowElement.GetType()))
            {
                GenericFlowSwitchHelper.ReferenceCopy(currentFlowElement.GetType().GetGenericArguments()[0],
                                                      currentFlowElement,
                                                      modelItems,
                                                      clonedFlowElements);
            }
            else
            {
                Debug.Fail("Unknown FlowNode");
            }
        }