« February 2008 | Main | April 2008 »

March 2008

March 31, 2008

Open Source Ambassador

Yep, that’s right. That’s my other job here at the company. This means that I participate in a set of events that have nothing to do with IronRuby as a technology, but have everything to do with IronRuby as part of a movement toward greater openness within the company.

Last week, I participated in the Microsoft Technical Summit that we held here on campus. Every year we invite a bunch of Microsoft skeptics to campus and subject them to mind conditioning engage in a dialogue with them. I talked about why we were doing Open Source, why we were doing dynamic languages in particular, and showed them a few demos of stuff that works today. It was great to get blunt feedback from folks who took time out of their lives to attend, and hopefully we did move the dial on their perceptions of what we’re up to here at the company.

I had a lot of fun talking to Adam Keys who rocked my world with his RubyConf one-man play (warning – you need to either be a Ruby programmer to really appreciate the crazy humor that this is, or be fascinated by what geeks think is funny):

On Friday, I participated in our inaugural Open Source Day internal conference at Microsoft. I was on a panel with three other folks: Rob Mensching, who did the first Open Source project at Microsoft – WiX, Shawn Burke, who runs the AJAX Control Toolkit project, and made the .NET library source code available among many other cool things, and Tom Hanrahan who runs our Linux Interoperability lab. We talked about experiences – Rob and Shawn have been at the company a long time and had a ton of fun anecdotes about what it was like to try and do Open Source at the company back in the dark ages. I contributed some stories about how we do IronRuby development and some pointers about how other product groups can think about why and how they should participate in Open Source. Tom was our elder statesman, and talked a lot about why interop is important to our customers (bottom line is that virtually all of our medium to large customers live in a heterogeneous aka non-100% Windows environment).

One thing that came out in the discussions is how we need to be better at transparency, even while developing our non-Open Source products. One of the powerful ideas of Open Source is the ability for outsiders to actively participate in the creation of products even if they never crack open the sources themselves. That’s a powerful idea, and one that I think that (at least in Developer Division – where I work) we’re in a great position to deliver on.

*

I’m a huge fan of vimperator after discovering it via Zed Shaw. If you’ve internalized the vim keybindings, you’ll be surprised at how you can leverage your muscle memory while surfing the web.

March 13, 2008

Steve Yegge on Interviewing

Steve Yegge

Sorry, Steve for dragging out that lovely photo of yours that I took at Foo Camp. But hey, it's the only one that I have :)

I've been interviewing a bunch of folks for our 4 open positions (a nice fellow just accepted our IronRuby SDET position). Some of the other folks I would like to believe would have done better if they had read Steve's Get that job at Microsoft blog post [1].

I've told folks that my MS interview was on par in difficulty as my Ph.D. candidacy oral examination, partly due to the fact that it was much, much longer. (A Ph.D. oral exam is done by 3-5 professors vs. you in a room and they decide whether you continue in your studies or whether they kick you out). Mine started at 10am and ended at 6:30pm or so when I sat down with Scott Guthrie at the end of my loop.

Steve has a lot of good tips (including bring your own dry-erase markers - my last interview candidate actually ran out of ink and I wound up running down the hall to get some more for him). It's essentially a syllabus on what to study for a technical interview. 

[1] At least that's what IE on MS CorpNet shows me :)

March 10, 2008

Henry's Adventure in Las Vegas

One day, Daddy put Ben's favorite train Henry in his pocket. He was cleaning up the house the night before he was going to Las Vegas for the MIX conference. When Daddy got up the next day, he brought Henry with him in his pocket! Silly Daddy!

When Daddy got to the airport, he reached into his pocket for something else, and he found ... Henry! So Daddy decided to take a picture of Henry at the airport:

img020

Soon, it was time to get onto the airplane. Here's a picture of Henry looking out the window just before the airplane takes off!

img021

After a long plane ride, we finally landed in Las Vegas. Henry was excited to be off the airplane. Here he is in front of the gate, D25:

img022

We got into a taxi van to go to our hotel. Here is Henry looking out the window at some of the signs in Las Vegas. It was a sign for Defending the Caveman:

img024

When Henry got to his hotel, the Mirage, he saw the biggest fish tank he had ever seen right behind the check-in counter. Look at all the fish!

img025

Next, we went up to our new hotel room on the 5th floor. We opened the curtains and saw all the other hotels outside! The hotel that Daddy was going to for his conference was right across the street. It's called the Venetian.

