Archive for the 'silverlight' Category

02JulA rant on a talk falling to pieces

Earlier this week I had the pleasure of doing a talk for the Belgian .NET user group.  During this talk I ran in to all kinds of problems. I’ve done presentations where I was royally underprepared and to avoid that this time I actually started prepping for this talk on time. I was done on time, was prepared had 5 backups of my presentation and samples. What did I learn from this, if you’re prepared other things will go wrong.
I’ll share the story of stuff that can go wrong.

Before starting the rant I have some links to share.

I have a device that I call internet on a stick, which is a vodafone usb 3G modem that I plug in to my system and it gets me on the internet (mistake 1). Since I assumed that that thing would continue to work I made most of my demos internet enabled (mistake 2). For example I have a demo where I go download pics from flickr and then show them with some animations with silverlight.
Before my presentation I changed the fonts, opened all the files I was going to talk about ran all the demos again to make sure they would work and everything went fine.
I unplug the USB device and go into the room to hook up the projector etc. The presentation starts and for the first hour everything went really well (from my perspective at least don’t know about the people attending).
We have a break and I plug the USB device in, at this point the vodafone program hangs (first time ever I swear). What’s more I can’t make it go away at all so I reboot my pc (this is still during the break).

Now I’m getting a little desperate because it still doesn’t work. With rebooting I also lost all my carefully opened files earlier (I’m showing code in about 3 different environments and 2 different OS’es).
So during the presentation I apologise and try to reboot once more while taking questions from the audience and hoping somebody will try to start a discussion with me. After rebooting I got a message saying my date was set to 2001 which I thought was peculiar but clicked it away.  I boot vmware fusion with windows 7 (this took fairly  long and is a little bit funky as the screen resolution changes a lot during this process).
Ok so far so good, by now I’ve already skipped the silverlight demo promising that it will be available as a download on my blog and will be moving on to the ironrubymvc sample. To prove I do actually use visual studio at times I wanted to open my demo project in visual studio. I open visual studio only for it to tell me that my trial has expired and I can either upgrade or close the application. Oooooookay this is completely weird because i get my software through my msdn subscription and I had been using it earlier that day.

Moral of the story: Either go vastly underprepared and wing it. Or don’t rely on the internet and always take at least 2 laptops that have identical configurations but I’m pretty sure those would or explode in my face or something will fall from the ceiling, building collapses or other mishaps.

Instead of having one demo go bad on me now I’m probably facing a reinstall of my mac because it lost a bunch of settings, for which I’m holding the vodafone responsible. At this moment I’m fairly certain that I should go less prepared and just wing it just out of fear for bigger disasters, people may die.

19AugIronNails: Some progress

I thought it might be a good idea to update you guys on how IronNails is progressing.  I think I’ve got it so that you aren’t exposed to writing many of the boring boilerplate code that comes with taking this approach (M – V – VM- C). Also to execute an action on a controller asynchronously you can by just adding :mode => :asynchronous to your view_action declaration.

A lot is still left to do but this proves that it is possible to use IronRuby today to do some pretty cool stuff. From the top of my head here are some things that still need to be done:

  • The ability to load xaml from an assembly like the one that is generated when you use Blend for your design.
  • More predefined behaviors
  • Templated generators
  • Silverlight support

But the core of the framework is working. Now it’s a matter of extending the functionality. Some of the features the framework does support

  • Binding to controller actions through commands
  • Binding to controller actions through event handlers on the view proxy
  • Asynchronous execution of actions
  • Timed execution of actions
  • Binding to models

I will be developing my sample for my chapter against this framework and will add the pieces I’m missing as I get on.

Some of the things I foresee that might need to be added are:

  • support for controlling the application from an IronRuby console so that you can interact with the interface as it is running.
  • support for a console to interact with the code of the application.
  • support for plugins

So after all these lists how would an application look like when you are developing it?

The controller:

# file name: demo_controller.rb
class DemoController < IronNails::Controller::Base
  view_object :status_bar_message, "The status bar message"

  view_action :change_message

  def change_message
    @status_bar_message = "#@status_bar_message appended"
  end
end

The ViewModel:

# file name: DemoViewModel.cs
public class DemoViewModel : IronNails.View.ViewModel { }

The View:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:behaviors="clr-namespace:IronNails.Library.Behaviors;assembly=IronNails.Library"
    Title="Window1" Height="300" Width="300">
    <StackPanel>
        <TextBlock Text="{Binding Objects[StatusBarMessage].Value}" ></TextBlock>
        <Button Content="Click me" behaviors:ClickBehavior.LeftClick="{Binding Commands[ChangeMessage]}" />
    </StackPanel>
</Window>

There are currently 2 dictionaries available to the view. One that contains the models (Objects) and one that contains the commands (Commands).  The value of an entry in the Objects needs to be observable by implementing INotifyPropertyChanged and that is what’s responsible for the binding syntax Objects[ModelName].Value

At this moment there are only a couple of behaviors implemented: LeftClick, RightClick, DoubleClick and Hover.

The framework expects that you follow the basic naming conventions of the technology you’re programming in. So in ruby you underscore names but in C# and xaml you camelcase them.

By defining an object with view_object :o bject_name, default value you define it with a default value that you can change afterwards in the controller actions.  By defining an action with view_action :action_name, :mode => :asynchronous you tell that framework that you want to link a method or a block as a controller action and execute it asynchronously.

07AugIronNails : Rails like development for IronRuby with WPF/Silverlight

For my book IronRuby I’m working on chapter 4. That chapter is about doing WPF development with IronRuby. I started out with a straight port of Witty to IronRuby. As I was doing that the cogs started turning and I came up with a way to bring the rails style of development to WPF.   I decided to investigate that route a little bit further and now I have a small framework that enables you to write WPF applications with the MVC paradigm. I decided to open that code up as open source and host it on github. 

