如何正确保存WF4 ActivityBuilder [英] How to correctly save a WF4 ActivityBuilder

查看:238
本文介绍了如何正确保存WF4 ActivityBuilder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前救了我的.NET FX 4.0.1的StateMachine活动是这样的:

  VAR SB =新的StringBuilder() ; 
变种的XamlWriter = ActivityXamlServices.CreateBuilderWriter(
新XamlXmlWriter(新的StringWriter(SB),
新XamlSchemaContext()));
XamlServices.Save(的XamlWriter,activityBuilder);

返回sb.ToString();

这工作正常,并生成XAML看起来不错。不幸的是,它是无效的。我可以读回用 ActivityXamlServices.Load 但是当我执行它,它说,它不知道在工作流程定义的属性。在Visual Studio设计打开它产生了同样的错误:




编译器错误(S)遇到处理表达式ActiveCall。 ActiveCall未声明。它可能无法访问由于其保护级别。




通过对比我的代码生成的XAML原来的XAML中,我发现了如何要解决这个问题。我必须有的StateMachine 标记之前这个标签:

 < MVA:VisualBasic.Settings> 
集引用和内部实现
将导入的命名空间; / MVA:VisualBasic.Settings>



顺便说一句:结果
,在标签内的文本必须是完全一样,否则在VS打开WF的时候会有一个错误:




无法创建一个设置从文本fooBar'的




问:结果
我有什么在我的代码更改为有这样的在生成的XAML标记?


解决方案

我想我找到了答案。



保存之前打电话来使用下面的代码:

  VisualBasic.SetSettings(activityBuilder,新VisualBasicSettings()); 






如果在 activityBuilder <



<$ p:/ code>已经从 DynamicActivity 它甚至更好的使用下面的代码创建$ p> VisualBasic.SetSettings(activityBuilder,
VisualBasic.GetSettings(dynamicActivity));

如果这是不使用的,即只需要扩展方法命名空间不会写入XAML和,将导致加载并执行XAML时出错






我总结我的的代码项目


I am currently saving my .NET FX 4.0.1 StateMachine activity like this:

var sb = new StringBuilder();
var xamlWriter = ActivityXamlServices.CreateBuilderWriter(
                     new XamlXmlWriter(new StringWriter(sb),
                     new XamlSchemaContext()));
XamlServices.Save(xamlWriter, activityBuilder);

return sb.ToString();

This works fine and the generated XAML looks good. Unfortunately, it is invalid. I can read it back in using ActivityXamlServices.Load but when I execute it, it says that it doesn't know the properties defined in the workflow. Opening it in the Visual Studio designer yields the same errors:

Compiler error(s) encountered processing expression "ActiveCall". "ActiveCall" is not declared. It may be inaccessible due to its protection level.

Through comparing the original XAML with the XAML produced by my code, I found out how to fix this problem. I have to have this tag before the StateMachine tag:

<mva:VisualBasic.Settings>
    Assembly references and imported namespaces for internal implementation
</mva:VisualBasic.Settings>

By the way:
The text inside the tag must be exactly like this, otherwise there will be an error when opening the WF in VS:

Failed to create a 'Settings' from the text 'FooBar'

Question:
What do I have to change in my code to have this tag in the generated XAML?

解决方案

I think I found the answer.

I have to use the following code before calling Save:

VisualBasic.SetSettings(activityBuilder, new VisualBasicSettings());


If the activityBuilder has been created from a DynamicActivity it is even better to use the following code:

VisualBasic.SetSettings(activityBuilder,
                        VisualBasic.GetSettings(dynamicActivity));

If this is not used, namespaces that are only needed for extension methods are not written to the XAML and will lead to an error when loading and executing the XAML.


I summarized my findings on code project.

这篇关于如何正确保存WF4 ActivityBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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