img027

It was the afternoon, and it was time for Daddy to take a nap before dinner. After he woke up, we went with Henry to go across the street. On the way out, they saw some dolphin statues. Here's Henry in front of the dolphins:

img028

After they walked across the street to the Venetian, they saw a water fountain. Henry wanted to take a closer look:

img029

There were also people floating around in gondolas. Henry wanted to have a ride:

img030

Daddy and Henry went inside the Venetian. They saw lots of paintings on the ceiling!

img031

Later, they went into a big indoor shopping mall. There were even gondolas inside! Henry wanted to say hello to the people!

img032

Daddy was walking into the MIX conference when he saw a tiny model of the Venetian hotel. Henry wanted to take a closer look. Here's Henry flying over the model of the Venetian! It looks like he's a giant engine flying over the real hotel!

img033

When Henry got to the conference, he went to the MIX Sandbox area where he signed up to give his own talk about Ruby, Ruby, Ruby! Just kidding. It was really Daddy who was giving the talk!

img034

Daddy and Henry were getting hungry. It was time for dinner! They went to a nice restaurant called Canaletto. Here's Henry eating some oil:

img035

Here's Henry drinking some wine:

img038

After a big dinner with lots of wine, it was time to go back to the hotel for sleepy time. The next morning when Henry woke up, he had to go and check his email at Mix:

img041

After checking his email, he had to go and eat some breakfast. It was some bacon and eggs with mushrooms!

img042

After breakfast it was time to watch the opening keynote. Here's Henry watching Ray Ozzie give a talk about the future of Microsoft:

img043

After watching the keynote from the overflow room (the place where trains had to watch the keynote because trains didn't actually pay to go to the conference), it was time to go play in the MIX Sandbox. Henry had a big surprise at the Sandbox. He made some new friends. Here's his new best friend, Roby the Robot (aka Channel 9 guy).

img085

Henry had a lot of fun playing with Roby. It was a pretty busy day, and Henry decided that he needed to get a massage. OK it was really Daddy who needed to get a massage. But here's Henry sitting on the massage chair after Daddy's massage:

img086

It was time to go back to the Mirage to get ready to go out to see a show. On the way out of the Venetian, Henry stopped to have a drink in the fountain, and to listen to the man playing the accordion:

img089

It was a fun show called Mystere. They don't allow trains into the show, so Henry had to stay back at the hotel room to watch American Idol all by himself. He had a good time though.

The next day, Roby came over to play. Henry and Roby went outside to play in front of the Venetian. Here they are on a nice, sunny day:

img091

When they went inside they saw the wheel of fortune game. Roby was too young to go into the casino, so we had to take a picture of Henry:

img092

We went over to Daddy's talk about Ruby, here's Henry getting the computer ready for the talk about Ruby:

img093

The talk was lots of fun - it wasn't really a talk, it was a conversation with some nice people who really like Ruby. Henry and Roby worked up a real appetite listening to Daddy talk to the nice people. It was time for a snack. Lucky for them, there was lots of ice cream to go around!

img094

It was time for dinner! Henry, Roby, Daddy and some of Daddy's friends went out to eat at the fin Chinese restaurant in the Mirage.

img095

It was time to go back to the hotel room so that Roby and Henry could watch Daddy hack on Dynamic Silverlight code. By the morning, Daddy had everything ready for his talk at MIX. Here's Roby and Henry helping to hold up Daddy's computer on stage just before his talk:

img096

Once the talk was over, it was time to have some fun! Roby and Henry decided to go and play the Rock Band game. They didn't do so good since they were really little and couldn't play the really big instruments. But they did have fun watching other people play:

img097

Roby and Henry realized that they were inside most of the time. They found out that the Mirage has a pool outside and that there was a big yellow thing in the sky called the sun. They went outside to have a few drinks by the pool. Here they are in front of the waterfall!

img098

Now, a Las Vegas experience wouldn't be complete without playing a hand of black jack:

img099

Daddy and a few of his friends decided to go walking around Las Vegas. Where did they go first? The Sony Store, where Roby and Henry watched Ratatouille on the 52" LCD TV:

img101

They also walked around Caesar's Palace and had their picture taken in front of some of the big sculptures:

img102

Finally, it was almost time to go home. There was one last picture that they took in front of the giant horse and dragon thing before they got on the plane to fly home to Seattle.

img103

It was a fun trip. Henry had a great time. He made a new friend, Roby! But best of all, Henry was really happy to come home to see his most favorite boy in the world: Ben!

The End.

(written with some help from Matthew)

Looking back on MIX 08

Hard Rock Cafe Memorabilia in Silverlight

Last year I was involved in the keynote, so by the time it happened, I had heard it several times already. This year, I could just sit in the audience as a spectator. And wow, what a show!

Highlights from the first keynote for me were:

1. NBC Olympics demo. The whole picture-in-picture thing with live interactive stats was stunning. I'm hoping that Verizon gets FIOS to my house by the time the Olympics start ...

2. Hard Rock Cafe Memorabilia app. The Seadragon Deep Zoom technology was amazingly well done. And nobody tops Scott Stanfield for meticulous demo preparation. Well done!

3. Aston Martin. Well, the demo was OK (and the cars are awesome), but Marek Reichman from Aston Martin was awesome. He was totally 'on message' about Aston Martin and the superlatives (and his accent) that he used to describe the car were priceless.

The Ballmer / Kawasaki Show

The second keynote was pure entertainment. Guy Kawasaki and Steve Ballmer put on a show to remember (apparently quite unlike the Zuckerberg / Lacy show at SXSW). There were lots of good-humored barbs traded back and forth and Ballmer gave as good as he got. It really presents Steve in a good light -both as a guy who can take a joke, as well as a guy who really understands the industry and knows how to set the direction for the company.

Highlights for me were:

1. Jab at the MacBook Air "being heavier than my PC" (27:20) and "I'll have a bake-off between my Tosh and that thing backstage" (27:50).

2. Kawasaki's suggestion that Apple is a chihuahua to Windows that Microsoft kicks away (along with Ballmer's imitation of a chihuahua)

