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 }
protected override void BuildDataList() { var variableList = ScenarioContext.Current.Get<List<Tuple<string, string>>>("variableList"); variableList.Add(new Tuple<string, string>(ResultVariable, "")); BuildShapeAndTestData(); var flowSwitch = new DsfFlowSwitchActivity { ExpressionText = string.Format( "Dev2.Data.Decision.Dev2DataListDecisionHandler.Instance.FetchSwitchData(\"{0}\",AmbientDataList)", variableList.First().Item1), }; var sw = new FlowSwitch<string>(); sw.Expression = flowSwitch; var multiAssign = new DsfMultiAssignActivity(); int row = 1; foreach(var variable in variableList) { multiAssign.FieldsCollection.Add(new ActivityDTO(variable.Item1, variable.Item2, row, true)); row++; } TestStartNode = new FlowStep { Action = multiAssign, Next = sw }; ScenarioContext.Current.Add("activity", flowSwitch); }
public static void GenericCopy <T>(FlowNode currentFlowElement, Dictionary <FlowNode, FlowNode> clonedFlowElements) { FlowSwitch <T> currentFlowSwitch = (FlowSwitch <T>)currentFlowElement; FlowSwitch <T> clonedFlowSwitch = (FlowSwitch <T>)clonedFlowElements[currentFlowElement]; //Update the default case. FlowNode defaultCase = currentFlowSwitch.Default; if (defaultCase != null && clonedFlowElements.ContainsKey(defaultCase)) { clonedFlowSwitch.Default = clonedFlowElements[defaultCase]; } else { clonedFlowSwitch.Default = null; } //Update the Cases dictionary. foreach (T key in currentFlowSwitch.Cases.Keys) { if (clonedFlowElements.ContainsKey(currentFlowSwitch.Cases[key])) { clonedFlowSwitch.Cases.Add(key, clonedFlowElements[currentFlowSwitch.Cases[key]]); } } }
/// <summary> /// 创建人工节点 /// </summary> /// <param name="setting"></param> /// <param name="displayName"></param> /// <param name="actioner"></param> /// <param name="humanResultTo"></param> /// <param name="nexts"></param> /// <param name="defaultFlowNode"></param> /// <returns></returns> public static FlowStep CreateHuman(ActivitySetting setting , string displayName , IActionersHelper actioner//Activity<string[]> actioner , Variable <string> humanResultTo , IDictionary <string, FlowNode> nexts , FlowNode defaultFlowNode) { var human = CreateHuman(setting, displayName, actioner, humanResultTo); var step = new FlowStep(); step.Action = human; if (nexts == null && defaultFlowNode == null) { return(step); } //设置finish cases //HACK:在进入switch之前就已经计算出任务结果 var flowSwitch = new FlowSwitch <string>(o => humanResultTo.Get(o)); if (defaultFlowNode != null) { flowSwitch.Default = defaultFlowNode; } if (nexts != null) { nexts.ToList().ForEach(o => flowSwitch.Cases.Add(o.Key, o.Value)); } step.Next = flowSwitch; return(step); }
IEnumerable <IDev2Activity> ParseSwitch(FlowSwitch <string> switchFlowSwitch, List <IDev2Activity> seenActivities) { var activity = switchFlowSwitch.Expression as DsfFlowSwitchActivity; if (activity != null) { if (seenActivities.Contains(activity)) { return(new List <IDev2Activity> { activity }); } var val = new StringBuilder(Dev2DecisionStack.ExtractModelFromWorkflowPersistedData(activity.ExpressionText)); Dev2Switch ds = new Dev2Switch { SwitchVariable = val.ToString() }; var swi = new DsfSwitch(activity); if (!seenActivities.Contains(activity)) { seenActivities.Add(swi); } swi.Switches = switchFlowSwitch.Cases.Select(a => new Tuple <string, IDev2Activity>(a.Key, ParseTools(a.Value, seenActivities).FirstOrDefault())).ToDictionary(a => a.Item1, a => a.Item2); swi.Default = ParseTools(switchFlowSwitch.Default, seenActivities); swi.Switch = ds.SwitchVariable; return(new List <IDev2Activity> { swi }); } throw new Exception("Invalid activity"); }
/// <summary> /// 创建SubProcess子流程节点 /// </summary> /// <param name="setting"></param> /// <param name="displayName"></param> /// <param name="serverScript">节点执行内容脚本</param> /// <param name="finishRule">节点完成规则</param> /// <param name="serverScriptResultTo">执行内容的结果输出到指定变量</param> /// <param name="serverResultTo">节点执行结果输出到变量</param> /// <param name="nexts"></param> /// <param name="defaultFlowNode"></param> /// <returns></returns> public static FlowStep CreateSubProcess(ActivitySetting setting , string displayName , IDictionary <string, string> finishRule , Variable <string> resultTo , IDictionary <string, FlowNode> nexts , FlowNode defaultFlowNode) { var server = CreateSubProcess(setting, displayName, finishRule, resultTo); var step = new FlowStep(); step.Action = server; if (nexts == null && defaultFlowNode == null) { return(step); } //设置finish cases var flowSwitch = new FlowSwitch <string>(o => resultTo.Get(o)); if (defaultFlowNode != null) { flowSwitch.Default = defaultFlowNode; } if (nexts != null) { nexts.ToList().ForEach(o => flowSwitch.Cases.Add(o.Key, o.Value)); } step.Next = flowSwitch; return(step); }
protected override void BuildDataList() { var variableList = scenarioContext.Get <List <Tuple <string, string> > >("variableList"); variableList.Add(new Tuple <string, string>(ResultVariable, "")); BuildShapeAndTestData(); var flowSwitch = new DsfFlowSwitchActivity { ExpressionText = string.Format( "Dev2.Data.Decision.Dev2DataListDecisionHandler.Instance.FetchSwitchData(\"{0}\",AmbientDataList)", variableList.First().Item1), }; var sw = new FlowSwitch <string>(); sw.Expression = flowSwitch; var multiAssign = new DsfMultiAssignActivity(); int row = 1; foreach (var variable in variableList) { multiAssign.FieldsCollection.Add(new ActivityDTO(variable.Item1, variable.Item2, row, true)); row++; } TestStartNode = new FlowStep { Action = multiAssign, Next = sw }; scenarioContext.Add("activity", flowSwitch); }
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); }
public void FlowSwitchRequiresExpression() { TestFlowchart flowchart = new TestFlowchart(); Act.Flowchart prod = flowchart.ProductActivity as Act.Flowchart; FlowStep step1; FlowStep step2; FlowSwitch <object> flowSwitch = new FlowSwitch <object> { Cases = { { 2, step2 = new FlowStep { Action = new WriteLine{ Text = "Dummy" } } } }, Default = step1 = new FlowStep { Action = new WriteLine { Text = "Dummy" } } }; prod.StartNode = flowSwitch; prod.Nodes.Add(step1); prod.Nodes.Add(step2); List <string> errors = new List <string>(); errors.Add(string.Format(ErrorStrings.FlowSwitchRequiresExpression, prod.DisplayName)); Validate(flowchart, errors); }
IEnumerable<IDev2Activity> ParseSwitch(FlowSwitch<string> switchFlowSwitch, List<IDev2Activity> seenActivities) { var activity = switchFlowSwitch.Expression as DsfFlowSwitchActivity; if (activity != null) { if (seenActivities.Contains(activity)) { return new List<IDev2Activity> { activity }; } var val = new StringBuilder(Dev2DecisionStack.ExtractModelFromWorkflowPersistedData(activity.ExpressionText)); Dev2Switch ds = new Dev2Switch { SwitchVariable = val.ToString() }; var swi = new DsfSwitch(activity); if (!seenActivities.Contains(activity)) { seenActivities.Add(swi); } swi.Switches = switchFlowSwitch.Cases.Select(a => new Tuple<string, IDev2Activity>(a.Key, ParseTools(a.Value, seenActivities).FirstOrDefault())).ToDictionary(a => a.Item1, a => a.Item2); swi.Default = ParseTools(switchFlowSwitch.Default, seenActivities); swi.Switch = ds.SwitchVariable; return new List<IDev2Activity> { swi }; } throw new Exception("Invalid activity"); }
private IWorkflowNode CalculateFlowSwitch(FlowSwitch <string> node) { var wfTree = WorkflowNodeFrom(node.Expression as IDev2Activity); foreach (var item in node.Cases.Values) { wfTree.Add(GetWorkflowNodeFrom(item)); } return(wfTree); }
public FlowSwitchLink(ModelItem flowSwitchMI, T caseValue, bool isDefault) { this.flowSwitchModelItem = flowSwitchMI; object flowSwitch = this.flowSwitchModelItem.GetCurrentValue(); this.parentFlowSwitch = (FlowSwitch <T>) this.flowSwitchModelItem.GetCurrentValue(); this.internalChange = true; this.internalDefaultCaseChange = true; if (!isDefault) { this.CaseObject = caseValue; } this.IsDefaultCase = isDefault; this.internalDefaultCaseChange = false; this.internalChange = false; }
static ModelItem CreateSwitchModelItem(FlowStep flowStep) { var dsfSwitch = new FlowSwitch <string>(); var uniqueId = Guid.NewGuid(); var activity = new DsfFlowSwitchActivity { UniqueID = uniqueId.ToString() }; dsfSwitch.Expression = activity; dsfSwitch.Cases.Add("Case1", flowStep); dsfSwitch.Cases.Add("Case2", new FlowStep()); dsfSwitch.Default = new FlowStep(); var modelItem = ModelItemUtils.CreateModelItem(dsfSwitch); return(modelItem); }
// oldNewFlowNodeMap: <OldFlowNode, NewFlowNode> // sometimes, OldFlowNode == NewFlowNode, say, FlowNode is a FlowDecesion. // if FlowNode is FlowStep, OldFlowNode != NewFlowNode public static void GenericRemapFlowSwitch <T>(FlowNode currentFlowElement, ModelItem modelItem, Dictionary <FlowNode, FlowNode> oldNewFlowNodeMap) { FlowSwitch <T> currentFlowSwitch = (FlowSwitch <T>)currentFlowElement; //Update the default case. FlowNode defaultCase = currentFlowSwitch.Default; if (defaultCase != null && oldNewFlowNodeMap.ContainsKey(defaultCase)) { modelItem.Properties["Default"].SetValue(oldNewFlowNodeMap[defaultCase]); } else { modelItem.Properties["Default"].SetValue(null); } // collect all the cases that should be update Dictionary <object, object> keyValueMap = new Dictionary <object, object>(); foreach (T key in currentFlowSwitch.Cases.Keys) { if (oldNewFlowNodeMap.ContainsKey(currentFlowSwitch.Cases[key])) { keyValueMap.Add(key, oldNewFlowNodeMap[currentFlowSwitch.Cases[key]]); } } // Update the Cases dictionary. ModelProperty casesProperty = modelItem.Properties["Cases"]; // remove all key foreach (ModelItem key in GenericFlowSwitchHelper.GetCaseKeys(casesProperty)) { GenericFlowSwitchHelper.RemoveCase(casesProperty, key.GetCurrentValue()); } // add back keys foreach (T key in keyValueMap.Keys) { GenericFlowSwitchHelper.AddCase(casesProperty, key, keyValueMap[key]); } }
private IWarewolfWorkflow GetRealWorkflowBuilder() { var jsonSerializer = new Dev2JsonSerializer(); var dev2DecisionStackParent = GetDecisionStackParent(); var dev2DecisionStackChild = GetDecisionChild(); var switchId = Guid.Parse("0d723deb-402d-43ec-bdbc-97c645a3a8f1"); var flowSwitch = new FlowSwitch <string>() { Expression = new DsfFlowSwitchActivity { ActivityId = switchId, UniqueID = switchId.ToString(), DisplayName = "Switch (dsf)", } }; flowSwitch.Cases .Add("Case1", new FlowStep { Action = new DsfMultiAssignActivity { ActivityId = Guid.Parse("f8aec437-38c3-47c8-be1c-e5f408efa3bc"), UniqueID = Guid.Parse("f8aec437-38c3-47c8-be1c-e5f408efa3bc").ToString(), DisplayName = "Assign (case 1)" } }); flowSwitch.Cases .Add("Case2", new FlowStep { Action = new DsfMultiAssignActivity { ActivityId = Guid.Parse("a8c186a2-bb5e-4382-84a6-699622034e8d"), UniqueID = Guid.Parse("a8c186a2-bb5e-4382-84a6-699622034e8d").ToString(), DisplayName = "Assign (case 2)" } }); flowSwitch.Cases .Add("Case3", new FlowDecision() { Condition = new DsfFlowDecisionActivity { ExpressionText = jsonSerializer.Serialize(dev2DecisionStackParent) }, DisplayName = "Decision (parent)", True = new FlowStep { Action = new DsfMultiAssignActivity { DisplayName = "Assign (success)" } }, False = new FlowDecision() { Condition = new DsfFlowDecisionActivity { ExpressionText = jsonSerializer.Serialize(dev2DecisionStackChild) }, DisplayName = "Decision (child)", True = new FlowStep { Action = new DsfMultiAssignActivity { DisplayName = "Assign (Decision child)-True Arm" } }, False = new FlowStep { Action = new DsfMultiAssignActivity { DisplayName = "Assign (Decision child)-False Arm" } } } }); flowSwitch.Default = new FlowStep(); var flowNodes = new Collection <FlowNode> { flowSwitch }; return(new Workflow(flowNodes)); }
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; }
public void Workflow_WorkflowNodes_When_FlowSwitch_HandlingNestedObjects_Executed_WorkflowNodesForHtml_ShouldReturnAllNodesInWorkflow() { var jsonSerializer = new Dev2JsonSerializer(); var dev2DecisionStackParent = GetDecisionStackParent(); var dev2DecisionStackChild = GetDecisionChild(); var switchId = Guid.Parse("0d723deb-402d-43ec-bdbc-97c645a3a8f1"); var flowSwitch = new FlowSwitch <string>() { Expression = new DsfFlowSwitchActivity { ActivityId = switchId, UniqueID = switchId.ToString(), DisplayName = "Switch (dsf)" } }; flowSwitch.Cases .Add("Case1", new FlowStep { Action = new DsfMultiAssignActivity { DisplayName = "Assign (case 1)" } }); flowSwitch.Cases .Add("Case2", new FlowStep { Action = new DsfMultiAssignActivity { DisplayName = "Assign (case 2)" } }); flowSwitch.Cases .Add("Case3", new FlowDecision() { Condition = new DsfFlowDecisionActivity { ExpressionText = jsonSerializer.Serialize(dev2DecisionStackParent) }, DisplayName = "Decision (parent)", True = new FlowStep { Action = new DsfMultiAssignActivity { DisplayName = "Assign (success)" } }, False = new FlowDecision() { Condition = new DsfFlowDecisionActivity { ExpressionText = jsonSerializer.Serialize(dev2DecisionStackChild) }, DisplayName = "Decision (child)", True = new FlowStep { Action = new DsfMultiAssignActivity { DisplayName = "Assign (Decision child)-True Arm" } }, False = new FlowStep { Action = new DsfMultiAssignActivity { DisplayName = "Assign (Decision child)-False Arm" } } } }); flowSwitch.Default = new FlowStep(); var flowNodes = new Collection <FlowNode> { flowSwitch }; var sut = new Workflow(flowNodes); var nodes = sut.WorkflowNodes; Assert.AreEqual(8, nodes.Count); Assert.AreEqual(1, sut.WorkflowNodesForHtml.Count); }
private string buildXaml(PD_Process process, PD_Subject subject) { Flowchart flow = new Flowchart(); Variable flowGlobalTransition = new Variable <String> { Name = "GlobalTransition" }; Variable flowGlobalVariables = new Variable <DynamicValue> { Name = "GlobalVariables" }; string globVariablesInit = ""; if (subject.GlobalParameters.Count > 0) { globVariablesInit = "{"; foreach (string p in subject.GlobalParameters) { var par = _pdesignerDB.PD_Parameters.Find(subject.PD_Process_Id, p); globVariablesInit = globVariablesInit + "\"" + p + "\":" + par.Config + ","; } globVariablesInit = globVariablesInit.Remove(globVariablesInit.Length - 1, 1); globVariablesInit = globVariablesInit + "}"; } Variable flowGlobalVariablesSchema = new Variable <string> { Name = "GlobalVariablesSchema", Default = globVariablesInit }; Dictionary <int, FlowStep> nodeList = new Dictionary <int, System.Activities.Statements.FlowStep>(); flow.Variables.Add(flowGlobalTransition); flow.Variables.Add(flowGlobalVariables); flow.Variables.Add(flowGlobalVariablesSchema); foreach (var state in subject.States) { FlowStep f; if (state.Type == PD_StateTypes.FunctionState) { var s = (PD_FunctionState)state; string timeout = ""; try { var timeouttransition = subject.Transitions.First(result => result.Source == s.Id && result.Type == PD_TransitionTypes.TimeoutTransition); timeout = ((PD_TimeoutTransition)timeouttransition).TimeSpan; } catch (Exception e) { } var transitions = subject.Transitions.Where(result => result.Source == s.Id && result.Type == PD_TransitionTypes.RegularTransition); List <string> titems = new List <string>(); transitions.ToList().ForEach(i => titems.Add(((PD_RegularTransition)i).Name)); f = new FlowStep() { Action = new FunctionStateT() { DisplayName = s.Name, OrderId = s.Id, name = s.Name, GlobalTransition = new OutArgument <string>(flowGlobalTransition), GlobalVariables = new InOutArgument <DynamicValue>(flowGlobalVariables), isEndState = s.EndState, readableParameters = collectionToString(s.ReadableParameters), editableParameters = collectionToString(s.EditableParameters), TimeOut = timeout, transitions = collectionToString(titems) } }; } else if (state.Type == PD_StateTypes.SendState) { var s = (PD_SendState)state; string timeout = ""; try { var timeouttransition = subject.Transitions.First(result => result.Source == s.Id && result.Type == PD_TransitionTypes.TimeoutTransition); timeout = ((PD_TimeoutTransition)timeouttransition).TimeSpan; } catch (Exception e) { } var message = process.Messages.First(result => result.Id == s.Message); string to = process.Subjects.First(result => result.Id == message.To).Name; f = new FlowStep() { Action = new SendStateT() { DisplayName = s.Name, OrderId = s.Id, name = s.Name, GlobalTransition = new OutArgument <string>(flowGlobalTransition), GlobalVariables = new InOutArgument <DynamicValue>(flowGlobalVariables), isEndState = s.EndState, readableParameters = collectionToString(s.ReadableParameters), editableParameters = collectionToString(s.EditableParameters), messageType = message.PD_MessageType.Name, parameters = collectionToString(message.PD_MessageType.Parameters), toSubject = to, TimeOut = timeout } }; } else //(state.Type == PD_StateTypes.ReceiveState) { var s = (PD_ReceiveState)state; string messages = ""; List <string> messagelist = new List <string>(); var receivetransitions = subject.Transitions.Where(result => result.Source == s.Id && result.Type == PD_TransitionTypes.ReceiveTransition); foreach (var i in receivetransitions) { messagelist.Add(receiveTranstionToString(process, (PD_ReceiveTransition)i)); } messages = collectionToString(messagelist); string timeout = ""; try { var timeouttransition = subject.Transitions.First(result => result.Source == s.Id && result.Type == PD_TransitionTypes.TimeoutTransition); timeout = ((PD_TimeoutTransition)timeouttransition).TimeSpan; } catch (Exception e) { } f = new FlowStep() { Action = new ReceiveStateT() { DisplayName = s.Name, OrderId = s.Id, name = s.Name, GlobalTransition = new OutArgument <string>(flowGlobalTransition), GlobalVariables = new InOutArgument <DynamicValue>(flowGlobalVariables), isEndState = s.EndState, TimeOut = timeout, messages = messages } }; } flow.Nodes.Add(f); nodeList.Add(state.Id, f); } var initGP = new FlowStep() { Action = new InitializeGlobalParameters() { DisplayName = "init GP", DynamicVal = new InOutArgument <DynamicValue>(flowGlobalVariables), GlobalParameterSchema = new InArgument <string>(flowGlobalVariablesSchema) } }; initGP.Next = nodeList[subject.States.First(result => result.StartState == true).Id]; flow.StartNode = initGP; // flow.StartNode = nodeList[subject.States.First(result => result.StartState == true).Id]; foreach (var state in subject.States) { List <PD_Transition> transitions = new List <PD_Transition>(); try { subject.Transitions.Where(result => result.Source == state.Id).ToList().ForEach(item => transitions.Add(item)); } catch (Exception e) { } if (transitions.Count > 0) { if (transitions.Count == 1) { var t = transitions[0]; nodeList[t.Source].Next = nodeList[t.Target]; } else { FlowSwitch <String> newSwitch = new FlowSwitch <String> { Expression = flowGlobalTransition }; flow.Nodes.Add(newSwitch); nodeList[state.Id].Next = newSwitch; try { var timeouttransition = transitions.First(result => result.Type == PD_TransitionTypes.TimeoutTransition); newSwitch.Cases.Add("TimeOut!", nodeList[timeouttransition.Target]); transitions.Remove(timeouttransition); } catch (Exception e) { } if (state.Type == PD_StateTypes.SendState) { newSwitch.Default = nodeList[transitions[0].Target]; } else if (state.Type == PD_StateTypes.ReceiveState) { foreach (var t in transitions) { newSwitch.Cases.Add(receiveTranstionToString(process, (PD_ReceiveTransition)t), nodeList[t.Target]); } } else { foreach (var t in transitions) { newSwitch.Cases.Add(((PD_RegularTransition)t).Name, nodeList[t.Target]); } } } } } ActivityBuilder builder = new ActivityBuilder(); builder.Name = "strICT.InFlowTest.WFProcesses." + process.Name + "." + subject.Name; builder.Implementation = flow; VisualBasic.SetSettings(builder, new VisualBasicSettings()); //StringBuilder sb = new StringBuilder(); StringWriterUtf8 stream = new StringWriterUtf8(); XamlWriter writer = ActivityXamlServices.CreateBuilderWriter(new XamlXmlWriter(stream, new XamlSchemaContext())); XamlServices.Save(writer, builder); string res = stream.GetStringBuilder().ToString(); res = res.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", ""); return(res); }
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); }
public override FlowNode GetFlowNode() { var swt = new FlowSwitch <string>(); return(swt); }
/// <summary> /// 创建人工节点 /// </summary> /// <param name="setting"></param> /// <param name="displayName"></param> /// <param name="actioner"></param> /// <param name="humanResultTo"></param> /// <param name="nexts"></param> /// <param name="defaultFlowNode"></param> /// <returns></returns> public static FlowStep CreateHuman(ActivitySetting setting , string displayName , IActionersHelper actioner//Activity<string[]> actioner , Variable<string> humanResultTo , IDictionary<string, FlowNode> nexts , FlowNode defaultFlowNode) { var human = CreateHuman(setting, displayName, actioner, humanResultTo); var step = new FlowStep(); step.Action = human; if (nexts == null && defaultFlowNode == null) return step; //设置finish cases //HACK:在进入switch之前就已经计算出任务结果 var flowSwitch = new FlowSwitch<string>(o => humanResultTo.Get(o)); if (defaultFlowNode != null) flowSwitch.Default = defaultFlowNode; if (nexts != null) nexts.ToList().ForEach(o => flowSwitch.Cases.Add(o.Key, o.Value)); step.Next = flowSwitch; return step; }
/// <summary> /// 创建SubProcess子流程节点 /// </summary> /// <param name="setting"></param> /// <param name="displayName"></param> /// <param name="serverScript">节点执行内容脚本</param> /// <param name="finishRule">节点完成规则</param> /// <param name="serverScriptResultTo">执行内容的结果输出到指定变量</param> /// <param name="serverResultTo">节点执行结果输出到变量</param> /// <param name="nexts"></param> /// <param name="defaultFlowNode"></param> /// <returns></returns> public static FlowStep CreateSubProcess(ActivitySetting setting , string displayName , IDictionary<string, string> finishRule , Variable<string> resultTo , IDictionary<string, FlowNode> nexts , FlowNode defaultFlowNode) { var server = CreateSubProcess(setting, displayName, finishRule, resultTo); var step = new FlowStep(); step.Action = server; if (nexts == null && defaultFlowNode == null) return step; //设置finish cases var flowSwitch = new FlowSwitch<string>(o => resultTo.Get(o)); if (defaultFlowNode != null) flowSwitch.Default = defaultFlowNode; if (nexts != null) nexts.ToList().ForEach(o => flowSwitch.Cases.Add(o.Key, o.Value)); step.Next = flowSwitch; return step; }
private string buildXaml(PD_Process process, PD_Subject subject) { Flowchart flow = new Flowchart(); Variable flowGlobalTransition = new Variable<String> { Name = "GlobalTransition" }; Variable flowGlobalVariables = new Variable<DynamicValue> { Name = "GlobalVariables"}; string globVariablesInit = ""; if (subject.GlobalParameters.Count > 0) { globVariablesInit = "{"; foreach (string p in subject.GlobalParameters) { var par = _pdesignerDB.PD_Parameters.Find(subject.PD_Process_Id, p); globVariablesInit = globVariablesInit + "\""+ p +"\":"+ par.Config +","; } globVariablesInit = globVariablesInit.Remove(globVariablesInit.Length - 1, 1); globVariablesInit = globVariablesInit + "}"; } Variable flowGlobalVariablesSchema = new Variable<string> { Name = "GlobalVariablesSchema", Default = globVariablesInit }; Dictionary<int, FlowStep> nodeList = new Dictionary<int, System.Activities.Statements.FlowStep>(); flow.Variables.Add(flowGlobalTransition); flow.Variables.Add(flowGlobalVariables); flow.Variables.Add(flowGlobalVariablesSchema); foreach (var state in subject.States) { FlowStep f; if (state.Type == PD_StateTypes.FunctionState) { var s = (PD_FunctionState)state; string timeout = ""; try { var timeouttransition = subject.Transitions.First(result => result.Source == s.Id && result.Type == PD_TransitionTypes.TimeoutTransition); timeout = ((PD_TimeoutTransition)timeouttransition).TimeSpan; } catch (Exception e) { } var transitions = subject.Transitions.Where(result => result.Source == s.Id && result.Type == PD_TransitionTypes.RegularTransition); List<string> titems = new List<string>(); transitions.ToList().ForEach(i => titems.Add(((PD_RegularTransition)i).Name)); f = new FlowStep() { Action = new FunctionStateT() { DisplayName = s.Name, OrderId = s.Id, name = s.Name, GlobalTransition = new OutArgument<string>(flowGlobalTransition), GlobalVariables = new InOutArgument<DynamicValue>(flowGlobalVariables), isEndState = s.EndState, readableParameters = collectionToString(s.ReadableParameters), editableParameters = collectionToString(s.EditableParameters), TimeOut = timeout, transitions = collectionToString(titems) } }; } else if (state.Type == PD_StateTypes.SendState) { var s = (PD_SendState)state; string timeout = ""; try { var timeouttransition = subject.Transitions.First(result => result.Source == s.Id && result.Type == PD_TransitionTypes.TimeoutTransition); timeout = ((PD_TimeoutTransition)timeouttransition).TimeSpan; } catch (Exception e) { } var message = process.Messages.First(result => result.Id == s.Message); string to = process.Subjects.First(result => result.Id == message.To).Name; f = new FlowStep() { Action = new SendStateT() { DisplayName = s.Name, OrderId = s.Id, name = s.Name, GlobalTransition = new OutArgument<string>(flowGlobalTransition), GlobalVariables = new InOutArgument<DynamicValue>(flowGlobalVariables), isEndState = s.EndState, readableParameters = collectionToString(s.ReadableParameters), editableParameters = collectionToString(s.EditableParameters), messageType = message.PD_MessageType.Name, parameters = collectionToString(message.PD_MessageType.Parameters), toSubject = to, TimeOut = timeout } }; } else //(state.Type == PD_StateTypes.ReceiveState) { var s = (PD_ReceiveState)state; string messages = ""; List<string> messagelist = new List<string>(); var receivetransitions = subject.Transitions.Where(result => result.Source == s.Id && result.Type == PD_TransitionTypes.ReceiveTransition); foreach (var i in receivetransitions) { messagelist.Add(receiveTranstionToString(process, (PD_ReceiveTransition)i)); } messages = collectionToString(messagelist); string timeout = ""; try { var timeouttransition = subject.Transitions.First(result => result.Source == s.Id && result.Type == PD_TransitionTypes.TimeoutTransition); timeout = ((PD_TimeoutTransition)timeouttransition).TimeSpan; } catch (Exception e) { } f = new FlowStep() { Action = new ReceiveStateT() { DisplayName = s.Name, OrderId = s.Id, name = s.Name, GlobalTransition = new OutArgument<string>(flowGlobalTransition), GlobalVariables = new InOutArgument<DynamicValue>(flowGlobalVariables), isEndState = s.EndState, TimeOut = timeout, messages = messages } }; } flow.Nodes.Add(f); nodeList.Add(state.Id, f); } var initGP = new FlowStep() { Action = new InitializeGlobalParameters() { DisplayName = "init GP", DynamicVal = new InOutArgument<DynamicValue>(flowGlobalVariables), GlobalParameterSchema = new InArgument<string>(flowGlobalVariablesSchema) } }; initGP.Next = nodeList[subject.States.First(result => result.StartState == true).Id]; flow.StartNode = initGP; // flow.StartNode = nodeList[subject.States.First(result => result.StartState == true).Id]; foreach (var state in subject.States) { List<PD_Transition> transitions = new List<PD_Transition>(); try { subject.Transitions.Where(result => result.Source == state.Id).ToList().ForEach(item => transitions.Add(item)); } catch (Exception e) { } if (transitions.Count > 0) { if (transitions.Count == 1) { var t = transitions[0]; nodeList[t.Source].Next = nodeList[t.Target]; } else { FlowSwitch<String> newSwitch = new FlowSwitch<String> { Expression = flowGlobalTransition }; flow.Nodes.Add(newSwitch); nodeList[state.Id].Next = newSwitch; try { var timeouttransition = transitions.First(result => result.Type == PD_TransitionTypes.TimeoutTransition); newSwitch.Cases.Add("TimeOut!", nodeList[timeouttransition.Target]); transitions.Remove(timeouttransition); } catch (Exception e) { } if (state.Type == PD_StateTypes.SendState) { newSwitch.Default = nodeList[transitions[0].Target]; } else if (state.Type == PD_StateTypes.ReceiveState) { foreach (var t in transitions) { newSwitch.Cases.Add(receiveTranstionToString(process, (PD_ReceiveTransition)t), nodeList[t.Target]); } } else { foreach (var t in transitions) { newSwitch.Cases.Add(((PD_RegularTransition)t).Name, nodeList[t.Target]); } } } } } ActivityBuilder builder = new ActivityBuilder(); builder.Name = "strICT.InFlowTest.WFProcesses." + process.Name + "." + subject.Name; builder.Implementation = flow; VisualBasic.SetSettings(builder, new VisualBasicSettings()); //StringBuilder sb = new StringBuilder(); StringWriterUtf8 stream = new StringWriterUtf8(); XamlWriter writer = ActivityXamlServices.CreateBuilderWriter(new XamlXmlWriter(stream, new XamlSchemaContext())); XamlServices.Save(writer, builder); string res = stream.GetStringBuilder().ToString(); res = res.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", ""); return res; }
public MyFlowSwitch(XElement e) { _elem = e; _activity = new FlowSwitch<string>(); _activity.DisplayName = _elem.Attribute("name").Value; }
private static void GetNextNodeofActivityWithoutParallel(IEnumerable<XElement> wfslElements, XElement currentXmlNode, FlowNode currentFlowNode, Dictionary<string, FlowNode> resultListNodes, Guid templateId) { try { var nextNodeId = GetXElementAttribute(currentXmlNode, "NextNodeID"); if (!string.IsNullOrEmpty(nextNodeId)) { if (!resultListNodes.ContainsKey(nextNodeId)) //避免有回路,已经添加过的节点不用再添加,否则会死循环 { var nextXmlNode = GetXmlNode(wfslElements, "UniqueID", GetXElementAttribute(currentXmlNode, "NextNodeID")); var nextNodeType = GetXElementAttribute(nextXmlNode, "WFSLElementType"); if (nextNodeType == "WFSLActivity") { var nextFlowNode = GetFlowStep(nextXmlNode); ((FlowStep)currentFlowNode).Next = nextFlowNode; resultListNodes.Add(GetXElementAttribute(nextXmlNode, "UniqueID"), nextFlowNode); SaveStateInfo(nextXmlNode, templateId, false); if (!string.IsNullOrEmpty(GetXElementAttribute(nextXmlNode, "DealWayName"))) { var dealWayType = 0; IEnumerable<XElement> result = from s in wfslElements where s.Attribute("Title").Value == nextXmlNode.Attribute("DealWayName").Value && s.Attribute("PointStateId").Value == nextXmlNode.Attribute("NextNodeID").Value select s; if (result != null) { int.TryParse(GetXElementAttribute(result.ToList<XElement>()[0], "DealWayType"), out dealWayType); } SaveDealWay(new Guid(GetXElementAttribute(nextXmlNode, "UniqueID")), Guid.NewGuid(), GetXElementAttribute(nextXmlNode, "DealWayName"), nextXmlNode, templateId, dealWayType); } GetNextNode(wfslElements, nextXmlNode, nextFlowNode, ref resultListNodes, templateId); } if (nextNodeType == "WFSLCondition") { var nextFlowNode = new FlowSwitch<string>(); resultListNodes.Add(GetXElementAttribute(nextXmlNode, "UniqueID"), nextFlowNode); ((FlowStep)currentFlowNode).Next = nextFlowNode; GetNextNode(wfslElements, nextXmlNode, nextFlowNode, ref resultListNodes, templateId); } if (nextNodeType == "WFSLFinish") { var nextFlowNode = GetEndNode(GetXElementAttribute(nextXmlNode, "Title"), GetXElementAttribute(nextXmlNode, "UniqueID")); ((FlowStep)currentFlowNode).Next = nextFlowNode; SaveStateInfo(nextXmlNode, templateId, false); resultListNodes.Add(GetXElementAttribute(nextXmlNode, "UniqueID"), nextFlowNode); } } else //该节点已经包含在内,只需要画上连线即可,即表明关系即可 { ((FlowStep)currentFlowNode).Next = resultListNodes[nextNodeId]; } } } catch (Exception ex) { LogWritter.WriteSystemExceptionLog(ex); } }
private static void GetNextNodeofFlowSwitch(IEnumerable<XElement> wfslElements, XElement currentXmlNode, FlowNode currentFlowNode, Dictionary<string, FlowNode> resultListNodes, Guid templateId) { try { var branches = GetXElementAttribute(currentXmlNode, "Branches"); ((FlowSwitch<string>)currentFlowNode).Expression = new VisualBasicValue<string> { ExpressionText = "DealWay" }; if (!string.IsNullOrEmpty(branches)) { var pairs = branches.Split(','); var dealWayCondtionCount = 0; foreach (var branch in pairs) { var dealWayName = branch.Split('$')[0]; var nextStateId = branch.Split('$')[1]; var dealformId = branch.Split('$')[2]; var resultiXmlNode = GetXmlNode(wfslElements, "UniqueID", nextStateId); var dealWayType = 0; foreach (XElement element in wfslElements) { if (GetXElementAttribute(element, "Title") == dealWayName && GetXElementAttribute(element, "PointStateId") == nextStateId) { int.TryParse(GetXElementAttribute(element, "DealWayType"), out dealWayType); } } if (resultiXmlNode != null) { dealWayCondtionCount++; var dealwayId = Guid.NewGuid(); if (!resultListNodes.ContainsKey(GetXElementAttribute(resultiXmlNode, "UniqueID"))) { var resultiXmlNodeType = GetXElementAttribute(resultiXmlNode, "WFSLElementType"); FlowNode nextFlowNode = new FlowStep(); if (resultiXmlNodeType == "WFSLActivity") { nextFlowNode = GetFlowStep(resultiXmlNode); if (dealWayCondtionCount == 1) { ((FlowSwitch<string>)currentFlowNode).Default = nextFlowNode; } else { // ((FlowSwitch<string>)currentFlowNode).Cases.Add(GetXElementAttribute(currentXmlNode,"DealWay" + i), nextFlowNode); ((FlowSwitch<string>)currentFlowNode).Cases.Add(dealwayId.ToString().ToUpper(), nextFlowNode); } SaveStateInfo(resultiXmlNode, templateId, false); if (!string.IsNullOrEmpty(GetXElementAttribute(resultiXmlNode, "DealWayName"))) { var resultDealWayType = 0; IEnumerable<XElement> resultDeal = from s in wfslElements where s.Attribute("Title").Value == GetXElementAttribute(resultiXmlNode, "DealWayName") && s.Attribute("PointStateId").Value == GetXElementAttribute(resultiXmlNode, "NextNodeID") select s; if (resultDeal != null && resultDeal.ToList<XElement>().Count > 0) { int.TryParse(GetXElementAttribute(resultDeal.ToList<XElement>()[0], "DealWayType"), out resultDealWayType); } SaveDealWay(new Guid(GetXElementAttribute(resultiXmlNode, "UniqueID")), Guid.NewGuid(), GetXElementAttribute(resultiXmlNode, "DealWayName"), resultiXmlNode, templateId, resultDealWayType); } resultListNodes.Add(GetXElementAttribute(resultiXmlNode, "UniqueID"), nextFlowNode); GetNextNode(wfslElements, resultiXmlNode, nextFlowNode, ref resultListNodes, templateId); } if (resultiXmlNodeType == "WFSLCondition") { nextFlowNode = new FlowSwitch<string>(); if (dealWayCondtionCount == 1) { ((FlowSwitch<string>)currentFlowNode).Default = nextFlowNode; } else { // ((FlowSwitch<string>)currentFlowNode).Cases.Add(GetXElementAttribute(currentXmlNode,"DealWay" + i), nextFlowNode); ((FlowSwitch<string>)currentFlowNode).Cases.Add(dealwayId.ToString().ToUpper(), nextFlowNode); } GetNextNode(wfslElements, resultiXmlNode, nextFlowNode, ref resultListNodes, templateId); } if (resultiXmlNodeType == "WFSLFinish") { nextFlowNode = GetEndNode(GetXElementAttribute(resultiXmlNode, "Title"), GetXElementAttribute(resultiXmlNode, "UniqueID")); if (dealWayCondtionCount == 1) { ((FlowSwitch<string>)currentFlowNode).Default = nextFlowNode; } else { //((FlowSwitch<string>)currentFlowNode).Cases.Add(GetXElementAttribute(currentXmlNode, "DealWay" + i), nextFlowNode); ((FlowSwitch<string>)currentFlowNode).Cases.Add(dealwayId.ToString().ToUpper(), nextFlowNode); } SaveStateInfo(resultiXmlNode, templateId, false); //保存流程结束 2012年9月21日 } SaveDealWay(dealwayId, dealWayName, currentXmlNode, templateId, dealformId, nextStateId, dealWayType); } else { if (dealWayCondtionCount == 1) { ((FlowSwitch<string>)currentFlowNode).Default = resultListNodes[GetXElementAttribute(resultiXmlNode, "UniqueID")]; } else { // ((FlowSwitch<string>)currentFlowNode).Cases.Add(GetXElementAttribute(currentXmlNode, "DealWay" + i), resultListNodes[GetXElementAttribute(resultiXmlNode, "UniqueID")]); ((FlowSwitch<string>)currentFlowNode).Cases.Add(dealwayId.ToString().ToUpper(), resultListNodes[GetXElementAttribute(resultiXmlNode, "UniqueID")]); } SaveDealWay(dealwayId, dealWayName, currentXmlNode, templateId, dealformId, nextStateId, dealWayType); } } } } } catch (Exception ex) { LogWritter.WriteSystemExceptionLog(ex); } }
//得到自定义流程图 public static flowcharStruct getFlowcharStruct(string xaml) { char[] sp = { ',' }; char[] sl = { ' ' }; //(1) WorkflowStruct.flowcharStruct flowcharStruct = new WorkflowStruct.flowcharStruct(); //(2) DynamicActivity dynamicActivity = tool.activityByXaml(xaml) as DynamicActivity; Activity activity = tool.getImplementation(dynamicActivity); Flowchart flowchar = activity as Flowchart; if (flowchar == null) { return(null); } //(3)===================================== //(3.1)---------------------------------------------------------------------------------- flowcharStruct.beginNode.DisplayName = "开始"; flowcharStruct.beginNode.id = "begin"; //(3.1.1) if (WorkflowViewStateService.GetViewState(flowchar)["ShapeLocation"] != null) { string ShapeLocation = WorkflowViewStateService.GetViewState(flowchar)["ShapeLocation"].ToString(); flowcharStruct.beginNode.ShapeSize.x = double.Parse(ShapeLocation.Split(sp)[0]); flowcharStruct.beginNode.ShapeSize.y = double.Parse(ShapeLocation.Split(sp)[1]); } //(3.1.2) if (WorkflowViewStateService.GetViewState(flowchar)["ShapeSize"] != null) { string ShapeSize = WorkflowViewStateService.GetViewState(flowchar)["ShapeSize"].ToString(); flowcharStruct.beginNode.ShapeSize.width = double.Parse(ShapeSize.Split(sp)[0]); flowcharStruct.beginNode.ShapeSize.height = double.Parse(ShapeSize.Split(sp)[1]); } //(3.1.3) if (WorkflowViewStateService.GetViewState(flowchar)["ConnectorLocation"] != null) { string ConnectorLocation = WorkflowViewStateService.GetViewState(flowchar)["ConnectorLocation"].ToString(); string[] points = ConnectorLocation.Split(sl); WorkflowStruct.line oneline = new WorkflowStruct.line(); oneline.beginNodeID = flowchar.Id; oneline.text = flowchar.DisplayName; foreach (string item in points) { double x = double.Parse(item.Split(sp)[0]); double y = double.Parse(item.Split(sp)[1]); oneline.connectorPoint.Add(new WorkflowStruct.point() { x = x, y = y }); } flowcharStruct.lineList.Add(oneline); } //(3.2)-------------------------------------------------------------------------------- foreach (FlowNode flowNode in flowchar.Nodes) { FlowStep flowStep = flowNode as FlowStep; if (flowStep != null) { WorkflowStruct.node node = new WorkflowStruct.node(); node.DisplayName = flowStep.Action.DisplayName; node.id = flowStep.Action.Id; //(3.2.1) if (WorkflowViewStateService.GetViewState(flowStep)["ShapeLocation"] != null) { string ShapeLocation = WorkflowViewStateService.GetViewState(flowStep)["ShapeLocation"].ToString(); node.ShapeSize.x = double.Parse(ShapeLocation.Split(sp)[0]); node.ShapeSize.y = double.Parse(ShapeLocation.Split(sp)[1]); } //(3.2.2) if (WorkflowViewStateService.GetViewState(flowStep)["ShapeSize"] != null) { string ShapeSize = WorkflowViewStateService.GetViewState(flowStep)["ShapeSize"].ToString(); node.ShapeSize.width = double.Parse(ShapeSize.Split(sp)[0]); node.ShapeSize.height = double.Parse(ShapeSize.Split(sp)[1]); } //(3.2.3) if (WorkflowViewStateService.GetViewState(flowStep).Count(p => p.Key == "ConnectorLocation") == 1) { string ConnectorLocation = WorkflowViewStateService.GetViewState(flowStep)["ConnectorLocation"].ToString(); string[] points = ConnectorLocation.Split(sl); WorkflowStruct.line line = new WorkflowStruct.line(); line.beginNodeID = flowStep.Action.Id; line.text = flowStep.Action.DisplayName; foreach (string item in points) { double x = double.Parse(item.Split(sp)[0]); double y = double.Parse(item.Split(sp)[1]); line.connectorPoint.Add(new WorkflowStruct.point() { x = x, y = y }); } flowcharStruct.lineList.Add(line); } flowcharStruct.nodeList.Add(node); } } //(3.3)------------------------------------------------------------- foreach (FlowNode flowNode in flowchar.Nodes) { FlowSwitch <string> flowSwitch = flowNode as FlowSwitch <string>; if (flowSwitch != null) { WorkflowStruct.node node = new WorkflowStruct.node(); node.DisplayName = flowSwitch.Expression.DisplayName; node.id = flowSwitch.Expression.Id; //(3.3.1) if (WorkflowViewStateService.GetViewState(flowSwitch)["ShapeLocation"] != null) { string ShapeLocation = WorkflowViewStateService.GetViewState(flowSwitch)["ShapeLocation"].ToString(); node.ShapeSize.x = double.Parse(ShapeLocation.Split(sp)[0]); node.ShapeSize.y = double.Parse(ShapeLocation.Split(sp)[1]); } //(3.3.2) if (WorkflowViewStateService.GetViewState(flowSwitch)["ShapeSize"] != null) { string ShapeSize = WorkflowViewStateService.GetViewState(flowSwitch)["ShapeSize"].ToString(); node.ShapeSize.width = double.Parse(ShapeSize.Split(sp)[0]); node.ShapeSize.height = double.Parse(ShapeSize.Split(sp)[1]); } //(3.3.3) if (WorkflowViewStateService.GetViewState(flowSwitch).Count(p => p.Key == "Default") == 1) { string ConnectorLocation = WorkflowViewStateService.GetViewState(flowSwitch)["Default"].ToString(); string[] points = ConnectorLocation.Split(sl); WorkflowStruct.line line = new WorkflowStruct.line(); line.beginNodeID = flowSwitch.Expression.Id; line.text = flowSwitch.Expression.DisplayName; foreach (string item in points) { double x = double.Parse(item.Split(sp)[0]); double y = double.Parse(item.Split(sp)[1]); line.connectorPoint.Add(new WorkflowStruct.point() { x = x, y = y }); } flowcharStruct.lineList.Add(line); } //(3.3.4) foreach (var v in flowSwitch.Cases) { System.Activities.Statements.FlowNode next = v.Value; System.Console.WriteLine(v.Key); string caseValue = v.Key + "Connector"; if (WorkflowViewStateService.GetViewState(flowSwitch).Count(p => p.Key == caseValue) == 1) { string ConnectorLocation = WorkflowViewStateService.GetViewState(flowSwitch)[caseValue].ToString(); string[] points = ConnectorLocation.Split(sl); WorkflowStruct.line line = new WorkflowStruct.line(); line.beginNodeID = flowSwitch.Expression.Id; line.text = flowSwitch.Expression.DisplayName; foreach (string item in points) { double x = double.Parse(item.Split(sp)[0]); double y = double.Parse(item.Split(sp)[1]); line.connectorPoint.Add(new WorkflowStruct.point() { x = x, y = y }); } flowcharStruct.lineList.Add(line); } } flowcharStruct.nodeList.Add(node); } } return(flowcharStruct); }//end
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 } }); }