Like I mentioned in one of my previous posts, I was thinking on how to develop a report development suite using Silverlight and WCF as the backbone. In that process I had several questions for which I had been digging around the internet to see if I could get some answers. The intention of this post is to log my findings. Please note that I do not own the content posted here and I appreciate all the effort that the authors have put into writing these articles.
1. How would I bind unknown objects to the Silverlight Datagrid (or any grid for that matter)?
Problem: My plan is to take in queries that generates reports and run them against a database (SQL or Oracle). The returned results should bind to the datagrid. So I am not sure on what columns would be returned from the result set and more over I do not know what type of class should I be creating in advance so as to support all the possible results returned. Some times it might just return EmployeeName, EmployeeId while some other time it might just return EmployeeName, EmployeeSalary, EmployeeHikePercent. So the question is on how to generate dynamic typed objects in C#.
Solution: One idea is to generate IEnumerable<IDictionary> as described in Vladimir’s blog.
2. I would like to get a general idea on how to go ahead developing business/enterprise class applications in Silverlight. Is there a reference implementation or a tutorial?
Problem: Doing simple stuff in Silverlight is fairly easy but developing enterprise line-of-business applications using Silverlight would require decent experience with the new programming model that silverlight brings in. So learning from other’s experience would be great.
Solution: Look at Chris Andersons’ wonderful series on developing LOB applications in Silverlight.
3. Now let us think deep. Let us assume that somehow I am able to send my data using WCF service. The problem would be – what the most performance efficient way to implement paging or infinite scrolling?
Problem: you have the datasource and the most common requirement is to implement Paging functionality in the grid. So how would I go about doing this. Are there any clever methods?
Solution: Look at the following links. They are all very useful.
4. How about support for large datasets returned from the service?
I know with my 0.01 cent worth knowledge on WCF, it is too early for me to think on these lines but anyway the problem that I foresee is that if WCF service sends large dataset to the Silverlight client, the client application eventually runs out of memory. So how would I handle it.
So far, I just found this - http://weblogs.asp.net/cibrax/archive/2008/06/10/streaming-large-content-with-wcf-and-deferred-execution.aspx
5. More on large datasets, sorting, grouping on paged datagrids.
Problem: Let us assume that we have loaded only the first page of data in the datagrid and when we sort, the grid only sorts that particular page. But the client expects to see the whole data sorted and return only the first page. How would I achieve this with Silverlight datagrid and WCF as a data providing service?
Solution: On this one, I am yet to find proper solutions. May be I am not looking right. so if anyone reading this blog has prior idea on how to do this, I would be glad if you can share your experience or idea (need not share code as such, I am just looking for a proper pattern to do this).
6. The users viewing the report might want to apply certain filters. How would I go ahead and provide such a functionality?
Problem: Let us assume we displayed certain report. Now it would be nice if the user can view only those records which meets his criteria. So we provide the user with some filtering capabilities. The user would add a new filter expression which would be something like “ColumnX = 100”. So the filter should be evaluated and be applied on the dataset and display only those records which satisfy the filters specified.
Solution: One way is to use dynamic linq (http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx) which allows string LINQ expressions. So the user would be writing LINQ expressions which would be evaluated runtime and the result would be returned.
7. What if the user wishes to have more control, then he could write a filter in languages like IronRuby, IronPython and Managed JScript.
Problem: Consider the same scenario as above but with a more complex scenario. The user wishes to execute some script on the result returned, save the script as a filter and apply it on the report as he wishes to. So how would we provide such a capability ?
Solution: The idea would be to use DLR platform which provides scripting ability using DLR languages like IronRuby, IronPython and Managed JScript. For a basic understanding on how to enable your applications to have scripting ability, you might want to look at the following articles which discuss the subject in more detail.
My next immediate task is to be able to come up with a detailed article on how to make a simple extendable grid using WPF datagrid and IronRuby as scripting platform. Hopefully I should be done with it today and get a more detailed understanding on how things work.
8. Microsoft’s Silverlight Datagrid is very basic. Can I have a better grid that is free to use?
Problem: Silverlight datagrid does not provide functionality like grouping data, display summary items straight out of the box and requires more work.
Solution: Use DevExpress AgDataGrid the free silverlight datagrid control which has nice features like summary rows, sorting, grouping and many others that the Silverlight datagrid lacks.
9. So where else can you think of using scripting functionality on the reporting suite.
One idea is to auto-generate Ruby classes for a query based on the result returned, load them using DLR and generate data source out of it. But it might not actually be a great idea since I have no clue on how well it performs or how well it would act as a Data Transfer Object.
Custom Summary Rows : AgDatagrid allows us to display custom summary items which is very flexible. So we can extend the same flexibility to the report developer. He would write a script using one of the DLR languages which would be executed to get the custom summary value. This would make the application more flexible and depending on how well the developers are with scripting the possibilities are endless. Combined with filters functionality, this would turn out to be a great application to use – powerful and yet simple for basic reports.
Custom Event Handlers: Let us say the report has an event ReportDataFetched. Reports developer can specify a custom script which handles how the data would be filtered before actually rendering the data. He might want to filter out some data without even showing the user. Similarly such other events could be applied using scripting. For example, when we provide scheduling functionality we might have an event that says “ExecutionCompleteDataReady” which can execute a SendEmail script that the user would provide us.
With proper optimization of the script such that the end user does not feel bugged, DLR would be a great platform to make your applications extensible. You just need to figure out ways to work with it.
10. Let us say everything is going well with the reporting suite and finally I would like to implement the following – Charts, Dynamic Charts, Exporting data to Excel-PDF-CSV, Exporting charts as images. How would I be doing all this?
Silverlight, at this moment, does not allow data to be printed at the client. So the conversion should be done on the service. For this, I found a codeplex project called Exporter (Exporter). In order to generate charts in Excel documents, one could use the help of this MSDN article. Some discussion on this subject is available here.
As of the charts, Silverlight charts looks like a great suite that could be used. Another option is to use Visifire controls
but they are not free for commercial use.I received a comment from Chirag, Product Manager at Visifire stating that Visifire is indeed free for commercial applications if it conforms to the GPL. As a more important note, Silverlight Toolkit is a very good suite that one could use in many ways.
If we move ahead on how to export Silverlight control rendered as an image, as a starting place, I would look at Silverlight Contrib project. This project provides a Silverlight implementation of XamlWriter which can be used to get the XAML for the current silverlight element and then render it to a PNG. (Use this article)
I am glad on how this blog has turned out to be. It really helped me to think in the proper direction. Now in the next article I would focus on making extendible grid and demo the filter functionality with the help of DLR, I guess I would pick Ruby (I need to learn on how to use it, though).