Workflow Foundation 4.0 中设计时验证的模式是什么?
我不清楚何时以及如何在 WF 4.0 中的自定义活动/自定义活动工厂/自定义设计器中进行验证。
我的活动中唯一提供验证错误支持的地方是 CacheMetadata 方法(我相信在设计过程中会多次调用该方法)。这是我应该进行验证的地方吗? ActivityDesigner 中是否支持验证?
I'm unclear about when and how I should be doing validation in my custom activities/custom activity factories/custom designers in WF 4.0.
The only place within my activity that seems to provide validation error support is within the CacheMetadata method (I believe this is called multiple times during the design process). Is this where I should be doing my validation? Is there support for validation within the ActivityDesigner?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您的活动中的 CacheMetadata 是您应该进行验证的地方。验证是一个适用于工作流运行时和设计者的概念。 (您可以从以下事实中看出这一点:您仍然可以尝试运行具有验证错误的已编译或声明式工作流程,但这样做时会抛出异常。)
示例:(
请参阅 ActivityMetadata.AddValidationError)
您的第二个问题是是否支持从 ActivityDesigner 端添加验证?答案是“不,不是真的” - 可以进行一些自定义 WPF 和数据绑定,在 ActivityDesigner 之上添加一些“自定义验证”,甚至可以使用 AttachedPropertiesService 在活动类上定义您自己的 SatisfiesConstraints 属性。但这是额外的工作,并且不会与运行时验证一致地配合,因此这是一个价值有限的想法。
Yes, CacheMetadata in your activity is where you should be doing your validation. Validation is a concept which applies to the workflow runtime as well as the designer. (You can see this from the fact that you can still attempt to run workflows, compiled or declarative, which have validation errors, but an exception will be thrown when you do.)
Example:
(See ActivityMetadata.AddValidationError)
Your secondary question is is there support for adding validation from the ActivityDesigner side? The answer is 'no, not really' - it would be possible for to do some custom WPF and data binding which adds some 'custom validation' on top of the ActivityDesigner, maybe even use AttachedPropertiesService to define your own SatisfiesConstraints property on your activity class. But it's extra work, and it's not going to tie in with the runtime validation consistently, so it's a limited value idea.