Sunday, March 14, 2010

Data Dynamics Reports: Show the Data from the Windows Azure Table Storage

Preface
Some time ago I tested Data Dynamics Reports on Windows Azure platform. I never dealt with Windows Azure before and was happy to learn something new. In particular I've learned the basics of Windows Azure Storage Services. There are 3 storage types in Windows Azure: blobs, queues and tables. I thought about the scenario when a developer wants to visualize the data from Window Azure Table Storage using Data Dynamics Reports. I've found that Data Dynamics Report provides developer with all needed ammunition to achieve that goal, so I thought that it would be worth to write about.

Windows Azure Table Storage
Windows Azure Table Storage differs from the tables in a relational database. Table storage is object-oriented and saves the entities and the entity properties. The details of table storage is not the subject of this post. I believe that the best way to show how Data Dynamics Reports can be used with the table storage is going through the live example. This walkthrough is based on the post in "Cloudy in Seattle" blog. However, that blog post sample uses Windows Azure SDK 1.0 and I used the newer version 1.1. A few things was changed in version 1.1, I highlighted them later in this post.

Walkthrough
This walkthrough is totally based on "Windows Azure Walkthrough: Table Storage". I just aligned it with the changes in Windows Azure SDK v1.1 and added the steps for show the data using Data Dynamics Reports.
(1) Get started with Windows Azure - install the prerequisites and SDK v1.1. Install the latest release of Data Dynamics Reports.
(2) Download and extract Windows Azure Additional Samples from MSDN code gallery.
(3) In Visual Studio 2008 or 2010 create the new Windows Azure Cloud Service project.
(4) In the pop-up dialog add C# ASP.NET Web Role into the Cloud Service Solution.
(5) Compile StorageClient solution that is included in the advanced samples obtained on step (2). From the Web Role add the reference to StorageClient assembly.
(alternatively you can include the *.cs files from StorageClient solution to the Web Role project. F.e. I've added them as a link in my test project).
(6) Add the reference to System.Data.Services.Client in Web Role project.
Steps (7)-(23) are the same as in Table Storage Walkthrough. However step 22(Create Test Storage Tables) is not needed with Windows Azure SDK 1.1.
(24) Add several contacts using the form on the default page of the cloud service. We will show the contacts list using Data Dynamics Reports.
(25) Add the new Data Dynamics Reports Report Item in the Web Role Project(in the root folder). Name it "Contacts.rdlx". Set Build Action property of Contacts.rdlx file to "Content".
(26) Using the Report Data Explorer, add the new Data Source in the report. On the General Page set the Data Source Type to Object Provider.
(27) Add the new Data Set to the Data Source that is created on step (26). Leave the data set query empty. On the Fields Page of the Data Set add two fields "Name" and "Address".
(28) Add the Table to the report, bind the table to the Data Set that is created on step (27). Adjust the table so that it contains 2 columns and the 1st column shows Name field and the 2nd column shows Address field.
(29) Add the new Web Form in the Web Role Project. Name the new form "ReportForm.aspx".
(30) Add Data Dynamics Reports Web Viewer to ReportForm page.
(31) Add the following code to the Page_Load event handler of ReportForm:

const string rptPath = "~/Contacts.rdlx";
string rptPath2 = Server.MapPath(rptPath);
var def = new ReportDefinition(new FileInfo(rptPath2));
var runtime = new ReportRuntime(def);
runtime.LocateDataSource += (s, args) =>
{
   var ds = new ContactDataSource();
   args.Data = ds.Select();
};
WebReportViewer1.SetReport(runtime);

So, we used Object Data Provider for the report data source. Object Data Provider accepts the objects that implement IEnumerable interface. ContactDataSource.Select method returns the results of the query to the TableStorage as IEnumerable<ContactModel> instance and we can use it for the report data source.
(32) Set ReportForm.aspx as the Start Page, run the cloud service and you will see that web-viewer shows the contacts that you added on step (24).
End of walkthrough.