詳解WF4 Beta 2中新功能特性
本文將介紹WF4 Beta 2中新功能特性,并通過WF4 Beta 2與WF4 Beta 1的對比,使大家能更好的了解WF4 Beta 2。
Acticvity結(jié)構(gòu)說明 WF4 Beta 2的Activity結(jié)構(gòu)
1. 取消了[WorkflowElement], 與WF3.0一樣,[Activity]成為了WF功能Activity的根類型
2. 增加了表達(dá)式Activity [ ActivityWithResult]
- public sealed class wxwinterActivityResult :CodeActivity<string>
- {
- protected override string Execute(CodeActivityContext context)
- {
- return "wxwinter";
- }
|
3. 增加了異步Activity [AsyncCodeActivity] 可以實(shí)現(xiàn) Begin/End的異步執(zhí)行方式
- public sealed class wxwinterActivity : AsyncCodeActivity
- {
- protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
- {
- return callback.BeginInvoke(null, null, null);
- }
- protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
- {
- }
- }
4. 取消 [InvokePowershell] Activity
關(guān)于[InvokePowershell] Activity的介紹見我寫的WF4.0 Beta1 調(diào)用PowerShell
( http://www.cnblogs.com/foundation/archive/2009/06/28/1512542.html)
5. 添加Activity [Rethrow] 以實(shí)現(xiàn)再次引發(fā)異常
變化很大,基本上可以認(rèn)為是兩個(gè)產(chǎn)品
- class Program
- {
- static void Main(string[] args)
- {
- WorkflowApplication instance = new WorkflowApplication(new wxwinterActivity());
- instance.Run();
- System.Console.Read();
- }
- }
- public class wxwinterActivity : CodeActivity
- {
- protected override void Execute(CodeActivityContext context)
- {
- System.Console.WriteLine("wxd");
- }
- }
WF4 Beta 2與WF4 Beta1的運(yùn)行環(huán)境對比說明
流程實(shí)例 [WorkflowInstance] 被 [WorkflowApplication] 取代
- class Program
- {
- static void Main(string[] args)
- {
- WorkflowInstance instance = new WorkflowInstance(new wxwinterActivity());
- instance.Run();
- System.Console.Read();
- }
- }
- public class wxwinterActivity : CodeActivity
- {
- protected override void Execute(CodeActivityContext context)
- {
- System.Console.WriteLine("wxd");
- }
- }
WF3.X與WF4運(yùn)行環(huán)境最明顯的變化是,在WF3.X中要?jiǎng)?chuàng)建實(shí)例要使用WorkflowRuntime的CreateWorkflow方法.
而在WF4中,不需要顯示創(chuàng)建一個(gè)[WorkflowRuntime],而是直接使用[WorkflowInstance (Beta1中)] 創(chuàng)建,這也是到了Beta2中將[WorkflowInstance ]改名為[WorkflowApplication]的原因
- class Program
- {
- static void Main(string[] args)
- {
- WorkflowRuntime workflowRuntime = new WorkflowRuntime();
- WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(wxwinterActivity));
- instance.Start();
- System.Console.Read();
- }
- }
- public class wxwinterActivity : System.Workflow.ComponentModel.Activity
- {
- protected override System.Workflow.ComponentModel.ActivityExecutionStatus Execute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext)
- {
- System.Console.WriteLine("wxd");
- return base.Execute(executionContext);
- }
- }
WF4 Beta 2只提供了一個(gè)[Activity]的模板,
當(dāng)使用個(gè)[Activity]的模板創(chuàng)建流程時(shí),會(huì)提供一個(gè)只能放入一個(gè)控件的空環(huán)境
- <Activity x:Class="ActivityLibrary1.wxwinterWorkFlow" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces"
- xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System"
- xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
- xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System"
- xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core"
- xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel"
- xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib"
- xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sd1="clr-namespace:System.Data;assembly=System.Data.DataSetExtensions"
- xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:st="clr-namespace:System.Text;assembly=mscorlib"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
- < SPAN>Activity>
當(dāng)向空Activity中放入[Sequence]時(shí),就可認(rèn)為是[順序工作流]
- <Activity x:Class="ActivityLibrary1.wxwinterWorkFlow"
- mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces"
- xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System"
- xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
- xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System"
- xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core"
- xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel"
- xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib"
- xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sd1="clr-namespace:System.Data;assembly=System.Data.DataSetExtensions"
- xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:st="clr-namespace:System.Text;assembly=mscorlib"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
- < SPAN>Activity>
當(dāng)向空Activity中放入[Flowchart]時(shí),就可認(rèn)為是[Flowchart工作流]
- <Activity mc:Ignorable="sap" x:Class="ActivityLibrary1.wxwinterWorkFlow" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces"
- xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
- xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml"
- xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities"
- xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System"
- xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core"
- xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data"
- xmlns:sd1="clr-namespace:System.Data;assembly=System.Data.DataSetExtensions" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core"
- xmlns:st="clr-namespace:System.Text;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
- <Sequence sad:XamlDebuggerXmlReader.FileName="d:\users\wxd\documents\visual studio 2010\Projects\ActivityLibrary1\ActivityLibrary1\wxwinterWorkFlow.xaml"
- sap:VirtualizedContainerService.HintSize="235,288">
- <sap:WorkflowViewStateService.ViewState>
- <scg3:Dictionary x:TypeArguments="x:String, x:Object">
- <x:Boolean x:Key="IsExpanded">True< SPAN>x:Boolean>
- < SPAN>scg3:Dictionary>
- < SPAN>sap:WorkflowViewStateService.ViewState>
- <WriteLine sap:VirtualizedContainerService.HintSize="213,62" />
- <WriteLine sap:VirtualizedContainerService.HintSize="213,62" />
- < SPAN>Sequence>
- < SPAN>Activity>

WF4 Beta1 非常鮮明的提供了兩個(gè)工作流模板[Flowchart工作流], [順序工作流]
[順序工作流]
[Flowchart工作流]
WF3.0/3.5也提供了兩個(gè)工作流模板[狀態(tài)機(jī)工作流], [順序工作流]
其中[狀態(tài)機(jī)工作流]與[Flowchart工作流]有相似之處
[狀態(tài)機(jī)工作流]
[順序工作流]
WF4 的工作流可以是用代碼構(gòu)建的,也可以是由xaml構(gòu)建的, xaml可以動(dòng)態(tài)/靜態(tài)的編譯為一個(gè)類,也可以直接以字符串方式加載
WF3.X的工作流可以是用代碼構(gòu)建的,也可以是由xoml構(gòu)建的,帶class頭的xoml可以動(dòng)態(tài)/靜態(tài)的編譯為一個(gè)類,沒有class頭的xoml可以直接以字符串方式加載
其他功能說明WF4與WF3.5都提供了持久化,跟蹤,通訊,阻塞等功能,但實(shí)現(xiàn)方式不同,也不通用.
WF4與WF3.5的流程設(shè)計(jì)器從UI風(fēng)格與實(shí)現(xiàn)方式上也有很大不同
原文標(biāo)題:WF4 Beta 2
鏈接:http://www.cnblogs.com/foundation/archive/2009/10/22/1587798.html
【編輯推薦】