Workflow Foundation 4

21
For more information see www.bbd.co.za and www.drp.co.za Workflow Foundation 4

description

An introduction to Windows Workflow Foundation (WF) in .NET 4

Transcript of Workflow Foundation 4

  • 1. Setup Visual Studio Rule 18

2. Workflow Foundation 4 3. 10110000 01100001 What is WF4? MOV AL, 61h Console.WriteLine(Hello!); 4. Why is a picture better? Highlights missing/not completed areas Easy to Understand Patterns 5. Simplify complex patterns Multiple Branches Running in parallel 6. NO... Its bigger than that So its a code visualiser? 7. Evolution 8. Code Activity Ruleset What was lost? 9. Isolation Workflow instances are isolated from the host application and each other. Workflows are not aware of information in the application other than what is passed to it. Threaded Instances are separately threaded from your main thread. Important Concepts 10. Workflow Foundation Demo 11. New Project -> .NET 4 -> Workflow Console App -> OK Drag a WriteLine on -> Set text to "Hello" Run (Ctrl+F5) single activity issue demo: Now try drag on another writeline Remove writeline, bring on a sequence and put two writelines with different messages Add Argument -> Name: Firstname, Direction: In, Type: string Drag a If on (should be only thing on surface) - condition is: String.IsNullOrWhiteSpace(FirstName) Drag a writeline to true and set text to: "Hello, stranger" Drag a writeline to false and set text to: "Hello, " & FirstName Run it - note that it runs stranger Program.cs - explain what is happening Change main to (Ctrl+1):Workflow1 workflow = new Workflow1(); workflow.FirstName = "Robert"; WorkflowInvoker.Invoke(workflow); Run Create new PUBLIC class Person. Add string property FirstName. Build Delete the current workflow argument Add new arguement name=person, direction=in, type=Person Change if condition to: String.IsNullOrWhiteSpace(person.FirstName)Change else writeline: "Hello, " & person.FirstName Build Change main to (Ctrl+2):Person person = new Person(); person.FirstName = "Robert"; Workflow1 workflow = new Workflow1(); workflow.person = person; WorkflowInvoker.Invoke(workflow); Run and fail! 12. Change main to (Ctrl+3): Person person = new Person(); person.FirstName = "Robert"; Dictionary parameters = new Dictionary(); parameters.Add("person", person); Workflow1 workflow = new Workflow1(); WorkflowInvoker.Invoke(workflow, parameters); Run 13. Alternative Hosts 14. WorkflowInvoker.Invoke(newWorkflow1()); Alternative Hosts WorkflowApplicationwfApp=newWorkflowApplication(newWorkflow1());wfApp.Run(); Uriuri=newUri("http://localhost:8080/Workflow");WorkflowServiceHostwfHost=newWorkflowServiceHost(newWorkflow1(),uri);wfHost.Open(); 15. Types of Workflow Sequential State* Flow Chart * http://wf.codeplex.com/ 16. Flow chart 17. Remove everything from workflow Drag a flow chart on Drag a flow decision Link start to decision Set decision condition to: String.IsNullOrWhiteSpace(person.FirstName) Show tooltop and tooltip sticky Drag two writelines on and link one to true and one to false true writeline text: "Hello, stranger" false writeline text: "Hello, " & person.FirstName Run Link false writeline to true writeline run 18. Custom activities 19. Add new item -> Code activity Set value to (Ctrl+4) public InArgument FirstName { get; set; } // If your activity returns a value, derive from CodeActivity // and return the value from the Execute method. protected override void Execute(CodeActivityContext context) { // Obtain the runtime value of the Text input argument Console.WriteLine(this.FirstName.Get(context)); } Build Drag CodeActivity onto flowchart and link it to true writeline run 20. Passing Data Application Global Instance Variables Database, MSMQ, File, etc Workflow 21. Services Personperson=newPerson();person.FirstName="Robert";Dictionaryparameters=newDictionary();parameters.Add("person",person);Workflow1workflow=newWorkflow1();StringWriterwriter=newStringWriter();WorkflowInvokerinvoker=newWorkflowInvoker(workflow);invoker.Extensions.Add(writer);invoker.Invoke(parameters); 22. Services - Persistence Application Application Workflow Runtime Workflow Runtime Wait for event 2o kb Instance C 20 Mb - Executing Instance A 20Mb 1 Week Instance C 20 Mb - Executing Instance B 20Mb Event Delay 1 week 2o kb SQL Database Before After 23. Services - Persistence Application Application Workflow Runtime Workflow Runtime Wait for event 2o kb Instance B Sleeping 20Kb Instance C 20 Mb - Executing Instance A 20Mb 1 Week Instance C 20 Mb - Executing Delay 1 week 2o kb SQL Database Before After 24. When? Persist On Idle Persist On Command No Persist Zones Options? Persist Only Persist + Unload Where? SQL Custom Services - Persistence 25. Allows the WF Engine to share/store information on the workflows.Storage is, by default, to SQL but can be anywhere. Uses: Real time monitoring Reviewing completed workflows For Bugs/supporting For KPI/Metrics For Auditing Services - Tracking 26. Security Pack State Machine ADO.NET Migration Kit wf.codeplex.com