accessing cloud data with windows azure …az12722.vo.msecnd.net/.../lab.docx · web viewworking in...

43
Hands-On Lab Accessing Cloud Data with Windows Azure Marketplace Lab version: 1.0.0 Last updated: 7/8/2022

Upload: others

Post on 18-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Hands-On LabAccessing Cloud Data with Windows Azure Marketplace

Lab version: 1.0.0

Last updated: 5/20/2023

Page 2: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

CONTENTS

OVERVIEW................................................................................................................................................. 4

EXERCISE 1: SUBSCRIBE TO A MICROSOFT WINDOWS AZURE MARKETPLACE DATASET..........6Task 1 – Registering for a Windows Azure Marketplace Account........................................................6

Task 2 – Subscribing to the DATA.Gov Dataset....................................................................................7

Task 3 – Reviewing your My Data Pages..............................................................................................8

Task 4 – Exploring GOV.Data...............................................................................................................9

Exercise 1 Verification.......................................................................................................................10

EXERCISE 2: CREATE A BUSINESS DATA CATALOG MODEL TO ACCESS THE DATASET..........10Task 1 – Adding a Service Reference to the DATA.Gov Web Service.................................................11

Task 2 – Modifying the Entity1 Class..................................................................................................12

Task 3 – Modifying the ReadList Method of the Entity1Service Class................................................13

Task 4 – Modifying the ReadItem Method of the Entity1Service Class..............................................15

Task 5 – Updating the Model’s Type Descriptors...............................................................................16

Task 6 – Adding the SiteUrl Property to the Feature’s Element File..................................................19

Task 7 – Modifying the Model’s Permission in Central Administration.............................................21

EXERCISE 3: CREATE AN EXTERNAL LIST TO CONSUME THE MARKETPLACE DATASET..........24Task 1 – Creating an External List......................................................................................................24

Exercise 3 Verification.......................................................................................................................26

EXERCISE 4: CREATE A WEB PART TO DISPLAY THE MARKETPLACE DATA...............................26Task 1 – Opening and Review the Starter Solution............................................................................26

Task 2 – Adding the Silverlight Client Side Object Model References................................................27

Task 3 – Completing the Existing View Model...................................................................................28

Task 4 – Replacing and Review the MainPage Xaml Markup.............................................................32

Task 5 – Completing the Existing MainPage.Xaml.cs Code Beside.....................................................32

Exercise 4 Verification.......................................................................................................................34

EXERCISE 5: DEPLOY THE WEB PART................................................................................................34Task 1 – Deploying the Solution.........................................................................................................34

Page 3: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

SUMMARY................................................................................................................................................ 37

Page 4: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Overview

Working in the cloud is becoming a major initiative for application development departments. Windows Azure is Microsoft’s cloud incorporating data and services. This lab will guide the reader through a series of exercises that creates a Silverlight Web Part that displays Windows Azure Marketplace data on a Silverlight Bing map control.

Objectives

This lab will demonstrate how you can consume Windows Azure data using SharePoint 2010 and a Silverlight Web Part. To demonstrate connecting to Windows Azure data the reader will

Subscribe to a Microsoft Windows Azure Marketplace dataset

Create a Business Data Catalog model to access the dataset

Create an external list to expose the dataset

Create a Silverlight Web Part to display the data

Deploy the Web Part.

System Requirements

You must have the following items to complete this lab:

2010 Information Worker Demonstration and Evaluation Virtual Machine

Microsoft Visual Studio 2010

Bing Silverlight Map control and Bing Map Developer Id

Silverlight WebPart

Internet Access

Setup

You must perform the following steps to prepare your computer for this lab...

1. Download the 2010 Information Worker Demonstration and Evaluation Virtual Machine from http://tinyurl.com/2avoc4b and create the Hyper-V image.

2. Install the Visual Studio 2010 Silverlight Web Part. The Silverlight Web Part is an add-on to Visual Studio 2010.

Page 5: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

