本文将介绍WF4 Beta 2中新功能特性,并通过WF4 Beta 2与WF4 Beta 1的对比,使大家能更好的了解WF4 Beta 2。
Acticvity结构说明 WF4 Beta 2的Activity结构WF4 Beta 2与WF4 Beta1的Activity结构变化对比说明
1. 取消了[WorkflowElement], 与WF3.0一样,[Activity]成为了WF功能Activity的根类型
2. 增加了表达式Activity [ ActivityWithResult]
- public sealed class wxwinterActivityResult :CodeActivity<string>
- {
- protected override string Execute(CodeActivityContext context)
- {
- return "wxwinter";
- }
3. 增加了异步Activity [AsyncCodeActivity] 可以实现 Begin/End的异步执行方式
- 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
关于[InvokePowershell] Activity的介绍见我写的WF4.0 Beta1 调用PowerShell
( http://www.cnblogs.com/foundation/archive/2009/06/28/1512542.html)
5. 添加Activity [Rethrow] 以实现再次引发异常
WF4 Beta 2与WF3.0/3.5 的Activity结构变化对比说明
变化很大,基本上可以认为是两个产品
运行环境说明 WF4 Beta 2的运行环境WorkflowApplication
- 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的运行环境对比说明
流程实例 [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运行环境最明显的变化是,在WF3.X中要创建实例要使用WorkflowRuntime的CreateWorkflow方法.
而在WF4中,不需要显示创建一个[WorkflowRuntime],而是直接使用[WorkflowInstance (Beta1中)] 创建,这也是到了Beta2中将[WorkflowInstance ]改名为[WorkflowApplication]的原因
工作流开发说明 WF4 Beta 2所提供的工作流模板
- 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只提供了一个[Activity]的模板,
当使用个[Activity]的模板创建流程时,会提供一个只能放入一个控件的空环境
- <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>
当向空Activity中放入[Sequence]时,就可认为是[顺序工作流]
- <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>
当向空Activity中放入[Flowchart]时,就可认为是[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 非常鲜明的提供了两个工作流模板[Flowchart工作流], [顺序工作流]
[顺序工作流]
[Flowchart工作流]
WF4 Beta 2与WF3.0/3.5 所提供的工作流对模板比说明
WF3.0/3.5也提供了两个工作流模板[状态机工作流], [顺序工作流]
其中[状态机工作流]与[Flowchart工作流]有相似之处
[状态机工作流]
[顺序工作流]
工作流格式说明
WF4 的工作流可以是用代码构建的,也可以是由xaml构建的, xaml可以动态/静态的编译为一个类,也可以直接以字符串方式加载
WF3.X的工作流可以是用代码构建的,也可以是由xoml构建的,带class头的xoml可以动态/静态的编译为一个类,没有class头的xoml可以直接以字符串方式加载
其他功能说明WF4与WF3.5都提供了持久化,跟踪,通讯,阻塞等功能,但实现方式不同,也不通用.
WF4与WF3.5的流程设计器从UI风格与实现方式上也有很大不同
原文标题:WF4 Beta 2
链接:http://www.cnblogs.com/foundation/archive/2009/10/22/1587798.html
【编辑推荐】