Geeks With Blogs
Jennifer Zouak JENNIFER · ZOUAK's · BizTalk · and · .NET · column

In creating a custom workflow activity and trying to follow the advice on creating a validator, I ran into one issue which was that I have two types of activity properties: Those which need to be set at design-time and those which are dynamic or bound at runtime. The validator examples give little detail on how to differentiate the two. Here is *a* solution:

In your activity base class "CustomActivityBase", expose the property which will indicate when we are in design mode:

internal bool IsDesignMode { get { return this.DesignMode; } }

(This method calls a protected member, but we'll need to access it in the validator class)

Next, in the validator base class, we have to distinguish validating the activity in design mode, runtime and also for some reason the validator is also called when the activity itself is compiled. In your Validate method, you need to add the checks.

public override ValidationErrorCollection Validate(ValidationManager manager, object obj) {

ValidationErrorCollection errors = base.Validate(manager, obj);

 //only do validation when the activity is in a workflowif (((CustomActivityBase)obj).Parent != null) {

 

  if (((CustomActivityBase)obj).IsDesignMode) { implDesigntimeValidation(errors, manager, obj); }

  else { implRuntimeValidation(errors, manager, obj); }

}

return errors;

}

Finally, notice that you can repeat these steps and perform this same validation on a workflow (although you don't need to check activity.Parent for null since it is the parent).

Posted on Thursday, December 13, 2007 8:32 AM Windows Workflow Foundation (WF) | Back to top


Comments on this post: Workflow Custom Activity Validation - Design time versus Runtime

# re: Workflow Custom Activity Validation - Design time versus Runtime
Requesting Gravatar...
When we were researching the workflow engine, before incorporating it into SplendidCRM, we put a lot of effort into the validation of the activities. When we got to the production code, we simply skipped all that. It simply was too much work with very little gain.
Left by SplendidCRM on Mar 31, 2009 4:35 PM

# re: Workflow Custom Activity Validation - Design time versus Runtime
Requesting Gravatar...
Too bad that theory doesn't work. DesignMode seems to always been true when it's available inside Validate().
Left by Dave on Jul 28, 2010 5:50 PM

Your comment:
 (will show your gravatar)


Copyright © Jennifer Zouak | Powered by: GeeksWithBlogs.net