3. Create a document library named SilverlightXaps located at http://intranet.contoso.com/silverlightxaps. This is where you will store the Silverlight Xap in SharePoint.

4. Create a Bing Map Developer Account.

5. Download and install the Bing Map Silverlight Control.

Exercises

This Hands-On Lab comprises the following exercises:

1. Subscribe to a Microsoft Windows Azure MarketPlace Dataset

2. Create a Business Data Catalog Model to Access the Dataset

3. Create an External List to Consume the MarketPlace Dataset

4. Create a Web Part to Display the MarketPlace Data

5. Deploy the Web Part

Estimated time to complete this lab: 60 minutes.

Starting Materials

This Hands-On Lab includes the following starting materials.

Visual Studio solutions. The lab provides the following Visual Studio solutions that you can use as starting point for the exercises.

◦ <Install>\Labs\ACDM\Source\Begin\TheftStatisticsBDCModel \ TheftStatisticsBDCModel.sln: This solution creates the Business Data Catalog application.

◦ <Install>\Labs\ACDM\Source\Begin\ TheftStatisticsWebPart \ TheftStatisticsWebPart.sln: This solution creates the Silverlight Web Part and Silvelright application that will consume data using an external list.

Note: Inside each lab folder, you will find an end folder containing a solution with the completed lab exercise.

Page 6: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Exercise 1: Subscribe to a Microsoft Windows Azure Marketplace dataset

Task 1 – Registering for a Windows Azure Marketplace Account

In this task, you will use Internet Explorer to navigate to Windows Azure Marketplace and register for a Marketplace account.

1. Open Internet Explorer and navigate to http://datamart.azure.com.

2. Click the Sign In link in the right-top corner.

Figure 1Sign In of DataMarket

3. Sign in using your Windows Live Id account.

4. Click the Register link in the upper-right corner to create a new DataMarket account.

5. Enter your account details including first name, last Name, organization name and E-mail address.

Figure 2DataMarket registration

6. Click Continue.

7. Select “I accept the terms of use” check box on the bottom of the Registration page.

8. Click Register link in lower right hand corner of the page.

Page 7: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 3Register Button

Task 2 – Subscribing to the DATA.Gov Dataset

In this task, you will subscribe to the DATA.Gov dataset. If you have just finished with Task 1 are still signed into Windows Azure MarketPlace you can skip steps 2 and 3.

1. Open Internet Explorer and navigate to http://datamart.azure.com.

2. Click the Sign In link in the right-top corner.

3. Sign in using your Windows Live Id account.

4. Click Explorer the MarketPlace link.

Figure 4Explore the MarketPlace link

5. Click on the DATA.Gov image.

Figure 5Data.gov image

6. Click Sign Up to subscribe to the dataset.

Page 8: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

7. Verify the subscription price on this page. Select “I have read and agree to the terms of use “ checkbox on the Subscription Dataset Terms page.

8. Click Sign Up.

Task 3 – Reviewing your My Data Pages

In this task, you will review the three My Data pages and located your Account key that is used for authentication and tracking MarketPlace requests later in this lab. If you have just finished with Task 2 are still signed into Windows Azure MarketPlace you can skip steps 2 and 3.

1. Open Internet Explorer and navigate to http://datamart.azure.com.

2. Click the Sign In link in the right-top corner.

3. Sign in using your Windows Live Id account.

4. Click My Data menu item at the top of the page.

Figure 6My Data menu item

5. Click on Account Information link located in the left-hand navigation.

Figure 7Account Information Link

6. Review the data in the Account Information Page. You can edit your account information from this page.

7. Click on Account Keys link located in the left-hand navigation.

8. Review the Account Keys page. Notice that you can create and edit keys in this page. You will use the key later in the lab for tracking and data access purposes.

9. Click on DataSets link located in the left-hand navigation.

10. Review the DataSets page. This page contains information and links to datasets subscriptions.

Page 9: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Task 4 – Exploring GOV.Data

In this task, you will explore the Gov.Data dataset using the Windows Azure MarketPlace explorer web page. If you have just finished with Task 3 are still signed into Windows Azure MarketPlace you can skip steps 2 and 3.