3. Steve's revelation that he gets 60 pieces of email a day (with no human filters) and that he responds to them personally (or delegates to someone to follow up).

Of course, there was also a reprise of Monkey Boy that made the headlines as well.

Introducing Dynamic Silverlight

This year, our talk was on Friday morning. I'd much rather get talks over with earlier in a conference since it means that I can relax and enjoy the show but such is life. This year, we had a pretty ambitious agenda planned for our talk, and with the exception of the voices that I could hear from the PC on stage, it went off without a hitch.

Here are some links to the talk that Jimmy and I gave this year. It's available in a bunch of formats:

Silverlight player

iPod formatted MP4 (57.6MB)

WMV for Zune (84.1MB)

The slides are available online, but they're largely content-free. The real meat of the talk is in our demos, and I wrote out those demos as a series of three blog posts:

Part 1: Hello, World! in Dynamic Silverlight

Part 2: Managed JScript and flickr

Part 3: Integrating Silverlight with ASP.NET MVC

You'll need the latest bits that we uploaded just after my talk to run these demos. You can download them from here.

March 08, 2008

Dynamic Silverlight bits now available!

Thanks to the hard work of John Messerly and Jimmy Schementi, we pushed the Dynamic Silverlight bits out to our temporary web site. We also published the hands on lab that we created for MIX up to the site as well.

Enjoy!

March 07, 2008

Dynamic Silverlight Part 3: Integrating Silverlight with ASP.NET MVC

We'll finish off our tour of Dynamic Silverlight (DSL) by looking at how we can connect it with an ASP.NET MVC app. Building on our flickr photo search app from Part 2, we'll add support for saving links to your favorite photos to your MVC app. This is what the final app looks like:

image

You should download the solution for this part of the lab if you want to follow along.

Download demos3.zip

Configuring ASP.NET MVC

This tutorial shows Visual Studio integration so you'll need to have the Silverlight Tools for Visual Studio installed along with the Silverlight SDK. Let's open up the solution in the demos\mvc_start sub-directory using Visual Studio. The first thing you should notice is how we've organized things in the project:

image

This is pretty much the standard ASP.NET MVC directory layout (I started from an ASP.NET MVC project); I added the App and Assets directories.

If you look at the App directory, you'll see that I've also added all of the DSL assemblies that are needed to run the app. Since we're going to be running Chiron statically (eg zap everything in this directory) instead of dynamically (look in this directory and figure out what languages I'm using and then find and zap all of those files), those files must be in that directory.

