从 ActivityDesigner 中验证活动? [英] Validate an Activity from within an ActivityDesigner?

查看:23
本文介绍了从 ActivityDesigner 中验证活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从子活动的设计器之一验证设计图面(在本例中为 Visual Studio)内的工作流.我想阻止用户继续前进,直到其他错误得到纠正,以简化以后的设计体验.

I'd like to validate the workflow within the design surface (in this case, Visual Studio) from within one of the child Activities' designer. I'd like to prevent users from moving forward until other errors are corrected in order to simplify the design experience later down the road.

天真的实现不起作用:

var activity = (this.ModelItem.Root.GetCurrentValue() as ActivityBuilder)
                    .Implementation as Activity;
var validationResult = ActivityValidationServices.Validate(activity);
if (validationResult.Errors.Count > 0))
{
    MessageBox.Show("The Workflow is invalid.  Fix it.", "Derp");
    return;
}

问题是 ActivityBuilder(它不是活动,不能传递给 Validate)包含任何和所有变量和参数在工作流的根上定义.因此,当您尝试验证根的第一个子节点 (Implementation) 时,您会收到无效错误,因为它们的任何绑定都失败了.

The problem is that the ActivityBuilder (which is not an Activity and cannot be passed to Validate) contains any and all Variables and Arguments defined on the root of the workflow. So, when you attempt to validate the first child of the root (Implementation), you get invalid Errors as any bindings to these fail.

我看到了一些建议的技巧,您将 Implementation 添加到载体活动(例如,Sequence),然后将 ActivityBuilder 中的所有 变量和参数添加到运营商.

I've seen suggested hacks where you add the Implementation to a carrier Activity (say, Sequence) and then add all Variables and Arguments found in the ActivityBuilder to the carrier.

这太臭了.

有没有更好的方法?

推荐答案

Hacks.除了黑客什么都没有.

Hacks. Nothing but hacks.

var sb = new StringBuilder();
using (var tw = new StringWriter(sb))
using (var xw = ActivityXamlServices.CreateBuilderWriter(
                    new XamlXmlWriter(tw, new XamlSchemaContext())))
{
    XamlServices.Save(xw, 
                      this.ModelItem.Root.GetCurrentValue() as ActivityBuilder);
    tw.Flush();
}
using(var tr = new StringReader(sb.ToString()))
using (var xr = ActivityXamlServices.CreateReader(
                    new XamlXmlReader(tr, new XamlSchemaContext())))
{
    var activity = ActivityXamlServices.Load(xr);
    var validationResult = ActivityValidationServices.Validate(activity);
    if (!validationResult.IsValid())
    {
        MessageBox.Show("OMG what an awful hack.", "Validation Sucks");
        return;
    }
}

是否有更好的方法将 ActivityBuilder 转换为 Activity 而无需序列化它???

Can there be a better way to convert the ActivityBuilder to an Activity without serializing it???

这篇关于从 ActivityDesigner 中验证活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