Using Azure to Store and Load DevExpress Reports Across All Supported Platforms

In this blog post we'll describe how you can store DevExpress Reports on Azure. As you'll soon discover, you can use this approach to create a shared report repository and make it available via simple Open/Save report commands. 

If you are currently using DevExpress Reports for .NET, you already know that we offer Report Viewers and Designers for ASP.NET, WinForms and WPF. The benefit of the implementation described herein is that regardless of target platform (Desktop or Web clients), end-users will have access to all the reports you store on Azure.

Those of you with no interest in storing reports on Azure might still find this example quite useful - as it's an excellent way to store your Report Gallery (predefined elements/reports) and share it with users.

Report Storage on Azure

Regardless of the usage scenario, our implementation is straightforward and based on the following:

  • The API used to manage Azure storage provided by the "WindowsAzure.Storage" NuGet package.
  • The storage extension engine in our Reporting platform.

I'll explain the basics in this article, but if you’re ready to get started and want to skip the explanation, download the sample published in our Knowledge Base.

Setting Up Azure Access

If you don't already have an Azure account, you'll want to get one setup using the following link:  

https://docs.microsoft.com/en-us/azure/storage/storage-create-storage-account

Once you've obtained login credentials, we recommend that you add them to app.config, as shown below. You’ll then transmit the connection string to method calls that register your custom extensions.

<appSettings>
  <add key="StorageConnectionString" 
 value="DefaultEndpointsProtocol=https;AccountName=ACCOUNT;AccountKey=KEY" />
</appSettings>

Create a Shared Azure Storage for Reports

Let’s start with the extension that creates a common Azure storage for reports accessed through Open/Save UI commands. First, you'll need to create a ReportStorageWebExtension descendant and implement methods that cover basic actions such as display the report list, obtain a specific report, save a report to storage. Here’s your class stub with comments.

 
public class MyReportStorageWebExtension : 
      DevExpress.XtraReports.Web.Extensions.ReportStorageWebExtension { 
    // use Microsoft Azure API 
  readonly Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container; 
  public MyReportStorageWebExtension(string storageAccountConnectionString) { 
      // initialize your storage using the connection string 
  } 
 
  public override Dictionary GetUrls() { 
      // retrieve report collection 
  } 
  
  public override byte[] GetData(string url) { 
      // obtain a report identified by its URL 
  } 
  
  public override bool CanSetData(string url) { 
      // can a report be updated? 
  } 
  
  public override void SetData(XtraReport report, string url) { 
      // update the report 
  } 
  
  public override string SetNewData(XtraReport report, string defaultUrl) { 
      // save a new report 
  } 
} 

You'll then register this newly created extension so that it takes effect. In our ASP.NET sample, you see a call to a static method in the Application_Start() method in Global.asax.cs. In WinForms, put it inside the Main() method.

ReportStorageWebExtension.RegisterExtensionGlobal(
   new MyReportStorageWebExtension(
      ConfigurationManager.AppSettings["StorageConnectionString"]
   )
); 

Create a Shared Azure Storage for the Report Gallery

The report Gallery is one of the Tool Windows you’ll find in the End-User Report Designer. It lists report templates, re-usable blocks with a few controls grouped together, or commonly used styles you can apply to elements.

If you want all these to be stored in the same centralized Azure storage, the procedure is mostly the same. This time, you need a ReportGalleryExtension class descendant.

class CloudReportGalleryExtension :
       ReportGalleryExtension { 
    // use Microsoft Azure API 
    readonly Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container; 
    public CloudReportGalleryExtension(string connectionString){ 
        // initialize storage container 
    } 
    public override void SaveGallery(Gallery gallery) { 
        // save gallery 
    } 
  
    public override bool TryLoadGallery(out Gallery gallery) { 
        // check if a gallery can be loaded 
    } 
  
    CloudBlockBlob LoadBlob() { 
        // load gallery contents 
    } 
} 

Use the following to register the class in the system:

ReportGalleryExtension.RegisterExtensionGlobal(
   ConfigurationManager.AppSettings["StorageConnectionString"]
); 

Try Our Sample

As mentioned, we've published a complete sample demonstrating implementation details. The downloadable solution contains both an ASP.NET and WinForms application. If you have your Azure Storage account set up, update the connection string settings in the project and run it to see how it works.

Please remember, while we chose to showcase Azure storage in this sample, our extension model allows you to implement any kind of cloud or non-cloud storage provided that you have the necessary API.

no comments
No Comments

Please login or register to post comments.