Activity容器控件
IfElseActivity
1.IfElseActivity有兩個IfElseBranch子控件,分別作為IfElse的兩個分支容器,系統(tǒng)自動添加,
2.其中左邊(為真件條)的IfElseBranch容器要設(shè)Condition
3.IfElse左邊(為真件條)的IfElseBranch容器的Condition有兩個條件模式:Code Condition,Declarative Rule Condition
Code Condition模式
Code Condition模式,由對e.Result賦不同值決定執(zhí)行不同的分支
要使用該模式,會在代碼中用到CodeCondition對象與CodeCondition對象的Condition事件
| IfElseActivity |
| IfElseBranch1 |
| IfElseBranch2 |
| Activities.CodeCondition Condition事件 |
| (Object sender, System.Workflow.Activities.ConditionalEventArgs e) |
| 手工 代碼 從下拉框綁定時如報錯 | Dim codecondition1 As Workflow.Activities.CodeCondition = New CodeCondition AddHandler codecondition1.Condition, AddressOf Me.ifElse_a_Condition Me.ifElseBranchActivity1.Condition = codecondition1 |
| System.Workflow.Activities.CodeCondition codecondition1 = new CodeCondition(); codecondition2.Condition += new System.EventHandler<Activities.ConditionalEventArgs>(this.ifElse1_Condition); this.ifElseBranch1.Condition = codecondition2; | |
| 方法 格式 | ?'Code Condition模式的判斷,由對e.Result賦不同值決定執(zhí)行不同的分支 ?Private Sub ifElse_a_Condition(ByVal sender As Object, ByVal e As Workflow.Activities.ConditionalEventArgs) ??????? 'e.Result如果為真,就執(zhí)行左邊(為真件條)的IfElseBranch容器 ??????? 'e.Result如果為假,就執(zhí)行右邊(為假件條)的IfElseBranch容器 ??????? If temp = "456" Then ??????????? e.Result = True ??????? Else ??????????? e.Result = False ??????? End If ??? End Sub |
| ??????? void ifElse1_Condition(Object sender, System.Workflow.Activities.ConditionalEventArgs e) ??????? { ??????????? if (wxwinter = "lzm") ??????????? { e.Result = true; } ??????????? else ??????????? { e.Result = false; } ????????? } |
Declarative Rule Condition模式
Declarative Rule Condition模式:由指定的表達(dá)式的值是否符合條件定執(zhí)行不同的分支
| ?Dim ruleconditionreference1 As Workflow.Activities.Rules.RuleConditionReference = New .RuleConditionReference ?ruleconditionreference1.ConditionName = "Condition1" ?Me.ifElseBranchActivity3.Condition = ruleconditionreference1 |
| System.Workflow.Activities.Rules.RuleConditionReference ruleconditionreference1 = new Rules.RuleConditionReference(); ruleconditionreference1.ConditionName = "abcd"; this.ifElseBranch3.Condition = ruleconditionreference1; |
| <RuleDefinitions xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow"> ????? <RuleDefinitions.Conditions> ?????????? <RuleExpressionCondition Name="abcd"> ???????????????? <RuleExpressionCondition.Expression> ????????????????????? <ns0:CodeBinaryOperatorExpression Operator="ValueEquality" xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> ??????????????????????????? <ns0:CodeBinaryOperatorExpression.Left> ????????????????????????????????? <ns0:CodeFieldReferenceExpression FieldName="wxwinter"> ?????????????????????????????????????? <ns0:CodeFieldReferenceExpression.TargetObject> ???????????????????????????????????????????? <ns0:CodeThisReferenceExpression /> ?????????????????????????????????????? </ns0:CodeFieldReferenceExpression.TargetObject> ????????????????????????????????? </ns0:CodeFieldReferenceExpression> ??????????????????????????? </ns0:CodeBinaryOperatorExpression.Left> ??????????????????????????? <ns0:CodeBinaryOperatorExpression.Right> ????????????????????????????????? <ns0:CodePrimitiveExpression> ?????????????????????????????????????? <ns0:CodePrimitiveExpression.Value> ???????????????????????????????????????????? <ns1:String xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">wxd</ns1:String> ?????????????????????????????????????? </ns0:CodePrimitiveExpression.Value> ????????????????????????????????? </ns0:CodePrimitiveExpression> ??????????????????????????? </ns0:CodeBinaryOperatorExpression.Right> ????????????????????? </ns0:CodeBinaryOperatorExpression> ???????????????? </RuleExpressionCondition.Expression> ?????????? </RuleExpressionCondition> ????? </RuleDefinitions.Conditions> </RuleDefinitions> |
| 手工 代碼 從下拉框綁定時如報錯 | Dim codecondition1 As Workflow.Activities.CodeCondition = New CodeCondition AddHandler codecondition1.Condition, AddressOf Me.ifElse_a_Condition Me.ifElseBranchActivity1.Condition = codecondition1 |
| System.Workflow.Activities.CodeCondition codecondition1 = new CodeCondition(); codecondition2.Condition += new System.EventHandler<Activities.ConditionalEventArgs>(this.ifElse1_Condition); this.ifElseBranch1.Condition = codecondition2; | |
| 方法 格式 | ?'Code Condition模式的判斷,由對e.Result賦不同值決定執(zhí)行不同的分支 ?Private Sub ifElse_a_Condition(ByVal sender As Object, ByVal e As Workflow.Activities.ConditionalEventArgs) ??????? 'e.Result如果為真,就執(zhí)行左邊(為真件條)的IfElseBranch容器 ??????? 'e.Result如果為假,就執(zhí)行右邊(為假件條)的IfElseBranch容器 ??????? If temp = "456" Then ??????????? e.Result = True ??????? Else ??????????? e.Result = False ??????? End If ??? End Sub |
| ??????? void ifElse1_Condition(Object sender, System.Workflow.Activities.ConditionalEventArgs e) ??????? { ??????????? if (wxwinter = "lzm") ??????????? { e.Result = true; } ??????????? else ??????????? { e.Result = false; } ????????? } |
Declarative Rule Condition模式
Declarative Rule Condition模式:由指定的表達(dá)式的值是否符合條件定執(zhí)行不同的分支
WhileActivity
提供了一個條件循環(huán)容器,Condition有兩個條件模式:Code Condition,Declarative Rule Condition設(shè)置見IfElseActivity
SequenceActivity
System.Workflow.Activities
功能:
1.一個簡單的的容器,容器里的結(jié)點(diǎn)按序順執(zhí)行
2.在中ParallelActivity中作為分支容器
說明:
1.SequenceActivity容器以排列好的方式依次運(yùn)行容器內(nèi)的子結(jié)點(diǎn)
2.當(dāng)所有的子結(jié)點(diǎn)都完成時,SequenceActivity結(jié)點(diǎn)結(jié)束
3.從SequenceActivity派生的類,將不能實(shí)現(xiàn) IActivityEventListener 接口.或不能被正確執(zhí)行
ParallelActivity
System.Workflow.Activities.ParallelActivity
并行容器,使用SequenceActivity作為分支容器,當(dāng)所有分支中的結(jié)點(diǎn)都執(zhí)行完成后,該P(yáng)arallelActivity結(jié)點(diǎn)才結(jié)束,繼續(xù)向下執(zhí)行.其特點(diǎn)如下:
1.當(dāng)所有分支中的結(jié)點(diǎn)都執(zhí)行完成后,該P(yáng)arallelActivity結(jié)點(diǎn)才結(jié)束
2.每分支容器SequenceActivity不是在一個獨(dú)立的線程上運(yùn)行的,而是在同一線程中作為一個獨(dú)立的任務(wù)隊列運(yùn)行,特點(diǎn)如下:
每個分支容器SequenceActivity作為ParallelActivity的一個任務(wù)隊列
SequenceActivity分支容器中的Activity作為任務(wù)隊列中的每個任務(wù)項
ParallelActivity以下圖方式周期性的查看每個Sequence隊列中的第一項,如果是可執(zhí)行的Activity就執(zhí)行,如果是不可執(zhí)行的,(如Delay沒到期或HardleExternalEvent沒被外部觸發(fā))就跳過
如果有掛起結(jié)點(diǎn),將是工作流被掛起.
EventDrivenActivity
一個容器,該容器內(nèi)的第一個結(jié)點(diǎn)必需是可以進(jìn)入idle狀態(tài)的結(jié)點(diǎn),如Delay或HandExternalEvent
1.狀態(tài)機(jī)結(jié)點(diǎn)
2.在ListenActivity中作為分支容器
System.Workflow.Activities
| Wraps an Activity whose execution is initialized by an event. This class cannot be inherited. |
| 包裝一個 Activity 執(zhí)行,執(zhí)行一個事件對其初使化 |
| The EventDrivenActivity is a CompositeActivity, meaning the EventDrivenActivity can contain other activities. The EventDrivenActivity is similar to the SequenceActivity activity, with some additional characteristics. An EventDrivenActivity must have a parent that is either a ListenActivity, StateActivity, or StateMachineWorkflowActivity. |
| ?EventDrivenActivity 是 CompositeActivity,表示EventDrivenActivity??? 能包含其他Avtivity, 他與SequenceActivity相似,很多額外的特征 EventDrivenActivity必需有一個ListenActivity, StateActivity, or StateMachineWorkflowActivity.作為父容器 |
| The first child of an EventDrivenActivity activity must be an activity that inherits from IEventActivity. All subsequent children can be activities of any type. The IEventActivity blocks the pending occurrence of some events, such as starting a timer or the arrival of a message. When the event occurs, the IEventActivity finishes running, and then all subsequent activities are executed. |
| ?EventDrivenActivity第一個子結(jié)點(diǎn)必需是一個繼承 IEventActivity接口的Activity, 后面所有的結(jié)點(diǎn)可以是任意Activity。 IEventActivity 阻塞一些沒解決的狀態(tài),如一個時間狀態(tài)或一個外部消息的到來。當(dāng)event完成,IeventActivity 完成運(yùn)行,后面所有的Activity將執(zhí)行 |
| When the StateMachineWorkflow contains an EventDrivenActvity, the EventDrivenActivity has some restrictions. The EventDrivenActivity may contain one, and only one, activity of type IEventActivity, and the HandleExternalEventActivity must be the first child activity. (An HandleExternalEventActivity cannot be in the event handler for a child activity and cannot be a child to the EventDrivenActivity if the HandleExternalEventActivity is not the first child.) As long as the first activity is the HandleExternalEventActivity, the event handler can contain any activities. If an activity other than HandleExternalEventActivity is contained in EventDrivenActivity, that activity cannot have an event handler. |
| 當(dāng)狀態(tài)機(jī)工作流包含一個EventDrivenActvity,這個EventDrivenActvity會有一些限制。 EventDrivenActivity ?可以包含并且只能包含一個類開為 IEventActivity 的Activity. 并且 HandleExternalEventActivity 必須是第一個結(jié)點(diǎn).(一個HandleExternalEventActivity不能被添加到 event handler里,不能被放入EventDrivenActivity 如果HandleExternalEventActivity 不是第一個結(jié)點(diǎn)) 只要HandleExternalEventActivity是第一個結(jié)點(diǎn),event handler能包含任意Activity,如果一個activity other 那么HandleExternalEventActivity 包含在EventDrivenActivity 里的,that activity 不能有event handler |
| For example, an activity that supports event handling can be used inside the EventDrivenActivity but the activity cannot have event handlers attached to itself. Another example is that the EventDrivenActivity can contain a ConditionedActivityGroup, but the ConditionedActivityGroup itself cannot contain any HandleExternalEventActivity classes. |
| 例如:一個提供 event handling的Activity,可以放到EventDrivenActivity 里,但這個activity不能有event handlers綁定到他自身 |
SequenceActivity
System.Workflow.Activities
功能:
1.一個簡單的的容器,容器里的結(jié)點(diǎn)按序順執(zhí)行
2.在中ParallelActivity中作為分支容器
說明:
1.SequenceActivity容器以排列好的方式依次運(yùn)行容器內(nèi)的子結(jié)點(diǎn)
2.當(dāng)所有的子結(jié)點(diǎn)都完成時,SequenceActivity結(jié)點(diǎn)結(jié)束
3.從SequenceActivity派生的類,將不能實(shí)現(xiàn) IActivityEventListener 接口.或不能被正確執(zhí)行
ParallelActivity
System.Workflow.Activities.ParallelActivity
并行容器,使用SequenceActivity作為分支容器,當(dāng)所有分支中的結(jié)點(diǎn)都執(zhí)行完成后,該ParallelActivity結(jié)點(diǎn)才結(jié)束,繼續(xù)向下執(zhí)行.其特點(diǎn)如下:
1.當(dāng)所有分支中的結(jié)點(diǎn)都執(zhí)行完成后,該ParallelActivity結(jié)點(diǎn)才結(jié)束
2.每分支容器SequenceActivity不是在一個獨(dú)立的線程上運(yùn)行的,而是在同一線程中作為一個獨(dú)立的任務(wù)隊列運(yùn)行,特點(diǎn)如下:
每個分支容器SequenceActivity作為ParallelActivity的一個任務(wù)隊列
SequenceActivity分支容器中的Activity作為任務(wù)隊列中的每個任務(wù)項
ParallelActivity以下圖方式周期性的查看每個Sequence隊列中的第一項,如果是可執(zhí)行的Activity就執(zhí)行,如果是不可執(zhí)行的,(如Delay沒到期或HardleExternalEvent沒被外部觸發(fā))就跳過
如果有掛起結(jié)點(diǎn),將是工作流被掛起.
ListenActivity
單線觸發(fā)容器,使用EventDrivenActivity作為分支容器,當(dāng)某條分支中的結(jié)點(diǎn)執(zhí)行完成后,該ListenActivity結(jié)點(diǎn)就結(jié)束,繼續(xù)向下執(zhí)行,其他分支內(nèi)的結(jié)點(diǎn)就不執(zhí)行了
關(guān)于EventDrivenActivity容器的使用方法見EventDrivenActivity容器介紹
另外,其他分支中已執(zhí)行部分的操作回滾的另附文章
SynchronizationScopeActivity
System.Workflow.ComponentModel
1.SynchronizationScopeActivity容器可設(shè)置一個互斥標(biāo)記,有了互斥標(biāo)記的SynchronizationScopeActivity容器相對另一個容器,是一個完整的執(zhí)行單元,當(dāng)一個容器沒有完成時,其他有互斥標(biāo)記的容器不會執(zhí)行。
2.這時,具有同一互斥標(biāo)記的容器,執(zhí)行模式已經(jīng)與ParallelActivity中描述有所不同,此時他們是串行的,下例中的等待時間變?yōu)樗蠨elay的累加,順序也成了:A1,A2,A3,B1,B2,C1,C2
3.可以將多組分組字符加入SynchronizationHandles屬性,具有相同分組字符的SynchronizationScopeActivity不會同時執(zhí)行
4.如果不設(shè)SynchronizationHandles屬性,SynchronizationScopeActivity不起任何做用
| Represents a section of workflow that requires controlled access to shared variables. If two or more instances of a SynchronizationScopeActivity access the same variables, then the execution of these activities is effectively serialized. This class cannot be inherited. |
| 表示一個workflow部分,that 請求管理進(jìn)入靜態(tài)變量,如果多個實(shí)例of a SynchronizationScopeActivity 請求變量 ,當(dāng)執(zhí)行這些Activity時,是一個有效的連續(xù) |
SynchronizationHandles屬性
| System.Collections.Generic.List<string> stringcollection1 = new System.Collections.Generic.List<string>(); System.Collections.Generic.List<string> stringcollection2 = new System.Collections.Generic.List<string>(); System.Collections.Generic.List<string> stringcollection3 = new System.Collections.Generic.List<string>(); stringcollection1.Add("wxwinter"); this.syn3.SynchronizationHandles = stringcollection1; ?stringcollection2.Add("wxwinter"); this.syn2.SynchronizationHandles = stringcollection2; stringcollection3.Add("wxwinter"); this.syn1.SynchronizationHandles = stringcollection3; |
| 可以將多組分組字符加入SynchronizationHandles屬性,具有相同分組字符的SynchronizationScopeActivity不會同時執(zhí)行 |
ConditionedActivityGroup
1.可以通過定義條件觸發(fā)CAG組中的某個Activity
2.拖入CAG中的每各個Activity 都有一個When Condition ,
When Condition有兩種方式,一種是CodeCondition 一種是RuleConditionReferences
當(dāng)When Condition條件滿足時,在CAG的每個輪詢周期內(nèi),該Activity 會執(zhí)行一次
Activity 的When Condition可以不設(shè),這時,該Activity只在第一次輪詢時被執(zhí)行,以后的輪詢都不會被執(zhí)行了
3.CAG有一個Until condition 屬性,條件成立時,該CAG就退出輪詢,結(jié)點(diǎn)完成
CAG輪詢每一次新輪詢開始時,會查看Until condition ,如果條件成立就退出,完成結(jié)點(diǎn)
? CAG的Until condition 屬性可以不設(shè),這時只CAG輪詢不到When Condition條件成立還成立的Activity時,才完成結(jié)點(diǎn)
ConditionedActivityGroup
1.可以通過定義條件觸發(fā)CAG組中的某個Activity
2.拖入CAG中的每各個Activity 都有一個When Condition ,
When Condition有兩種方式,一種是CodeCondition 一種是RuleConditionReferences
當(dāng)When Condition條件滿足時,在CAG的每個輪詢周期內(nèi),該Activity 會執(zhí)行一次
Activity 的When Condition可以不設(shè),這時,該Activity只在第一次輪詢時被執(zhí)行,以后的輪詢都不會被執(zhí)行了
4.在CAG的每個輪詢周期內(nèi),只要有Activity的When Condition條件成立,該Activity就會被執(zhí)行一次
? 在下一個CAG輪詢周期內(nèi),如果該Activity的When Condition條件成立還成立,仍會被執(zhí)行,直到When Condition條件不成立
replicatorActivity
1.Replicator可以在運(yùn)行時刻,建立某個Activity 的多組實(shí)例
2.Replicator容器,只能包含一個Activity。
CurrentChildData屬性
通過設(shè)定CurrentChildData屬性,決定在運(yùn)行時刻Replicator 啟動Activity的實(shí)例個數(shù)
ExecutionType屬性
可以設(shè)置replicator容器中的Activity實(shí)例是串行還是并行
UntilCondition屬性
默認(rèn)的情況下,UntilCondition屬性沒設(shè),這時所有Replicator容器中的Activity的實(shí)例執(zhí)行完成后,Replicator結(jié)點(diǎn)完成。如果設(shè)置UntilCondition 屬性,當(dāng)UntilCondition條件滿足刊,Replicator會取消或中斷正在運(yùn)行的所有實(shí)例,結(jié)束該結(jié)點(diǎn)
ChildInitialized事件
每次創(chuàng)建子Activity 實(shí)例時執(zhí)行
? 事件中有一個System.Workflow.Activities.ReplicatorChildEventArgs 對象,它是Replicator容器,將數(shù)據(jù)傳遞給每個子Activity 實(shí)例的通道
| ??????? void replicatorActivity1_ChildInitialized(object sender, ReplicatorChildEventArgs e) ??????? { ?????????? 子控件 obj = (子控件)e.Activity; ??????????? obj.標(biāo)記數(shù)據(jù)屬性 = (string)e.InstanceData; ??????? } |
| e.Activity 代表當(dāng)前子Activity 實(shí)例的引用,通過這個對象可以訪問子Activity 中的屬性 |
| e.InstanceData 就是CurrentChildData 屬性,它是IList對象 運(yùn)行時刻每建立一個子Activity 的實(shí)例,就會從這個IList中取出一個對象作為該實(shí)例使用的數(shù)據(jù) 上例中的[標(biāo)記數(shù)據(jù)屬性]是子控件中定義的一個屬性,使用這種方式將不同的參數(shù)傳入每個子控件實(shí)例的內(nèi)部 replicatorActivity會跟據(jù)CurrentChildData 屬性中的項個數(shù),自動建立與之對應(yīng)個數(shù)的子控件實(shí)例,并把項依次分配給每個子控件實(shí)例 |
ChildCompleted 事件
每次子Activity 實(shí)例完成執(zhí)行
| ?????? void replicatorActivity1_ChildCompleted(object sender, ReplicatorChildEventArgs e) ??????? { ??????????? 子控件 obj = (子控件)e.Activity; ??????????? 結(jié)果列表.Add(obj.投票數(shù)據(jù).投票人 + obj.投票數(shù)據(jù).結(jié)果 + obj.投票數(shù)據(jù).投票時間); ??????? } |
| e.Activity 代表當(dāng)前子Activity 實(shí)例的引用,通過這個對象可以訪問子Activity 中的屬性 |
| e.InstanceData 對應(yīng)ChildInitialized事件所分配的值 |
5.如果控制不好Activity的When Condition,與CAG的Until condition,可能會出現(xiàn)一個死循環(huán)
replicatorActivity
1.Replicator可以在運(yùn)行時刻,建立某個Activity 的多組實(shí)例
2.Replicator容器,只能包含一個Activity。
CurrentChildData屬性
通過設(shè)定CurrentChildData屬性,決定在運(yùn)行時刻Replicator 啟動Activity的實(shí)例個數(shù)
ExecutionType屬性
可以設(shè)置replicator容器中的Activity實(shí)例是串行還是并行
UntilCondition屬性
默認(rèn)的情況下,UntilCondition屬性沒設(shè),這時所有Replicator容器中的Activity的實(shí)例執(zhí)行完成后,Replicator結(jié)點(diǎn)完成。如果設(shè)置UntilCondition 屬性,當(dāng)UntilCondition條件滿足刊,Replicator會取消或中斷正在運(yùn)行的所有實(shí)例,結(jié)束該結(jié)點(diǎn)
總結(jié)
以上是生活随笔為你收集整理的Activity容器控件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Activity功能控件
- 下一篇: 贷款2万一年利息多少钱