Saturday, July 21, 2007

Introducing Windows Workflow Foundation

This is a brief post introducing Windows Workflow Foundation - We will try to introduce basic concepts and definitions. We will know also why Workflow Foundation can be useful for building large scale projects.




Workflow - Concept & Definition

First let's start by defining Workflow as a word - according to wikipedia definition: "A workflow is a reliably repeatable pattern of activity enabled by a systematic organization of resources, defined roles and mass, energy and information flows, into a work process that can be documented and learned". In workflow-based projects you have a certain flow defines a specific organization or business process. Through this flow, you can't do a certain step in this business flow without making sure that one or more pre-request steps are completed.

If you think a little about this model, you will find most of the applications you develop daily can fit in this definition. You have a certain logic and business rules you want to automate. Ideal Examples will include: Document Management Applications, Insurance/Financial Applications, Governmental Projects and Customer-Relationship Management Applications.

This type of applications have some specific characteristics. These applications has high rate/cost of change over time. Your client may come after a while saying that the flow of the application is to be modified. He needs to add another step inside the current flow which is not currently exist. He wants to remove a flow path. He wants to manage more information on his business flow.

This also make us think about the usability. You're not using the flow one time. Suppose you build an automation software for a Hospital and you still get many deals for the same industry. In most of the cases, the features will be common for the same projects in the same industry field. You may need a way to build a flow once and use it as more as you need for any kind of projects serving the Medical industry for instance. It's all about productivity. Building once and use whenever you need.


Windows Workflow Foundation

WWF - Windows Workflow Foundation - is a solution provided in .NET 3.0 to solve most of these problems. You're able to define your organization flow in a graphical way using Workflow Designer Component which can be hosted - not only on Visual Studio - but on any other hosting applications you may develop. This gives you some kind of extensibility of building your own flow and enables business administrators or manager to change the business flow even on-the-fly.

Another side of extensibility that you can build your own libraries for domain specific activities. This help in increasing your development usability and so the productivity.

The extensibility is not limited for this point. The Workflow runtime is the engine which handle the creation of the Workflow Instances. Extensibility applies here as well. You may extend the behavior of the runtime itself. You may change the default way of persistence. You may want to change the persistence so that you don't save the state of the workflow on the database and decide to persist it on another media like XML or whatever.

Windows Workflow Process Types

Let's talk about the workflow types provided by WF. WF provides two types of workflow. The first one is called Sequential Workflow. This one will be your choice when you know exactly the predefined path your application should follow. This type is most like a flowchart. You have conditions, loops and rules stuff which control the desired flow of your workflow.

The second type is called: State-Machine Workflow. Here you have a collections of states and you define the flow so that state-A will go to state-B - if and only if - a certain event or trigger is raised. This kind of flow helps when you don't have a predefined flow and states may go to many other states in non-ordered way.

What the best model of building workflow-based applications? The best model for this kind of projects is MVC model - Model View Controller. The model here is mapped to the "Workflow" engine, the View is your UI and the Controller is controlling the flow between the Model and View. So that, the UI (View) don't know that it's controlled by the Workflow engine and vise versa - the Workflow doesn't know that it controls the UI.


Starting Up

You will need - .NET Framework 3.0 or higher - installed on your machine and - Workflow extension - for Visual Studio 2005. The last one will include the Workflow Designer for Visual Studio 2005 - this is not compatible with Visual Studio Express Edition - and project templates for building workflow projects. You start building your flow using the Workflow Designer. Your flow can be represented on either XML or Code. For XML, you will have an XML representation of your workflow in an *.xoml file. This is best solutions if you may change this XML later or even auto generate it with any other tools. The other representation is representing the Workflow as Code. Your workflow will be represented as a class which you can use when instantiating workflow instances using Workflow Runtime.

kick it on DotNetKicks.com

0 comments: