如何从单个活动中序列化工作流程?

时间:2012-06-28 23:36:26

标签: c# workflow-foundation-4 workflow-foundation

我希望能够在以编程方式创建的单个自定义活动上使用XamlInjector,以便动态模拟它。目前我有以下内容抛出System.ArgumentException: Illegal characters in path。从喷射器。任何想法如何使这项工作?

string serializedActivity = CreateXaml(new MyActivity()); //(Activator.CreateInstance(activityType));
var xamlInjector = new XamlInjector(serializedActivity);

private static string CreateXaml(object activity) {
    StringBuilder builder = new StringBuilder();
    StringWriter writer = new StringWriter(builder);
    XamlWriter xamlWriter = ActivityXamlServices.CreateBuilderWriter(new XamlXmlWriter(writer, new XamlSchemaContext()));
    XamlServices.Save(xamlWriter, activity);
    return builder.ToString();
}

以下是创建的xaml的示例:

<?xml version="1.0" encoding="utf-16"?><Delay xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" />

<?xml version="1.0" encoding="utf-16"?><CreateTemplate AuthenticationHeader="{x:Null}" BaseTdeUri="{x:Null}" CreatedTemplateId="{x:Null}" Password="{x:Null}" TemplateContent="{x:Null}" UserName="{x:Null}" xmlns="clr-namespace:XYZ.Workflow.TdeRestApi;assembly=XYZ.Workflow.Activities" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" />

1 个答案:

答案 0 :(得分:1)

有趣的想法 - 我应该为执行此操作的XamlInjector添加一个重载。

您收到错误的原因是XamlInjector ctor期望文件名,而不是序列化的xaml。