views:

46

answers:

1

Long version: What would be the essential elements/components of a workflow to be implemented in C# (without using any part of WF 3.5 or WF 4)?

Note I: I want to implement a master-slave communication where server-side is always passive(slave) and my workflow mainly performs tasks related to such communication scheme.

Note II: Since in my project it is decided that we will not use WF 4 (IMHO a right decision), I need some design guide-lines in implementing a (simple) workflow toolbox.

Thanks

A: 

If you don't want to use Workflow foundation you can create your workflow as implementation of GOF State pattern.

Simple implementation:

public class Workflow
{
  internal IState Current { get; set; }

  public void Start()
  {
     Current = new StartState();
     Current.Start(this);
  }

  public void DoSomething()
  {
     Current.DoSomething(this);
  }

  public void DoSomethingElse()
  {
     Current.DoSomethingElse(this);
  }
}

public interface IState
{
  Start(Workflow context);
  DoSomething(Workflow context);
  DoSeomethingElse(Workflow context);
}

public abstract BaseState : IState
{
  public virtual void Start(Workflow context)
  {
    throw new InvalidStateOperationException(); 
  }

  public virtual void DoSomething(Workflow context)
  {
    throw new InvalidStateOperationException(); 
  }

  public virtual void DoSomethingElse(Workflow context)
  {
    throw new InvalidStateOperationException(); 
  }
}

public class StartState : BaseState
{
  public override void Start(Worklfow context)
  {
    // Do something
    context.Current = new OtherState();
  }
}

This is juse very basic implementation. You can futher extend it. You can add other set of methods like CanDoSomething, you can maintain collection of created State instances because State instance is stateless so you don't need to create new instnace each time you move to the state etc.

Ladislav Mrnka
Thanks. It seems to be the answer. I will try it to see if fulfills my requirements.
Kaveh Shahbazian