开发者

Saving in the WF4 WorkflowDesigner

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, 开发者_Python百科it says "Type 'System.Activities.Presentation.Model.ModelItemImpl' not visible. If the type is local, please set the LocalAssembly field in XamlReaderSettings.


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