Académique Documents
Professionnel Documents
Culture Documents
Run the workflow CustomerState endState = customerWorkflow.Start(new CustomerState()); Last edited Sep 19, 2012 at 12:00 PM by djnz_gea, version 6
Api Documentation
Defining workflow operations Workflows are composed of operations. These can be functions, defined using lamda syntax, or custom classes that are subclasses of the frameworks BasicOperation<T> abstract class. Defining workflows Workflow<T> Do Then And AsAWorkflow<T> Policies Policies define additional behaviour expected of operations. Retry Repeat Then<T> Exceptions Constraints Constraints can be applied to an operation to determine whether it should be executed. Helper classes are used to compose constraints.
Workflow patterns
Common design patterns for workflows
Sequence
Workflow operations are performed one after another. Operation B only starts when operation A has completed.
And Split
Performs operations concurrently. B and C wait for A to finish but execute concurrently.
And Join
Merges back to sequence pattern following an and-split. D will execute only when all parallel operations have completed. Last edited Aug
Example code
This example registers two operation instances to perform the logic. One requires a variable reference for use in the later constraint evaluation, the other is registered using the generic interface method. Finally, a function is registered for the simpler step of sending the result to the console. In this example the generic doublespace registration will not execute because the constraint will always evaluate to false (the first operation succeeded). static void Main(string[] args)
{ var doubleSpace = new DoubleSpace(); var result = Workflow<Colour>.Definition() .Do(doubleSpace) .Do<DoubleSpace>(If.Not.Successfull(doubleSpace)) .Do((c) => { Console.WriteLine(c.Name); return c; }) .Start(new Colour("Green")); Console.WriteLine("\r\nPress any key"); Console.ReadKey(); } We could also have encapsulated the workflow definition using the AsAWorkflow<T> abstract class; var workflow = new RainbowWorkflow(Workflow<Colour>.Definition()); IExecuteWorkflow<Colour> flow = workflow; var result = flow.Start(new Colour("Green")); The client code has become simpler. Two lines is all that is needed as I cast the workflow variable to an IExecuteWorkflow<Colour> simply to show the polymorphic behaviour. The workflow definition is encapsulated by the RainbowWorkflow class below. public class RainbowWorkflow : AsAWorkflow<Colour> { public override IWorkflow<Colour> Configure() { var doubleSpace = new DoubleSpace(); return Configurer .Do(doubleSpace) .Do<DoubleSpace>(If.Not.Successfull(doubleSpace)) .Do((c) => { Console.WriteLine(c.Name); return c; }); } }