Presentation is loading. Please wait.

Presentation is loading. Please wait.

Developing Event Driven State Machine Workflows S1 S2 S3 S4 Adam Calderon Principal Engineer - Interknowlogy Microsoft MVP – C#

Similar presentations


Presentation on theme: "Developing Event Driven State Machine Workflows S1 S2 S3 S4 Adam Calderon Principal Engineer - Interknowlogy Microsoft MVP – C#"— Presentation transcript:

1 Developing Event Driven State Machine Workflows S1 S2 S3 S4 Adam Calderon Principal Engineer - Interknowlogy Microsoft MVP – C#

2 Session Objectives And Key Takeaways Objectives What is Windows Workflow Foundation Why State Machine Workflows State Machine Workflow Structure The State Activity The Event Driven Activity The Set State Activity Skip and Rework Patterns Dynamic Updates to State Machines Key Takeaways State machine as a powerful modeling paradigm

3 Agenda State Machine Workflow Introduction Building State Machine Workflows Recursive Composition Skip and Rework Pattern Additional State Machine Patterns SummaryQ&A

4 Types of Business Processes Control flow processes Are self driven once they are initiated The set of events that may happen are highly predictable Mostly sequential in nature Highly suitable for process automation Event Driven processes Are driven by external events Must be able to respond to any high priority event even if the some other work is in process The sequence of events may not be predictable The process can jump to any step in the process Highly suitable for processes where human actions are involved

5 What Do State Machines Workflows Offer Provide an effective modeling paradigm for Event driven processes Provide a natural paradigm for the business users to express business intent Business users always think in terms of logical states of the process, possible events in those states and actions in response to the events Provide an easy way to query and visualize the process The current state of the process is the current state of the state machine The set of possible transitions from the current state can be easily obtained Provide very powerful business exception handling State Machines are a familiar paradigm for IT professionals

6 When to Use State Machine Workflow State Machine workflow provides a very powerful design paradigm Not all processes can be modeled using State Machines Use it when there is a lot of human interactions with the process Use it when the workflow is driven by external events Use it when there is a lot of out of band events that can be received in the workflow Use it when it is hard to wire all the possible paths within the process in a sequential workflow

7 Basic Concepts of State Machine Workflows The basic elements of a state machine workflow StatesEventsActionsTransitions A state machine workflow is composed of a set of states In a given state a set of events can be received Based on the event received an action is performed at the end of which a state transition may or may not be made

8 Example : A Simple PO Process On Order CreatedOn Order Approved Order Created Order Approved Order Shipped On Order Shipped On Order Completed On Order Completed Waiting to Create Order On Order Completed On Order Shipped Order Completed

9 A Purchase Order State Machine Workflow Developing Event Driven State Machine Workflows

10 Agenda State Machine Workflow Introduction Building State Machine Workflows Recursive Composition Skip and Rework Pattern Additional State Machine Patterns SummaryQ&A

11 State Machine Implementation in WinWF The state machine workflow is a root activity like the sequential workflow There are 4 activities which work in the state machine workflow State -- Represents the state of the state machine Event Driven – Used to handle an event in a given state Set State – Used to transition from one state to another State Initialization – Used for default action on entering a state Event Driven State Machine Workflow Event Driven State Initialization State Set State State

12 State Machine Workflow Activities The State Activity The state activity represents a logical state of the state machine It can contain a collection of event driven activities To be in a particular state in the state machine means to execute that state activity The state activity can also contain the State Initialization activity The state initialization activity is optional and if present is executed by default Event Driven State Initialization State Set State State

13 How to Design a State The State is the logical state of the process E.g. Order Shipped, Document Approved The State is similar to a milestone in a process Is a natural fit as a tracking point for a process The state machine workflow can only be in one logical state at any point in time In a given state the process may receive only a valid set of events E.g. publish document event in the document approved state

14 Initial State and Completed State A state machine workflow must have a start state This is the state in which the state machine will be when the state machine instance is created A state machine workflow can have a completed state When the workflow reaches the completed state the workflow instance stops executing The Start state and completed state can be specified as properties on the root state machine workflow activity

15 State Machine Workflow Activities: The Event Driven Activity The event driven activity is used to handle an event received in a particular state The event driven activity is common to State machine and sequential workflows An event driven activity is a composite activity which behaves like a sequence with some additional attributes Must have the first activity as an activity that receives an event or a delay activity Cannot contain any other activity that receives an event Event Driven Set State Receive Event / Delay Action

