Morphing

Lets talk about a couple of common customer scenarios/questions that I have encountered till date.

1. Workflow authors want to use the generic activities such that they can start with Activity<Object> and then dynamically without having to replace the activity on the canvas want it to be changed to Activity<string>. Specifically, this should happen without having the user to remove the activity from the canvas and then replacing it with the right generic definition, there is no simple way.

2. Depending on some property value or some activity added/removed from the workflow, the author would want to see that a specific activity A is replaced by activity B. How do we go about doing that?

3. Refactoring of Workflows into simpler custom activities. Currently out of the product, we do not provide a refactoring mechanism where a activity composition can be refactored into a custom activity type and then replace the workflow with this type instead of the complete definition.

4. The workflow author would want to surround his activity with other composite activity. And instead of deleting/cut-pasting his activity – the author would want to just wrap his leaf activity as soon as the composite activity is hovered over the leaf activity during drag drop.

5. Workflow authors sometimes start with a simple activity and as they configure the activity he would want that additional activities be added on to the workflow. And this should happen dynamically based on property configurations without having the user to drag drop each activity separately.

All these scenarios can be accomplished using a concept we call Morphing of the Model Items. Example, say we have a Workflow wiht a root Sequence and its children being as follows:

Sequence

Activity1

PlaceHolderActivity

Activity2

This Workflow needs to be replaced as:

Sequence

Activity1

MyNewActivity

Activity2

Couple of things need to happen to accomplish this

1. Of course the model item representing the PlaceHolderActivity on the workflow designer surface needs to be replaced by the model item representing MyNewActivity.

2. Also, the Sequence activity’s Children collection needs to be updated so that the index with PlaceHolderActivity is replaced to the MyNewActivity.

3. Finally, we also need to ensure that all the incoming and outgoing links in Sequence towards and pointing out of the PlaceHolderActivity needs to now reference the MyNewActivity.

How do we achieve this:

  private void Morph(ModelItem oldModelItem, ModelItem newModelitem)
        {
            try
            {
                MorphHelper.MorphObject(oldModelItem, newModelitem);
            }
            catch(Exception ex)
            {
                //MessageBox.Show(ex.Message);
            }
           
        }

Please note that this will also have the properties’ values form the old PlaceHolderActivity would also be copied over to the new activity if there is a common subset between the two activities’ property collection.

 Thanks,
 Kushal.