天天看點

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

Windows Workflow Foundation之旅(二)——指南1(構造一個順序工作流)

翻譯自 ms-help://MS.WinWF.v1.EN/WinWF_GettingStarted/html/9c3e5551-4eff-4977-89ac-f81ab092d996.htm

   順序工作流(sequentialworkflow)是為執行一種由一系列預定義的步驟組成的任務而設計的。這種體系結構是模拟基于過程的應用程式的。這一節将用幾個步驟來編寫一個簡單的開支報告程式,這個小程式使用WinFrom做界面,用順序工作流做業務邏輯。  這個小程式有一個TextBox來輸入開支報告的總數,一個Button點選送出報告。工作流将評估開支,如果開支小于1000則提請領班審批,如果大于等于1000則提請經理審批。之後,工作流會發送一個審批意見,此時,出現一個Label顯示審批意見,兩個Button分别表示通過和拒絕審批。當某一個按鈕被點選的時候,應用程式會通知回應工作流,工作流繼續處理發生的事件。   開始構造順序工作流   建立工作流類   WWF SDK中定義了一個SequentialWorkFlow類,我們定義一個ExpenseRoportWorkflow類,并繼 承自SequentialWorkflow,這樣就建立一個順序工作流。如:

   1

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

using  System;

 2

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

using  System.Workflow.Activities;

 3

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

using  System.Workflow.Activities.Rules;

 4

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 5

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

namespace  Microsoft.Samples.Workflow.Quickstarts.SequentialWorkflow

 6

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

 7

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    [RuleConditionsAttribute(typeof(Microsoft.Samples.Workflow.Quickstarts.SequentialWorkflow.ExpenseReportWorkflow))]

 8

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    public sealed partial class ExpenseReportWorkflow : System.Workflow.Activities.SequentialWorkflow

 9

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

10

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        public ExpenseReportWorkflow()

11

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

12

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

13

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        }

14

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    }

15

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

}

16

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    聲明工作流參數    在一個工作流運作時,它可以從宿主應用程式中接收參數。參數是ParameterDeclaration類型的對象,一旦工作流初始化完成,參數的值就能通過工作流的Parameters集合來通路。  這裡的開始報告程式用了兩個參數。第一個參數是開支的總數;第二個是一個傳出參數,用來放置審批意見。  定義一個新的方法InitializeComponent,并在構造ExpenseRoportWorkflow類的構造函數中調用它。一下的例子示範了怎樣定義兩個參數并把它們加到Parameters集合中。

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 1

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

public ExpenseReportWorkflow()

 2

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 3

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

 4

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 5

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    InitializeComponent();

 6

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 7

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

}

 8

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 9

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

10

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

11

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

private void InitializeComponent()

12

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

13

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

14

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

15

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    System.Workflow.ComponentModel.ParameterDeclaration Amount = new System.Workflow.ComponentModel.ParameterDeclaration();

16

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

17

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    System.Workflow.ComponentModel.ParameterDeclaration Result = new System.Workflow.ComponentModel.ParameterDeclaration();

18

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

19

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    //

20

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

21

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    // Workflow Parameters

22

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

23

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    //

24

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

25

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    Amount.Direction = System.Workflow.ComponentModel.ParameterDirection.In;

26

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

27

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    Amount.Name = "Amount";

28

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

29

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    Amount.Type = typeof(int);

30

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

31

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    Amount.Value = null;

32

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

33

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    Result.Direction = System.Workflow.ComponentModel.ParameterDirection.Out;

34

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

35

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    Result.Name = "Result";

36

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

37

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    Result.Type = typeof(string);

38

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

39

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    Result.Value = null;

40

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

41

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    this.Parameters.Add(Amount);

42

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

43

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    this.Parameters.Add(Result);

44

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

45

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

}

46

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

