« WF and Type properties | Main | WCF, WS-RM and Partial Trust »
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:
/// <summary>
/// Validator class for the MsmqReceiveActivity
/// </summary>
public class MsmqReceiveActivityValidator : ActivityValidator
{
/// Validate the receive activity
/// <param name="manager">Validation Manager to use</param>
/// <param name="obj">Activity instance to validate</param>
/// <returns>Collection of validation errors</returns>
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:
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>
Tomas Restrepo is a software developer located in Colombia, South America. His interests include .NET, Connected Systems, PowerShell and lately dynamic programming languages. More...
email: tomas@winterdom.com msn: tomasr@passport.com
Copyright © 2002-2008, Tomas Restrepo.
Powered by: newtelligence dasBlog 2.2.8279.16125