This project is read-only.


Package: MyToolkit (PCL)
Platforms: All (PCL)

A WorkflowDefinition acts as template for multiple WorkflowInstance objects.


A workflow definition consists of optional global parameters (an object of type WorkflowParametersBase), activities (WorkflowActivityBase objects), a starting activity and transitions (WorkflowTransition objects):

var workflow = new WorkflowDefinition();
workflow.Parameters = new MyParameters();
workflow.Activities = new List<WorkflowActivityBase>
    new MyActivity { Id = "1" },
    new MyActivity { Id = "2" },
    new MyActivity { Id = "3" },
workflow.StartActivity = workflow.Activities.First();
workflow.Transitions = new List<WorkflowTransition>
    new WorkflowTransition { From = "1", To = "2" },
    new WorkflowTransition { From = "2", To = "3" },
return workflow;

After defining a workflow definition, we can create WorkflowInstance objects from it:

var instance = workflow.CreateInstance();

The instance is now in the initial state and has the StartActivity in the list of current activities.


A workflow definition object can be serialized and deserialized from XML:

var xml = workflow.ToXml();
var workflow = WorkflowDefinition.FromXml(xml, activityTypes, parameterTypes);

As we can see, the FromXml needs to know all the possible activity and parameter types so that the serialization can work. These types could be loaded using reflection:

var activityTypes = Assembly.GetExecutingAssembly()
    .Where(t => typeof(WorkflowActivityBase).IsAssignableFrom(t))

var parameterTypes = Assembly.GetExecutingAssembly()
    .Where(t => typeof(WorkflowParametersBase).IsAssignableFrom(t))

Last edited Jul 30, 2014 at 6:07 PM by rsuter, version 7