If you're building custom Windows Workflow Foundation activities, then you'll likely want to write your own custom ActivityValidator-derived classes, in order to provide your own custom validation logic to ensure activities are correctly configured at design time.
Here's a very simple sample ActivityValidator class:
///
/// Validator class for the MsmqReceiveActivity
///
public class MsmqReceiveActivityValidator : ActivityValidator
{
///
/// Validate the receive activity
///
///
Validation Manager to use
///
Activity instance to validate
///
public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
{
ValidationErrorCollection errors = base.Validate(manager, obj);
MsmqReceiveActivity act = (MsmqReceiveActivity)obj;
if ( !act.IsBindingSet(MsmqReceiveActivity.QueueProperty) )
{
if ( act.GetValue(MsmqReceiveActivity.QueueProperty) == null )
{
errors.Add(ValidationError.GetNotSetValidationError("Queue"));
}
}
if ( act.MessageType == null )
{
errors.Add(ValidationError.GetNotSetValidationError("MessageType"));
}
if ( !act.IsBindingSet(MsmqReceiveActivity.MessageReceivedProperty) )
{
errors.Add(ValidationError.GetNotSetValidationError("MessageReceived"));
}
return errors;
}
} // class MsmqReceiveActivityValidator
This validator simply does the following checks:
- Ensures that the Queue property (which is a dependency property) of the activity is either bound to an external property, or has a direct value.
- Ensures that the MessageType property of the activity has an actual value assigned to it.
- Ensures that the MessageReceive property of the activity (an attached dependency property) has been explicitly bound.
The validator is then attached to the activity via the [ActivityValidator] attribute, like this:
[SRDescription("Recv_Description")]
[ToolboxItem(typeof(ActivityToolboxItem))]
[Designer(typeof(MsmqReceiveActivityDesigner), typeof(IDesigner))]
[ToolboxBitmap(typeof(MsmqReceiveActivity), "Resources.MessageQueuing.bmp")]
[ActivityValidator(typeof(MsmqReceiveActivityValidator))]
public partial class MsmqReceiveActivity
: Activity, IEventActivity, IActivityEventListener<QueueEventArgs>