47

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

  使用IfElse活動    IfElse活動用條件表達式來控制工作流中流程的運作。工作流将根據條件表達式的結果來決定執行條件分支(IfElseBranch)中的哪一個活動。  例子中将使用IfElse活動。通過判斷從宿主應用程式中傳入的Amount參數的值是否小于1000,來決定是否将審報發送到領班,否則發送到經理。   建立IfElse活動  1.定義4個私有變量

類型 名稱
IfElse evaluateExpenseReportAmount
IfElseBranch ifNeedsLeadApproval
IfElseBranch elseNeedsManagerApproval
CodeCondition ifElseLogicStatement

 2.在InitializeComponent中用預設構造函數執行個體以上4個對象。  以下的代碼示例了怎樣建立IfElse活動,并用IfElseBranch活動聯系兩個邏輯分支。你需要把以下代碼放到InitializeComponent方法底部。

   1

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  

 2

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 3

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  EvaluateExpenseReportAmount

 4

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 5

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

// 

 6

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 7

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.EvaluateExpenseReportAmount.Activities.Add(this .ifNeedsLeadApproval);

 8

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 9

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.EvaluateExpenseReportAmount.Activities.Add(this .elseNeedsManagerApproval);

10

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

11

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.EvaluateExpenseReportAmount.ID = "EvaluateExpenseReportAmount" ;

12

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

13

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  

14

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

15

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  ifNeedsLeadApproval

16

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

17

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

// 

18

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

19

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.ifNeedsLeadApproval.Activities.Add(this .invokeGetLeadApproval);

20

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

21

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

ifElseLogicStatement.Condition += new System.Workflow.Activities.ConditionalExpression(this .DetermineApprovalContact);

22

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

23

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.ifNeedsLeadApproval.Condition =  ifElseLogicStatement;

24

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

25

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.ifNeedsLeadApproval.ID = "ifNeedsLeadApproval" ;

26

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

27

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  

28

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

29

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  elseNeedsManagerApproval

30

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

31

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

// 

32

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

33

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.elseNeedsManagerApproval.Activities.Add(this .invokeGetManagerApproval);

34

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

35

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.elseNeedsManagerApproval.Condition = null ;

36

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

37

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.elseNeedsManagerApproval.ID = "elseNeedsManagerApproval" ;

38

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

   WWF在IfElse活動中,有兩種評估條件表達式的方式。一種是RoleCondition,這個對象通過使用一組規則來判斷條件表達式的結果;另一種就是使用CodeCondition活動。CodeCondition使用一個回調方法,這個回調方法傳回一個代表評估結果的布爾值。上面的例子就是使用CodeCondition來決定條件表達式的值。如果Amount參數小于1000,回調方法傳回true,否則傳回false。以下的代碼就是這個回調函數的定義,你可以把它加到工作流類的定義中。

   1

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

private bool DetermineApprovalContact(object  sender, EventArgs e)

 2

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 3

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

 4

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 5

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    if ( Convert.ToInt32(this.Parameters["Amount"].Value) < 1000 )

 6

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 7

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        return true;

 8

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 9

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

10

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

11

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    return false;

12

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

13

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

}

14

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

  構造IfElse分支(IfElseBranch)活動    建立完IfElse活動之後,我們來構造IfElseBranch活動  在這個例子中,每一IfElse活動的分支都使用InvokeMethodActivity活動來通知宿主程式——工作流需要領班或經理的審批才能繼續執行。InvokeMethodActivity被設計成調用一個在WWF運作時中的服務接口。我們在同一份代碼檔案中定義了這個接口。當我們在之後構造宿主程式時,宿主類将實作這個接口,以便能建立工作流和宿主程式的通信(這一段文檔上寫的很模糊,我reflect後看了源碼才明白過來,在最後将補充描述一下)。

    建構IfElseBranch活動  1. 在類中定義兩個私有字段

