views:

556

answers:

4

Hello!
I am trying to use Windows Workflow and have a model that looks similar to the image in the link below:
Workflow screen shot

After each of the Send Activities (GetSomthing, GetSomthingElse, GetSomeMoreStuff) the same custom acitvity is being called (LogSomthingBadHappened). Whilst it might not look so bad in this picture in my real model the custom activity is a SequenceActivty, has quite a few nodes, and when its repeated 3 times starts to make the workflow look very ugly.

I would like to do somthing like this:
Edited Workflow screen shot

Can the IfElse branches be merged like this?
Should I be using a State Machine work flow instead (havn't figured these out yet)?

Thanks.

+1  A: 

Use a FaultHandler on the workflow and throw a specific exception type that the handler will catch. Not the most graceful, but I think it should work.

MattK
+1  A: 

In sequential workflows all steps must appear in a specific order, and the execution path is regulated exclusively by control structures (IF, WHILE).
Altering the execution path in the way you describe would be like using a GOTO statement in imperative code, which we know leads to unnecessary complexity.

If the activities contained in the SequenceActivity that you need to execute at different stages of your workflow are exacty the same, you could embed them in a custom activity. This way it is easier to manage them since they are contained in a single logical unit.
In imperative code, this would be like refactoring out a portion of duplicated code into a method, which is then invoked multiple places.

Enrico Campidoglio
+1  A: 

Another alternative that might work is to put your LogSomthingBadHappened activity into a custom workflow and include that several time. Several things to watch out for: Subworkflow are executed asynchronously, if the LogSomthingBadHappened activity needs state information from the main workflow, copying it to the sub workflow might be hard.

I have not tried this, so it might not even work.

gbanfill
A: 

Hello

I think the answer by gbanfill points to the right direction. To generalize, I define the problem as : is there a way to define a group of activities that will be executed in several places of a workflow? Further requirements are : 1.The group of activities should be defined in XAML only ie no code. 2.Type of input to this group will, of course, be fixed but actual values should depend on call (like calling a function). Maybe the way to do it is define sub-workflows and build a custom activity that would instantiate the sub-workflow and wait for it to complete before continuing. This custom activity should have at least two parameters : the sub-workflow id and input parameters.

Has anybody tried something similar?