Next, we'll make sure that Chiron is integrated into the build system. If you recall from Part 1 of this series, Chiron is our local web server that will automatically generate XAP files. Since we're now going to be running using the ASP.NET Development Web Server, we'll need to statically generate our XAP file. The good news is that it's pretty easy to do this: you just need to add a post-build step to your project. The bad news is that you'll need to build the project to run changes in your script files - just refreshing the page in the browser won't do the trick. I know I've been caught by this once or twice while writing this app.

Let's add the post-build step. Open your Project properties page, click on the Build Events tab, and add this string to your project:

$(ProjectDir)DynamicSilverlight\chiron.exe /d:$(ProjectDir)App /x:$(ProjectDir)App.xap.

It should look like this when you're done:

image

Notice that there's a DynamicSilverlight subdirectory which contains a local copy of Chiron. I did this so that this would be a self contained project. Once we work out the details of how we'll setup the paths and ship Chiron as part of a DSL SDK, you won't need the DynamicSilverlight directory.

We'll need to make other change to the project file: enable Silverlight debugging on the client. Click on the Web tab in the project's properties dialog and make sure you select the Silverlight checkbox under the Debuggers section:

image

Next, we have to generate the correct HTML to boot our Silverlight app. We'll edit the code under Views\Home to add the Silverlight boostrap <object> tag to our MVC app:

image

If you build and run your solution, you should see the app start up in your browser. If you look at the file system, you should see that Visual Studio + Chiron has generated the App.xap file for you.

Tour of the Ruby code

The Ruby code looks an awful lot like the JScript code from Part 2 except for the parts of the app that generate WPF. In the JScript code, we were generating XAML strings and injecting them into the page. But we can do much better in IronRuby :)

We build up the WPF element tree for the photo and its border using this fragment of Ruby:

image

One of the reasons why programming with XAML is so easy is that the XAML parser does a lot of the heavy lifting involved in doing the proper type conversions. If you're programming against WPF directly, you're going to have to ensure that properties are assigned values of the correct type.

There's a fair amount of code in Silverlight.rb that does property transformations. For example, take a look at the code that sets render_transform_origin:

image

Notice how we convert the Ruby array parameter into a WPF Point object before assigning to the property. Also notice how we've monkey-patched this behavior in the UIElement class, which is where the render_transform_origin property is introduced in the type hierarchy. All current and future descendents of UIElement will automatically inherit this behavior.

Another thing to point out is BounceAnimation. This is a class that encapsulates a WPF storyboard that knows how to generate the 'bounce' effect that you'll see when the photos appear (side note: I'm not really a Silverlight guy, I only play one on TV, and I'm too embarrassed to say just how long it took me to figure this out last year). If you look at the definition for BounceAnimation in Silverlight.rb, you'll see that it's quite compact:

image

The other important thing to point out is that you now have a named animation. So you can now nicely encapsulate different animations, like Twirl or Zoom or Fade and simply apply them to your elements without having to copy and paste XAML.

While generating WPF trees using Ruby is more compact than generating them using XAML, there are other reasons why it is useful. Recall the code from Part 2 that loaded the images:

image

This code uses a grotesque hack to ensure that the WPF for the photo isn't inserted into the scene until the image has finished loading. How does it do this? By loading the image twice.

Let's look at how we can elegantly solve this problem by programmatically loading the photo from flickr:

image

Here, we're using the Silverlight WebClient API to asynchronously download the image. The open_read_async method initiates the download, and the open_read_completed event fires when the download is complete. The args.result property references a Silverlight Stream object which we pass to the set_source method of the Bitmap object (created earlier). Notice how we can use a Ruby closure to close over the bitmap object without resorting to passing it as a parameter to the event handler. Finally, we inject the canvas object into the scene, and tell Silverlight to begin playing the animation that we assigned to the scene.

Posting back to MVC

Let's add some additional functionality to the app. First, let's add an event handler to each photo so that it sends the photo's URI back to the MVC app when you click on it:

image

Notice that we're just posting the URI back to the server. Let's look at the ASP.NET MVC code that handles the HTTP GET request. This code lives in the Controllers\HomeController.cs file:

image

Notice how we're just stuffing URLs into the ASP.NET Session object. It's an exercise left to the reader to add user management and hook this up to a database to make this a real multi-user app.

Once the user has selected some favorites, we want to let them see their collection of favorite photos. First, we'll need to add some code to our HomeController to display the view:

