WorkflowFoundation 验证样式未显示在 WFDesigner 中

发布于 2024-12-13 09:22:55 字数 1260 浏览 0 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

又怨 2024-12-20 09:22:55

我发现它是如何工作的。整个工作流程需要重新评估。您可以通过使用 WorkflowDesigner 的 ValidationService 来实现此目的。

var validationService = workflowDesigner.Context.Services.GetService<ValidationService>();
validationService.ValidateWorkflow();

I found out how it works. The entire Workflow needs to be Re-Evaluated. You can achieve this by using the WorkflowDesigner's ValidationService.

var validationService = workflowDesigner.Context.Services.GetService<ValidationService>();
validationService.ValidateWorkflow();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文