我希望能夠在編程創建的單個自定義活動上使用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" />
那太傻了!我只是將CreateXaml的返回類型更改爲Stream來使其工作。然而,看起來雖然這種解決方案適用於任何類型的組合活動,但對於需要嘲笑XamlInjector的子實現的NativeActivity來說,並不足以取代它。 – Hubris