At first I used the name Sails for my framework but it turns out there is java clone of rails that is called opensails. So to avoid confusion David M. Peterson proposed the name IronNails.

On Sat, 02 Aug 2008 08:00:44 -0600, Charles Oliver Nutter wrote:

    FYI, there’s already a framework named "Sails" for Java:
http://www.opensails.org/

For the sake of sticking to the "Iron" theme, why not replace the ‘S’ with an ‘N’ and go with IronNails. ;-)   Maybed it’s just me, but if given the choice, I’d much rather nail it than sail it any day of the week. :D


/M:D

M. David Peterson

You can find the project here: http://github.com/casualjim/ironnails

At this moment it’s definitely not finished at all, but it does work. The remainder of the week I’ll move my previous demo code onto this framework, update the code samples in my chapter and finish the content. I hope I will have all of this done by the end of next week.

Back to the IronNails project:

Because DLR objects cannot be used to bind to in WPF you have to define a skeleton of the ViewModel in C#, but this will change in the future. When that changes I’ll look at extending the framework to make use of some other WPF patterns like defining a DependencyObject and Behaviors. Once those are defined you get a very clean separation between design and behavior.

This is abstracted away from you but in the background the framework works with the View – ViewModel – Model – Controller pattern although I’ve tried to keep your exposure to the view model to a minimum. The framework follows naming conventions per language. So in C# and XAML you camel case stuff and in IronRuby you underscore stuff.

The very core of the framework is defined in C# but most of the code is IronRuby, depending on how hard it will be after the DLR RTM’s I may look at adding support for all the DLR languages.

IronNails
=========

IronNails is a framework inspired by the Rails and rucola frameworks. It offers a rails-like way of developing
applications with IronRuby and Windows Presentation Foundation (WPF).
This framework uses the pattern Model – ViewModel – View – Controller (M-VM-V-C). It should be able to run on both WPF
and Silverlight.
The idea is that the views can be created using a design tool like Blend for example and just save that xaml as is. The
designer should not need to use anything else than drag and drop to create a GUI design. The behaviors are then added to
the view by using predefined behaviors in the framework or by defining your own behavior.
The framework then generates a proxy for the view which will be used to transparently wire up the commands in the
behaviors to controller actions.

You are now able to write the following code for a controller:

class MyController < IronNails::Controller::Base

  view_action :show_message, :triggers => :my_button do
    MessageBox.show "This is the great message from a block"
  end

  view_action :change_color, :triggers => { :element => :my_text_block, :event => :mouse_enter }
  view_action :reset_color, :triggers => { :element => :my_text_block, :event => :mouse_leave } do |view|
    view.my_text_block.foreground = :black.to_brush
  end

  view_object :people, Person.find_all

  def change_color(view)
    view.my_text_block.foreground = :red.to_brush
  end

end

At this moment the project has 0 unit tests, it has below minimal documentation and it still needs a work like defining the behaviors. I have to move on with my book but intend to continue developing this framework after my book is finished and IronRuby RTM’s.  There are some more workarounds in the project that will all disappear as IronRuby progresses.

kick it on DotNetKicks.com

12JunDynamic Script Control

Both Silverlight and WPF use XAML markup to describe their user interface.  As I’m currently writing my chapter on WPF for my book IronRuby In Action and I want to use some xaml that has been generated before for a different project but with an IronRuby class to load the xaml I’m in trouble. This is because you can declare assembly references in the xml namespace declarations so you can use the types in that assembly from xaml. 

The DLR based languages don’t compile into static assemblies and this means that you can’t use those xml namespace definitons to reference your assemblies.  I wrote a fairly trivial control that acts like a hook for DLR based controls in the XAML tree.

You can check it out at codeplex.
http://codeplex.com/dynamicscriptcontrol

The idea behind this control is that you can "hook" your DLR based control into the visual tree by setting some properties.  You can set properties on the DLR based control by setting the Attributes property on the DynamicScriptControl

Let’s look at a quick example:

1. The ruby file defining a custom TextBox. But you can do whatever  you want in that ruby file of course.

dynamic_script_control_rubyscript

All this textbox does is preset it’s text property to "I’m prefilled"

2. The xaml for the window

dynamic_script_control_window_xaml 

You first declare a namespace for the assembly that has the DynamicScriptControl. Next I have a StackPanel that contains 2 DynamicScriptControls. The first just contains the 2 mandatory properties. We need to know which class you want to instantiate in the file you provide by setting the ScriptFile property. This script file property is a path to your ruby file in my case prefilled_text_box.rb.
The second DynamicScriptControl is one where I want to initialize the control with my own text property. To declare those properties you have to add them to the Attributes collection of the DynamicScriptControl. At this moment it’s not smart enough to know which datatype you give it so you can specify a format string which was necessary in this case because text is a string.

3. The result

dynamic_script_control_window

Michael Foord the author of IronPython In Action will provide the python integration in this control.

There was a release of the Dynamic Silverlight SDK earlier this week which contained the necessary source code files to compile a common DLR for both IronRuby and IronPython.  That is what makes it possible to support multiple scripting languages from the start. 

I’ve hosted the source code on google and you can find that at:

http://code.google.com/p/dynamic-script-control

15AprMinimal IronRuby/silverlight examples online

I just posted the first post in my series on getting started with Silverlight and IronRuby on the rubydoes.net website

You can read more about it here: http://rubydoes.net/2008/04/14/silverlight-minimal-examples/


Recent Flickrs

    Blogroll

    Recent Listening

    Scrobbler