1. Open Internet Explorer and navigate to http://datamart.azure.com.

2. Click the Sign In link in the right-top corner.

3. Sign in using your Windows Live Id account.

4. Click My Data menu item at the top of the page.

5. Click on DataSets link located in the left-hand navigation.

6. Click on Use link on the left hand side of the DATA.Gov dataset information.

Figure 8Use Link

7. Review the DataSet information page. This page provides links and information on how to use the dataset including accessing the data using Visual Studio and PowerPivot.

8. Click on Explore this DataSet.

Figure 9Explore this DataSet Link

9. Enter Washington in the State parameter textbox.

Figure 10

Page 10: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Optional Parameters box

10. Click Run Query link to execute the query.

11. Review the results. Notice the Current query URL value. DataMarket exposes data using Restful APIs.

Figure 11Current Query URL

Exercise 1 Verification

In order to verify that you have correctly performed all steps of exercise 1, proceed as follows:

Verification 1

In this verification, repeat

1. Open Internet Explorer and navigate to http://datamart.azure.com.

2. Click the Sign In link in the right-top corner.

3. Sign in using your Windows Live Id account.

4. Click My Data menu item at the top of the page.

5. Click on DataSets link located in the left-hand navigation.

6. Click on Use link on the left hand side of the DATA.Gov dataset information.

7. Click on Explore this DataSet.

8. Click Run Query link to execute the query.

A result without errors verifies your subscription has been created correctly.

Exercise 2: Create a Business Data Catalog Model to Access the Dataset

Task 1 – Adding a Service Reference to the DATA.Gov Web Service

Page 11: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

In this task, you will use Visual Studio 2010 to create a Business Data Catalog model to access the DATA.Gov subscription.

1. Using Visual Studio open the starter solution named TheftStatisticsBDCModel from <Install>\Labs\ACDM\source\begin folder.

Figure 12Solution Explorer

2. Click on plus icon next to TheftStatisticsDBModel project in the Solution Explorer to expand the project and display the project files.

3. Right-click the References folder

4. Select Add Service Reference… to display the Add Service Reference dialog box.

Figure 13Add Service Reference…

5. Enter https://api.datamarket.azure.com/Data.ashx/data.gov/Crimes into the Address field.

6. Click Go.

7. Enter DataGovService as the Namespace.

Page 12: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 14Add Service reference dialog box

8. Select OK.

Task 2 – Modifying the Entity1 Class

In this task, you will replace the existing Entity1 class with code from a file in the SupportingFiles folder included in the project files. The Entity1 class stores individual row data. Normally you will rename the Entity1 class to a more meaningful class name.

1. In the Solution Explorer, click the plus icon next to BDCModel1 to expand the model.

2. Right-click Entitiy1 and select Open to view it in the code pane.

3. Delete all the code in Entity1 leaving a blank file.

4. Open Entity1.cs from the SupportingFiles folder.

5. Copy the SupportingFiles\Entity1.cs code into the project’s Entity1.cs file.

Figure 15Entity1.cs

Page 13: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

6. Review Entity1.cs. Notice that it is a simple entity that stores the basic information used later in the solution.

7. Save and close Entity1.cs

Task 3 – Modifying the ReadList Method of the Entity1Service Class

In this task, you will modify ReadList method the existing Entity1Service class to access the DATA.Gov dataset using the service reference created in Task 1. You will limit the data returned from the dataset to include valid records from the state of Washington for the years 2007 and 2008. The ReadList method is an existing Finder method for the BDCModel1 model.

1. In the Solution Explorer, click the plus icon next to BDCModel1 to expand the model.

2. Right-click Entitiy1Service and select Open to view it in the code pane.

3. Right-click the References folder

4. Select Add Reference… to display the Add Reference dialog box.

5. Select WindowsBase.

6. Click OK.

7. Add the following using statements to the class (Snippet 7.1.1)

Figure 16Using Statements Added

8. Create a private GetProxy method which will create return an instance of the service reference object. (Snippet 7.1.2)

Figure 17Get Proxy method

Page 14: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

This method sets the ServerCertificateValidationCallback property to ignore SSL certification errors. You must enter your Windows Live Id account and your subscription Account Key in this method. The Account Key is located in your Account information on your MY Data pages show in Exercise 1. This method will return an instance of the service reference.

9. Locate the ReadList method in EntityService1.

10. Delete the code and comments in the body of the ReadList.

11. Create new Generic List collection to contain our results. (Snippet 7.1.3)

Figure 18Generic list collection added

12. Retrieve the service reference proxy. (Snippet 7.1.4)

Figure 19Call Get Proxy method

13. Create a new DataServiceCollection object to query the dataset. Use a While loop and the Continuation object to retrieve all records from the dataset. (Snippet 7.1.5)

Figure 20New Data Service Collection

Data from the DATAGov dataset is batching at 100 records per call. The DataServiceCollection uses the Continuation object to determine if more data is still available.

14. Create an Entity1 object for each item in the DataQueryCollection and add the new Entity1 object to the queryResults collection created in this task. (Snippet 7.1.6)

Page 15: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 21Create Entity1 for each item

15. Finally, return the list of Entity1 objects. (Snippet 7.1.7)

Figure 22Return Entity1 list

Task 4 – Modifying the ReadItem Method of the Entity1Service Class

In this task, you will modify ReadItemt method the existing Entity1Service class to access a specific row of data in the DATA.Gov dataset using the service reference created in Task 1. The ReadItem method is an existing SpecificFinder method for the BDCModel1 model.

1. In the Solution Explorer, click the plus icon next to BDCModel1 to expand the model.

2. Right-click Entitiy1Service and select Open to view it in the code pane.

3. Locate the ReadItem method in EntityService1.

4. Delete the code and comments in the body of the ReadItem method.

5. Change the ReadItem’s Id parameter from a string to an int data type.

Figure 23ReadItem parameter change

6. Retrieve the service reference proxy. (Snippet 7.1.8)

Page 16: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 24Call Get Proxy method

7. Create the query to return a single item from the service. (Snippet 7.1.9)

Figure 25New Query

8. Return the new Entity1 object (Snippet 7.1.11)

Figure 27Return Entity1 object

9. Create a new Entity1 object and copy the query result into the Entity1 item. (Snippet 7.1.10)

Figure 26New Entity1

10. Save and close the Entity1Service.cs file.

Page 17: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Task 5 – Updating the Model’s Type Descriptors

In this task, you will open the model in the BDC Explorer and modify the associated type descriptors to match our new Entity1 class.

1. In the Solution Explorer, right-click on the BdcModel1.bdcm file and select Open. This will open the model in the designer and display the BDC Explorer tab.

Figure 28BDC Explorer Tab

2. Expand the nodes in the BDC Explorer tab to access the ReadItem’s Identifier1 type descriptor.

Figure 29identifier 1 type descriptor

3. Using the property pane, change the Identifier1’s data type from System.String to System.Int32

Figure 30Property pane - Type name

Page 18: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

4. Expand the BDC Explorer nodes to access the ReadItem’s returnParamter node and select the Identifier1 type descriptor

5. Using the property pane, change the Identifier1’s Data Type property from System.String to System.Int32.

6. Right-click on the Message type descriptor and select delete.

7. Right-click on the returnParamter’s Entity1 node and select Add Type Descriptor.

8. Using the property panel change the Name property of the new type descriptor to City and the Data Type property to System.String.

9. Add six more Type Descriptors to the Entity1 node. Set the properties to:

Type Descriptor Name Type Descriptor Data Type

Burglary System.Int32

LarcenyTheft System.Int32

MotorVehicleTheft System.Int32

Population System.Int32

State String

Year System.Int32

10. The Entity1 type descriptor should now look like the following image:

Figure 31Entity1 type descriptor

Page 19: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

11. Repeat steps 4-12 for the Entity1 type descriptor associated with ReadList.