類型 名稱
InvokeMethodActivity invokeGetLeadApproval
InvokeMethodActivity invokeGetManagerApproval

 2. 在InitializeComponent中用預設構造函數執行個體化這兩個對象  以下的代碼示例了怎樣在父活動(IfElse)中建立IfElseBranch活動,并把兩個的InvokeMethodActivity聯系到對應的IfElseBranch活動上,每個InvokeMethodActivity将調用定義在IExpenseReportService接口中的方法,接口會在稍微實作。你需要把以下代碼放到InitializeComponent方法底部。

     1

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  

 2

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 3

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  invokeGetLeadApproval

 4

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 5

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

// 

 6

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 7

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.invokeGetLeadApproval.ID = "invokeGetLeadApproval" ;

 8

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 9

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.invokeGetLeadApproval.InterfaceType = typeof (Microsoft.Samples.Workflow.Quickstarts.SequentialWorkflow.IExpenseReportService);

10

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

11

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.invokeGetLeadApproval.MethodName = "GetLeadApproval" ;   

12

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

13

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  

14

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

15

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  invokeGetManagerApproval

16

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

17

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

// 

18

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

19

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.invokeGetManagerApproval.ID = "invokeGetManagerApproval" ;

20

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

21

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.invokeGetManagerApproval.InterfaceType = typeof (Microsoft.Samples.Workflow.Quickstarts.SequentialWorkflow.IExpenseReportService);

22

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

23

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.invokeGetManagerApproval.MethodName = "GetManagerApproval" ;

24

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

25

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    以下代碼定義了IExpenseReportService接口  1

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

using  System;

 2

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 3

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

using  System.Workflow.ComponentModel;

 4

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 5

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

using  System.Workflow.Runtime.Messaging;

 6

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 7

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 8

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 9

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

namespace  Microsoft.Samples.Workflow.Quickstarts.SequentialWorkflow

10

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

11

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

12

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

13

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    [DataExchangeService]

14

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

15

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    public interface IExpenseReportService

16

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

17

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

18

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

19

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        void GetLeadApproval();

20

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

21

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        void GetManagerApproval();

22

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

23

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        event EventHandler<WorkflowMessageEventArgs> ExpenseReportApproved;

24

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

25

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        event EventHandler<WorkflowMessageEventArgs> ExpenseReportRejected;

26

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

27

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    }

28

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

29

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

}

30

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

31

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

  監聽宿主事件   在這個階段,工作流已經從宿主程式接受了兩個參數(譯者注:其中一個為out參數,此時設為null),評估了Amount參數,作出了到底該提請誰确認審批的決定,并通知了宿主程式在繼續接下來的處理之前,确認審批。這裡,Listen活動和EventSinkActivity活動往往配合使用,來監聽宿主程式觸發指定的事件。接着,一個approval或rejection事件被引發,工作流繼續執行,傳回審批結果Result,并終止流程。 Listen活動的每個分支是一個EventDriven活動。EventDriven活動隻能使用實作了IEventActivity接口的活動。Listen活動的每個分支中的EventDriven各有一個EventSinkActivity,它們是用來監聽宿主程式觸發的ExpenseReportApproved或者ExpenseReportRejected事件的。這種工作流和宿主的通信方法其實類似于之前的InvokeMethodActivity的過程,隻不過前者是工作流監聽宿主事件,而後者是宿主事件工作流中注冊的接口。 我們已經在前面的步驟中,把接口和兩個事件的定義都完成了。在這裡,我們将建立一個Listen活動并和兩個EventDriven分支建立連接配接。每個分支包含一個EventSinkActivity活動,每個EventSink監聽一種對應的事件。此外,我們還将建立一些事件處理程式,來處理AfterInvoke事件(譯者注:這裡的AfterInvoke事件應為Invoked事件)。這些事件處理程式将會把Result參數的值設為approval或者rejected。   構造監聽活動 1.在工作流類中定義5個私有字段