image

Notice how we're adding our list of semi-colon separated URIs to our ViewData.

Next we'll generate a new <object> tag that injects a list of favorites into the initParams property. We'll need to add a Favorites view to our MVC project. Everything in Favorites.aspx is identical to the code that I showed you earlier for Index.aspx, except for the part where we set the initParams property:

<param name="initParams"
  value="urls=<%= ViewData["urls"] %>,debug=true,reportErrors=errorLocation" />

Here, we retrieve our list of URIs from ViewData and inject it into the page.

Finally, we'll add a button that connects the UI on the client to the Favorites view. Open Views\Shared\Site.Master, and edit the code in there to add a Favorites button:

image

If you run the app now, you'll be able to add photos to favorites, and look at your favorites. The solution is also in the zip file - look in the mvc_end sub-directory.

It's an exercise left to the reader to improve the UI of the app so that favorite photos are selected when you click on them :)

Summary

We saw how IronRuby can generate WPF scenes without using any XAML at all. The heavy lifting of doing the type conversions is done behind the scenes by the code in Silverlight.rb. We also saw how straightforward it is to add some Dynamic Silverlight code to an MVC app. It's as simple as adding a post-build step and adding some the DSL files to a standard MVC project.

Dynamic Silverlight Part 2: Managed JScript and flickr

In part 1 of this series, we looked at how to build a simple Hello, World application using Dynamic Silverlight and IronRuby. In this part we're going to build a more sophisticated application using Managed JScript, IronPython, Silverlight 2, and the flickr API. It lets you find the most interesting 5 photos for your search term using the flickr api:

App

Let's start by walking through an existing JScript app that knows how to display flickr photos on the screen. Download the source code for this tutorial from here:

Download demos.zip

Open a command prompt, navigate to the demos\flickr_start directory and startup the application using Chiron:

chiron_start

Let's look inside of app.xap, which was generated by Chiron:

app.xap

You'll see that the assemblies for managed JScript, and Dynamic Silverlight (DSL) are in the xap, along with some Silverlight controls assemblies from the Silverlight SDK. The complete list of assemblies can be found in AppManifest.xaml:

image

Notice that there is also an assembly called contract.dll - more on this assembly later.

This is a Managed JScript application, and execution begins in app.js.

In Silverlight 1.0 applications, you modified an existing scene by injecting XAML strings, much like how you would use innerHTML in the HTML DOM. In the next part of this tutorial, I will show you how you can do the same thing using just code (and it turns out to be considerably harder than just injecting strings).

The initial scene is defined by app.xaml:

image

This file shows off some cool new Silverlight 2 features. First, notice the two XML namespaces. The c and e namespace prefixes are mapped to types in the System.Windows.Controls, and System.Windows.Controls.Extended assemblies. These assemblies contain our new Silverlight Controls, which are available as part of the Silverlight SDK.

I'm also really pleased to see that we're releasing the source code for these controls under the Microsoft Limited Public License, as well as the test harness that Shawn's team uses to test these controls. Awesome. We're moving in the right direction folks, and we're not done yet.

As you can see, we're using two simple controls: the WatermarkedTextBox (which makes it trivial to create a Search textbox a'la the search widget in all modern web browser), and the venerable Button.

Let's look at the code in app.js to see what happens when you click on the Search button:

image

We bind a JScript anonymous method to the search_button control's click event using a familiar (to C# developers) delegate-style binding syntax. Notice how we're also using a JScript closure to bind to the App instance and the application's root visual.

There's a bit of magic going on in scene.search_text.Text. Here, we're using a DLR feature called member injectors, to dynamically inject attributes onto the scene object. Next, let's look at how we generate our flickr query:

image

Here, we initiate an asynchronous REST all to flickr. QUERY contains a scary flickr REST string that we'll append our search term to. Notice how we again use an anonymous JScript method which functions as a closure to perform an action when the download is complete.

The OpenReadAsync method returns a .NET Stream object which we can pass to Silverlight's built-in JSON serializer. This is where the fun begins :)

The original version of this application was written in IronRuby, and I didn't have a working JSON deserializer handy. While Managed JScript can certainly use any of the widely available JavaScript JSON serialization libraries, I didn't have this luxury in IronRuby. Instead, I used the built-in Silverlight JSON serializer. Unfortunately, this API is designed to be used from statically typed languages. Once we finish implementing the Ruby language, we'll be able to use an off-the-shelf Ruby JSON serialization library. For the time being, however, let me describe the hack that lets you use the Silverlight JSON serializer from a dynamic language.