Figure 32Entity1 type descriptor

12. In the design pane, select Identifier1.

Figure 33Design Pane - Entity1

13. Using the property pane set the Identifier1 Data Type property to System.Int32.

14. Save the project and the solution

Task 6 – Adding the SiteUrl Property to the Feature’s Element File

In this task, you will open the TheftStatisticsBDCModel feature and add the SiteUrl property to the elements file. Without this property the feature will not deploy.

1. In the Solution Explorer, click the plus icon next to Features folder to expand the Feature node

Page 20: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 34Features Folder

2. Right-click TheftStatisticsBDCModel.feature and click Open to open the Feature designer.

Figure 35Open Feature Designer

3. Click the Manifest link located towards the bottom of the designer to open the manifest.

Figure 36Manifest Link

4. Click the plus icon next to Edit Options to expand the manifest editing panel

Figure 37Expand Manifest editing panel

5. Add the SiteUrl property into the feature’s manifest file.

Page 21: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 38Site URL on feature’s manifest

6. Save and close the feature.

Task 7 – Modifying the Model’s Permission in Central Administration

In this task, you will build and deploy the project. Once the project is deployed, you will modify the permissions on the model in Central Administration to allow all authenticated users to view the data.

1. With the solution open in Visual Studio right-click the solution and select Deploy Solution to build and deploy the model. Note, if you use F5 Deployment the BDC model will retract and not be available when Visual Studio is done debugging.

2. Using Internet Explorer, navigate to the Central Administration home page located at http://demo2010a:2010/default.aspx.

3. Click on Manage service applications link located in the Application Management section.

Figure 39Manage Service Applications link

4. Click on Business Data Connectivity Service link.

Figure 40Business Data Connectivity Service lin

5. Hover over Entity1 and select Set Permissions from the drop down menu.

Page 22: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 41Set permissions Link

6. Click the Browse icon to display the Select People and Groups dialog.

Figure 42Select People and Groups

7. Select All Users in the left hand side of the dialog and then All Authenticated Users from the right-hand side of the dialog.

Page 23: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 43Users dialog box

8. Click Add to add the users.

9. Click OK to close the dialog.

10. Click Add to add the All Authenticated Users to the permissions list of the model

11. With All Authenticated Users highlighted, click the Execute permission checkbox to give the users the ability to view the data.

Page 24: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 44Add permissions for all authenticated users

12. Click OK.

Exercise 3: Create an External List to Consume the MarketPlace Dataset

Task 1 – Creating an External List

In this task, you will use Internet Explorer to navigate to Windows Azure Marketplace and register for a Marketplace account.

1. Using Internet Explorer, navigate to http://intranet.contoso.com.

2. Click on Site Actions in the upper left corner.

3. Select More Options menu item.

Page 25: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 45More Options Link

4. Select List and Data items in the left hand pane.

Figure 46Create Dialog Box

5. Select External List item and click the Create button on the right hand side of the dialog.

6. Enter a name of DataGov in the name textbox.

7. Click the Select External Content Type icon in the Data source configuration section.

Figure 47External Content Type

8. Select BDCModel1 and click OK.

Page 26: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 48BDCModel1 External Content Type

9. Click Create to create the external list.

10. Review the new external list.

Exercise 3 Verification

In order to verify that you have correctly performed all steps of exercise 1, proceed as follows:

Verification 1

In this verification, you will view the list and select a single list item to view.

1. Using Internet Explorer, navigate to http://intranet.contoso.com/Lists/DataGov/ReadList.aspx.

2. Verify the list loads without error.

3. Click on a City value. The item dialog box should appear displaying all the data for the item.

Exercise 4: Create a Web Part to Display the MarketPlace Data

Task 1 – Opening and Review the Starter Solution

In this task you will open the Web Part starter solution and review the existing code

1. Using Visual Studio, open the starter solution named TheftStatisticsWebPart from <Install>\Labs\ACDM\source\begin folder.

Page 27: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 49Solution Explorer