16 Non Blocking Execution of the Event Driven Activity The event driven activity execution in a state machine workflow must be non blocking If the event driven execution is blocked other event may happen which may invalidate the current state and hence the execution of the event handler The state machine workflow enforces this pattern by allowing only one event receive activity

17 State Machine Workflow Activities The Set State Activity The set state activity causes the actual transition from one state to another The set state activity must be used inside an event driven activity The set state activity must be the last executing activity in the event handler The pattern enforced here is that an event is handled any needed actions performed and then a transition is made There can be multiple set state activities (For e.g. in an if/else activity) but each one of them must be the last one to execute in the event handler

18 Purchase Order State Machine Workflow a Deeper Look Developing Event Driven State Machine Workflows

19 Agenda State Machine Workflow Introduction Building State Machine Workflows Recursive Composition Skip and Rework Pattern Additional State Machine Patterns SummaryQ&A

20 Recursive Composition of States in a State Machine States activities can be recursively composed When a state activity contains other states then that state cannot be transitioned to Transition is only allowed to a leaf level state Recursive composition provides a very powerful design pattern Help in business exception handling Help in reuse of event handlers where the same event needs to be handled in multiple states

21 PO Process Revisited On Order Changed Order Changed On Order CreatedOn Order Approved Order Created Order Approved Order Shipped On Order Shipped On Order Completed On Order Completed Waiting to Create Order On Order Completed On Order Shipped Order Completed

22 Recursive State Composition Developing Event Driven State Machine Workflows

23 Agenda State Machine Workflow Introduction Building State Machine Workflows Recursive Composition Skip and Rework Pattern Additional State Machine Patterns SummaryQ&A

24 Ability to query the workflow model The ability to query the model is a very crucial is creating effective workflow visualizations State machine workflow offers a robust infrastructure to query and interact with a workflow instance You can answer queries like What is the current state of the workflow? What transitions are possible from the current state? Enumerate all the states in the workflow?

25 Skip and Rework Patterns Workflow involves ad hoc steps that may not be modeled in advance E.g. In the PO process the PO creator may want to skip the approval action E.g. The PO creator may want to send the PO through an extra approval; The State machine workflow has a built in mechanism to reset the state of the state machine to desired state

26 On Order Changed Order Changed On Order CreatedOn Order Approved Order Created Order Approved Order Shipped On Order Shipped On Order Completed On Order Completed Waiting to Create Order On Order Completed On Order Shipped Order Completed PO Process – Skip & Rework Set State Event

27 Skip and Rework Pattern Developing Event Driven State Machine Workflows

28 Agenda State Machine Workflow Introduction Building State Machine Workflows Recursive Composition Skip and Rework Pattern Additional State Machine Patterns SummaryQ&A

29 Dynamic Change Patterns Dynamic change is the ability to make structural changes to the process In the state machine dynamic change can be introduced at several levels Add a new state to the state machine Handle a new event in a particular state Rewire the state transitions The dynamic update to the state machine follows the same steps as for a sequential workflow

30 Multiple State Machines in an application An application is hardly made up of one workflow Multiple workflows work in tandem within an application These workflows can be autonomous but cooperating with each other They synchronize their states but not necessarily control the lifetimes of other workflows Order Fulfillment Application S1 S2 S3 S4 S1 S2 S3 S4 S1 S2 S3 S4 Order Approval Order Shipment WarehouseProcesses

31 Summary State Machine workflows are a key innovation in WinWF State machine workflows provide a very powerful tool for modeling business applications Use it when the process to be implemented has a lot of human interaction in it The state machine is very easy to query and visualize The state machine model and sequential model and complimentary

32 Adam Calderon More info on InterKnowlogy More info on InterKnowlogy Contact Information Contact Information Phone: x274 Blog: About Adam Calderon Microsoft ® MVP – C# Microsoft ® ASP.NET (UI Server Frameworks) Advisory Council Developer / Author / Speaker

33


Download ppt "Developing Event Driven State Machine Workflows S1 S2 S3 S4 Adam Calderon Principal Engineer - Interknowlogy Microsoft MVP – C#"

Similar presentations


Ads by Google