Sunday, April 18, 2010

ActiveReports: Show the Data from the Windows Azure Table Storage

Preface
Some time ago I blogged about using Data Dynamics Reports to visualize the data that are stored in Windows Azure Table Storage. Originally I planned to compose that blog post around both of Data Dynamics Reports and ActiveReports but then I found that the latter has the issues with running against a cloud environment. But ActiveReports team did the great job for preparing Service Pack 1 which includes the fix for those issues! And this blog post repeats the "show the table storage data" walkthrough for ActiveReports6 SP1. I believe that it will be useful for someone.

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 ActiveReports 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 ActiveReports.
(1) Get started with Windows Azure - install the prerequisites and SDK v1.1. Install the latest release of ActiveReports6.
(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 ActiveReports.
(25) Add the new ActiveReports 6(code-based) File in the Web Role Project(in the root folder). Name it "Contacts.cs".
(26) Add two textboxes to the detail section of the report. Set DataField property to "Name"(without quotes) for the 1st textbox. Set DataField property to "Address"(without quotes) for the 2nd textbox.
(27) Add the new Web Form in the Web Role Project. Name the new form "ARReportForm.aspx".
(28) Add ActiveReports6 web-based report viewer in ARReportForm page.
(29) Add the following code to the Page_Load event handler of ARReportForm:

var rpt = new Contacts();
var ds = new ContactDataSource();
rpt.DataSource = (from c in ds.Select() select new {c.Name, c.Address}).ToArray();
rpt.Run(false);
WebViewer1.ClearCachedReport();
WebViewer1.Report = rpt;

ActiveReports allows you to use the collection of the objects as the data source, so we can use the result that is returned by ContactDataSource.Select method.
(30) Set ARReportForm.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.

No comments:

Post a Comment