WEB开发网
开发学院软件开发C语言 WF4.0 Beta2:关于动态保存和装载XAML工作流 阅读

WF4.0 Beta2:关于动态保存和装载XAML工作流

 2010-09-30 21:05:54 来源:WEB开发网   
核心提示:1.ActivityXamlServices类的主要功能是从XAML文件创建活动树的实例。提供了下面四个方法:CreateBuilderReader:Overloaded.Mapsanx:ClassactivitytreetoanActivityBuilderorActivityBuilder<(Of<(T

1.ActivityXamlServices类的主要功能是从XAML文件创建活动树的实例。提供了下面四个方法:

CreateBuilderReader:Overloaded. Maps an x:Class activity tree to an ActivityBuilder or ActivityBuilder<(Of <(TResult>)>).
CreateBuilderWriter:Maps an ActivityBuilder or ActivityBuilder<(Of <(TResult>)>) from the specified writer to an
                     x:Class activity tree.
CreateReader:Overloaded. Maps an x:Class activity tree to an DynamicActivity or DynamicActivity<(Of <(TResult>)>).
Load:Overloaded. Creates an instance of a declarative workflow.

Load方法遇到标记有<Activity x:Class的XAML会返回一个DynamicActivity.

2.下面一个具体的例子:

ActivityBuilder ab1 = new ActivityBuilder();
 ab1.Name = "HelloWorldCary";
 ab1.Properties.Add(new DynamicActivityProperty { Name = "input1", Type = typeof(InArgument<string>) });
 ab1.Properties.Add(new DynamicActivityProperty { Name = "input2", Type = typeof(InArgument<string>) });
 ab1.Properties.Add(new DynamicActivityProperty { Name = "output", Type = typeof(OutArgument<string>) });
 ab1.Implementation = new Sequence
 {
     Activities = 
     {
         new WriteLine{Text="Getting Started"},
         new Delay{Duration=TimeSpan.FromSeconds(4)},
         new WriteLine{Text=new VisualBasicValue<string>{ExpressionText="input1+input2"}},
         new Assign<string>{To=new VisualBasicReference<string>{ExpressionText="output"},
                 Value=new VisualBasicValue<string>{ExpressionText="input1+input2+\"  that's ok!\""}}
     }
 };
 StringBuilder sb = new StringBuilder();
 StringWriter tw = new StringWriter(sb);
 XamlWriter xw = ActivityXamlServices.CreateBuilderWriter(new XamlXmlWriter(tw,new XamlSchemaContext()));
 XamlServices.Save(xw,ab1);
 string serializedAB = sb.ToString();
 DynamicActivity da2 = ActivityXamlServices.Load(new StringReader(serializedAB)) as DynamicActivity;
 var result = WorkflowInvoker.Invoke(da2, new Dictionary<string, object> { {"input1","hello"},{"input2","world"}});
 Console.WriteLine("result text is {0}",result["output"]);
 ActivityBuilder ab = XamlServices.Load(
     ActivityXamlServices.CreateBuilderReader(
         new XamlXmlReader(new StringReader(serializedAB)))) as ActivityBuilder;
 Console.WriteLine("there are {0} arguments in the activity builder",ab.Properties.Count);
 Console.WriteLine("press enter to exit");
 Console.WriteLine(sb.ToString());
 Console.ReadLine();

1 2  下一页

Tags:WF 关于

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接