Chris Carter's Web Log

Motivation

I've been wanting to use Castle Monorail for a real project, so last Friday I finally decided to rework my blog to use Monorail and start moving blog content away from Subtext.

Presenting the Content

I wanted to use Monorail but I didn't want to have to rewrite everything I was already getting from Subtext. The blog look and feel was what I really wanted Monorail to take over, so I started researching how the Subtext database schema worked. It's pretty simple, subtext_Content and subtext_Config are the two tables I'm concerned with for presenting the blog content. ActiveRecord is my choice for data access, and HyperActive did the trick in generating all of the ActiveRecord classes needed.

I chose Brailfor the view engine. It uses the Boo language which I'm starting to really like. One of the coolest features is that you can do something like this in the controller:

SubtextContent[] posts = 
  SubtextContent.SlicedFindAll(0, 10, 
    new Order[] { Order.Desc("Datesyndicated") }, 
    Expression.IsNotNull("Datesyndicated"));
PropertyBag.Add("posts", posts);

Then in the view you can do this:

for post in posts:
# do stuff here
end

I like how adding it to the property bag doesn't require explicit extraction from the property bag plus casting, you just start using the variable you added.

URL Rewriting

Subtext uses friendly urls through url rewriting. In order to use Monorail to handle the page requests, I needed to intercept the same style of urls. Luckily, Monorail comes ready to rewrite through routing. I figured it would be easy to grab the existing Subtext regular expressions for the urls and plug them into the Monorail configuration but that didn't work for me right away. Using Roy Osherove's Regulator to tweak the regex and got the routing to work like a champ.

Log4net Conflicts

I'm not sure which one of these is the imposter, but log4net version 1.2.10.0 in Subtext is different then log4net 1.2.10.0 in the Castle stuff I've pulled off of the build server. Not there's 24k difference in the size of the assemblies. Using the Subtext version of log4net broke the Castle stuff and vice versa. Here are the two assemblies:

log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=227c66cf5503649a //Subtext
log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821 //Castle

I ended up pulling down the last tag of Subtext 1.9.5, adding the log4net from Castle everywhere and recompiling. That did the trick, now they both play well together.

RSS - Let's Use Subtext...

The RSS for this site needed to remain the same for now, I didn't feel like rewriting that for now. This was not as easy as I was hoping. It required modifying Subtext code and recompiling and then making sure the right config settings were in place. The changes I made were to the BaseRssWriter class and the UrlBasedBlogInfoProvider class. I the BlogInfo result of the GetBlogInfo method in the UrlBasedBlogInfoProvider:

public virtual BlogInfo GetBlogInfo()
{
  BlogInfo info = new BlogInfo();
  info.Author = "Chris Carter";
  info.Email = "chris at panteravb dot com";
  info.Host = "panteravb.com";
  info.Title = "chris carter's web log";
  HttpContext.Current.Items[cacheKey] = info;
  return info;
}

And in the BaseRssWriter I changed the spot where it writes the description to this:

this.WriteElementString("description", GetBodyFromItem(item));

There was a lot of other code on the original line, something in there was throwing a null reference exception. I didn't feel like figuring out what the problem was so I just removed the offending code. I'm sure that'll bite me back at some point.

Now What

Currently, the state of my blog is that it's pretty much read only. No comments, actually no admin either aside from some pages I'm testing locally. Next will be trying to get the interaction a little more consistent and clean, I'm very much a noob to Monorail, so I'll need to dig deeper into the framework, but so far me likes.

 
Author: , 0000-00-00