Saturday, December 26, 2009

Workflow Without Windows Workflow

Hello, it has been a while since I wrote my last blog. Anyway, I am back again. I have a nice blog today, I have been working for a while with a team which his main target is to use everything Microsoft has released. It is a good thing sometimes and a very bad thing the other times. They read a "workflow" word in the requirements document, the first came to their mind was WF (Windows Workflow Foundation). The problem was so simple using WF would be over engineering. So, I decided to think of a more simple solution. As I am a Spring.NET Freak and I think we can't build an application without using it, I thought of using it :).

First, Let us create a State class first:

publicclassState

{

privatestring _id;

privatestring _name;

privateList<link> _links;

publicList NextStates

{

get

{

return Links.Select(l => l.State).ToList();

}

}

publicstring Id

{

get { return _id; }

set { _id = value; }

}

publicList<link> Links

{

get { return _links; }

set { _links = value; }

}

publicstring Name

{

get { return _name; }

set { _name = value; }

}

publicbool IsEndState

{

get

{

return Links.Count == 0;

}

}

}

And a Link class:

publicclassLink

{

//this condition will written used SPEL (Spring Expression Langauge)

publicstring Condition { get; internalset; }

public State State { get; internalset; }

}

Then create the interface for the state machine:

publicinterfaceIStateMachine

{

State InitialState { get; }

State CurrentState { get; }

void SetCurrentState(string id);

bool Advance();

List NextStates { get; }

}

Then comes spring to the rescue, Spring here will used for 2 main tasks:

Configuration File for our Workflow (State Machine): Keeps the state information and the transitions between states.

Spring Expression will be used to define the transition rules between different states.

I decided to implement a simple interview process as an illustration for my small framework:

The spring configuration file for the mentioned process will be as follows: