SDDN October: Silverlight with RIA and using MVVM

I just got home from the attending the October Silverlight Designer and Designer Network (SDDN) meeting. It was a trillogy presentation from the Readify guys, Jordan Knight, David Burela and Philip Beadle.

Who respectively presented on:

  • Connecting Silverlight to RIA,
  • Binding data to Bing Maps and
  • A testable Silverlight architecture and development approach walk-through

There was also an announcement for the 2010 Melbourne Silverlight CodeCamp, with registrations now open at the SilverlightCodeCamp.com.au. The schedule is still open for volunteers to offer up presentations. It will be run at the new NAB training facilities. The registration site was mentioned with the footnote of “it’s not tested yet” which at the time of this post seems to be the case, my registration isn’t being processed correctly or at least there’s no feedback of success.

First up Jordan ran through the basics of using .NET RIA Services to produce a simple data-bound Silverlight website log-in component. It included demonstrating how to use attributes to decorate the RIA based entities to assist with validation that can be shared server side and client side. The benefit being a visually well designed Silverlight application can benefit from robust validation logic, and make use of it through field level bindings to easily display validation feedback to the user.

Next up was a quick presentation from David showing us data binding capabilities of data collections to Bing Maps, to produce overlays and interactive features on a map view. He should be posting the material up soon on his blog, including some code snippets that will make achieving what he demonstrated quick and easy.

The final presentation from Phil, which was nicely presented using Prezi.com was all about putting together a collection of tools and concepts to develop a robust and testable Silverlight based application. It focused around using the Model-View-ViewModel (MVVM) architecture/design pattern. It included examples of regular unit tests, automated UI tests, and integration tests, making use of an Inversion of Control (IoC) framework called Unity a Microsoft Application Block up on CodePlex and the Visual Studio 2008 Test Edition. There’s a bit of a discussion going on at StackOverflow about Unity.

Some key things that Phil pointed out to stay up to date with Silverlight and of course to assist with building more testable Silverlight applications include:

All up, a good round of presentations.

Exceptions in (my) LINQ (presentation)

Last night I presented to the Melbourne Patterns & Practices group, thanks to my audience for paying attention, having great input and asking interesting questions. I would like to clarify some things I glossed over in the powerpoint slides, and explain why some of the simple extension methods didn’t execute in the live code demos. I also have posted the pptx file here.

The first thing that I did not give a detailed enough explanation about was the Exception Handling slide where I was using the ‘let’ keyword in a LINQ statement. The question was along the lines of the benefit of the exception handling offered up by making use of let in a LINQ query. To clarify this, the let keyword is used to create a contextual keyword as part of the LINQ query (a Range Variable). This range variable can then be used to create an anonymous type using projection. I incorrectly tied the explanation of let to the point I was trying to make about handling exceptions. The key take-away is that because the query is a deferred execution any exception handling needs to be wrapped around the code that performs the execution. So have the Try {} Catch (E ex) {} surround the processing code not the query definition.

There’s a great post about using ‘Let’ in a LINQ Query by Greg Beech that goes into greater detail. This topic lead to a question about what would happen to processing when an exception did occur.

Another issue that came up during live code tweaking was making use of certain extensions, in particular .Reverse() didn’t seem to compile. I am unable to recreate the issue quite possible some weird state in Visual Studio 2010 Beta 1, if that was the case then the clean and rebuild was the solution.

But here is the final very simple code that reads a directory and outputs the file names in a reverse order:

var xmlFilesQuery = 
      from fileInfo in 
           System.IO.Directory.GetFiles(@"D:\soExportData\")
      where fileInfo.Contains(".xml")
      select fileInfo;

foreach (var fileName in xmlFilesQuery.Reverse())
{
    Console.WriteLine(fileName);
}

The last clarification point was a scenario where the PLINQ execution of a task compared to it’s LINQ execution offered up a speed up of 2.18 times. Not sure what state the application was in to allow that. I’ll do some investigation and based on how complex the cause was either update here or create a new post.

Greater Than 2x Speed Up (On Dual Core Machine)

Greater Than 2x Speed Up (On Dual Core Machine)