Far Away Developer

Sebastien Lachance

Archive for the 'Tools' Category

Posts about tools

WHILSOF : Getting started with NHibernate

Posted by Sebastien Lachance on March 3, 2008

Without digging in too much detail about NHibernate, I will presume you are familiar with what this O/R Mapper can do.

The application configuration file :

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
  </configSections>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <property name="hibernate.dialect">NHibernate.Dialect.MsSql2005Dialect</property>
      <property name="hibernate.connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="hibernate.connection.connection_string">Server=.SQLEXPRESS;Initial Catalog=RecipeHelperTest;User Id=recipeuser;Password=recipeuser;</property>
      <mapping assembly="RecipeHelper.Domain" />
    </session-factory>
  </hibernate-configuration>
</configuration>

This is standard stuff that you can find in the documentation. One interesting point however is the mapping. You can specify where your domain object to be persisted are. This will allow you to not worry about specifying them in code.

Creating a mapping file :

To be able to persist your entities, you’ll need to create a mapping file. In my opinion, this is the hardest thing to learn about NHibernate. But don’t worry, it is well documented.

The strategy I am using is one file per entities, in the same assembly. I also use the same name with the extension “.hbm.xml”. The trickiest part is that you need to set the Build Action to “Embedded Resource“. Once all this is completed you can now start writing your mapping information :

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="RecipeHelper.Domain" namespace="RecipeHelper.Domain" default-lazy="false">
  <class name="Recipe" table="Recipes" >
    <id name="ID" column="ID" type="int" access="field.lowercase-underscore">
      <generator class="native" />
    </id>
    <property name="Name" column="Name" type="string" not-null="false"/>
    <property name="Reference" column="Reference" type="string" not-null="false" />
    <property name="Rating" column="Rating" type="int" not-null="false" />
  </class>
</hibernate-mapping>

Preparation for using NHibernate :

The biggest performance hit is the creation of the ISessionFactory. For this reason, it should only be instantiated once. I created a singleton that will allow me to have access to a single session factory.

using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;

namespace RecipeHelper.Domain
{
    public class NHibernateConfig
    {
        private static ISessionFactory _sessionFactory;

        static NHibernateConfig()
        {
            Configuration config = new Configuration();

            _sessionFactory = config.Configure().BuildSessionFactory();
        }

        public static ISessionFactory GetSessionFactory()
        {
            return _sessionFactory;
        }

    }
}

Conclusion :

This isn’t a complete tutorial to get started with NHibernate but should cover the essential steps to prepare your project to use it.

Posted in Agile, Learning, Tools | No Comments »

Screencast and my opinion about TypeMock

Posted by Sebastien Lachance on January 24, 2008

I have always been told that TypeMock was too powerful, not strongly typed and for that, It shouldn’t be used. I believed that. The problem is : I should have given it a try before taking that for granted.

I have watched the Roy Osherove screencast and was impressed! I am currently working on an existing code base that was done before we went Agile and even before we were doing object-oriented development. When I need to refactor certain features I usually start writing tests and then using dependency injection to be able to mock some object. The minimum to be testable with Rhino Mocks. But with TypeMock you can mock object and don’t even need to inject them. You can also make expectation on static methods. Isn’t that just great! I believe so.

However, I will stick with Rhino Mocks for now. I like the way It force me to decouple my code and in some sense, it provide me with guidance to make my work testable.

P.S. : This is just my opinion and not the absolute truth.

Posted in Agile, Design, Tests, Tools | No Comments »

NHibernate - SaveOrUpdate does nothing?

Posted by Sebastien Lachance on January 23, 2008

Of course it does something, just make sure you call the Flush method on your session…

I have just started playing around with NHibernate for a personal project (the one I use for the Building a new application series) and I’m liking it. This make all the data access seems so easy. Maybe I will change my point of view after dealing with some collections and relationships.

Posted in .NET, Design, Learning, Project, Tools | No Comments »

Setting up a basic continuous integration server with CruiseControl.NET

Posted by Sebastien Lachance on December 11, 2007

(Index of the whole series)

Before we go on, you need to now what is “Continuous Integration”. This is a long topic and you should probably read Martin Fowler’s article on Continuous Integration.

Now that we have determined the structure of the project and put the source in the repository, we need to set up the continuous integration server. The tool we will use for that is CruiseControl.NET. The guys behind it have really done a great job. We need first to define “what we want”.

What we want :
  1. Checking for modifications in the source repository.
  2. Get the latest version if modifications are detected.
  3. Build the project.
  4. Run the test suite.
  5. Reporting any successes of failures.

We also want to “fail fast”. This means that at any step, if something is wrong, we won’t go further and report it.

So here is the step by step approach :

1. Downloading and Installing CruiseControl.NET

Download CruiseControl.NET here. I’m using the version 1.3. Then double-click on the executable and follow each step. Normally, I’m leaving everything checked except the help files and examples.

