Flexible CSV exports over web-api with server side MEF – the silverlight and html client. (part 3)


We want to consume now the MEF based export functionality from the silverlight client.

Let’s first take a look at a potential screen where we use it:


So, we have a bunch of customer (with orders) data and there are some buttons where we can select a specific export strategy:



As you can see, we can ask for customers with orders count and customers with full name only.

How do we initiate the web-api call in the silverlight client?

 partial void CustomersWithOrderCountExport_Execute()
            string projectionName = "Customers with order count";

        private static void GetExport(string projectionName)
            Dispatchers.Main.Invoke(() =>
                Uri baseAddress = new Uri(new Uri(System.Windows.Application.Current.Host.Source.AbsoluteUri), "../../");
                string url = baseAddress.AbsoluteUri
                    + @"api/CSVExport/GetExport/?dataServiceName=ApplicationData&entitySetName=Customers&projectionName=" + projectionName;
                HtmlPage.Window.Navigate(new Uri(url), "_blank");

We only need to provide the dataService (ApplicationData), the entity set type (e.g. Customers) and the name of the specific projection strategy (in my example: Customers with order count).

How do we initiate the web-api call in the html client?

Place a button on the browse customer screen, and provide following code:

myapp.BrowseCustomers.GetCustomersWithOrderCountExport_execute = function (screen) {

    var baseAddress = window.location + "../..";
    window.open(baseAddress +
        "/api/CSVExport/GetExport/?dataServiceName=ApplicationData&entitySetName=Customers&projectionName=Customers with order count");

Why do I believe this is cool?

That’s of course a difficult question to answer for me since I designed the above :)

I think it’s cool because the heavy lifting of export generation is completely moved to the infrastructure level (assumed you can inject it via nuget). Adding a new export type is only a matter of writing the lamdba expression for the projection and providing it a meaningful name.

Furthermore, since we use web-api, the whole infrastructure works both in the html client and the silverlight client !

Enjoy !