The inject_photo_list method creates an instance of the JSON serializer, and passes the QueryResults CLR type to its constructor. It then dots into QueryResults to retrieve the properties that we need to retrieve images from flickr.

image

But where did QueryResults come from? At the top of the file, you'll see this call:

image

Recall that we had a reference to contract.dll in AppManifest.xaml. This assembly contains the static definition of the JSON result set from flickr. The source for contract.cs can be found in lib\contract.cs. You'll also find a build script that shows how to compile an assembly for Silverlight, assuming that the paths to the Silverlight SDK line up.

image

The get_photo_url method generates the url that we'll use to get each photo, and you can see how easily we can consume the C# type definitions from Managed JScript:

image

Finally, we generate the XAML for the photo in the BouncePhoto function:

image

Can anyone spot the grotesque hack in this example? This hack will be fixed in the next part of the tutorial. For the time being, however, it works :)

Mixing in a little Norvig

If you look carefully at the screenshot of the completed app, you'll notice that the app suggested another spelling for 'howse'. That suggestion was courtesy of Peter Norvig's awesome naive spell checker. Here it is in its entirety (just 21 lines of Python 2.5 code):

image Wouldn't it be awesome if we could just use this code from our Managed JScript application? Let's take a look at what we need to do to make it happen.

First, we must add a reference to the IronPython assemblies to our AppManifest:

image

Next, we'll need to download Peter's code, as well as big.txt, which is a 6MB 'training file' containing about a million words that is used to train the spelling corrector. Both of these files will be added to our app directory, which means that they will be downloaded within the XAP file:

image

You might be wondering why we didn't just download big.txt from the web. I chose not to because I didn't want to modify Peter's code at all. Files that are downloaded as part of the XAP can be read using the standard IronPython file I/O libraries.

Next, let's look at what we need to do to access IronPython code from Managed JScript:

image

This code loads the managed spell.py module and stores a reference to the correct method. That method is invoked in the spell_check method, which also generates the UI for the suggestion:

image

Managed JScript has very nice cross-language integration, which only requires loading the module and invoking it.

Summary

We took a look at Managed JScript as a language that you can use to write Silverlight apps in the browser. You can access the Silverlight libraries, as well as a custom C# assembly that contained the types we used in the Silverlight JSON serializer. Finally, we saw a nice example of integrating a piece of code directly off the Internet, written in a different language (Python) into your Dynamic Silverlight app.

In the next part of this series, we'll take a look at integrating our application with ASP.NET MVC, and switching the language back to IronRuby on the client.

March 05, 2008

Dynamic Silverlight Part 1: Hello, World!

Our team is happy to announce Dynamic Silverlight (DSL), which integrates our DLR dynamic languages with Silverlight. It requires Silverlight 2, which includes the cross-platform CLR and a set of libraries for rich graphics, media and web programming. It is packaged as a Silverlight extension, which means that it is downloaded in addition to Silverlight on an as-needed basis.

DSL has a runtime and an SDK component. The runtime consists of two assemblies: Microsoft.Scripting.dll, and Microsoft.Scripting.Silverlight.dll. You'll also need the language assemblies, which are IronRuby.dll and IronRuby.Libraries.dll for Ruby and IronPython.dll and IronPython.Modules.dll for Python. The runtime component is a small additional download. Today, the IronRuby Silverlight runtime is just a 712KB download, which takes less than 5 seconds to download over modern broadband.

There is also an SDK component to DSL. The piece of software that you'll interact with the most is our local web server called Chiron. Created by John Messerly and Dmitry Robsman, it gives you a very nice interactive development experience using nothing more than your local file system. Let's take a look at Chiron.[1]

Update: Here's a link to the download of the Dynamic Silverlight SDK. The dsl.bat file can be found in the \bin directory of the SDK.

Open up a command prompt and ensure that Chiron is on your path:

Chiron

Next, use our template generator to create a starter IronRuby Dynamic Silverlight project:

DSL

You'll see that we've generated a set of starter files for you. To run this app, type chiron /b on your command prompt:

StartChiron

This should bring up a browser window with the current directory's contents displayed:

Directory

If you click on the index.html file, you'll see that the browser fetches a number of files from the server, and displays our Hello, World message:

