This project is read-only.

Break out / if else workflow manipulation

Jun 12, 2013 at 3:12 PM
Hi all

I'm impressed with the project so far and am keen to use it in my current project.

The workflow I need to design requires a break-out clause that can end the current run or jump to another step or workflow.

I can mostly achieve this using the ICheckConstraint parameter of the Do method. However this is very cumbersome to do for each step because I either need need to define each operation into it's own variable and then check the success of the previous step or I can use the generic Do<T> methods and supply some a custom Func<bool> expression to check if the step should be run. Example below.
public class Work
{
    public string Message { get; set; }
}

public class StepOne : BasicOperation<Work>
{
    public override Work Execute(Work data)
    {
        data.Message = "StepOne";
    }
}

public class StepTwo : BasicOperation<Work>
{
    public override Work Execute(Work data)
    {
        data.Message = "StepTwo";
    }
}

public class StepThree : BasicOperation<Work>
{
    public override Work Execute(Work data)
    {
        data.Message = "StepThree";
    }
}

public void Main(string[] args)
{
    var stepOne = new StepOne();
    var stepTwo = new StepTwo();
    var stepThree = new StepThree();

    var work = new Work { Message = "new" };

    var wf = Workflow<Work>.Definition()
                        .Do(stepOne) // Execute using variable
                        .Do(stepTwo, If.Successfull(stepOne)) // Optionally execute operation if a previously executed operation was successful
                        .Do(stepThree, new Condition(() => stepTwo.SuccessResult)); // Optionally execute step based on some defined Func<bool> expression

    var result = wf.Start(work);                 
}
The second problem I face when using the current design is that if I had a workflow with three steps, similar to above, and I chose not to run the second step with some sort of check constraint, the third step will then be attempted. It would be great if I could optionally choose to exit the workflow or run some other steps. An else for the If, which can take the workflow in a different direction.

Have I got the wrong end of the stick / is there an easier way?

What I would like to see is another couple overloads for Do() and Do<T>. The first could be a bool that effectively ends the workflow run if the condition is met / not met and the second could be an alternative step / workflow to run in stead. I think this would allow for a more complete decision process. I would be happy to help out with the design / development of this feature if the project owns deem it the correct path.

Thanks
Jun 13, 2013 at 9:34 AM
Hi Mike,
Glad you are finding the project useful.

I didn't implement an If..else construct as I use the AsAWorkflow<T> to define sub workflows and execute those conditionally.

More information can be found on my blog; http://garfieldmoore.co.uk

This may be what you are looking for.

I'd be interested if this helps as conditional execution may be an area of weakness in the project as the workflows I designed it for were fairly simple.

Hope this helps.