azure lab example

Upload: srinichilaka

Post on 06-Apr-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Azure Lab Example

    1/35

    Hands-On Lab

    Accessing Cloud Data withWindows Azure Marketplace

    Lab version: 1.0.0

    Last updated: 2/10/12

  • 8/3/2019 Azure Lab Example

    2/35

    CONTENTS

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

    EXERCISE 1: SUBSCRIBE TO A MICROSOFT WINDOWS AZURE MARKETPLACE DATASET..........6

    Task 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..........10

    Task 1 Adding a Service Reference to the DATA.Gov Web Service..................11Task 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 Models Type Descriptors................................................16

    Task 6 Adding the SiteUrl Property to the Features Element File...................19

    Task 7 Modifying the Models Permission in Central Administration................21

    EXERCISE 3: CREATE AN EXTERNAL LIST TO CONSUME THE MARKETPLACE DATASET..........24

    Task 1 Creating an External List......................................................................24

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

    EXERCISE 4: CREATE A WEB PART TO DISPLAY THE MARKETPLACE DATA...............................26

    Task 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....................................................................................... .........34

    Task 1 Deploying the Solution.........................................................................34

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

  • 8/3/2019 Azure Lab Example

    3/35

    Summary

    Overview

    Working in the cloud is becoming a major initiative for application developmentdepartments. Windows Azure is Microsofts cloud incorporating data and services.This lab will guide the reader through a series of exercises that creates a SilverlightWeb Part that displays Windows Azure Marketplace data on a Silverlight Bing mapcontrol.

    Objectives

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

    Subscribe to a Microsoft Windows Azure Marketplace datasetCreate 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 EvaluationVirtual Machine from http://tinyurl.com/2avoc4b and create the Hyper-Vimage.

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

    http://tinyurl.com/2avoc4b%20http://code.msdn.microsoft.com/vsixforsphttp://tinyurl.com/2avoc4b%20http://code.msdn.microsoft.com/vsixforsp
  • 8/3/2019 Azure Lab Example

    4/35

    3. Create a document library named SilverlightXaps located athttp://intranet.contoso.com/silverlightxaps. This is where you will storethe 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 Studiosolutions that you can use as starting point for the exercises.

    \Labs\ACDM\Source\Begin\TheftStatisticsBDCModel

    \TheftStatisticsBDCModel.sln : This solution creates theBusiness Data Catalog application.

    \Labs\ACDM\Source\Begin\ TheftStatisticsWebPart \TheftStatisticsWebPart.sln : This solution creates the SilverlightWeb Part and Silvelright application that will consume data using anexternal list.

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

    Exercise 1: Subscribe to aMicrosoft Windows AzureMarketplace dataset

    https://www.bingmapsportal.com/http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=beb29d27-6f0c-494f-b028-1e0e3187e830https://www.bingmapsportal.com/http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=beb29d27-6f0c-494f-b028-1e0e3187e830
  • 8/3/2019 Azure Lab Example

    5/35

    Task 1 Registering for a Windows Azure Marketplace Account

    In this task, you will use Internet Explorer to navigate to Windows AzureMarketplace 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

    1. Sign in using your Windows Live Id account.

    2. Click the Register link in the upper-right corner to create a new DataMarketaccount.

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

    Figure 2DataMarket registration

    1. Click Continue.

    2. Select I accept the terms of use check box on the bottom of theRegistration page.

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

    Figure 3Register Button

    Task 2 Subscribing to the DATA.Gov Dataset

  • 8/3/2019 Azure Lab Example

    6/35

    In this task, you will subscribe to the DATA.Gov dataset. If you have just finishedwith Task 1 are still signed into Windows Azure MarketPlace you can skip steps 2and 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

    1. Click on the DATA.Gov image.

    Figure 5Data.gov image

    1. Click Sign Up to subscribe to the dataset.

    2. Verify the subscription price on this page. Select I have read and agreeto the terms of use checkbox on the Subscription Dataset Terms page.

    3. 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 keythat is used for authentication and tracking MarketPlace requests later in this lab. Ifyou have just finished with Task 2 are still signed into Windows Azure MarketPlaceyou can skip steps 2 and 3.

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

  • 8/3/2019 Azure Lab Example

    7/35

    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

    1. Click on Account Informationlinklocated in the left-hand navigation.

    Figure 7Account Information Link

    1. Review the data in the Account Information Page. You can edit your accountinformation from this page.

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

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

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

    5. Review the DataSets page. This page contains information and links todatasets subscriptions.

    Task 4 Exploring GOV.Data

    In this task, you will explore the Gov.Data dataset using the Windows AzureMarketPlace explorer web page. If you have just finished with Task 3 are still signedinto 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 datasetinformation.

  • 8/3/2019 Azure Lab Example

    8/35

    Figure 8Use Link

    1. Review the DataSet information page. This page provides links andinformation on how to use the dataset including accessing the data usingVisual Studio and PowerPivot.

    2. Click on Explore this DataSet.

    Figure 9Explore this DataSet Link

    1. Enter Washington in the State parameter textbox.

    Figure 10Optional Parameters box

    1. Click Run Query link to execute the query.

    2. Review the results. Notice the Current query URL value. DataMarketexposes 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, proceedas follows:

  • 8/3/2019 Azure Lab Example

    9/35

    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 DataCatalog Model to Access theDataset

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

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

    1. Using Visual Studio open the starter solution named TheftStatisticsBDCModelfrom \Labs\ACDM\source\begin folder.

    Figure 12Solution Explorer

    1. Click on plus icon next to TheftStatisticsDBModel project in the SolutionExplorer to expand the project and display the project files.

  • 8/3/2019 Azure Lab Example

    10/35

    2. Right-click the References folder

    3. Select Add Service Reference to display the Add Service Referencedialog box.

    Figure 13Add Service Reference

    1. Enter https://api.datamarket.azure.com/Data.ashx/data.gov/Crimesinto the Address field.

    2. Click Go.

    3. Enter DataGovService as the Namespace.

    Figure 14Add Service reference dialog box

    1. 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 storesindividual row data. Normally you will rename the Entity1 class to a moremeaningful class name.

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

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

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

  • 8/3/2019 Azure Lab Example

    11/35

    3. Open Entity1.cs from the SupportingFiles folder.

    4. Copy the SupportingFiles\Entity1.cs code into the projects Entity1.cs file.

    Figure 15Entity1.cs

    1. Review Entity1.cs. Notice that it is a simple entity that stores the basicinformation used later in the solution.

    2. 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 toaccess the DATA.Gov dataset using the service reference created in Task 1. You willlimit the data returned from the dataset to include valid records from the state ofWashington for the years 2007 and 2008. The ReadList method is an existingFinder method for the BDCModel1 model.

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

    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/3/2019 Azure Lab Example

    12/35

    1. Create a private GetProxy method which will create return an instance of theservice reference object. (Snippet 7.1.2)

    Figure 17Get Proxy method

    This method sets the ServerCertificateValidationCallback property to ignore SSLcertification errors. You must enter your Windows Live Id account and yoursubscription Account Key in this method. The Account Key is located in yourAccount information on your MY Data pages show in Exercise 1. This method will

    return an instance of the service reference.

    1. Locate the ReadList method in EntityService1.

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

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

    Figure 18Generic list collection added

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

    Figure 19Call Get Proxy method

    1. 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

  • 8/3/2019 Azure Lab Example

    13/35

    Data from the DATAGov dataset is batching at 100 records per call. TheDataServiceCollection uses the Continuation object to determine if more data is stillavailable.

    1. 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)

    Figure 21Create Entity1 for each item

    1. 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 toaccess a specific row of data in the DATA.Gov dataset using the service referencecreated in Task 1. The ReadItem method is an existing SpecificFinder method forthe BDCModel1 model.

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

    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 ReadItems Id parameter from a string to an int data type.

    Figure 23

  • 8/3/2019 Azure Lab Example

    14/35

    ReadItem parameter change

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

    Figure 24Call Get Proxy method

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

    Figure 25New Query

    1. Return the new Entity1 object (Snippet 7.1.11)

    Figure 27Return Entity1 object

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

    Figure 26New Entity1

    1. Save and close the Entity1Service.cs file.

  • 8/3/2019 Azure Lab Example

    15/35

    Task 5 Updating the Models Type Descriptors

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

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

    Figure 28BDC Explorer Tab

    1. Expand the nodes in the BDC Explorer tab to access the ReadItemsIdentifier1 type descriptor.

    Figure 29identifier 1 type descriptor

    1. Using the property pane, change the Identifier1s data type fromSystem.String to System.Int32

    Figure 30Property pane - Type name

  • 8/3/2019 Azure Lab Example

    16/35

    1. Expand the BDC Explorer nodes to access the ReadItems returnParamternode and select the Identifier1 type descriptor

    2. Using the property pane, change the Identifier1s Data Type property fromSystem.String to System.Int32.

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

    4. Right-click on the returnParamters Entity1 node and select Add TypeDescriptor.

    5. Using the property panel change the Name property of the new typedescriptor to City and the Data Type property to System.String.

    6. 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

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

    Figure 31Entity1 type descriptor

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

  • 8/3/2019 Azure Lab Example

    17/35

    Figure 32Entity1 type descriptor

    1. In the design pane, select Identifier1.

    Figure 33Design Pane - Entity1

    1. Using the property pane set the Identifier1 Data Type property toSystem.Int32.

    2. Save the project and the solution

    Task 6 Adding the SiteUrl Property to the Features Element File

    In this task, you will open the TheftStatisticsBDCModel feature and add the SiteUrlproperty 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 toexpand the Feature node

  • 8/3/2019 Azure Lab Example

    18/35

    Figure 34Features Folder

    1. Right-click TheftStatisticsBDCModel.feature and click Open to open theFeature designer.

    Figure 35Open Feature Designer

    1. Click the Manifest link located towards the bottom of the designer to openthe manifest.

    Figure 36Manifest Link

    1. Click the plus icon next to Edit Options to expand the manifest editingpanel

    Figure 37Expand Manifest editing panel

    1. Add the SiteUrl property into the features manifest file.

  • 8/3/2019 Azure Lab Example

    19/35

    Figure 38Site URL on features manifest

    1. Save and close the feature.

    Task 7 Modifying the Models Permission in Central Administration

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

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

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

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

    Figure 39Manage Service Applications link

    1. Click on Business Data Connectivity Service link.

    Figure 40Business Data Connectivity Service lin

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

    http://demo2010a:2010/default.aspxhttp://demo2010a:2010/default.aspx
  • 8/3/2019 Azure Lab Example

    20/35

    Figure 41Set permissions Link

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

    Figure 42Select People and Groups

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

  • 8/3/2019 Azure Lab Example

    21/35

    Figure 43Users dialog box

    1. Click Add to add the users.2. Click OKto close the dialog.

    3. Click Add to add the All Authenticated Users to the permissions list of themodel

    4. With All Authenticated Users highlighted, click the Execute permissioncheckbox to give the users the ability to view the data.

  • 8/3/2019 Azure Lab Example

    22/35

    Figure 44Add permissions for all authenticated users

    1. Click OK.

    Exercise 3: Create an External Listto Consume the MarketPlaceDataset

    Task 1 Creating an External ListIn this task, you will use Internet Explorer to navigate to Windows AzureMarketplace 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.

    http://intranet.contoso.com/http://intranet.contoso.com/
  • 8/3/2019 Azure Lab Example

    23/35

    Figure 45More Options Link

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

    Figure 46Create Dialog Box

    1. Select External List item and click the Create button on the right handside of the dialog.

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

    3. Click the Select External Content Type icon in the Data source configurationsection.

    Figure 47External Content Type

    1. Select BDCModel1 and click OK.

  • 8/3/2019 Azure Lab Example

    24/35

    Figure 48BDCModel1 External Content Type

    1. Click Create to create the external list.

    2. Review the new external list.

    Exercise 3 Verification

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

    Verification 1

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

    1. Using Internet Explorer, navigate tohttp://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 thedata for the item.

    Exercise 4: Create a Web Part toDisplay 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 namedTheftStatisticsWebPart from \Labs\ACDM\source\beginfolder.

    http://intranet.contoso.com/Lists/DataGov/ReadList.aspxhttp://intranet.contoso.com/Lists/DataGov/ReadList.aspx
  • 8/3/2019 Azure Lab Example

    25/35

    Figure 49Solution Explorer

    1. Review the projects and code in the solution. The TheftStatisticsWebPartsolution was created using the Silverlight Web Part project template. Twoprojects are created, one SharePoint project and a Silverlight Application

    project. The lab will focus on the Silverlight Application. All of the filesneeded for the application exist in the starter solution.

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

    3. Review the code in CrimeStat class. This class is used to store individualresults from a search.

    4. Right-click on CrimeStatsViewModel.cs and select Open. The view modelincluded the necessary using statements, service reference to the BingGeocode service and the asynchronous code to geocode our results.

    Task 2 Adding the Silverlight Client Side Object Model ReferencesIn this task, you will add the needed references to the two required Silverlight ClientSide Object Model assemblies.

    1. In Solution Explorer, right-click the References folder located in theTheftStatisticsApplication 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\WebServer Extensions\14\TEMPLATE\LAYOUTS\ClientBin.

    5. Select both Silverlight assemblies.

  • 8/3/2019 Azure Lab Example

    26/35

    Figure 50Add Reference dialog box

    1. Click OKto 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 CrimeStatsViewModelclass will asynchronously query the external list, geocode the results and add theresults to an ObservableCollection for data binding.

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

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

    Figure 51Add public TheftStatistic collection

    1. Add a public TheftStatisitc property named CurrentStatistic to contain thecurrently selected TheftStatistic. This property will raise theOnPropertyChange event. (Snippet 7.1.13)

  • 8/3/2019 Azure Lab Example

    27/35

    Figure 52Add public TheftStatisitc property

    1. Add a public method to find the current TheftStatistic from the collection andset the CurrentStatistic property. (Snippet 7.1.14)

    Figure 53Create SetCurrentStatistic method

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

    Figure 54Add private TheftStatistic collection

    1. Add a variable named bcslist of type IEnumerable< ListItem>. (Snippet7.1.16)

  • 8/3/2019 Azure Lab Example

    28/35

    Figure 55Add bcsList variable

    1. Create a method named GetTheftStats. This method clears the databoundcollection and sets up the successful callback reference to process theresults. The GetTheftStats method uses Client Side Object Mode and a CAMLquery to retrieve only year values of 2008 from the external list. (Snippet7.1.17)

    Figure 56Create GetTheftStats method

    1. Create the successful callback method to process the query results. Thesuccessful callback creates a TheftStatistic object for each result and adds itto the temporary storage collection. Once all the TheftStatistic objects havebeen added to the collection, each object is passed to the Geocode method.(Snippet 7.1.18)

  • 8/3/2019 Azure Lab Example

    29/35

    Figure 57

    Create QueryCallback method

    1. Review the existing Geocode method. This method dispatches the calls tothe UI thread to access the Bing map control in the UI to retrieve the mapcredentials. It then creates an asynchronous call to the Geocode servicepassing in the TheftStatistics State, City and Id values. The Id value isrequired in the callback method for retrieval of the correct object for update.

    2. Review and modify the existing geocodeService_GeocodeCompletedmethod. This method is called once per item geocoded. It retrieves the id ofthe object that was associated with the City and State values, selects theitem from the temporary storage collection and updates the Location

    property. The selected item is added to the data bound TheftStatisticscollection Replace the //Add code here comment located in the existinggeocodeService_GeocodeCompleted with the lines displayed below (Snippet7.1.19)

    Figure 58Review and modify geocodeService_GeocodeCompleted method

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

    2. Create the CrimeStatsViewModel constructor. The constructor requires aparameter for the view reference. The constructor will initialize ourcollections and call GetTheftStats to populate our databound collection.(Snippet 7.1.21)

  • 8/3/2019 Azure Lab Example

    30/35

    Figure 59Create CrimeStatsViewModel constructor

    1. 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 markupfrom 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 openMainPage.xaml.txt file.

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

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

    5. Review the MainPage.xaml markup. Notice that the markup includes a Mapcontrol named CrimeMap. The Map control contains a MapItemsControlwhich references the static resource named Pushpin. The DataTemplate is

    bound to the view models TheftStatistics collection. The PushPin controldefines the MouseEnter and MouseLeave event handlers that are defined inthe code beside.

    6. The Map control also defines a MapLayer control that is used to display thepopup that is bound to the view models CurrentStatistic property.

    7. Save and close MainPage.xaml.

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

    In this task, you will complete the existing MainPage.xaml.cs code beside page. Thecode will manage the controls 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) :

  • 8/3/2019 Azure Lab Example

    31/35

    Figure 60

    Add using statement

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

    Figure 61Add viewModel Variable

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

    Figure 62Modify MainPage method

    1. Add the PushPins MouseEnter handler. This method retrieves thePushPins tag property that contains the associated TheftStatistics id andcall the view models SetCurrentStatistic property. The rest of the methodsets the layers location and visibility. (Snippet 7.1.25)

    Figure 63Add the PushPins MouseEnter handler

    1. Add the PushPins MouseLeave handler. This method will hide the maplayer. (Snippet 7.1.26)

  • 8/3/2019 Azure Lab Example

    32/35

    Figure 64

    Add the PushPins MouseLeave handler

    Exercise 4 Verification

    In order to verify that you have correctly performed all steps of exercise 1, proceedas 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 andselect Deploy.

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

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

    Figure 65Edit button

    1. Click the Insert Ribbon tab.

    http://intranet.contoso.com/http://intranet.contoso.com/
  • 8/3/2019 Azure Lab Example

    33/35

    Figure 66Insert Tab

    1. With the cursor located as shown in image below, click the Web Partbutton.

    Figure 67Web Part Button

    1. Select Custom located in the Categories pane and Theft Statistics in theWeb Part pane.

    Figure 68Web Part Pane

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

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

  • 8/3/2019 Azure Lab Example

    34/35

    Figure 69Theft Statistics Web Part

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

    Figure 70Save Button

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

    Figure 71

  • 8/3/2019 Azure Lab Example

    35/35

    ThreatStatistic details

    Summary

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