WF4B1 的Procedural Activity 之Sequence,Delay,Pick,PickBranch,Parallel,ForEach,ForEach<T>使用

WF4B1 的Procedural Activity 之Sequence,Delay,Pick,PickBranch,Parallel,ForEach,ForEach<T>使用

 

目录

1.1    Sequence 顺序容器    1

1.2    Delay 延时    1

1.2.1    例    1

1.3    Pick 与 PickBranch    2

1.3.1    Pick 中的 PickBranch是单线执行的    2

1.3.2    例    2

1.4    Parallel 并行容器    3

1.4.1    例    4

1.5    ForEach 循环    5

1.5.1    Values属性    5

1.5.2    例    6

1.6    ForEach<T> 循环    7

1.6.1    例    7

 

 

 

 

Sequence 顺序容器

类名: System.Activities.Statements.Sequence

基类: NativeActivity

文件: System.Activities.dll

类型: sealed

说明: 1.[Activities]集合,可以存放Activity

2.[Activities]集合中的Activity按顺序从上向下执行

3.默认为[顺序工作流]的根容器

 

Delay 延时

 

类名: System.Activities.Statements.Delay

基类: NativeActivity ,

接口: System.Activities.IActivityExtensionProvider

文件: System.Activities.dll

类型: sealed

说明: 1.延迟,按指定的时间阻止当前的工作流执行。 持续时间过期后,工作流继续执行

2.[Duration]属性,类型为System.Activities.InArgument<System.TimeSpan>,表示阻止当前的工作流执行的时间

3.不触发[OnIdel]

 

流程

<p:Activity mc:Ignorable=""

x:Class="WorkflowConsoleApplication3.Sequence1"

xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities/design"

xmlns:__Sequence1="clr-namespace:WorkflowConsoleApplication3;"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/activities"

xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<p:Sequence >

<p:WriteLine DisplayName="WriteLine(print:begin+Now)">["begin:" + System.DateTime.Now.ToString()]</p:WriteLine>

<p:Delay DisplayName="Delay(10秒)">[New TimeSpan(0, 0, 10)]</p:Delay>

<p:WriteLine DisplayName="WriteLine(print:begin+Now)">["end:" + System.DateTime.Now.ToString()]</p:WriteLine>

</p:Sequence>

</p:Activity>

宿主

 

WorkflowInstance myInstance = new WorkflowInstance(new Sequence1());

 

myInstance.Run();

 

System.Console.Read();

结果

 

Pick 与 PickBranch

类名: System.Activities.Statements.Pick

基类: NativeActivity

文件: System.Activities.dll

类型: sealed

说明: 1.[Pick]触发容器,提供了基于事件的控制流。

2.[Branches]集合的类型为[System.Collections.ObjectModel.Collection<System.Activities.Statements.PickBranch>]

是子控件集合, 只能添加[PickBranch]

 

类名: System.Activities.Statements.PickBranch

基类: object

文件: System.Activities.dll

类型: sealed

说明: 1.[Pick]触发容器的分支。 [PickBranch] 只可添加到[Pick]中

2.[Trigger] 属性,只能放入触发类Activity

3.[Action] 当[Trigger] 被触发时,所要执行的Activity

 

 

Pick 中的 PickBranch是单线执行的

1. 只要有一个[PickBranch]的[Trigger]被触发,其他[PickBranch]就不会被触发了

2. 即使在被执行的[PickBranch]还没完成时,其他[PickBranch]也不会被触发

 

 

流程

<p:Activity mc:Ignorable=""

x:Class="WorkflowConsoleApplication3.Sequence1"

xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities/design"

xmlns:__Sequence1="clr-namespace:WorkflowConsoleApplication3;"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/activities"

xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<p:Sequence >

<p:WriteLine>["begin"]</p:WriteLine>

<p:Pick>

<p:PickBranch>

<p:PickBranch.Trigger>

<p:Delay>[New TimeSpan(0, 0, 10)]</p:Delay>

</p:PickBranch.Trigger>

<p:WriteLine>["10"]</p:WriteLine>

</p:PickBranch>

<p:PickBranch>

<p:PickBranch.Trigger>

<p:Delay>[New TimeSpan(0, 0, 5)]</p:Delay>

</p:PickBranch.Trigger>

<p:WriteLine>["5"]</p:WriteLine>

</p:PickBranch>

</p:Pick>

<p:WriteLine>["end"]</p:WriteLine>

</p:Sequence>

</p:Activity>

宿主

WorkflowInstance myInstance = new WorkflowInstance(new Sequence1());

myInstance.Run();

System.Console.Read();

结果

 

Parallel 并行容器

类名: System.Activities.Statements.Parallel

基类: object

文件: System.Activities.dll

类型: sealed

说明: 1.[Branches]集合的类型为System.Collections.ObjectModel.Collection<System.Activities.WorkflowElement>,容器会并行执行容器内的所有Activity

2.[CompletionCondition] 属性[System.Activities.WorkflowElement<bool>],当[ CompletionCondition 属性]为真时,完成

 

 

 

 

流程

<p:Activity mc:Ignorable=""

x:Class="WorkflowConsoleApplication3.Sequence1"

xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities/design"

xmlns:__Sequence1="clr-namespace:WorkflowConsoleApplication3;"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/activities"

xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<p:Sequence >

<p:WriteLine DisplayName="WriteLine(print:begin+Now)">["begin:" + System.DateTime.Now.ToString()]</p:WriteLine>

<p:Parallel>