You will be asked if you want to use CC.NET server as a Windows Service. Basically, if you want CC.NET to always run (and in my opinion, it should), my advice is to run it as a service. But some scenario may require that you need to run it only once in while. In that case you only need to execute ccnet.exe to start the server. Next, it ask you if you want to create a virtual directory in IIS for the Web Dashboard. I’m leaving it checked as I want to use CC.NET as a service.

2. Setting a basic project in ccnet.config

Find your ccnet.config (in your ccnetinstallationfolder\server). Every step you want to be executed will be defined here. This require some basic knowledge in xml.

 

 

<!--<ccnetconfig><configurationVersion>1.3</configurationVersion></ccnetconfig>-->
<cruisecontrol>
  <project name="LogItAll">

  </project>
</cruisecontrol>

I’m usually starting with an empty configuration file. The <cruisecontrol> tag is the root and you have one <project> tag per project.

 

 

<cruisecontrol>
    <project name="LogItAll">

        <workingDirectory>c:\dev\logitall</workingDirectory>
        <artifactDirectory>c:\dev\logitall\artifact</artifactDirectory>
        <category>Personal application</category>
        <modificationDelaySeconds>10</modificationDelaySeconds>

        <triggers>
          <intervalTrigger name="continuous" seconds="30"/>
        </triggers>

        <labeller type="defaultlabeller">
          <prefix>0.0.</prefix>
        </labeller>

   </project>
</cruisecontrol>

The <workingDirectory> will serve as the root for all our operations. Instead of specifying the full path, we will use the relative path. Example : \tools\nant\nant.exe instead of C:\dev\LogItAll\tools\nant\nant.exe.

The <artifactDirectory> is where every logs (builds, unit tests) is stored. This tag is not needed.

The <category> is simply in which category you want the project to be. This tag is also not needed.

The <modificationDelaySeconds> is the interval of time in which no modification must be done to the source to continue executing all remaining tasks.

We then have the triggers bloc. This block contains all the reasons that we want to perform a build. I recommend using the documentation of CC.NET to learn more. The <intervalTrigger> is, as the name imply, a trigger that will launch the build process every 30 seconds if any modifications is done to the source.

Finally we have the <labeller> which will give a label to the project. There is a lot of different labelers to use. In my case, I’m going with the default and starting the build number at 0.0.*.

3. Checking if any modifications is done to the source and getting the latest version.

The sourcecontrol tag is need to know if the source have changed. This will also get the latest version of the project.

 

 

<cruisecontrol>
    <project name="LogItAll">

   ...

    <sourcecontrol type="svn">
      <trunkUrl>svn://localhost/repos/LogItAll</trunkUrl>
      <workingDirectory>c:\dev\logitall</workingDirectory>
    </sourcecontrol>

    ...

    </project>
</cruisecontrol>

I can’t go on all the details because each source control has it’s own set of properties and features.

A lot of source control providers are supported (SourceSafe,CVS, etc..).

4. Build the project and run the unit tests suite.

First, we need a <tasks> section. This section should contains all action you want to happen in order. Several tasks are available.

A build file will help tremendously. Since we already have the build process in our own file for development, why shouldn’t we use it to build the application on the CI server. Instead of using an MSBuild task and modifying two files each time we change something in our build process, we should use it. You can use the nant task to run our build file.

 

 

<cruisecontrol>
    <project name="LogItAll">

    ...

    <tasks>
      <nant>
        <executable>tools\nant\nant.exe</executable>
        <buildFile>logitall.build</buildFile>
        <targetList>
          <target>test</target>
        </targetList>
      </nant>
    </tasks>

    ...

    </project>
</cruisecontrol>
5. Integrating the results.

Every log files you want to see in the Web Dashboard need to be merged. To do that you need to add the File Merge Task of the publisher task.

 

 

<cruisecontrol>
    <project name="LogItAll">

    ...

    <publishers>
      <merge>
         <files>
            <file>Logs\*.xml</file>
         </files>
      </merge>
      <xmllogger/>
    </publishers>

    </project>
</cruisecontrol>

This will embed the content of all the xml files in the logs folder in an xml file that the Web Dashboard will use to render it’s content. It’s really important that you add the <xmllogger>. It is required for the Web Dashboard to function properly.

If you are like me and you are using MbUnit as a test tool, you will need to perform some additional step to integrate your results files into the Web Dashboard. The solution is described in the Andrew Stopford’s Weblog. If you don’t see the report after that, verify that MbUnit genarate an xml file instead of an html file.

6. The Web Dashboard

The Web Dashboard is the easiest way to see every test results, builds logs, coverage statistics, etc…

You can access it via the http://nameofyourserver/ccnet.

7. CCTray

