Update: Exciting times! Lots of things have changed in the fortnight since I wrote this post, and I’m no longer going to work at InfoMentor. Instead I’m proud to say I’ve founded a new software house down here in Devon, 36degrees, alongside my former employers at Tech 13. Really excited, it’s a great opportunity and I really hope I can make a good go of it! :)


I recently moved from Birmingham down to Devon, and began working from home. Unfortunately, (at this point in my life at least) the isolation and lack of social interaction that comes from working from home was not for me, and so it is with a very heavy heart than I am leaving my current job at Tech13 to work for InfoMentor developing collaborative online learning tools. Don’t get me wrong, I’m very excited for the new experience at a new company, but it’s always difficult to leave, especially a job that I enjoyed so much.

I’ve been with Tech13 for a little over a year, and am incredibly grateful for the opportunities and experiences I have had whilst working there. It’s a great team, and I’m particularly thankful to have been mentored by Paul Cox, an incredibly talented developer whose passion for learning has been hugely infectious and has fundamentally shaped the way I approach the betterment of my craft. Through Paul I learnt the joy of immersing myself into a community that I really had a limited knowledge of beforehand. I feel shocked now when I meet a developer that doesn’t read blogs or listen to podcasts, and who is unfamiliar with the great technologies and open-source projects that exist outside of his/her own little bubble; but that was once me. It was Paul who reccommended I start this blog, Paul who advised me to really dig deep into the systems that I’m using, and Paul who showed me that in order to really succeed you could not be afraid to take a few chances.

I wrote a blog post at the start of the year on my experiences so far in the real world of software development, and on the decision to pursue experience over further education. I’m only a little further on now, so I’m probably still not qualified to answer my own question: “Did I make the right decision to work rather than to continue down the educational track?” That said, I stand by it being one of the best decisions that I ever made.

Obviously it’s tough to be moving on, but I’m very excited for the next chapter of my career to begin and for the new experiences and opportunities that working for InfoMentor will bring.

Oh yeah, and Paul, in case you happen to be reading this: for god’s sake, start your bloody blog! I’m going to miss hearing the things you have to talk about, so please write them down so I can still get my fix!

I’m currently working on implementing an issue tracker within a customer’s web portal so that their users can more easily log system issues with us and be updated on their progress, without the need for additional phone calls and emails, and it’s been decided that a convenient feature would be for it to integrate closely with our own issue tracking (which is hosted on BitBucket).

After a quick google I stumbled across a nice, albeit fairly young, API wrapper that uses RestSharp – conveniently named BitBucketSharp. It was started just a couple of months ago by Dillon Buchanan, and has made it really easy to start use the BitBucket API from within a web application.

There is another similar project, CSharp.Bitbucket, which is built upon the Spring.NET Social framework; but a quick look at the download counts on NuGet shows developers clearly favour RestSharp, with 28,230 downloads, rather than Spring.NET Social’s 529. CSharp.Bitbucket does, however, have the advantage of being hosted on NuGet, so makes it really easy to pull down and have a play with.

Since BitBucketSharp is fairly new, it currently only really has support for GET requests, so I’ve forked it and am in the process of adding support for creating/updating resources, and I’d also like to get a NuGet package up when I get the opportunity.

Check it out at bitbucket.org/j_wallwork/bitbucketsharp

<div class='box'>
    <h2 style='-webkit-user-select: none;'>Title</h2>
    <div class='boxSlide'>
        <div class='boxBg'>
            <div class='boxContent'>
                content...
            </div>
        </div>
        <div class='boxFooter'><img src='img/ws_box_footer.png'></div>
    </div>
</div>

Apologies for the above code. I realise it’s not very pleasant to look at, but unfortunately I was working on a website not too long ago which was based off of an online template, and this was the structure I’d been asked to use to add some fancy, styled boxes to a whole bunch of pages so as not to break the existing site’s css.

Now that’s quite a lot of markup for a simple section – please understand I’d be far happier using cleaner and more semantic markup, such as section, article, or even a single div if needsbe – but unfortunately that wasn’t an option. However, even if that was the code that I had to use, it sure as hell wasn’t the code I was going to write. Not over and over and over…

I first wrote a HtmlHelper extension method which would allow me to use the syntax @Html.Section(“header”, “content…”), which was definitely a marked improvement on all that code, and lead to much more readable source.

public static MvcHtmlString Section(this HtmlHelper html, string header, string content) {
   return MvcHtmlString.Create(
              "<div class='box'>" +
                  "<h2 style='-webkit-user-select: none;'>" + title + "</h2>" +
                  "<div class='boxSlide'>" +
                      "<div class='boxBg'>" +
                          "<div class='boxContent'>" +
                              content +
                          "</div>" +
                      "</div>" +
                      "<div class='boxFooter'><img src='img/ws_box_footer.png'></div>" +
                  "</div>" +
              "</div>";
}

Job done. Well, kind of. This worked well for just text-only sections. A section containing multiple paragraphs, images, or other html elements was possible, but looked a mess and was harder to read that the original syntax! It completely ruled out the option of using more complicated contents in a section – ie. if I wanted a section to contain a form. Furthermore, these boxes were nestable – so one box could potentially contain multiple. Since they took an string as content and returned an MvcHtmlString, then in addition to these problems I would have had to keep adding .ToString() to the end of each nested Html.Section().

@using (Html.BeginForm()) { ... }

How many times have we all used the above code? And what does it do? Well that’s easy, it’s an HtmlHelper for creating forms. The interesting thing with BeginForm, however, is that unlike most other HtmlHelpers, this allows for start and end tags, but with any other content nested within the curly braces (or if you prefer, open/close mustaches).

Oh what a coincidence, that sounds almost exactly like what I need to do!

So how does it work? Well fortunately, the solution is brilliantly easy. When you call BeginForm, it first outputs the opening

tag, not by returning an MvcHtmlString, but by writing directly to the view context using HtmlHelper’s htmlHelper.ViewContext.Writer.Write(string). It then returns a class implementing IDisposable (in this instance, an MvcForm), which is passed the view context when instantiated. All this class does is to write out to the view context when it is being disposed of – which as we all know is at the close of the braces.

Therefore, the code needed to allow me the freedom to write my sections as

@using (Html.Section("title here")) {
    ... any content I want! ...
}

is as follows:

public static HtmlSection Section(this HtmlHelper html, string title)
{
    html.ViewContext.Writer.Write(
              "<div class='box'>" +
                  "<h2 style='-webkit-user-select: none;'>" + title + "</h2>" +
                  "<div class='boxSlide'>" +
                      "<div class='boxBg'>" +
                          "<div class='boxContent'>"
        );
    return new HtmlSection(html.ViewContext);
}


public class HtmlSection : IDisposable
{
    private readonly ViewContext _viewContext;

    public HtmlSection(ViewContext viewContext)
    {
        _viewContext = viewContext;
    }

    public void Dispose()
    {
        _viewContext.Writer.Write(
                          "</div>" +
                      "</div>" +
                      "<div class='boxFooter'><img src='img/ws_box_footer.png'></div>" +
                  "</div>" +
              "</div>"
        );
    }
}

Not long ago I blogged about auditing with NHibernate.Envers. I’m using it again in another project but I don’t want to audit all the fields on the entity; furthermore, Envers automatically tries to audit referenced tables, so tables that are not configured to be audited cause an error message: An audited relation from SomeAuditedEntity to a not audited entity NonAuditedEntity! Such mapping is possible, but has to be explicitly defined using [Audited(TargetAuditMode = RelationTargetAuditMode.NotAudited)]. Understandably I expected that adding this attribute to the properties that I didn’t want auditing would prevent this behaviour, but it didn’t. I then added it to the class that I didn’t want auditing, but the message still didn’t go away. A quick google revealed another similar attribute, NotAudited, but this didn’t work either.

Finally after hacking around with my code I stumbled across the solution; the properties to be excluded must be defined in the Envers configuration. Although I think I’d prefer to annotate the fields in the entity class itself, this is the solution that worked for me:

var enversConf = new NHibernate.Envers.Configuration.Fluent.FluentConfiguration();
enversConf.SetRevisionEntity<REVINFO>(e => e.Id, e => e.RevisionDate, new AuditUsernameRevInfoListener());
enversConf.Audit<SomeAuditedEntity>()
          .Exclude(x => x.NonAuditedProperty1)
          .Exclude(x => x.NonAuditedProperty2)
          .ExcludeRelationData(x => x.NonAuditedCollection;
configuration.IntegrateWithEnvers(enversConf);