2. Review the projects and code in the solution. The TheftStatisticsWebPart solution was created using the Silverlight Web Part project template. Two projects are created, one SharePoint project and a Silverlight Application project. The lab will focus on the Silverlight Application. All of the files needed for the application exist in the starter solution.

3. Click on the plus sign associated with the ViewModels folder to expand the folder contents.

4. Review the code in CrimeStat class. This class is used to store individual results from a search.

5. Right-click on CrimeStatsViewModel.cs and select Open. The view model included the necessary using statements, service reference to the Bing Geocode service and the asynchronous code to geocode our results.

Task 2 – Adding the Silverlight Client Side Object Model References

In this task, you will add the needed references to the two required Silverlight Client Side Object Model assemblies.

1. In Solution Explorer, right-click the References folder located in the TheftStatisticsApplication project.

2. Select Add Reference… to display the Add Reference dialog box.

3. Select the Browse tab.

4. Navigate to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin.

5. Select both Silverlight assemblies.

Page 28: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 50Add Reference dialog box

6. Click OK to add the assembly references to the project

Task 3 – Completing the Existing View Model

In this task, you will complete the existing view model. The CrimeStatsViewModel class will asynchronously query the external list, geocode the results and add the results to an ObservableCollection for data binding.

1. Right-click CrimeStatsViewModel.cs in the Solution Explorer pane and select Open.

2. Add a public collection of TheftStatistic objects used for data binding. (Snippet 7.1.12)

Figure 51Add public TheftStatistic collection

3. Add a public TheftStatisitc property named CurrentStatistic to contain the currently selected TheftStatistic. This property will raise the OnPropertyChange event. (Snippet 7.1.13)

Page 29: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 52Add public TheftStatisitc property

4. Add a public method to find the current TheftStatistic from the collection and set the CurrentStatistic property. (Snippet 7.1.14)

Figure 53Create SetCurrentStatistic method

5. Add a private collection of TheftStatistic objects for temporary storage of the results returned from the Client Side Object Model query. This collection will not be data bound to the user interface. (Snippet 7.1.15)

Figure 54Add private TheftStatistic collection

Page 30: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

6. Add a variable named bcslist of type IEnumerable< ListItem>. (Snippet 7.1.16)

Figure 55Add bcsList variable

7. Create a method named GetTheftStats. This method clears the databound collection and sets up the successful callback reference to process the results. The GetTheftStats method uses Client Side Object Mode and a CAML query to retrieve only year values of 2008 from the external list. (Snippet 7.1.17)

Figure 56Create GetTheftStats method

8. Create the successful callback method to process the query results. The successful callback creates a TheftStatistic object for each result and adds it to the temporary storage collection. Once all the TheftStatistic objects have been added to the collection, each object is passed to the Geocode method. (Snippet 7.1.18)

Page 31: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 57Create QueryCallback method

9. Review the existing Geocode method. This method dispatches the calls to the UI thread to access the Bing map control in the UI to retrieve the map credentials. It then creates an asynchronous call to the Geocode service passing in the TheftStatistic’s State, City and Id values. The Id value is required in the callback method for retrieval of the correct object for update.

10. Review and modify the existing geocodeService_GeocodeCompleted method. This method is called once per item geocoded. It retrieves the id of the object that was associated with the City and State values, selects the item from the temporary storage collection and updates the Location property. The selected item is added to the data bound TheftStatistics collection Replace the //Add code here comment located in the existing geocodeService_GeocodeCompleted with the lines displayed below (Snippet 7.1.19)

Figure 58Review and modify geocodeService_GeocodeCompleted method

11. Add a private class variable named _view of type MainPage. This will be our connection back to the MainPage (view). (Snippet 7.1.20)

Page 32: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

12. Create the CrimeStatsViewModel constructor. The constructor requires a parameter for the view reference. The constructor will initialize our collections and call GetTheftStats to populate our databound collection. (Snippet 7.1.21)

Figure 59Create CrimeStatsViewModel constructor

13. Save and close CrimeStatsViewModel.cs.

