DOC

COMHOL08 - Authoring Advanced Workflows

By Frederick Wilson,2014-09-09 15:51
15 views 0
COMHOL08 - Authoring Advanced Workflows

Hands-On Lab

    Lab Manual

    Lab 08 Authoring Advanced Workflows

    Please do not remove this manual from the lab

     ;

    Information in this document, including URL and other Internet Web site references, is subject to change without notice. This document supports a preliminary release of software that may be changed substantially prior to final commercial release, and is the proprietary information of Microsoft Corporation.

    This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EITHER EXPRESS OR IMPLIED, AS TO THE INFORMATION IN THIS DOCUMENT.

    The entire risk of the use or the results from the use of this document remains with the user. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

    Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.

    Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, email address, logo, person, place or event is intended or should be inferred.

? 2005 Microsoft Corporation. All rights reserved.

    Microsoft, MS-DOS, Windows, Windows NT, Windows Server, Visual C# and Visual Studio are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.

    The names of actual companies and products mentioned herein may be the trademarks of their respective owners.

     ;

Contents

    LAB 08: AUTHORING ADVANCED WORKFLOWS............................................................................................ 1 Lab Objective .................................................................................................................................................. 1 Exercise 1 Using the Conditioned Activity Group Activity ............................................................................... 1 Task 1 Create a new Sequential Workflow Console Application ................................................................ 1 Task 2 Add the ConditionedActivityGroup and Code activities ................................................................... 2 Task 3 Define the conditions ..................................................................................................................... 8 Task 4 Run the workflow......................................................................................................................... 11 Exercise 2 Using the Replicator Activity ...................................................................................................... 12 Task 1 Create a new Sequential Workflow Console Application .............................................................. 12 Task 2 Add the Replicator....................................................................................................................... 13 Task 3 Run the workflow......................................................................................................................... 16 Exercise 3 Using a Policy Activity ................................................................................................................ 18 Task 1 Create a new Sequential Workflow Console Application .............................................................. 18 Task 2 Add an Activity Library project and create a Policy-based activity................................................. 18 Task 3 Add the activity to the workflow.................................................................................................... 24 Task 4 Run the workflow......................................................................................................................... 25 Lab Summary ................................................................................................................................................ 27

    Page i

Lab 08: Authoring Advanced Workflows

    Estimated time to complete this lab: 60 minutes

    The project files for this lab are in the c:\Windows Workflow Foundation \Labs\Lab08 folder.

Lab Objective

    The objective of this lab is to introduce several of the more advanced activities provided with Windows Workflow Foundation. After completing this lab, you will be able to:

     Use the Conditioned Activity Group activity.

     The Conditioned Activity Group activity allows you to provide condition-driven execution behavior to a collection of activities. This behavior allows you to define the condition under which a given activity will execute, as opposed to defining a strict sequencing or flow of activity execution. Use the Replicator activity to launch multiple copies of other activities.

     The Replicator activity allows you to dynamically generate multiple instances of an activity based on the data provided in a collection at runtime. The instances can be created in sequential or parallel fashion.

     Use a Policy based activity to implement application logic

     The Policy activity encapsulates a forward chaining rules engine. Creating a custom activity that inherits from the Policy activity allows you to define sophisticated application logic that is then available for use in your workflows.

Exercise 1 Using the Conditioned Activity Group Activity

    In this exercise you will create a simple console application to instantiate the Windows Workflow Foundation runtime and start a Conditioned Activity Group based workflow.

Task 1 Create a new Sequential Workflow Console Application

    1. Open Visual Studio 2005 by going to the Start Menu | Programs | Microsoft Visual Studio 2005 Beta

    2 | Microsoft Visual Studio 2005 Beta 2

    2. In Visual Studio 2005, select the File | New | Project menu command.

    3. Visual Studio will display the New Project dialog window.

    4. In the New Project dialog window, expand Visual C# | Workflow in the Project Types tree on the left

    side.

    5. Select the template named “Sequential Workflow Console Application” and accept the default name for

    the project but change the location to C:\Windows Workflow Foundation\Labs\Lab08\CAG and leave the "Create directory for solution" box checked. This will create a subdirectory to C:\Windows Workflow

    Page 1

Foundation\Labs\Lab08\CAG and place the project and solution files there. The directory will be named

    WorkflowConsoleApplication1.

    6. Click OK and the basic project will be generated. Task 2 Add the ConditionedActivityGroup and Code activities 1. Let's start by adding some activities to the workflow. First drag and drop a ConditionedActivityGroup

    activity onto the workflow from the toolbox (select View | Toolbox from the menu if the toolbox is not shown). It should look like this:

    Page 2

    2. Now we need to add two Code activities to the ConditionedActivityGroup. In the screen shot above you can see a section of the ConditionedActivityGroup drawing that has the words "Drop Activities Here". Grab a Code activity and place in on that area and you should see this:

    Page 3

    3. The little red balls with the exclamation marks are an indication that we have not yet connected the Code activity for code1 to a function. We will do that next, but first add another Code activity so that your screen looks like this:

    Page 4

4. Next we will add the code handlers for the two Code activities that were added. Place the code below

    in the Workflow1 class in Workflow1.cs (you can use the snippet titled: Lab08Exercise01CodeHandlers). You can go to Workflow1.cs by right clicking on the design surface and choose View Code.

     public enum NumberIs { Odd = 0, Even = 1}

     private NumberIs currentNumber = NumberIs.Even;

     private bool userRequestsExit;

     //number entered is odd

     public void code1_ExecuteCode(object sender, EventArgs e)

     {

     Console.WriteLine("the number is odd");

     GetNextNumber();

     }

     //number entered is even

     public void code2_ExecuteCode(object sender, EventArgs e)

     {

     Console.WriteLine("the number is even");

     GetNextNumber();

     }

     //evaluate number entered by user and set currentNumber variable

     private void GetNextNumber()

     {

     int numIn;

    Page 5

     Console.WriteLine("enter a number.");

     string charIn = Console.ReadLine();

     if (Int32.TryParse(charIn, out numIn))

     {

     if ((numIn % 2) == 0)

     {

     currentNumber = NumberIs.Even;

     }

     else

     {

     currentNumber = NumberIs.Odd;

     }

     }

     else if (charIn.Contains("x"))

     {

     userRequestsExit = true;

     }

     else

     {

     GetNextNumber();

     }

     }

5. Now that we have these two functions, go to the property window for code1. It should look like this; the

    red ball with the exclamation mark indicating that this is a property we need to set.

    6. Click on ExecuteCode in the Handlers section. The drop down list should contain the code1_ExecuteCode and code2_ExecuteCode methods that we just added. Select code1_ExecuteCode if it hasn't already been done. It should look like this:

    Page 6

    7. You can see that there is a red ball with an exclamation mark next to code2. Now you can click on the code2 activity and connect its ExecuteCode handler to code2_ExecuteCode. It should look like this when

    you are done:

    Page 7

Report this document

For any questions or suggestions please email
cust-service@docsford.com