類型 名稱
Listen listenApproveReject
EventDriven approveEventDriven
EventDriven rejectEventDriven
EventSinkActivity approveEvent
EventSinkActivity rejectEvent

 2. 在InitializeComponent中執行個體化。  以下的代碼示例了怎樣在建立Listen活動和EventSinkActivity活動,來監聽宿主程式發出的事件。你需要把以下代碼放到InitializeComponent方法底部。 使用EventSinkActivity時,為了在工作流中加入一些附加邏輯,你可以為Invoked事件建立一個事件處理程式。一下是事件處理程式的代碼。  1

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  

 2

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 3

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  listenApproveReject

 4

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 5

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

// 

 6

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 7

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.listenApproveReject.Activities.Add(this .approveEventDriven);

 8

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 9

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.listenApproveReject.Activities.Add(this .rejectEventDriven);

10

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

11

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.listenApproveReject.ID = "listenApproveReject" ;

12

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

13

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  

14

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

15

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  approveEventDriven

16

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

17

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

// 

18

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

19

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.approveEventDriven.Activities.Add(this .approveEvent);

20

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

21

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.approveEventDriven.ID = "approveEventDriven" ;

22

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

23

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  

24

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

25

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  approveEvent

26

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

27

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

// 

28

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

29

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.approveEvent.EventName = "ExpenseReportApproved" ;

30

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

31

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.approveEvent.ID = "approveEvent" ;

32

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

33

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.approveEvent.InterfaceType = typeof (Microsoft.Samples.Workflow.Quickstarts.SequentialWorkflow.IExpenseReportService);

34

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

35

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.approveEvent.Roles = null ;

36

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

37

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.approveEvent.Invoked += new System.EventHandler(this .approveEvent_Invoked);

38

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

39

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  

40

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

41

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  rejectEventDriven

42

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

43

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

// 

44

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

45

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.rejectEventDriven.Activities.Add(this .rejectEvent);

46

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

47

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.rejectEventDriven.ID = "rejectEventDriven" ;

48

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

49

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  

50

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

51

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  rejectEvent

52

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

53

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

// 

54

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

55

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.rejectEvent.EventName = "ExpenseReportRejected" ;

56

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

57

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.rejectEvent.ID = "rejectEvent" ;

58

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

59

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.rejectEvent.InterfaceType = typeof (Microsoft.Samples.Workflow.Quickstarts.SequentialWorkflow.IExpenseReportService);

60

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

61

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.rejectEvent.Roles = null ;

62

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

63

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.rejectEvent.Invoked += new System.EventHandler(this .rejectEvent_Invoked);

64

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

65

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

完成順序工作流  1

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

private void approveEvent_Invoked(object  sender, EventArgs e)

 2

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 3

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

 4

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 5

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    this.Parameters["Result"].Value = "Report Approved";

 6

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 7

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

}

 8

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 9

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

10

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

11

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

private void rejectEvent_Invoked(object  sender, EventArgs e)

12

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

13

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

14

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

15

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    this.Parameters["Result"].Value = "Report Rejected";

16

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

17

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

}

18

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

19

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    這個工作流包括兩個主要的步驟:第一,監聽宿主程式的遞交審批事件,并把傳入的值作為工作流參數;第二,監聽通過或拒絕審批消息。一下的代碼示例了怎樣通過把之前建立好的活動加到工作流活動集中,來完成工作流的構造。  1

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  

 2

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 3

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

//  ExpenseReportWorkflow

 4

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 5

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

// 

 6

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 7

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.Activities.Add(this .EvaluateExpenseReportAmount);

 8

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 9

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.Activities.Add(this .listenApproveReject);

10

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

11

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.DynamicUpdateCondition = null ;

12

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

13

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

this.ID = "ExpenseReportWorkflow" ;

14

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

