Friday, May 23, 2014

Cross-stage workflows for beginners. Part II. WorkflowDesigner in Visual Studio

Hi everyone!
As I wrote in previous part, we are studying to program cross-stage workflows. Today we'll look at how it implements by more powerful instrument - Visual Studio 2012.

In Visual Studio there is a special mechanism for that purposes, which came from discrete mathematics - (finite)-state machine (wikipedia). A state machine is a "machine" that can take a finite number of states. And there is a one special state that determines the result of state machine work - final state. After modeling our business-logic states, representing these states as state-machine states, we can implement it in Visual Studio.

Create a workflow item:



And drag and drop StateMachine activity to the workflow pane (sequence):


Then drop one or more State activity to that. Double-click and you can define trigger actions before state-changing (Entry) and after it (Exit):



Transitions settings are similar:


And of course you must determine a final state and a transition to it to eliminate a possibility of endless loop.
As a result you will get something like this:

If you define a boolean variable and set it to different transitions, you may get an interest WorkflowTerminatedException: "The workflow instance exceeded the throttle of 10000 activities executed in a row and could not be unloaded because it was not persistable".


 
That's all, folks!

No comments:

Post a Comment