DOC

COMHOL07 - Data Activities

By Pauline Olson,2014-09-09 15:51
8 views 0
COMHOL07 - Data Activities

Hands-On Lab

    Lab Manual

    Lab 07 Data Activities & XML Documents

    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 07: DATA ACTIVITIES AND FORMS ............................................................................................................... 1 Lab Objective ......................................................................................................................................................... 1 Exercise 1 Accessing Console Host Data from a Workflow ................................................................................ 2 Task 1 Create a new Workflow Project ........................................................................................................... 2 Task 2 Create the Data Class and the IDataHandler ..................................................................................... 2 Task 3 Create the Workflow Design ............................................................................................................... 4 Task 4 Update the Console Host .................................................................................................................... 8 Task 5 Run the Workflow ................................................................................................................................ 9 Summary .......................................................................................................................................................... 10 Exercise 2 Windows Forms Host with Data Centric Binding to Controls on the Form...................................... 11 Task 1 Create a new Workflow Project ......................................................................................................... 11 Task 2 Add the Windows Forms Project to the Solution .............................................................................. 11 Task 3 Add Controls to the Form .................................................................................................................. 12 Task 4 Add Workflow Host code to the Form ............................................................................................... 12 Task 5 Create the Workflow.......................................................................................................................... 14 Task 6 The Workflow State ........................................................................................................................... 18 Task 7 Run the Application ........................................................................................................................... 19 Lab Summary ....................................................................................................................................................... 19

    Page i

Lab 07: Data Activities and Forms

    Estimated time to complete this lab: 60 minutes

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

Lab Objective

    The objective of this lab is to demonstrate the Data Activities features of Windows Workflow Foundation.

    After completing this lab, you will be able to:

    ; Share XML data between the host and the workflow using Data Exchange Activities.

    ; Create a windows forms application with data exchange.

    ; Bind XML data to workflow data.

    Page 1

Exercise 1 Accessing Console Host Data from a Workflow

    In this exercise, you will create a Data Class in a sequential workflow project and you will use this Data

    Class to access data updates from the host.

    Task 1 Create a new Workflow Project

    1. Open Visual Studio 2005 by going to Start | All Programs | Microsoft Visual Studio 2005

    Beta | Microsoft Visual Studio 2005 Beta 2

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

    3. In the New Project dialog box, expand the Visual C# | Workflow in the Project types tree on

    the left

    4. Select the template Sequential Workflow Console Application from the Visual Studio

    installed templates and enter the following for the name and location and Click OK.

    Name: UpdateDataWorkflow

    Location: C:\Windows Workflow Foundation\Labs\Lab07

    5. You will have now created a new solution and workflow project.

Task 2 Create the Data Class and the IDataHandler

    This is being done in preparation for using the WaitForData activity.

    1. Add New Item to the UpdateDateWorkflow by right-clicking in the UpdateDataWorkflow project

    item on the Solution Explorer.

    2. On the Add New Item dialog window select the XML Schema template, name it

    XMLSchema1.xsd, and press Add. This will display an XMLSchema1.xsd window.

    3. Using the XML Schema components in the Toolbox drag-and-drop an Element into the

    XMLSchema1.xsd window. Rename the element1 to MyDocument.

    4. Add a sub-element by typing the name MyProperty in the area below MyDocument.

    5. Add an attribute by typing the name MyID in the area below MyProperty. To denote an attribute,

    change the element descriptor from E to A.

    Page 2

This will generate a class called MyDocument inside the XMLSchema1.cs file. This file will be

contained under the XMLSchema1.xsd.

Page 3

    6. Right-click the Workflow1.cs file in the solution explorer and choose View Code. 7. At the bottom of the file add a new class just before the final closing brace of the file. Your class

    should declare an implementation of IDataHandler. Enter the declaration as follows:

    public class MyDataHandler : IDataHandler

    {

    }

    8. Click on the interface name IDataHandler and use the smart tag that appears to choose

    Implement Interface ‘IDataHandler’. Note: If you do not see the smart tag you should right-

    click on the interface name IDataHandler to use the context menu to take the same action which

    is listed as Implement Interface | Implement Interface. Doing either of these actions will

    result in the following class declaration:

    public class MyDataHandler : IDataHandler

    {

    #region IDataHandler Members

    public object SelectData(object message, DataSourceInfo dataSourceInfo)

    {

     throw new Exception("The method or operation is not implemented.");

    }

    public void UpdateData(object message, DataSourceInfo dataSourceInfo)

    {

     throw new Exception("The method or operation is not implemented.");

    }

    #endregion

    }

    9. In our exercise these methods are not required so we will leave the throw new Exception code

    there.

    Task 3 Create the Workflow Design

    1. Double click on the Workflow1.cs file in your project to open it in the Visual Studio 2005

    designer for Windows Workflow Foundation.

    2. From the menus choose View | Toolbox to show the toolbox. Ensure that the Windows

    Workflow Foundation section is expanded.

    3. Drag on a WaitForData activity to the blank workflow.

    4. Drag on a Code activity under the WaitForData. The workflow should look like this.

    Page 4

    5. You can see that both activities have red circles with exclamation points in them. This indicates

    that there are incomplete items that the activity validators have found which need addressing.

    Click to select the WaitForData activity.

    6. Click on the red circle next to the WaitForData activity and select the smart tag Property

    ‘DataSource’ is not set.

    7. The DataSource property will be selected in the properties pane and click the […] to bring up

    the Data Source selection dialog.

    Page 5

8. There are no current Data Sources so click New… to create a new one.

9. Choose an XsdDataSource and change the name to documentDataSource1. Click OK.

    10. You will see the Configure Xsd Data Source dialog next.

    Page 6

    11. This figure shows the completed dialog. XMLSchema1.xsd is selected from the pull down

    menu. MyDataHandler is selected from the […] choosers and //@MyID is entered after

    selecting the Add button.

    12. Click OK when this is done.

    13. Click OK also on the Select Data Source dialog.

    14. Next the DataObject property has a red circle with an exclamation point. 15. Click on the DataObject property.

    16. Type documentObj as the value and press enter.

    17. If you now right-click on the file Workflow1.cs in the solution explorer and choose View Code

    you will see the documentObj member variable has been added to the source in the Workflow1

    class.

    public sealed partial class Workflow1 : SequentialWorkflow

    {

     public Workflow1()

     {

     InitializeComponent();

     }

     public MyDocument documentObj = new UpdateDataWorkflow.MyDocument();

    }

18. We also need the constructor to set the ID for the data so that it can be found by the host. Add

    the line to the constructor as follows:

    Page 7

Report this document

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