Validate an Activity from within an ActivityDesigner?

送分小仙女□ 提交于 2019-12-06 15:42:08

I don't think there is. I am guessing your Google searched turned up this question on the forums where Tim came up with pretty much the same result.

Given that the ModelItem is your activity adding a custom function to call and going your own checks in there might be a solutions. That way you can call the function from both the CacheMetadata and your activity builder.

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;
    }
}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!