保存在 WF4 WorkflowDesigner 中
如何在重新托管的设计器中保存 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,使用 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.
嗯,我没用过这个; API 看起来有点……奇怪。但从文档来看,当您在
WorkflowDesigner
的实例上调用Flush()
时,它会将当前工作流程保存到名为Text< 的公共属性中。 /代码>。您应该能够抓取该文本并将其粘贴到数据库中。
来自文档:
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 theWorkflowDesigner
, it saves the current workflow to a public property calledText
. You should be able to grab that text and stick it in your database just fine.From the docs:
使用 ActivityXamlServices 和 StringWriter 来将内容刷新为字符串。
Using ActivityXamlServices and a StringWriter to flush the content to a string.