Hello IronRuby

Xap Appears

Chiron prints a list of files that the browser requested. The interesting file is app.xap. This is the way we package Silverlight components for distribution. It's just a ZIP file with a different name. To look at its contents, just point your browser at http://localhost:2060/app.xap, and you'll see that it contains:

app.xap

This illustrates what Chiron does: it dynamically packages everything that you need to run your DSL application into the XAP and serves it up to your browser. The core DSL runtime pieces and the IronRuby assemblies are in the file, along with all of the other files that we generated in our starter application.

Binaries are listed in the AppManifest.xaml file that Chiron generated for you. You can see how Silverlight 2 boots DSL when you open the file:

AppManifest

The EntryPointAssembly is the DSL 'shim' that connects the DLR to Silverlight. The EntryPointType is the name of the type that Silverlight will run when it starts up. DynamicApplication derives from the Silverlight System.Windows.Application type, which defines the Startup event which is used to bootstrap the DLR.

Next, let's look at index.html. The <object> tag is all that is needed to startup Silverlight. No more external JS files for folks who are familiar with the older Silverlight 1.1 Alpha. The source attribute points to app.xap, and initParams are used to pass initialization data to your program.

ObjectTag

Notice the reportErrors = errorLocation parameter. This points to a <div> element that we generated for you. We use this <div> to report runtime errors and their stack traces to you.

errorLocation

This element also has a dependency on error.css to define the formatting for the error messages. I think it's pretty cool that we were able to use the extensibility mechanisms of Silverlight to inject custom DLR error message formatting into Silverlight.

Next, lets look at app.rb:

App.rb

You'll notice that we just run this script and inject our hello world message into the element tree defined by the XAML:

App.Xaml

There's a little bit of magic in layout_root.message.text. The message XAML element is a child of the layout_root element. How does Ruby resolve these references? The answer is found in the required file, Silverlight.rb:

Silverlight.rb

We're adding a method_missing method to the FrameworkElement class and the SilverlightApplication class. So when we try to retrieve layout_root, it delegates to the SilverlightApplication's implementation of method_missing. It dynamically invokes the target passed in m, which invokes the generic method_missing method in FrameworkElement. This gives a very natural feel for 'dotting through' a set of contained XAML elements, which is largely made possible by the Ruby programming language.

I hope this post gives you a feel for what Silverlight programming from IronRuby looks like. In the next part of this series, we'll look at how we can build a more sophisticated application that uses network stack, JSON, flickr, and some funky animation as well.

[1] The fine print:

There's still some work that we have left to do before we can push the sources and bits out. The code is baked, but packaging this stuff still takes some time. Check back here on Friday, the day of my talk at MIX (you are going, right?), and you'll have some bits that you can use to follow along with this tutorial.

Update: Here's a link to the download of the Dynamic Silverlight SDK.

You'll also need to have a working install of CRuby to run some of our utilities. I recommend the Ruby one-click installer for Windows. This will be fixed in the next release of IronRuby.

March 04, 2008

IronRuby @ MIX 08

Debugging IronRuby in Visual Studio

We announced IronRuby almost one year ago at MIX. We've come a long way since then, and we're going back to MIX to talk about where we are, where we're going and how you can help.

We've had a lot of fantastic help from our community to get us to where we are today. Our early contributors, Curt Hagenlocher and Peter Bacon Darwin helped us kick start the Open Source phase of IronRuby. Our most recent contributor, Wayne Kelly, is helping us drive our libraries effort while the team was busy getting ready for MIX. And to cap things off, Huw and Dermot over at Sapphire on Steel have recently released their free Personal Edition of Ruby in Steel for IronRuby.

The team spent the past month working on Silverlight integration. Yes, this means that you will be able to run Ruby in your browser in a safe security context. As of today, that means that you can run Ruby in your browser with just a 730K download (over and above Silverlight 2 which weighs in at around 4MB). Our Silverlight integration bits (and sources)will be available @ MIX once John Messerly works his magic.

I'll be @ MIX all week and would love to talk to folks who are interested in our work. I'm using MIX to try out my new Twitter account (john_lam); you can sign up and 'follow me' on Twitter.

Photos

  • www.flickr.com
    This is a Flickr badge showing public photos from John Lam. Make your own badge here.

Recent Comments

Recent Posts

May 2008

Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Blog powered by TypePad