This project is read-only.
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;
                        });
        }
    }

I removed superfluous classes to conserve space. Here is the missing code.

Last edited Mar 11, 2011 at 1:57 PM by djnz_gea, version 14

Comments

No comments yet.