15

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

  建立宿主程式   WWF需要一個宿主程式來運作工作流。當程式開始運作,WWF運作時引擎也随之啟動。而之前構造好的工作流,則到使用者點選了Submit按鈕後才真正啟動。 建立一個新的源檔案,取名Program。以下的代碼包含了完整的WinForm應用程式。IExpenseReportService接口GetLeadApproval和GetmanagerApproval方法已經定義在另一個檔案中。宿主程式實作了這個接口。在approval和rejected按鈕的click事件中,将引發ExpenseReprotApproval或ExpenseReprotRejected事件。     1

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

using  System;

  2

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

  3

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

using  System.ComponentModel;

  4

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

  5

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

using  System.Drawing;

  6

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

  7

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

using  System.Windows.Forms;

  8

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

  9

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

using  System.Collections.Generic;

 10

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 11

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

using  System.Workflow.Runtime;

 12

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 13

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

using  System.Workflow.Runtime.Hosting;

 14

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 15

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

using  System.Workflow.Runtime.Messaging;

 16

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 17

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 18

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 19

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

namespace  Microsoft.Samples.Workflow.Quickstarts.SequentialWorkflowHost

 20

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 21

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

 22

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 23

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    public class MainForm : Form, Microsoft.Samples.Workflow.Quickstarts.SequentialWorkflow.IExpenseReportService

 24

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 25

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

 26

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 27

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private System.Windows.Forms.Label label1;

 28

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 29

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private System.Windows.Forms.TextBox result;

 30

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 31

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private System.Windows.Forms.Label label2;

 32

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 33

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private System.Windows.Forms.Button submitButton;

 34

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 35

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private System.Windows.Forms.Label approvalState;

 36

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 37

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private System.Windows.Forms.Button approveButton;

 38

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 39

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private System.Windows.Forms.Button rejectButton;

 40

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 41

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private System.Windows.Forms.TextBox amount;

 42

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 43

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private System.Windows.Forms.Panel panel1;

 44

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 45

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 46

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 47

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private System.ComponentModel.IContainer components = null;

 48

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 49

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 50

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 51

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private delegate void GetApprovalDelegate();

 52

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 53

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private WorkflowRuntime workflowRuntime = null;

 54

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 55

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private WorkflowInstance workflowInstance = null;

 56

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 57

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 58

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 59

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        public MainForm()

 60

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 61

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

 62

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 63

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            InitializeComponent();

 64

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 65

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 66

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 67

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // Collapse approve/reject panel

 68

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 69

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.Height -= this.panel1.Height;

 70

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 71

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 72

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 73

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            workflowRuntime = new WorkflowRuntime();

 74

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 75

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            workflowRuntime.AddService(this);

 76

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 77

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            workflowRuntime.StartRuntime();

 78

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 79

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 80

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 81

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            workflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(workflowRuntime_WorkflowCompleted);

 82

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 83

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        }

 84

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 85

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 86

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 87

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        protected override void Dispose(bool disposing)

 88

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 89

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

 90

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 91

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            if (disposing && (components != null))

 92

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 93

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

 94

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 95

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                components.Dispose();

 96

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 97

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            }

 98

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

 99

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            base.Dispose(disposing);

100

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

101

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        }

102

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

103

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

104

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

105

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private void InitializeComponent()

106

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

107

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

108

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

109

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.label1 = new System.Windows.Forms.Label();

110

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

111

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.result = new System.Windows.Forms.TextBox();

112

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

113

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.label2 = new System.Windows.Forms.Label();

114

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

115

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.submitButton = new System.Windows.Forms.Button();

116

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

117

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.approvalState = new System.Windows.Forms.Label();

118

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

119

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.approveButton = new System.Windows.Forms.Button();

120

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

121

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.rejectButton = new System.Windows.Forms.Button();

122

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

123

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.amount = new System.Windows.Forms.TextBox();

124

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

125

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.panel1 = new System.Windows.Forms.Panel();

126

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

127

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.panel1.SuspendLayout();

128

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

129

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.SuspendLayout();

130

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

131

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

132

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

133

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // label1

134

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

135

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

136

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

