Dynamic Data and Silverlight?

July 6, 2008 19:00 by Rob

Yesterday I saw a demo on the new Dynamic Data contribution to Asp.net 3.5. It literally blew me away (really) because that was what I've been doing for most of my time over the last couple of years.

The base

Basically, we develop custom data driven web sites with Asp.net. Most of the time this also involves some kind of back-end content management. What our mini-cms actually did was the following:

  • Inspect the database model
  • Enrich that model with metadata such as preferred input method, validation and comments and associations,
  • Generate a whole lot of Asp.Net controls from the aforementioned properties,
  • Inject a lot of role-based security-stuff,
  • Present those forms to the end-user to allow basic site management.

So, what we had to build was a configuration file with all the meta data, the database, and of course the web site that got driven by that data.

Not any more. I'm out of a job.

With Visual Studio 2008, Asp.Net 3.5 framework and Dynamic Data the generic application that we wrote can be thrown out of the window, because with the DataContext designer this is not longer something somebody else will pay us to do. As you can see in the demo, by binding your decorated data model to the starter solution, you have an interface in a matter of minutes.

Fortunately the Internet-facing site cannot be generated yet. And, we can embrace the DynamicData technology to our advantage and create sites even faster.

On to the subject of this post!

Silverlight and Dynamic Data

Now this is all nice, but there is a simple problem. If I wanted to use this technology with Silverlight, In the last couple of weeks, I was working on a Silverlight application for our content management concept, and I was wondering if the object model could be easily extracted with the new LINQ To SQL designer. I would have to transfer all meta data and content through a WCF service, right?

Lucky for me, the DynamicData layer isn't even finished and does not yet generate WCF services. So, in order to build a generic Silverlight application you would have to serialize a lot of unknown types into a Silverlight application that was unaware of those types. That is not really what I wanted. I wanted a pre-compiled application that can be configured with just a single configuration property: the data model.

I decided to give it a go, and here's what I came up with. I will try to explain it one step at a time.

Here's my very basic data model:

image

Just a news item for a particular category that can have zero or more attachments to it. Nothing fancy.

Using the designer, this stuff generates classes for me with the all the properties and data access methods (select, update, delete etc.) while maintaining all the relations.

Here comes the cool bit: Did you know that the DataContext class actually gives us all the meta data without having to use reflection?  Just drill down into DataContext.Mapping and see that you find there:

image

(edit: since GetTables is a method, it should be written as .GetTables())

Silverlight does not have this nice API, So I created my own WCF contract to serialize these properties in a separate class. Here's a sample of the type specification that I use to transfer to Silverlight (I left the part out that maps the MetaDataMember stuff to my own classes on purpose).

image

To serialize an item of a particular type I perform a generic LINQ select on the table, I read all the properties of a data item and put them in a dictionary so that Silverlight can read and display those items:

image

Notice that for this demo I used the Convert.ToString() method on the value to get a nice presentation of the value. In a future version I will need to put the basic values (int, string, DateTime etc.) in the Values collection.

Of course this is not finished by far. I needed a way to decorate the designed classes with validation, descriptions, etc. Because I do not yet have the DynamicData beta installed on my machine I decided to borrow their approach to decorate generated code. Here's a snippet for the NewsItem class:

image

Because the data context designer generates partial classes, we have the ability to add functionality to those classes. Since I only need to apply some attributes to the generated class I need to define the class again (as partial) and apply my attributes. Since I cannot redefine the properties of that class I have to create an extension class that shadows the properties of the generated class (very nice idea, DynamicData Team!). To use the attributes of the extension class I do need to use reflection, but that is only once. Here's a video of how it works and how it is used. I just copied the concept to there's little more to tell.

A lot of work still needs to be done but I hope you understand that the rest is just more along the same line.

Looks like I still have a job!


Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Silverlight usage

June 18, 2008 01:35 by Rob

Over the last couple of days some discusion was raised about the use of silverlight in the new media, especially by the dutch public networks (add link), but it seems that more and more companies are starting to use silverlight for their presentations instead of just resorting to flash. I especially like this site from Renault, when they show off their new line of cars for the european market. I was surprised with the subtle use of animations and video in this silverlight app so check it out!

I'm probably not the first to notice this, but if you show off new technology, you'd better spell it right!


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: Silverlight
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

I love it!

June 7, 2008 14:20 by Rob

From what I've seen, Silverlight 2 beta 2 and Blend 2.5 june preview are amazing.

I've watched some of the new tutorials on silverlight.net, and I especially like the video titled ADD STATES TO A USERCONTROL FOR SILVERLIGHT 2. This demonstrates the fantastic way to add animations, flyout menus etc while having to write very little code or XAML yourself.

