Implementing Windows Workflow Foundation and a custom State Machine

07 July, 2014 · 2 minutes to read · written by Craig Pickles

In today's business world workflow is an integral part of any business process software. In Magnifica’s Fibre framework workflow is implemented using a combination of two different approaches

  • State Machine
  • Sequential Workflow

Using a mix of these approaches we are able to quickly map complex business processes in the bespoke software we develop. In this post we describe how each approach is used and how the interact.

State machine

A state machine stores the status of something at a given time and can operate on input to change the status and/or cause an action or output to take place for any given change.

A simple state machine workflow is used to represent a set of states and transitions that can be implemented on an object within the business domain. For example a support request within a customer support system.

Within the Fibre Framework state machine, states are defined that describe each state the domain object can be in. Also transitions are defined for the possible changes between these states.

Going back to the customer support system example a support request could have the following states:

  • New
  • In progress
  • With customer
  • Completed

Each other these states must have at least one transition, unless it is a final state in which case it will have none (i.e. completed), for example the “New” state might have the following transitions:

  • Respond to client (moves the state from “New” to “With customer”)
  • Notify technical team to undertake work (moves the state from “New” to “In progress”)

The State Machine workflow transitions are typically triggered by user actions and can be selected in any order, within the constraints defined by the states. This means the workflow can be never ending, to further understand this we could add an additional sate for re-opening a support request i.e. removing any final states.

Sequential workflow

A sequential workflow represents a series of steps where the steps are performed one after another until the last activity is completed. Typically these steps are completed straight after each other. However, items within the workflow can be completed in parallel and it is also possible to wait for external processes to take place before moving onto the next step.

Within the Fibre Framework sequential workflows are linked to transitions within a domain object’s State Machine and are used to complete a set of tasks either before or after the transition between states.

For example, after a support request state has been changed (via the State Machine) from “In progress” to “Completed” a sequential workflow might be used to lock the support request and send notifications to the individuals involved in the request.

Implementing sequential workflow in this way means we can leverage the workflow designer interface within Visual Studio. This makes it simpler to visualise and change workflow later by adding, removing or updating a workflow activity on the diagram.

Fibre Framework

Fibre uses the latest workflow technology from Microsoft, Windows Workflow Foundation, to create sequential workflows. Windows Workflow Foundation provides the ability to explicitly/declaratively model a workflow rather than embedding logic within the application code. This allows the workflow to be easily visualized, tracked and changed (even at runtime). It also enforces logic to be loosely coupled with the rest of the application.

So when it comes to implementing workflow at Magnifica we use Windows Workflow Foundation for Sequential Workflow and a bespoke State Machine's for each object within in a system that requires state based workflow.

There are lots of ways to implement workflow in bespoke software however if you want workflow that is maintainable and extensible your workflow needs to be implemented using the best available methods and tools. We invest in the latest technologies like WWF and our own State Machine.