How can multiple workflow with different state use the same interface

Topics: Architecture
Apr 20, 2007 at 10:30 AM
I am working on a workflow project.I need to allow user to use any state workflow present. And new workflow can be added . So how can this be achieved. how can i dynamically create and raise events for a new workflow, whose state is not yet known.
Apr 20, 2007 at 6:31 PM
I would separate the problem in 2:
  1. Dynamic creation of workflows
  2. Raising events to state machine workflows

1. Dynamic creation of Workflows
In LitwareHR, we are using a technique called “XAML activation” in order to start the workflows based on xaml code edited by the user through the workflow editor and then stored in the TenantMetadataStore Database.

This starting of a workflow is based on a xml reader that brings the definition of that workflow. That xaml definition extends a defined workflow type, "EvaluationProcess", which has the workflow code implementation (event handlers, properties, etc.). This way we let the tenant organize the structure of his evaluation process, leaving the code that will handle it in the base class.

XAML Activation for State Machine workflows:
You can start State machine workflows with XAML Activation too. State machine workflows are more suitable to model processes that can pass over the same steps more than once. For that processes, the logic in a sequential workflow would be more complicated.

2. Raising events to state machine workflows
Once the new state machine workflow was created and is instantiated, you should be able to raise events to it.
But before knowing if you can raise an X event to the workflow you may want to get the current state of that workflow. In order to do that, in LitwareHR we retrieve it from the Tracking Service. Another option would be using the StateMachineWorkflowInstance class:
StateMachineWorkflowInstance stateInstance = new StateMachineWorkflowInstance(workflowRuntime, instance.InstanceId);
Console.WriteLine(string.Format("The current state is '{0}'", stateInstance.CurrentStateName));

Does this make sense? I'm not quite sure if this is exactly what you meant, please tell me what you think.

Some links you may find useful
• You will find more XAML activation information in Tom Lake's blog , specially the "Using XAML activation in ASP.NET with a StateMachineWorkflow" post where you can download sample code.
• You can take a look at the Windows Workflow forums for more information on WF; for example the "Check Statemachine Status with InstanceID" post

Ariel Schapiro