I'll definitely be spending some time with these new toys!


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: Visual Studio | Silverlight
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Silverlight 2.0 beta 2 is coming this week

June 5, 2008 14:44 by Rob

Check out the changelist.

 


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: Silverlight
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Silverlight 2.0 Modified WrapPanel

June 3, 2008 19:18 by Rob

Inspired by this article on Codeproject I decided to give reproduce the wrappanel so I could learn a little more about custom panels in SilverLight 2.0 beta 1. The code provided by Inear has some small problems, one of it not being able to behave properly in a scrollviewer. I made some small adjustments after scourging the internet and here is my solution:

Just before you pass on the ArrangeOverride to the base class, inject this code fragment:

[code:c#] 

if (this.Height != startPoint.Y + largestHeight)

{

this.SetValue(HeightProperty, startPoint.Y + largestHeight);

}

I did make some other small modifications to clean up the code a bit, and I didn't implement the Orientation=Vertical stuff, but check below for the full code.  

WrapPanel.zip (1,11 kb)


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: C# | Silverlight
Actions: E-mail | Permalink | Comments (2) | Comment RSSRSS comment feed

Nice Silverlight + WCF demo

May 23, 2008 12:28 by Rob

Below is a ling to a video that demonstrates how easy it becomes to develop a datadriven Silverlight application.

http://blogs.msdn.com/swiss_dpe_team/archive/2008/03/17/silverlight-2-beta1-wcf-linq-to-sql-a-powerfull-combination.aspx

 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: Visual Studio | Silverlight
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Visual Studio 2008 SP1

May 13, 2008 20:11 by Rob

According to some post on the web, it seems that visual studio 2008 sp1 is out. Biggest noticable change (for me) is that VS2008 Express received the ability to build Web project and class library which make it possible to build Silverlight 2.0 applications with Express. Yeah.


Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: Visual Studio | Silverlight
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

No More Silverlight 1.1 - I am as amazed as you are.

December 1, 2007 16:19 by Rob

UPDATE: Now that silverlight 2 beta has arrived, I'm feeling a lot better. 

It seems that things are moving faster than I've expected. There has only been an alpha release of Silverlight 1.1, but since it is becoming bigger and bigger the branding people at Microsoft have decided that it is such a huge step forward they've rebranded it to SilverLight 2.0

...We now have a extensible control framework, two-way data binding, templates, styles, all the standard controls (TextBox, ScrollBar, CheckBox, RadioButton etc.), multiple layout containers (Grid, StackPanel, Canvas). In short, if you're familiar with WPF today, you'll be right at home with Silverlight 2.0.

With regards to the Rich Internet Application stuff, here's an interesting quote from the article on Tim Sneath's blog:

Moving forward, if you want to build a rich Internet application, Silverlight should absolutely be at the top of your list for consideration. No other platform will offer such a rich UI framework, and all the data templates and styling capabilities, coupled with the power of the .NET Framework and base class libraries, along with an easy migration path to a full unrestricted Windows desktop solution.

I'd better get up to speed with WPF...


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: C# | Silverlight
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

There's Silverlight at the end of the tunnel

November 21, 2007 14:38 by Rob

Amidst all excitement on the new silverlight 1.0 service release, I saw something that interested me more than the update itself. Check out this quote:

our team has been cranking on for Silverlight v1.1 (controls, databinding, layout, templates, styling and a package based app model, phew!)

This of course means that we'll be getting a great full featured set when SilverLight 1.1 beta will be released. I am so excited about this next version! What we'll be getting looks cool:

  • Controls: We definitely needed controls in 1.1. I have worked on some of my own layout controls and that is a lot of work. I hope they release these controls really soon.
  • Databinding: This will of course be much better than doing everything in codebehind
  • Layout: This one in combination with the new control set: I'm lovin' it.
  • Templates: While trying to build my own controls I was trying to find a solution for templates. Apparently, the silverlight team is way ahead of me. Go! go!
  • A package based app model. I have no idea what that'll accomplish.

Sadly enough, when I attended the TechEd Barcelona beginnen november this year, I have not heard one single person talk about these upcoming additions to silverlight. This is actually the first word I hear from the team about future plans with 1.1. So, in one sentence: Please give us another 1.1 alpha! (a beta would be better of course).

Edit: More big news: Visual Studio 2008 has been released. Please be aware that the release notes tell you that the SilverLight tools are not yet updated to work with the release, so if you need to work on SilverLight, you'll have to stick to VS2008 Beta 2 and have a little patience until the SilverLight tools are updated.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: Visual Studio | Silverlight
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed