Tuesday, 30 September 2008

A Ready-To-Hack Visual Studio 2008 Solution including NHibernate and Castle Active Record

metafinkI've been taking my first steps into the wonderful world of NHibernate and Castle ActiveRecord, and to make things easier, I've put together a Visual Studio 2008 solution that should build NHibernate, Castle Core, Castle Windsor, Castle Microkernel and Castle ActiveRecord from source, just by firing it up in VS2008 and hitting Ctrl-Shift-B, so you can load it, build it, run it, and start hacking around and getting your hands dirty.

I didn't actually create any  of this - NHibernate is from www.nhibernate.org, Castle is from www.castleproject.org. Thing is, these projects are all interdependent to some extent, the official binaries aren't always up-to-date or in sync with each other, and building them from source means setting up nant, working through various machine-specific configuration glitches... so hopefully this will save you a bit of head-scratching. I've just done an svn trunk checkout from the various projects over the last few days, built each project using nant as per the included instructions, then extracted the Visual Studio projects for the actual runtime libraries (so I've left out unit tests, etc.) and combined it into a single solution, along with a very rudimentary ActiveRecord model project, a simple console app showing how to get things up and running using app.config, and a SQL Express .mdf file containing some test data to make sure it's working.

This is undocumented and full of holes - but if, like me, you've decided it's time to learn this stuff and you just want a working build to play around with, it'll probably save you a couple of hours.

Oh, and it's called Metafink. No reason - things just need a name.

Download it from http://www.dylanbeattie.net/misc/metafink.zip

EDIT: Turns out this isn't quite complete - trying to build it on a machine that had never had any of this stuff on it before, and it appears that  log4net and a couple of other DLLs that are required by NHibernate are missing from the package. For the sake of completeness (and being able to step-debug through the whole stack), I'll try and incorporate these as projects rather than just linking to the binaries - should get this sorted out later today / tonight. Sorry!

Making Your SVN mod_dav_svn Repository Firefox-Friendly

There's a great add-on module for Subversion - mod_dav_svn, which I've blogged about before - that exposes the contents of your repository through a Web server interface. This is great for bringing up designs, ideas and HTML prototypes in meetings - we've got one of those interactive whiteboard things, and we've  saved lots of time, and probably a couple of acres of forest, by showing designs on the screen instead of printing handouts.

This doesn't quite work out-of-the-box, though. It'll sort-of work if you're using Internet Explorer to browse your WebDAV repository, but Firefox and Opera will probably display everything as plain text. Or gibberish. This is because Apache is sending a Content-Type header telling the browser that the content is text/plain, and Apache in turn is getting this information directly from Subversion. To get everything displaying properly, you'll need to make sure that every file in your repository has the proper MIME type associated with it in Subversion.

Using auto-props to set MIME types automatically when adding files to a repository

This bit depends on your client. Check out the official documentation on the auto-props feature; it's also worth knowing that you can open the svn configuration file in Notepad via the handy Edit button in the Tortoise settings dialog - right-click any folder window in Windows Explorer, hit TortoiseSVN -> Settings...

image 

To update files already in the repository

The auto-props feature is all very well, but if (as I did) you don't find out about it until you've already got a repository full of stuff, you have a second problem - how do you set the MIME-type properties on everything that's already in your repository?

This works on Windows, via the command shell, and needs the command-line version of svn installed - try the SlikSVN installer if you don't have svn already installed. Remember that although your repository is probably organised into projects, with their own trunks, tags and branches, it's still just a great big hierarchy of files and folders - if you do an svn checkout from svn://my.subversion.server/ without specifying /myproject/trunk, you will check out the HEAD version of your entire repository. (These techniques work just as well on individual trunks, branches and sub-folders, of course.)

First, check out the folder, branch or even the entire repository into a working folder - say c:\repository\.

Then run this:

C:\repository>for /r %1 in (*.gif) do svn propset svn:mime-type image/gif "%~f1"

for is the Windows shell command that basically says "repeat the following for every file matching this specification" - and we're saying for /r %1 in (*.gif), meaning "recursively find every file matching *.gif in or below the current folder, temporarily reference that file as %1, and run the following command" - where the command itself is svn propset svn:mime-type image/gif "%~f1"

Note that the %1 reference there is quoted, and we're using the ~f modifier to expand it to the full path - you may find

C:\repository>for /r %1 in (*.gif) do echo "%~f1"

enlightening if this doesn't make sense - remember, everything after the do is invoked for each matching file.

So, when for matches something.gif under myproject\trunk in your repository, it'll call svn.exe with the command line

svn propset mime-type image/gif "C:\repository\myproject\trunk\something.gif"

- which will set the MIME-type on something.gif to image/gif.

Repeat this incantation using the various file extensions and MIME types you need to configure, e.g.

C:\repository>for /r %1 in (*.jpg) do svn propset svn:mime-type image/jpeg "%~f1"
C:\repository>for /r %1 in (*.htm*) do svn propset svn:mime-type text/html "%~f1"

and once you're done, commit your changes back to the repository. You'll see a whole lot of SVN "Property changed" messages, and next time you browse your repository via mod_dav_svn, you should find things are working as expected.