Archive

Archive for February, 2009

Downloader for Resharper Nightly Builds

February 13th, 2009

If you use Resharper your probably a fan of getting the new features early with the Nightly builds. Now with 4.5 stable enough to develop with full time I thought I’d cut down on my daily ritual of downloading the latest nightly build with a little app to do most of the work for me.

Resharper Updater checks the website behind the scenes for you and changes the icon to one with a star when there’s a new version, so all you have to do when you come in in the morning is close studio and update to the latest version.

You can download it here resharper-updater-1.0.zip

Using Resharper Updater

There’s two ways to access the install

right click for the menu

13-02-2009-14-28-27

If you have resharper installed it will tell you there’s no new version

13-02-2009-14-28-51

If you Check for update it will tell you what build is available and the icon will change

13-02-2009-14-33-48

Otherwise if you choose Check and Install or you double click on the icon it will check,download and run the installer.

13-02-2009-14-34-51

There’s definitely room for improvement but this is the bare minimum before I could release it.

Automating your day

Uncategorized

Reusable Build Scripts

February 10th, 2009

246357466_cba52d3fc5

I started last week at Open Space Coding Day 1 and I had builds on my mind. I proposed a lot of different topics to code one but reusable build scripts picked up a bit of traction. I ran a quick tutorial on how to get an application compiling and tests running. We used NAnt because that’s what people wanted to learn but there’s plenty of alternatives including Powershell, Rake and MSBuild.

Here’s the repository from our session:

reusable build scripts subversion

When I first started off with build scripts it didn’t take long before they got ugly. Your build script goes from a simple compilation to a monstrous 1000 line file if your not careful. I remember adding all kinds of email notifications and deployment steps that I ended up cutting out during the hand over. I recommend if your new to build scripts and NAnt to read through with JP Boodhoo’s NAnt Starter Series which is a really good starting point.

The main tips for simplifying your build scripts are

  1. remove application specific information to a common properties file
  2. separate out common targets into separate files which you can include (ie: tests, compile, deploy)
  3. keep it simple

I maintain a number of projects for a data mining job and it started to bug me how across different projects on a few scattered lines of the build changed. Even after the tips I mentioned you can still find that you have application specific configurations in your build.

The problem I had was I was repeating myself in the build script and that defeats DRY. The steps I was taking were:

  1. compile all the .cs files in my source dir
  2. manually set the references for my project
  3. copy the referenced DLLs into the output directory

It doesn’t seem like much but anytime you add a reference you need to edit the build file. It ends up looking like this.

    <csc target="library" output="${dir.deploy}/sample.core.tests.dll" debug="true">
      <sources>
        <include name="${dir.src}/*.tests/**/*.cs" />
      </sources>
      <references>
        <include name="${dir.deploy}/sample.core.dll" />
        <include name="../thirdparty/tools/mbunit/MbUnit.Framework.dll" />
      </references>
    </csc>
    <copy todir="${dir.deploy}">
      <fileset>
        <include name="../thirdparty/tools/mbunit/MbUnit.Framework.dll" />
        <include name="../thirdparty/tools/mbunit/QuickGraph.Algorithms.dll" />
        <include name="../thirdparty/tools/mbunit/QuickGraph.dll" />
      </fileset>
    </copy>

The benefit of using csc over msbuild is that it lets you use the Mono Framework just by setting the target framework at command line.

The other problem with this approach is that mono needs reference DLL’s compiled for Mono like MySql Connector and Log4Net.

Cowan.Commons.Nant.ProjectsTask

My solution was to take all the logic I was repeating and put it into a custom task called ProjectsTask. It allows you to use wildcards to specify your projects to compile, which is not supported by SolutionsTask. This task uses XPath on each project file to retrieve references,resources and the project name.

<projects outputdir="${target.dir}">
      <fileset basedir="${sources.dir}">
        <include name="**/*.csproj" />
        <exclude name="*.tests/*.csproj" />
      </fileset>
</projects>

To fix the mono reference problem I’ve included references for both mono and .net in my lib folder but only referenced the .net dll.

\lib\log4net\net-3.5\log4net.dll
\lib\log4net\mono-3.5\log4net.dll

when you compile with mono it notices the net-3.5 directory and tries and finds a mono directory beside it. A new addition to NAnt is that it’s no longer sensitive to OS specific path seperators like / or \.

I still need to specify the build configuration (ie:debug or release) but it’s really simplified things for me.

you can see the code here

Work Smarter not Harder

Uncategorized

Using Fluent Interfaces

February 6th, 2009

A couple weeks ago I was mentioning a training I did at Concentra. Well here’s the codebase that came out of the three days of training.

You’ll need a subversion client to checkout the code (like tortoiseSVN)

http://sleepoverrated.googlecode.com/svn/2009-01-14-Training_Codebase

Fluent Interfaces

Fluent Interfaces are are a way of writing code in which its more readable. Wikipedia uses the example of having a method return its class so you can add up a series of method calls like this.

new ConfigurationFluent().SetColor("blue")
                                           .SetHeight(1)
                                           .SetLength(2)
                                           .SetDepth(3);

The preparation exercise was to create a Movie Library that allowed us to search and sort in an number of different ways. We used the specification pattern to search thru an in memory collection. For searching moved towards a way of having a Linq like query syntax that let us select all the movies of different criteria. You can see some examples of this used in MovieLibrary.cs

Here is an example of how we used Movie.is_of_genre to search for all the action movies in our library. The Search Criteria is built up as a Specification and then checked for each movie in all_movies() by satisfied_by()

        public IEnumerable<movie> all_action_movies()
        {
            return all_movies().satisfied_by(Movie.is_of_genre(Genre.action));
        }

Looking at Move.is_of_genre() in Movie.cs we can see the Fluent Interface we created for created a Specification to check if a Movie has a genre that we specify.

        public static ISpecification<movie> is_of_genre(Genre genre)
        {
            return Where<movie>.has(x => x.genre).equal_to(genre);
        }

this is our fluent interface that we developed for querying. I recommend you look thru the code for this.

How would you write this?

When writing Fluent Interfaces you want to just write some code to do the thing you want to do in the way you want it to look. Then you have to figure out some way to make it compile. You may have to change your code around to get it to work.

Implement classes in reverse

You may naturally feel like implementing the Where class first but the one thing you know is what has to be returned and that is the responsibility of the last method.

  1. equal_to needs to return an ISpecification<movie>
  2. Where.has() needs to return a class with an equal_to method

We named the class returned by Where.has() as SpecificationBuilder<T,TOutput>. The x=> x.genre is passed into the new SpecificationBuilder in the constructor as a Func<T,TOutput> property_accessor. This Func is a function we call that takes in a Movie and returns a Genre if it was a delegate it would look like

        public Genre property_accessor(Movie movie)
        {
            return movie.genre;
        }

The great thing with C# generics is that it actually infers the TOutput type of genre in from the lambda x => x.genre. I barely noticed this ability until I started using Generics in Java. It is easier to just do this in Linq and there are some examples of that in MovieLibrary.cs but it’s a challenging exercise to try.

Doing things differently teaches you different things.

Uncategorized