Saturday, June 13, 2009

A Good Mix 11: A Rules Engine, Embedding, SharePoint and NWSGI

Another selection of blog entries and articles relating to IronPython from the last few weeks.
A blog entry from Dave Fugate (IronPython testing and infrastructure guy) on an exception message that shouldn't be visible. Looks like it is actually a bug in Vista, but as it was triggered by IronPython it gets a mention here:
IronPython most definitely should not be able to spawn an error message box that's visible when Vista is locked at the username/password screen. Quite annoying yet very interesting at the same time...
Another blog entry from Mark Bloodworth (a Microsoft Architect evangelist) on using IronPython. It demonstrates writing classes in C# and using them from IronPython. The entry is short because this is something that IronPython makes trivially easy:
It’s really simple to use a .NET class in IronPython. The first thing to remember is that you’ll need to add a reference (just like you would in .NET). To do that you use the AddReference method of the clr module. In the case of an assembly you’ve written, IronPython needs to be able to find it, which means it needs to be in sys.path. It turns out that you can add the path to your assembly by using the append method of sys.path.
This project is actually not new at all, I just hadn't heard of it. It's nice to discover people using IronPython in ways I wasn't aware of. This project is by Glen Cooper and he describes it here:
This library provides the ability to automate various
SharePoint activities through easy to read and modify Python

The core library is located in the sp module. The scripts
module contains a number of scripts for performing specific
activities such as backing up sites.
A good use case for embedding IronPython in a .NET application is to use it as a rules engine for evaluating rules stored as text which can be modified or added to without requiring recompilation of the application. This is exactly what Nathan of the Crippeoblade blog has been up to:
In my last post I talked about creating a rules engine to generate a scouts evaluation of a player. Having played with IronPython for a few hours this evening I’ve managed to introduce a dynamic script to represent the rule engine. This means I can replace the rules engine or for that matter any one else can without having to re-compile the code. It’s suddenly dawned on me how this exciting technology can make a game extensible. With .NET 4 introducing the dynamic keyword plus other functionality for dynamic languages it’s going to make it even easier.

Performance wise it actually seemed pretty fast. This was one concern I had because of the greater work at runtime required. Objects aren’t statically typed so the runtime engine has to do the typing at runtime. Just starting to learn python and I must say I’m loving it so far. I’ve done nothing complex just followed a few tutorials and coded up a small script to test out ironpython running within c#. So how did I manage that.
It seems like only a few days since the release of NWSGI 1.1 Preview 2 was announced, but it seems there was a problem with configuration on 32bit machines: "NWSGI 1.1 Preview 3 is a refresh of Preview 2 that fixes issues with configuration on 32-bit platforms. The release can only be used for xcopy deployments."

NWSGI is an implementation of the WSGI specification (Web Server Gateway Interface) for IronPython. It is implemented as an ASP.NET HttpHandler and is supported on the IIS 6 / 7 webservers (or any ASP.NET capable server). NWSGI allows the integration of Python applications like Trac and Django with existing ASP.NET facilities such as caching, sessions, and user management.
Embedding IronPython in C# is so easy everyone is at it. Here is another example; including executing code and fetching the result and populating a DataTable and manipulating it from IronPython.

No comments:

Post a comment

Note: only a member of this blog may post a comment.