Task 4 – Replacing and Review the MainPage Xaml Markup

In this task, you will replace and review the MainPage.xaml markup with markup from the SupportingFiles folder.

1. Right-click MainPage.xaml in the Solution Explorer pane and select Open.

2. Open the SupportingFiles folder located in the starter solution and open MainPage.xaml.txt file.

3. Copy the text in the MainPage.xaml.txt files and pasted it over the existing MainPage.xaml markup.

4. Locate the Map control and enter your specific Bing map key as the CredentialsProvider attribute value.

5. Review the MainPage.xaml markup. Notice that the markup includes a Map control named CrimeMap. The Map control contains a MapItemsControl which references the static resource named Pushpin. The DataTemplate is bound to the view model’s TheftStatistics collection. The PushPin control defines the MouseEnter and MouseLeave event handlers that are defined in the code beside.

6. The Map control also defines a MapLayer control that is used to display the “popup” that is bound to the view model’s CurrentStatistic property.

7. Save and close MainPage.xaml.

Task 5 – Completing the Existing MainPage.Xaml.cs Code Beside

Page 33: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

In this task, you will complete the existing MainPage.xaml.cs code beside page. The code will manage the control’s events and set the datacontext.

1. In Solution Explorer, right-click MainPage.xaml and select View Code.

2. Delete the commented code.

3. Add the following using statement to MainPage.xaml.cs (Snippet 7.1.22) :

Figure 60Add using statement

4. Add a variable used to reference the view model. (Snippet 7.1.23)

Figure 61Add viewModel Variable

5. Modify the existing constructor to initialize the viewModel variable and set the DataContext to the view model reference. (Snippet 7.1.24)

Figure 62Modify MainPage method

6. Add the PushPin’s MouseEnter handler. This method retrieves the PushPin’s tag property that contains the associated TheftStatistic’s id and call the view model’s SetCurrentStatistic property. The rest of the method sets the layer’s location and visibility. (Snippet 7.1.25)

Page 34: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 63Add the PushPin’s MouseEnter handler

7. Add the PushPin’s MouseLeave handler. This method will hide the map layer. (Snippet 7.1.26)

Figure 64Add the PushPin’s MouseLeave handler

Exercise 4 Verification

In order to verify that you have correctly performed all steps of exercise 1, proceed as follows:

Verification 1

In this verification, you will build the Silverlight Web Part and Silverlight application. A successful build will verify the exercise.

1. In the Solution Explorer, right-click the TheftStatisticsWebPart solution.

2. Click Build Solution.

Exercise 5: Deploy the Web Part

Task 1 – Deploying the Solution

In this task, you will deploy the Web Part.

1. Using Solution Explorer right-click on TheftStatisticsWebPart solution and select Deploy.

2. After the solution has deployed, open Internet Explorer and navigate to http://intranet.contoso.com.

Page 35: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

3. Click the Edit icon in the top left corner of the home page.

Figure 65Edit button

4. Click the Insert Ribbon tab.

Figure 66Insert Tab

5. With the cursor located as shown in image below, click the Web Part button.

Figure 67Web Part Button

6. Select Custom located in the Categories pane and Theft Statistics in the Web Part pane.

Page 36: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

Figure 68Web Part Pane

7. Click Add to add the Web Part to the Rich Content control.

8. The Web Part will display in the Rich Content control.

Figure 69Theft Statistics Web Part

9. Click the Save icon to save the new page configuration.

Figure 70Save Button

Page 37: Accessing Cloud Data with Windows Azure …az12722.vo.msecnd.net/.../Lab.docx · Web viewWorking in the cloud is becoming a major initiative for application development departments

10. Move the mouse over a PushPin to display the ThreatStatistic details

Figure 71ThreatStatistic details

Summary

In this lab you have seen how to set up a Windows Azure MarketPlace account and how to subscribe and access a dataset. This dataset was consumed by a Business Data Catalog model using an external list. You saw how to use the Client Side Object Model to consume data from an external list and display it in a Bing Map.