A WPF - IronRuby Scripting Console User Control
One of the clear value added possibilities with IronRuby and IronPython (or any DLR language) has to offer is making applications scriptable. This opens the possibility for enabling scripting of your application, it’s types and potentially objects running in memory in your application at runtime. I recently went looking for an IronRuby console / shell window control written natively in WPF and turned up nothing. I did however come across some examples implemented for Windows Forms and the one that got my attention was Orion Edwards Embedded IronRuby Interactive Console.
Whilst Orion’s project provided the basis of what I was after, I was under no illusion that I would find exactly what I was after and would therefore have to build out the rest of the functionality I required.
The Basic Requirements List
- Reusable WPF User Control
- The Console should allow users to write script against in memory objects of the host application.
- Should persist (to a log) the state of variables in the IronRuby runtime scopes.
- Extensible Application Design and easily maintained and Testable.
So rather than re-invent the wheel I started out with Orion’s code and worked it into a WPF User Control that followed the MVP pattern. This version supports printing of all scope variable state to the console window, clearing of the console window text and all the out of the box access to the IronRuby runtime from the console itself. The IronRuby Console User control also allows the consumer application to pass through in memory variables from your managed CLR hosting application.
Finally I need to also make mention that some of the classes used to stream the STD/IO came directly from Ben Halls wonderful IronEditor. And before I forget, the code can found here on my blogs subversion repository.
3 Comments so far
Leave a reply









[...] my part so far I have delved into IronRuby and started to employ it for scripting my C# applications. Why did I choose IronRuby [...]
[...] I posted an IronRuby Console, purpose built as a WPF user control. The basic reasoning was to allow me drop in scripting into [...]
[...] What’s a little more interesting is using this pattern in interop scenarios when the templated class is defined in a statically typed language and the template method is supplied by a dynamic language created for the DLR. This can be demonstrated here with the given abstract class and by using my IronPython WPF interactive console control. [...]