137

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.label1.AutoSize = true;

138

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

139

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.label1.Location = new System.Drawing.Point(13, 13);

140

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

141

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.label1.Name = "label1";

142

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

143

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.label1.Size = new System.Drawing.Size(39, 13);

144

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

145

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.label1.TabIndex = 1;

146

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

147

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.label1.Text = "Amount";

148

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

149

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

150

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

151

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // result

152

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

153

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

154

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

155

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.result.Location = new System.Drawing.Point(13, 69);

156

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

157

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.result.Name = "result";

158

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

159

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.result.ReadOnly = true;

160

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

161

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.result.Size = new System.Drawing.Size(162, 20);

162

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

163

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.result.TabIndex = 1;

164

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

165

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.result.TabStop = false;

166

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

167

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

168

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

169

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // label2

170

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

171

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

172

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

173

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.label2.AutoSize = true;

174

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

175

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.label2.Location = new System.Drawing.Point(13, 54);

176

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

177

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.label2.Name = "label2";

178

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

179

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.label2.Size = new System.Drawing.Size(33, 13);

180

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

181

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.label2.TabIndex = 3;

182

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

183

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.label2.Text = "Result";

184

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

185

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

186

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

187

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // submitButton

188

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

189

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

190

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

191

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.submitButton.Enabled = false;

192

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

193

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.submitButton.Location = new System.Drawing.Point(56, 95);

194

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

195

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.submitButton.Name = "submitButton";

196

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

197

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.submitButton.Size = new System.Drawing.Size(75, 23);

198

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

199

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.submitButton.TabIndex = 2;

200

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

201

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.submitButton.Text = "Submit";

202

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

203

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.submitButton.Click += new System.EventHandler(this.submitButton_Click);

204

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

205

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

206

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

207

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // approvalState

208

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

209

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

210

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

211

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.approvalState.AutoSize = true;

212

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

213

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.approvalState.Location = new System.Drawing.Point(10, 9);

214

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

215

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.approvalState.Name = "approvalState";

216

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

217

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.approvalState.Size = new System.Drawing.Size(45, 13);

218

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

219

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.approvalState.TabIndex = 4;

220

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

221

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.approvalState.Text = "Approval";

222

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

223

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

224

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

225

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // approveButton

226

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

227

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

228

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

229

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.approveButton.Enabled = false;

230

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

231

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.approveButton.Location = new System.Drawing.Point(11, 25);

232

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

233

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.approveButton.Name = "approveButton";

234

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

235

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.approveButton.Size = new System.Drawing.Size(75, 23);

236

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

237

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.approveButton.TabIndex = 0;

238

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

239

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.approveButton.Text = "Approve";

240

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

241

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.approveButton.Click += new System.EventHandler(this.approveButton_Click);

242

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

243

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

244

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

245

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // rejectButton

246

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

247

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

248

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

249

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.rejectButton.Enabled = false;

250

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

251

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.rejectButton.Location = new System.Drawing.Point(86, 25);

252

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

253

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.rejectButton.Name = "rejectButton";

254

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

255

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.rejectButton.Size = new System.Drawing.Size(75, 23);

256

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

257

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.rejectButton.TabIndex = 1;

258

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

259

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.rejectButton.Text = "Reject";

260

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

261

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.rejectButton.Click += new System.EventHandler(this.rejectButton_Click);

262

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

263

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

264

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

265

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // amount

266

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

267

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

268

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

269

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.amount.Location = new System.Drawing.Point(13, 29);

270

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

271

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.amount.MaxLength = 9;

272

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

273

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.amount.Name = "amount";

274

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

275

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.amount.Size = new System.Drawing.Size(162, 20);

276

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

277

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.amount.TabIndex = 0;

278

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

279

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.amount.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.amount_KeyPress);

280

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

281

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.amount.TextChanged += new System.EventHandler(this.amount_TextChanged);

282

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

283

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

284

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