<p:Sequence>

<p:Delay DisplayName="Delay(10秒)">[New TimeSpan(0, 0, 10)]</p:Delay>

<p:WriteLine DisplayName="WriteLine(print:&quot;A&quot;)">["A"]</p:WriteLine>

</p:Sequence>

<p:Sequence>

<p:Delay DisplayName="Delay(15秒)">[New TimeSpan(0, 0, 15)]</p:Delay>

<p:WriteLine DisplayName="WriteLine(print:&quot;B&quot;)">["B"]</p:WriteLine>

</p:Sequence>

</p:Parallel>

<p:WriteLine DisplayName="WriteLine(print:begin+Now)">["end:" + System.DateTime.Now.ToString()]</p:WriteLine>

</p:Sequence>

</p:Activity>

宿主

WorkflowInstance myInstance = new WorkflowInstance(new Sequence1());

myInstance.Run();

System.Console.Read();

结果

 

ForEach 循环

类名: System.Activities.Statements.ForEach

基类: NativeActivity

文件: System.Activities.dll

类型: sealed

说明: 1.循环[Values]属性所指定的集合中的值,[Values]属性可指定到[object]对象上

2.可在[ForEach]内部添加[Activity]用以操作循环的[item],只能添加一个[Activity],[Activity]内部的子[Activity]也可访问[item]

3.使用[ForEach]时,内部[item]在表达式输入框中为[object]类型,可以使用[ForEach<T>],这样内部[item]在表达式输入框中为<T>

 

Values属性

有时设不上,要到xaml中手写

<p:Activity

mc:Ignorable="" x:Class="WorkflowConsoleApplication5.Sequence1"

xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities/design"

 

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/activities"

xmlns:s="clr-namespace:System;assembly=mscorlib"

xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"

 

>

<x:Members>

<x:Property Name="myInputCollection" Type="p:InArgument(scg:IEnumerable(x:String))" />

</x:Members>

 

<p:Sequence>

<p:ForEach Values="[myInputCollection]">

<p:ActivityAction x:TypeArguments="s:Object">

<p:ActivityAction.Argument>

<p:Variable x:TypeArguments="s:Object" Name="item" />

</p:ActivityAction.Argument>

<p:WriteLine>[item]</p:WriteLine>

</p:ActivityAction>

</p:ForEach>

</p:Sequence>

</p:Activity>

 

 

 

流程

<p:Activity

mc:Ignorable="" x:Class="WorkflowConsoleApplication5.Sequence1"

xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities/design"

 

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/activities"

xmlns:s="clr-namespace:System;assembly=mscorlib"

xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"

>

<x:Members>

<x:Property Name="myInputCollection" Type="p:InArgument(scg:IEnumerable(x:String))" />

</x:Members>

 

<p:Sequence>

<p:ForEach Values="[myInputCollection]">

<p:ActivityAction x:TypeArguments="s:Object">

<p:ActivityAction.Argument>

<p:Variable x:TypeArguments="s:Object" Name="item" />

</p:ActivityAction.Argument>

<p:WriteLine>[item]</p:WriteLine>

</p:ActivityAction>

</p:ForEach>

</p:Sequence>

</p:Activity>

宿主

Dictionary<string, object> inputCollection = new Dictionary<string, object>();

 

List<string> list = new List<string>();

 

list.Add("wxd");

list.Add("lzm");

list.Add("wxwinter");

 

inputCollection.Add("myInputCollection", list );

 

 

WorkflowInstance myInstance = new WorkflowInstance(new Sequence1(), inputCollection);

 

myInstance.Run();

 

System.Console.Read();

结果

 

 

 

ForEach<T> 循环

类名: System.Activities.Statements.ForEach<T>

基类: NativeActivity

文件: System.Activities.dll

类型: sealed

说明: 1.与[ForEach]不同的是,内部[item]在表达式输入框中为<T>

2.在添加[ForEach<T>]时,需要为内部[item]指定类型

3.其他使用与[ForEach]相同

 

 

流程

<p:Activity mc:Ignorable=""

x:Class="WorkflowConsoleApplication5.Sequence1"

xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities/design"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/activities"

xmlns:s="clr-namespace:System;assembly=mscorlib"

xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities"

xmlns:w="clr-namespace:WorkflowConsoleApplication5;assembly=WorkflowConsoleApplication5"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<x:Members>

<x:Property Name="myInputCollection" Type="p:InArgument(s:Object)" />

</x:Members>

<p:Sequence>

<p:ForEach x:TypeArguments="w:myType" Values="[myInputCollection]">

<p:ActivityAction x:TypeArguments="w:myType">

<p:ActivityAction.Argument>

<p:Variable x:TypeArguments="w:myType" Name="item" />

</p:ActivityAction.Argument>

<p:WriteLine>[item.myValue]</p:WriteLine>

</p:ActivityAction>

</p:ForEach>

</p:Sequence>

</p:Activity>

宿主

Dictionary<string, object> inputCollection = new Dictionary<string, object>();

 

List<string> list = new List<string>();

 

list.Add("wxd");

list.Add("lzm");

list.Add("wxwinter");

 

inputCollection.Add("myInputCollection", list );

 

 

WorkflowInstance myInstance = new WorkflowInstance(new Sequence1(), inputCollection);

 

myInstance.Run();

 

System.Console.Read();

结果

 

 

 

 

posted @ 2009-06-01 16:18  WXWinter(冬)  阅读(1304)  评论(4编辑  收藏  举报