Today I’ll go into more details on how to apply the changes based on the user input from the designer surface.

 

As I said in one of the previous posts, it is the DynamicUpdateDriver class that sinks the ComponentChanged event from the IComponentChangeService, and in the corresponding event handler it analyzes the passed arguments in the following way:

 

void componentChangeService_ComponentChanged(object sender, ComponentChangedEventArgs e)

{

      Activity modifiedActivity = e.Component as Activity;

      if (modifiedActivity != null)

      {

            if (e.NewValue == null && e.OldValue != null)

            {

                  ActivityCollectionChangeEventArgs collectionChangedArgs = e.OldValue as ActivityCollectionChangeEventArgs;

                  CompositeActivity owner = collectionChangedArgs.Owner as CompositeActivity;

 

                  if (collectionChangedArgs.RemovedItems.Count != 0 && collectionChangedArgs.AddedItems.Count == 0)

                  {

                        //deletion

                  }

                  else if (collectionChangedArgs.RemovedItems.Count == 0 && collectionChangedArgs.AddedItems.Count != 0)

                  {

                        //addition

                  }

            }

            else if (e.NewValue != null && e.OldValue != null)

            {

                  //modification

            }

      }

}

 

Based on the kind of changes it creates an instance of the ActivityDynamicChangeLog class and stores it along with other logged changes into a list. When the user submits the changes to the runtime, the ApplyDynamicUpdateBatch () iterates over the changes and applies them to the Transient Workflow in the same order they were performed (note that this.instance is a member variable of type WorkflowInstance):

 

Activity currentRoot = this.instance.GetWorkflowDefinition();

workflowChanges = new WorkflowChanges(currentRoot);

CompositeActivity root = workflowChanges.TransientWorkflow;

 

foreach (ActivityDynamicChangeLog change in dynamicUpdateCommitData.ChangeLog)

{

    if (change.ChangeType == ActivityDynamicUpdateType.Add)

    {

     

    }

    else if (change.ChangeType == ActivityDynamicUpdateType.Modify)

    {

     

    }

    else if (change.ChangeType == ActivityDynamicUpdateType.Remove)

    {

     

    }

}

 

this.instance.ApplyWorkflowChanges(workflowChanges);

 

And that's it!