CCTray is a little application that helps you monitor your build. Simply access you Web Dashboard, and it the left menu, there is an option to download CCTray.

cctraydownload

Then you need to add the projects you want to monitor. You do that first by entering the name of the server and then selecting the projects you want. I’m usually using the “Connect directly using .NET remoting.

addserver

Keep in mind that it is a basic tutorial and I intend to develop a little more in the following months. In the meanwhile, I will appreciate any comments, suggestion or ideas.

(Put me in your feed reader ! :P)

Posted in Agile, Continuous Integration, Tools | No Comments »

NAnt 0.86 beta 1 is out !!

Posted by Sebastien Lachance on December 10, 2007

NAnt 0.86 beta 1 is out! Now with support for .NET 3.5.

Posted in Tools | No Comments »

Setting up the build file

Posted by Sebastien Lachance on December 4, 2007

(Index of the whole series)

This is really easy on a new project! I think that the success on setting up a build file is going a step at a time. Unfortunately this is not always the case in some of our projects due to time constraints.

I am using NAnt for this.

Step 1. Deciding where I wanted to put my build.

Going with some advices I decided to go on the classic build folder. I make sure the folder is deleted and created back at every build.

 

 

<!-- Start by cleaning the build area -->
<target name="clean">
  <delete dir="build" if="${directory::exists('build')}" />
</target>

<!-- Create a build area -->
<target name="init">
  <mkdir dir="build"/>
</target>
Step 2. Compiling the project.
This is where the challenge lies. The csc Nant task is not aware of the .NET 3.5 framework. To get around this problem I have download a nightly build of NAnt 0.86. Works perfectly, until…

Remember I’m using WPF for my GUI. I was getting some strange errors about something missing in the System.Window. Full error :

