保存在 WF4 WorkflowDesigner 中

发布于 2024-09-15 06:52:39 字数 605 浏览 1 评论 0原文

如何在重新托管的设计器中保存 WF4 工作流的 XAML,而不将其写入文件?我想将序列化工作流程作为 XML 字符串存储在数据库中。

给定一个名为 w 的 WorkflowDesigner 实例,这可以很好地保存到文件中:

WorkflowDesigner.Flush();
w.Save("filename.xaml");

我希望这会序列化为字符串 - 但它失败了:

WorkflowDesigner.Flush();
var modelService = WorkflowDesigner.Context.Services.GetService<ModelService>();
var workflow = modelService.Root;
var xml = XamlServices.Save(workflow);

...在保存单个序列活动时,它显示“键入 'System.Activities.Presentation.Model” .ModelItemImpl' 不可见。如果类型是本地类型,请在 XamlReaderSettings 中设置 LocalAssembly 字段。

How do I save the XAML for a WF4 workflow in a rehosted designer, without writing it to a file? I want to store the serialised workflow in a database as an XML string.

Given a WorkflowDesigner instance called w, this saves to a file fine:

WorkflowDesigner.Flush();
w.Save("filename.xaml");

I was hoping this would serialise to a string - but it fails:

WorkflowDesigner.Flush();
var modelService = WorkflowDesigner.Context.Services.GetService<ModelService>();
var workflow = modelService.Root;
var xml = XamlServices.Save(workflow);

... while saving a single Sequence activity, it says "Type 'System.Activities.Presentation.Model.ModelItemImpl' not visible. If the type is local, please set the LocalAssembly field in XamlReaderSettings.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

梦开始←不甜 2024-09-22 06:52:39

是的,使用 Flush() 和 Text 将 xaml 获取为字符串。使用 Save() 保存到文件或流,在这种情况下不需要 Flush()。

Yes, use Flush() and Text to get the xaml as a string. Use Save() to save to a file or stream, no Flush() needed in that case.

我一向站在原地 2024-09-22 06:52:39

嗯,我没用过这个; API 看起来有点……奇怪。但从文档来看,当您在 WorkflowDesigner 的实例上调用 Flush() 时,它会将当前工作流程保存到名为 Text< 的公共属性中。 /代码>。您应该能够抓取该文本并将其粘贴到数据库中。

来自文档

在获取这个值之前,调用
Flush() 转换当前
工作流程到文本。设置完这个之后
value,调用Load()加载XAML
进入工作流程。

Hmmm, I haven't used this; the API seems a bit... odd. But from the docs, it appears that when you call Flush() on the instance of the WorkflowDesigner, it saves the current workflow to a public property called Text. You should be able to grab that text and stick it in your database just fine.

From the docs:

Before getting this value, call
Flush() to convert the current
workflow to text. After setting this
value, call Load() to load the XAML
into the workflow.

千寻… 2024-09-22 06:52:39

使用 ActivityXamlServices 和 StringWriter 来将内容刷新为字符串。

Using ActivityXamlServices and a StringWriter to flush the content to a string.

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