IgorShare Thoughts and Ideas

Consulting and Training

Workflow ActivityDesigner should notify everyone if it changes an activity property

Posted by Igor Moochnick on 01/29/2008

If your Activity Designer makes any property change on an activity it attached to, it should broadcast a notification to every activity in the workflow so the other activities can react to such a change if they need to. It is possible to acheive via a TypeDescriptor or, in more generic case, via the IComponentChangeService.

This is how you can do it in a quick way:

TypeDescriptor.GetProperties(parentActivity).Find(propertyName, false).SetValue(parentActivity, newValue);

And this is more generic approach:

private void NotifyActivityChange(Activity activity, string propertyName, object newValue)
    IComponentChangeService svc = (IComponentChangeService)this.GetService(typeof(IComponentChangeService));
    PropertyDescriptor propDescr = TypeDescriptor.GetProperties(activity).Find(propertyName, false);
    svc.OnComponentChanging(activity, propDescr);
    object oldValue = propDescr.GetValue(activity);
    propDescr.SetValue(activity, newValue);
    svc.OnComponentChanged(parentActivity, propDescr, oldValue, newValue);

[Thanks to MSDN Workflow Foundation Forum and to Matt Milner in particular]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: