My First Extension Method

This evening I wrote my first VB.Net extension method while working on my S#arp Architecture based project. I added another overload of the TextBox method (which is itself an extension method, I believe). I wanted to be able to specify the size of the text box. One of the existing TextBox methods has the following signature:

HtmlHelper.TextBox(name As String, value As Object, htmlAttributes As IDictionary(Of String, Object))

I wanted to be able to specify a text box size without having to declare a new IDictionary every time. So I wrote the following extension method:

<Extension()> _
Public Function(html As HtmlHelper, name As String, value As Object, size As Integer)
    Dim attributes as IDictionary(Of String, Object) = New Dictionary(Of String, Object)

    attributes.Add("size", size)

    Return html.TextBox(name, value, attributes)
End Function

Neat stuff.

Now I just have to figure out how to create an extension method that will allow me to pass a lambda expression to RedirectToAction().

The Inner Workings of *.vbproj Files: <ProjectTypeGuids>

During the conversion of the S#arp Architecture template project from C# to VB.Net I inadvertently broke (at least) one thing: the ability to add ASP.Net MVC items directly to the SharpArch.Web project directly from the “Add New Items…” dialog. This led to my first question asked on StackOverflow.com (which I ended up answering myself, 38 minutes later).

Turns out Visual Studio project files can have an element called <ProjectTypeGuids> which contains one or more guids identifying what type of project the file describes. ASP.Net MVC projects have a particular guid specified: {603c0e0b-db56-11dc-be95-000d561079b0}.

So I added this guid to both my SharpArch.Web project file and my SharpArch.Controllers project file, and now I can add new MVC template items directly from the “Add New Item…” dialog. Cool!

S#arp Architecture

I’ve been poking around in the latest release of the S#arp Architecture over the last couple days. I like what I see.

Pronounced “Sharp Architecture,” this is a solid architectural foundation for rapidly building maintainable web applications leveraging the ASP.NET MVC framework with NHibernate.

This evening I took about an hour and converted the basic starter solution template from C# to VB.Net. Why? Well, for the following reasons:

  1. While I can work with C# well enough, I’m much more familiar with VB.Net, which I am required to use at my 9 to 5 job. I tend to stick with VB.Net even for my personal projects for simplicity. Anything I learn on my own I can easily apply at work.
  2. It gave me an opportunity to confirm that I understand (at least at a high level) what the S#arp Architecture is doing.

The conversion was straight forward. Pretty well every line of C# had a corresponding line in VB.Net. The only thing I had to add was an Imports tag in the markup of the Site.Master page in order to get the ActionLink and Image extension methods to resolve. I had already tried adding an imports to the code-behind with no luck. Not sure why that was necessary, but it worked.

The architecture is pretty neat. Here’s a few things I’ve noted already:

  • The Models, Views and Controllers (I.e. the M, V and C in MVC) are each in their own projects.
  • The Repository/IRepository pattern is used, with the Interfaces defined in the same project as the Models, and the Repository implementation(s) in a separate project.
  • Includes support for NUnit, Castle Windsor, (Fluent) NHibernate, and Rhino Mocks
  • The ASP.Net MVC routes are defined in the Controllers project, not in the Global.asax of the Web/Views project. Excellent separation of concerns!

I’m going to go ahead and trying putting together an actual application based on S#arp Architecture.

Secunia Personal Software Inspector

I been using Secunia Personal Software Inspector (PSI) on my primary PC at home for about 3 or 4 weeks now and today I finally got my Secunia System Score to 100%.

Secunia PSI is an application that scans your PC for installed programs and compares them against Secunia’s list of applications with known security vulnerabilities. It’s free for home users. When it’s not scanning it sits quietly in your system tray watching for changes in programs (added or removed).

It helped me realize that even though I was updating some software regularly, the updates would often leave the old, vulnerable version installed (I’m looking at you Java). Here’s what the overview screen looks like on my PC right now:

image

Working from Home

In case you weren’t aware, we are on day 8 of a transit strike here in Ottawa. I don’t drive (at all) so I normally rely heavily on the bus system here (which, in my mind, is top notch, when it’s running). Fortunately the nature of my work (and my manager) has allowed me to work from home on most of the strike days so far.

I was a little worried about working from home. I wasn’t sure how productive I’d be. But as it turns out, I am more productive at home than I am in the office. Here is a quick pro and con list of my experience working from home so far:

Pros:

  • I control the work environment (temperature, lighting, etc.)
  • Quiet! I am all by myself all day (heaven for an introvert like me)
  • More screen real-estate. At the office I have dual 17″ monitors (both @ 1280×1024). At home I am using a laptop (@ 1600×1050), plus the laptop is hooked into my 2nd monitor via the KVM (@ 1280×1024) PLUS I have my 24″ monitor (@ 1920×1200) connected to my home PC, which I can use for web browsing, media, etc). That’s over 5 million pixels in all!
  • Quiet! I can get focused and stay focused (again, for an introvert, getting focused, or getting back into focus, can be difficult)
  • Lunch and snacks are closer, and cheaper.
  • I have full access to the office network (via VPN) and my office PC’s hard drive.
  • Better chair than the one in my office.
  • I can play my music as loud as I want!

Cons (both relatively easy to resolve):

  • The laptop only has 1 GB of RAM!
  • I haven’t been able to get the laptop to share my mouse and keyboard (the mouse works, but it’s laggy. No wonder though: USB Mouse -> USB to PS/2 adapter -> KVM -> KVM Cable -> PS/2 to USB adapter -> laptop). Update: Resolved via laptop docking station borrowed from the office.

Here’s my home office setup:

IMG_2150 IMG_2151