Moonlight: Silverlight Goes Monoby Edd Dumbill
You might have heard of Microsoft's Silverlight technology. It's a rich internet application (RIA) framework positioned to rival Adobe's Flash. Unlike Flash however, it's only available for Windows and Mac, not Linux. This is where Moonlight comes in. Moonlight is a project to create a Silverlight plug-in for the Mono environment, which will run on Linux, Mac and Windows.
Silverlight 1.0 was very much an early-stage implementation and, at the time of writing, is in release candidate stage. Though 1.0 is exciting in itself, many developers are waiting for Silverlight 1.1, widely seen as the serious release, as it introduces the ability to use managed code under the .NET runtime. This 1.1 version, currently in alpha release, is the one I'll reference in this article when making statements abou t functionality and compatibility. Moonlight targets compatibility with both 1.0 and 1.1 releases of Silverlight.
What Is Silverlight?
Silverlight is designed as a web browser plug-in that delivers richer interactivity and control than HTML plus scripting will allow. Effectively, it's Microsoft's answer to evolving the capability of the browser. Silverlight offers the expressive power of desktop GUI platforms, along with network awareness. So far, just like Flash. The difference from Flash is that Silverlight does this in languages you probably already know, as opposed to Flash's ActionScript.
The GUI layer is expressed in XAML, a simple markup language for user interfaces. Here's "Hello, World!"
Listing 1. Hello World in XAML
<Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <TextBlock>Hello, World!</TextBlock> </Canvas>
Rather than being monolithic, a Silverlight application is a bundle of files, most typically being the XAML description of the UI plus a script file to provide the behavior. Through the Silverlight APIs, applications have access to a broad spectrum of functionality, covering widgets, network access, and multimedia. Additionally, Microsoft's ASP.NET technology provides convenient integration APIs on the server side, though Silverlight can interact with any server via Ajax.
Just in case you were concerned that Microsoft expects people to code all this stuff by hand, don't worry. There's a whole tool suite called Expression that you can look at. It won't surprise you to find that Expression is positioned squarely in the same product space as Adobe's Creative Suite. The neat thing, of course, is that you can create Silverlight applications by hand, which lowers the bar for general adoption, integration, and source code sharing.
Technically, Silverlight is a hybrid of some of Microsoft's existing platform technologies: the Windows Presentation Foundation (WPF), .NET runtime, and ASP.NET on the server side. This puts the Mono project in a great place to get started on Moonlight, as many of the required components exist already in Mono.
Figure 1. Screenshot of Sprawl game, one of the Silverlight sample applications
Why Build Moonlight?
Moonlight emerged after a remarkable 21-day hackathon staged by the Mono project. Faced with an invitation to demo the then only-talked-about Moonlight at the REMIX'07 conference in Paris, Miguel de Icaza challenged Novell's Mono developers to a hack-a-thon. Their starting point was less than encouraging. Miguel described their initial state: "Other than the rectangle (that is currently not even rendering) and the video (without audio) I got nothing."
Miguel assembled a small team of expert Mono hackers, and over 21 days they committed more than 24,000 lines of C++ and 13,000 lines of C# into their subversion repository. The result was a partial Silverlight implementation and a collection of demos, including a working demo of the Surface application Miguel could show at the conference. You can see screen captures of their progress hosted on the Mono web site.
From such energetic beginnings, Moonlight has three aims: to enable Silverlight applications to run on Linux, to create an SDK, so that Silverlight applications can be developed on Linux alone, and to reuse the Moonlight engine to enable desktop applications.
This last aim is intriguing, and in the context of the Mono project at the moment, makes a lot of sense. It's a very tough game playing catch-up with Windows, and there's not much chance of Mono implementing the entirety of the Windows presentation subsystem. At the same time, GTK+ isn't a very satisfying cross-platform GUI toolkit, and it is certainly very strange for Windows developers coming over to Linux.
So, it would seem that Moonlight offers a promising route to creating lightweight graphical applications on Linux. If that doesn't grab you on the desktop, stop and think about all the neat little devices that now have Linux embedded in them. Moonlight on Linux could be seen as an alternative to developing for the iPhone, for instance.
Moonlight Implementation Challenges
Under the hood, Silverlight 1.1 is an extended subset of the .NET 2.0 framework. Many features have been trimmed, to leave those that make sense in a browser environment and some additional specialized APIs have been added. This in itself presents an interesting challenge to the Mono project. They don't really have the resources to manage multiple branches of the runtime, but want to be able to provide multiple incarnations of the package. A web user does not want to drag down 27 MB worth of Mono just to run a small applet.
Pages: 1, 2