285

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // panel1

286

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

287

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

288

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

289

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.panel1.Controls.Add(this.approvalState);

290

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

291

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.panel1.Controls.Add(this.approveButton);

292

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

293

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.panel1.Controls.Add(this.rejectButton);

294

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

295

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.panel1.Location = new System.Drawing.Point(3, 124);

296

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

297

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.panel1.Name = "panel1";

298

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

299

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.panel1.Size = new System.Drawing.Size(172, 66);

300

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

301

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.panel1.TabIndex = 8;

302

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

303

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

304

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

305

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // MainForm

306

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

307

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // 

308

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

309

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.AcceptButton = this.submitButton;

310

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

311

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

312

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

313

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

314

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

315

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.ClientSize = new System.Drawing.Size(187, 201);

316

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

317

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.Controls.Add(this.panel1);

318

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

319

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.Controls.Add(this.amount);

320

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

321

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.Controls.Add(this.submitButton);

322

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

323

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.Controls.Add(this.label2);

324

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

325

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.Controls.Add(this.result);

326

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

327

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.Controls.Add(this.label1);

328

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

329

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;

330

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

331

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.MaximizeBox = false;

332

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

333

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.MinimizeBox = false;

334

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

335

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.Name = "MainForm";

336

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

337

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.Text = "Simple Expense Report";

338

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

339

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.panel1.ResumeLayout(false);

340

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

341

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.panel1.PerformLayout();

342

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

343

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.ResumeLayout(false);

344

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

345

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.PerformLayout();

346

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

347

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

348

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

349

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        }

350

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

351

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

352

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

353

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private void submitButton_Click(object sender, EventArgs e)

354

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

355

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

356

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

357

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            Type type = typeof(Microsoft.Samples.Workflow.Quickstarts.SequentialWorkflow.ExpenseReportWorkflow);

358

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

359

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

360

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

361

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // Construct workflow parameters

362

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

363

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

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

364

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

365

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            properties.Add("Amount", Int32.Parse(this.amount.Text));

366

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

367

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            properties.Add("Result", string.Empty);

368

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

369

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

370

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

371

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // Start the workflow

372

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

373

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            workflowInstance = workflowRuntime.StartWorkflow(type, properties);

374

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

375

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        }

376

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

377

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

378

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

379

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        void workflowRuntime_WorkflowCompleted(object sender, WorkflowCompletedEventArgs e)

380

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

381

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

382

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

383

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            if (this.result.InvokeRequired)

384

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

385

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.result.Invoke(new EventHandler<WorkflowCompletedEventArgs>(this.workflowRuntime_WorkflowCompleted), sender, e);

386

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

387

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            else

388

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

389

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

390

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

391

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.result.Text = e.OutputParameters["Result"].ToString();

392

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

393

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

394

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

395

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                // Clear fields

396

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

397

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.amount.Text = string.Empty;

398

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

399

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

400

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

401

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                // Disable buttons

402

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

403

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.approveButton.Enabled = false;

404

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

405

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.rejectButton.Enabled = false;

406

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

407

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            }

408

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

409

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        }

410

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

411

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

412

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

413

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private void approveButton_Click(object sender, EventArgs e)

414

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

415

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

416

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

417

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // Raise the ExpenseReportApproved event back to the workflow

418

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

419

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            ExpenseReportApproved(null, new WorkflowMessageEventArgs(this.workflowInstance.InstanceId));

420

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

421

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.Height -= this.panel1.Height;

422

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

423

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.submitButton.Enabled = true;

424

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

425

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        }

426

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

427

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

428

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

429

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private void rejectButton_Click(object sender, EventArgs e)

430

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

431

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

432

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

433

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            // Raise the ExpenseReportRejected event back to the workflow

434

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

435

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            ExpenseReportRejected(null, new WorkflowMessageEventArgs(this.workflowInstance.InstanceId));

436

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

437

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.Height -= this.panel1.Height;

438

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

439

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            this.submitButton.Enabled = true;

440

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

441

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        }

442

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

443

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

444

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

445

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        IExpenseReportService Members#region IExpenseReportService Members

446

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

447

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

448

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

449

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        public void GetLeadApproval()

450

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

451

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

452

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

453

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            if (this.approvalState.InvokeRequired)

454

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

455

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.approvalState.Invoke(new GetApprovalDelegate(this.GetLeadApproval));

456

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

457

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            else

458

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

459

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

460

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

461

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.approvalState.Text = "Lead approval needed";

462

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

463

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.approveButton.Enabled = true;

464

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

465

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.rejectButton.Enabled = true;

466

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

467

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

468

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

469

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                // expand the panel

470

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

471

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.Height += this.panel1.Height;

472

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

473

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.submitButton.Enabled = false;

474

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

475

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            }

476

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

477

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        }

478

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

479

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

480

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

481

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        public void GetManagerApproval()

482

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

483

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

484

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

485

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            if (this.approvalState.InvokeRequired)

486

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

487

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.approvalState.Invoke(new GetApprovalDelegate(this.GetManagerApproval));

488

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

489

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            else

490

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

491

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

492

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

493

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.approvalState.Text = "Manager approval needed";

494

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

495

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.approveButton.Enabled = true;

496

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

497

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.rejectButton.Enabled = true;

498

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

499

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

500

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

501

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                // expand the panel

502

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

503

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.Height += this.panel1.Height;

504

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

505

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                this.submitButton.Enabled = false;

506

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

507

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            }

508

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

509

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        }

510

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

511

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

512

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

513

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        public event EventHandler<WorkflowMessageEventArgs> ExpenseReportApproved;

514

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

515

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        public event EventHandler<WorkflowMessageEventArgs> ExpenseReportRejected;

516

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

517

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

518

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

519

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        #endregion

520

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

521

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

522

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

523

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private void amount_KeyPress(object sender, KeyPressEventArgs e)

524

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

525

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

526

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

527

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            if (!Char.IsControl(e.KeyChar) && (!Char.IsDigit(e.KeyChar)))

528

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

529

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

                e.KeyChar = Char.MinValue;            

530

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

531

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        }

532

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

533

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

534

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

535

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        private void amount_TextChanged(object sender, EventArgs e)

536

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

537

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

538

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

539

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            submitButton.Enabled = amount.Text.Length > 0;

540

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

541

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        }

542

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

543

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    }

544

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

545

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

546

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

547

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    static class Program

548

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

549

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

550

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

551

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        /// <summary>

552

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

553

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        /// The main entry point for the application.

554

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

555

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        /// </summary>

556

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

557

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        [STAThread]

558

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

559

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        static void Main()

560

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

561

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)
Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

{

562

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

563

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            Application.EnableVisualStyles();

564

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

565

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

            Application.Run(new MainForm());

566

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

567

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

        }

568

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

569

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

    }

570

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

571

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

}

572

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

573

Windows Workflow Foundation之旅(二)——指南1(建立順序工作流)

Ps:上面還有個問題沒有解釋清楚,我reflect了一下,看了源碼才知道個大概。

那就是IfElseBranch中的InvokeMethodActivity。 InvokeMethodActivity中有一個Type類型的InterfaceType屬性,使用時,需要設定這個屬性,并把MethodName設為這個接口中的一個方法的名稱。運作時,工作流引擎(也就是WorkflowRuntime)将通過反射調用這個接口。 但引擎怎麼知道調用接口的哪個實作呢?你看 workflowRuntime = new WorkflowRuntime(); workflowRuntime.AddService(this); workflowRuntime.StartRuntime(); 原來,初始化引擎時,我們已經把實作了這個interface的類型的執行個體(this)注冊到工作流中了。運作時,引擎就周遊所有已經注冊的服務,如果實作了這個接口,這調用它。

繼續閱讀