[csc] Compiling 7 files to ‘C:\dev\LogItAll\build\LogItAll.exe’.
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\App.xaml.cs(13,32): error CS0246: The type or namespace name ‘Application’ could not be found (are you missing a using directive or an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(6,22): error CS0234: The type or namespace name ‘Controls’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(7,22): error CS0234: The type or namespace name ‘Data’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(8,22): error CS0234: The type or namespace name ‘Documents’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(9,22): error CS0234: The type or namespace name ‘Input’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(10,22): error CS0234: The type or namespace name ‘Media’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(11,22): error CS0234: The type or namespace name ‘Media’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(12,22): error CS0234: The type or namespace name ‘Navigation’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(13,22): error CS0234: The type or namespace name ‘Shapes’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(20,36): error CS0246: The type or namespace name ‘Window’ could not be found (are you missing ausing directive or an assembly reference?)

Humm, why is there something so obvious that it should be there failing? The reason is that some of the libraries required on a WPF project are not in the GAC. They are located in the C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\. Next, there is the problem that some file are generated and not always there, the InitializeComponent method is missing everywhere…. This is strange, how can I use csc.exe to generate those files? You can’t use csc.exe, when you use XAML ! After a lot of googling, I stumbled upon this MSDN page. I had no choice but start using MSBuild for the compilation.

So I changed my csc task to an exec task and called MSBuild. I was now facing the problem that the assembly are compiled and put in their respective folder. A little change to the Output path in Visual Studio 2008 did the trick. Note that I am not using it on all project. I’m only interested in the UI project and all the tests projects. They are all what I need to run the application and the unit test.

outputpath

This is what the NAnt section look like:

 

 

<target name="compile" depends="init">
    <exec
    program="C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe"
    commandline="LogItAll.sln"/>
</target>
3. Executing the tests.

 

 

<target name="test" depends="compile">
  <exec basedir="tools\mbunit\"
    useruntimeengine="true"
    workingdir="build"
    program="mbunit.cons.exe"
    commandline="LogItAll.Domain.Tests.dll /rt:html /rf:"."" />
</target>

I’m still trying to find a more generic way to execute all the test projects. As you can see I am using MBUnit as my unit testing tool for this application.

4. Result

 

 

<?xml version="1.0"?>
<project name="LogItAll" default="all">

  <target name="all"/>

  <!-- Start by cleaning the build area -->
  <target name="clean" description="remove all build products">
    <delete dir="build" if="${directory::exists('build')}" />
  </target>

  <!-- Create a build area -->
  <target name="init" depends="clean">
    <mkdir dir="build"/>
  </target>

  <target name="compile" depends="init">
      <exec
      program="C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe"
      commandline="LogItAll.sln"/>
  </target>

  <target name="test" depends="compile">
    <exec basedir="tools\mbunit\"
      useruntimeengine="true"
      workingdir="build"
      program="mbunit.cons.exe"
      commandline="LogItAll.Domain.Tests.dll /rt:html /rf:"."" />
  </target>

</project>

Posted in Agile, Learning, Tools, Visual Studio | No Comments »

Setting up a Subversion server (using svnserve)

Posted by Sebastien Lachance on November 29, 2007

(Index of the whole series)

I got hold of an old computer that I will be able to use as a continuous integration server and Subversion repository. This weekend, I got some free time and decided to set-up Subversion on it. I was surprised on how much it was easy. The documentation is all but superfluous and it was very instructive. So here is how you can do it.

Downloading and installing subversion

You can find the latest version here. I used the svn-1.4.5-setup.exe one. Just install it like any other program, there is no additional things to modify in the setup.

Setting up a repository

You may want to create a repository right now to make sure that you can make some test later. I recommend using TortoiseSVN for that, unless you want to learn all the command to use Subversion (not so hard to do). To do that, you simply need to create a folder that you want as a repository (this folder will hold all your files and every change made to them), and right click on it. Select the TortoiseSVN\Create repository here menu items and select the Native File System (FSFS) radio button. You now have fully working repository. For a comparison of Native File System versus Berkeley Database, take a look at this link.

createrepository

svnserve

You then have two choices to use Subversion remotely. First one is to use the Apache HTTP server and the second one is to use svnserve. I have decided to use svnserve because it’s a lightweight server program and I don’t need encryption and logging. Also svnserve is a lot faster and it’s the best options for small teams. You may want to make sure you are able to access it. Open a command prompt and type svnserve. You should see the following :

svnserve-commandprompt

If you still planning to use svnserve right now, you have two choices : install it as a service or open it each time you want to access a repository.

If you are planning to open it each time you want to access your repository, launch a command prompt and type svnserve -d. You have access to all the repositories you may have created on the server.

If, however, you decide to use it as a Windows Service (it will reopen automatically each time you start the server), Use this at a command prompt :

C:\> sc create svn binpath= “\”C:\program files\svn\bin\svnserve.exe\” –service -r C:\nameofyourrepository” displayname= “Subversion Server” depend= Tcpip start= auto

Controlling access

If you attempted to use this right now to make a check-in, you will find that you don’t have Write access. This can be changed by editing the svnserve.conf found in your repository folder. You need to find the # anon-access = read and change it to anon-access = write (don’t forget to remove #). This will grant write access to all anonymous users. This is not the ideal, but in a single programmer scenario it works perfectly. However, note that if you need a more robust authentication solution, it’s totally possible. I will not cover it right now, but the full procedure is described in the TortoiseSVN documentation (Section 3.2.4).

svnservedotconf

 

Accessing the repository remotely

Open the repository browser (shown below) and type svn://nameofyourserver/nameofyourrepository. Can it be more easy?

access

Posted in Agile, Project, Tools | No Comments »

Building a new application - Introduction

Posted by Sebastien Lachance on November 27, 2007

(Index of the whole series)

I want to build an application and release it to the community. This is an application I had in mind for a long time. Basically, it’s a logging application. Not the one you would use to track requirements and time spent on a project. I’m talking about a logging application to log your weight, track your goals, what you’ve eat, do reports , etc. I know it’s something people want. I’m not doing it for money. I want to learn as much as possible and I think that writing code and solving new problems is a great way to learn. I have to take some basic decision at the beginning of the project and I must admit it will be a good excuse to make a list of all the new things (for me) that I want to use in the project and blog about them. This is an opportunity for me to take the time of using object-oriented techniques and becoming more agile. I will also blog a lot about that, because I find that blogging an interesting tool to learn and explaining to others help reinforce knowledge and being more confident. Also, posting about your goals, makes it a little harder to abandon too early.

My requirements are the the following :

  • Test-Driven development. I want a coverage of 95% at least.
  • Building an continuous integration server.
  • Applying at the best of my knowledge Object-Oriented principle.
  • User stories.
  • Identify mistakes as soon as possible and learn from them.
  • Use a source control software and learn some of the best practices of source control management.

Technologies I want to use :

So I want It to be Agile as most as possible. First step, print the Agile Manifesto!

Posted in .NET, Agile, Programming, Tools | No Comments »

Scott Hanselman’s 2007 Ultimate Developer and Power Users Tool List for Windows

Posted by Sebastien Lachance on August 29, 2007

I always has this dilemma when I’m about to choose a tool to get the job done. Is that the better? I’m I loosing my time with this tool when there is another that does the job one hundred time better?

And then, came “the list” from Scott Hanselman. It’s a very complete one evaluated by someone who has experience with them. A lot of tools I’m using right now come directly from that list and has influenced my productivity a lot. For example :

  • SlickRun
  • Windows Live Writer
  • FireBug
  • TestDriven.NET
  • Colibri
  • Skype
  • Acronis
  • 7-Zip
  • etc.

I highly encourage you to check “the list” and don’t hesitate to try some of them. You could easily find one that will stick around for a while.

Scott Hanselman’s 2007 Ultimate Developer and Power Users Tool List for Windows

Posted in Tools | 2 Comments »