WorkflowFoundation 验证样式未显示在 WFDesigner 中
在 WF4 重新托管应用程序中,我需要根据存储在数据库中的自定义参数验证活动。
当用户输入一些值并且在设计器中更改选择时,将调用覆盖的 CacheMetadata 方法,如下所示:
protected override void CacheMetadata(CodeActivityMetadata metadata)
{
if (!ParamCache.ContainsKey(InstanceId.ToString())) return;
var paramsToValidate = ParamCache.Get(InstanceId.ToString());
var validationErrors = (from paramToValidate in paramsToValidate
let errorMessage = paramToValidate.Validate()
where !string.IsNullOrEmpty(errorMessage)
select new ValidationError(errorMessage, false)).ToList();
foreach (var validationError in validationErrors)
{
metadata.AddValidationError(validationError);
}
}
在运行时,使用此验证方法评估错误集合:
public void Validate()
{
var activity = ModelItem.GetCurrentValue() as Activity;
if (activity != null)
{
var validationResults = ActivityValidationServices.Validate(activity);
var designerRegionVieWModel = Parent as DesignerRegionViewModel;
IsValid = validationResults.Errors.Count <= 0;
...
}
尽管 ValidationError > 对象已添加,并且 IsValid
为 false,设计器未更新以使用红色感叹号样式可视化错误。
但是,如果我在 CacheMetadata 方法的开头添加一些错误(用于测试目的),则会根据需要显示错误。
这可能是一些计时问题,还是需要触发一些额外的运行时评估?
In a WF4 rehosting Application I need to validate an Activity based on custom parameters, which are stored in a database.
When the user entered some values and the selection is changed in the designer the overwritten CacheMetadata
Method is called as follows:
protected override void CacheMetadata(CodeActivityMetadata metadata)
{
if (!ParamCache.ContainsKey(InstanceId.ToString())) return;
var paramsToValidate = ParamCache.Get(InstanceId.ToString());
var validationErrors = (from paramToValidate in paramsToValidate
let errorMessage = paramToValidate.Validate()
where !string.IsNullOrEmpty(errorMessage)
select new ValidationError(errorMessage, false)).ToList();
foreach (var validationError in validationErrors)
{
metadata.AddValidationError(validationError);
}
}
During runtime the error collection is evaluated using this Validate Method:
public void Validate()
{
var activity = ModelItem.GetCurrentValue() as Activity;
if (activity != null)
{
var validationResults = ActivityValidationServices.Validate(activity);
var designerRegionVieWModel = Parent as DesignerRegionViewModel;
IsValid = validationResults.Errors.Count <= 0;
...
}
Although ValidationError
objects have been added, and IsValid
is false the designer is not updated to visualize the errors with the red exclamation mark style.
However, if I add some Errors (for testing purpose) right on the beginning of the CacheMetadata
Method the errors are displayed as required.
Could this be some timing problem or is there some additional runtime evaluation which has to be triggered?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现它是如何工作的。整个工作流程需要重新评估。您可以通过使用 WorkflowDesigner 的
ValidationService
来实现此目的。I found out how it works. The entire Workflow needs to be Re-Evaluated. You can achieve this by using the WorkflowDesigner's
ValidationService
.