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); }
static void Main(string[] args) { Console.WriteLine("◆実行したいワークフローを選択してください。"); Console.WriteLine(" 1: Sequenceのサンプル"); Console.WriteLine(" 2: Flowchartのサンプル"); Console.WriteLine(" 3: StateMachineのサンプル"); Console.Write("何番を実行しますか?:"); var num = Console.ReadLine(); Console.WriteLine(""); Activity act; if (num == "1") { act = new Sequence(); } else if (num == "2") { act = new Flowchart(); } else if (num == "3") { act = new StateMachine(); } else { throw new NotSupportedException(); } //ワークフローの実行 WorkflowInvoker.Invoke(act); }
internal override void OnOpen(Flowchart owner, NativeActivityMetadata metadata) { if (this.Condition == null) { metadata.AddValidationError(SR.FlowDecisionRequiresCondition(owner.DisplayName)); } }
// Returns true if this is the first time we've visited this node during this pass internal bool Open(Flowchart owner, NativeActivityMetadata metadata) { if (this.cacheId == owner.CacheId) { // We've already visited this node during this pass if (!object.ReferenceEquals(this.owner, owner)) { metadata.AddValidationError(SR.FlowNodeCannotBeShared(this.owner.DisplayName, owner.DisplayName)); } // Whether we found an issue or not we don't want to change // the metadata during this pass. return false; } // if owner.ValidateUnconnectedNodes - Flowchart will be responsible for calling OnOpen for all the Nodes (connected and unconnected) if (!owner.ValidateUnconnectedNodes) { OnOpen(owner, metadata); } this.owner = owner; this.cacheId = owner.CacheId; this.Index = -1; return true; }
public static ActivityBuilder GetActivityBuilder(string templateName, FlowNode startNode, Dictionary<string, FlowNode> resultListNodes, int numofParallelBranches) { var body = new Flowchart() { DisplayName = templateName, StartNode = startNode }; GetWfNodes(resultListNodes, ref body); body.Variables.Add(new Variable<int>("ParallelBranchesCount") { Default = numofParallelBranches }); var activityBuilder = new ActivityBuilder(); activityBuilder.Name = "WfXamlTemplate"; activityBuilder.Properties.Add(new DynamicActivityProperty { Name = "FlowDataParm", Type = typeof(InArgument<FlowData>) }); activityBuilder.Properties.Add(new DynamicActivityProperty { Name = "NextDeptType", Type = typeof(InArgument<string>) }); activityBuilder.Properties.Add(new DynamicActivityProperty { Name = "DealWay", Type = typeof(InArgument<string>) }); activityBuilder.Implementation = body; return activityBuilder; }
internal bool Open(Flowchart owner, NativeActivityMetadata metadata) { if (this.cacheId == owner.CacheId) { if (!object.ReferenceEquals(this.owner, owner)) { metadata.AddValidationError(System.Activities.SR.FlowNodeCannotBeShared(this.owner.DisplayName, owner.DisplayName)); } return false; } this.OnOpen(owner, metadata); this.owner = owner; this.cacheId = owner.CacheId; this.Index = -1; return true; }
public void FlowchartInitializerSyntax_Sequence() { Test.Common.TestObjects.CustomActivities.WriteLine writeLine1 = new Test.Common.TestObjects.CustomActivities.WriteLine { Message = new InArgument <string>("Hello1") }; Test.Common.TestObjects.CustomActivities.WriteLine writeLine2 = new Test.Common.TestObjects.CustomActivities.WriteLine { Message = new InArgument <string>("Hello2") }; Test.Common.TestObjects.CustomActivities.WriteLine writeLine3 = new Test.Common.TestObjects.CustomActivities.WriteLine { Message = new InArgument <string>("Hello3") }; FlowStep flowStep1 = new FlowStep { Action = writeLine1 }; FlowStep flowStep2 = new FlowStep { Action = writeLine2, Next = flowStep1 }; FlowStep flowStep3 = new FlowStep { Action = writeLine3, Next = flowStep2 }; System.Activities.Statements.Flowchart flowchart = new System.Activities.Statements.Flowchart { Nodes = { flowStep1, flowStep2, flowStep3 }, StartNode = flowStep3 }; AutoResetEvent are = new AutoResetEvent(false); WorkflowApplication application = new WorkflowApplication(flowchart) { Completed = delegate(WorkflowApplicationCompletedEventArgs e) { are.Set(); } }; application.Run(); are.WaitOne(); }
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); }
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 WorkflowHelperCompileExpressionsWithActivityExpectedCompilesExpressionsAddsToCacheThenInvalidate() { const string ExpressionParams = "(\"\",AmbientDataList)"; var fsa = new DsfFlowSwitchActivity { ExpressionText = GlobalConstants.InjectedSwitchDataFetchOld + ExpressionParams }; var fda = new DsfFlowDecisionActivity { ExpressionText = GlobalConstants.InjectedDecisionHandlerOld + ExpressionParams }; var startNode = new FlowStep { Action = new CommentActivityForTest() }; var chart = new Flowchart { StartNode = startNode }; chart.Nodes.Add(startNode); chart.Nodes.Add(new FlowDecision(fda)); chart.Nodes.Add(new FlowSwitch<string> { Expression = fsa }); var workflow = new DynamicActivity { Implementation = () => chart }; var guid = Guid.NewGuid(); new WorkflowHelper().CompileExpressions(workflow, guid); // No exception thrown means compilation worked var compiledExpressionRoot = CompiledExpressionInvoker.GetCompiledExpressionRootForImplementation(workflow) as ICompiledExpressionRoot; Assert.AreEqual(GlobalConstants.Resultscache.Count, 1); GlobalConstants.InvalidateCache(guid); Assert.AreEqual(GlobalConstants.Resultscache.Count, 0); Assert.IsNotNull(compiledExpressionRoot); }
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; }
internal abstract void OnOpen(Flowchart owner, NativeActivityMetadata metadata);
internal override void OnOpen(Flowchart owner, NativeActivityMetadata metadata) { }
public static void GetWfNodes(Dictionary<string, FlowNode> flowNodes, ref Flowchart flowChart) { foreach (FlowNode flowNode in flowNodes.Values) { if (!flowChart.Nodes.Contains(flowNode)) { flowChart.Nodes.Add(flowNode); } } }