<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Wiggly Line of Thought</title>
	<atom:link href="http://pwigle.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://pwigle.wordpress.com</link>
	<description>Petter Wigle blogs about software development and agile practices</description>
	<lastBuildDate>Wed, 24 Aug 2011 04:00:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='pwigle.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Wiggly Line of Thought</title>
		<link>http://pwigle.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://pwigle.wordpress.com/osd.xml" title="Wiggly Line of Thought" />
	<atom:link rel='hub' href='http://pwigle.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Don&#8217;t use Regions in .NET</title>
		<link>http://pwigle.wordpress.com/2011/08/23/dont-use-regions-in-net/</link>
		<comments>http://pwigle.wordpress.com/2011/08/23/dont-use-regions-in-net/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 19:40:02 +0000</pubDate>
		<dc:creator>pwigle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Clean-Code]]></category>

		<guid isPermaLink="false">https://pwigle.wordpress.com/?p=139</guid>
		<description><![CDATA[One thing that annoys me when reading other people&#8217;s C# or VB.NET code is the use of regions. The main reason why anyone should wrap a piece of code inside a region is that there is something inside that they don’t want you to see. Visual Studio’s default behavior is, as you know, to collapse [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=139&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One thing that annoys me when reading other people&#8217;s C# or VB.NET code is the use of <em>regions</em>. The main reason why anyone should wrap a piece of code inside a region is that there is something inside that they don’t want you to see. Visual Studio’s default behavior is, as you know, to collapse all regions when you open the file. Here are some of the uses I’ve seen of regions:</p>
<h3>Grouping of Constructors</h3>
<p>I can see the point with wrapping the constructors in a region. Usually nothing interesting should happen in the constructors. But I have been surprised many times by the code people put in their constructors. Therefore you can’t make the assumption that the constructor code is something you can ignore.</p>
<p>If you have so many constructors that you need to hide them, your class is too complicated.</p>
<h3>Grouping of Private methods</h3>
<p>The same argument as above applies to private methods as well. If you have so many private methods that you want to hide them, your class is too big. There is another class inside just waiting to be released!</p>
<h3>Grouping of field and property declarations</h3>
<p>Here are some simple rules to avoid many lines of property declarations:</p>
<ol>
<li>Avoid properties if you can. They violate encapsulation.</li>
<li>If you still need properties, at least use implicit backing fields</li>
<li>If you have many properties, your class is too big</li>
</ol>
<h3>Inside methods</h3>
<p>From time to time I see people dividing up methods in regions, usually with some hint of what the wrapped code is supposed to do, e.g. <code>#region Do processing</code>. This is the worst use of regions in my opinion. A well written method should not be more than maybe ten lines long, so there is not much room for regions, is it? Long methods are usually quite easy to refactor, especially with a refactoring tool. Even Visual Studio can do <em>Extract Method</em> out-of-the-box!</p>
<h3>Conclusion</h3>
<h2></h2>
<p>If you feel an urge to write <code>#region</code> in your code, you should refactor instead!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pwigle.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pwigle.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pwigle.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pwigle.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pwigle.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pwigle.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pwigle.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pwigle.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pwigle.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pwigle.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pwigle.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pwigle.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pwigle.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pwigle.wordpress.com/139/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=139&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://pwigle.wordpress.com/2011/08/23/dont-use-regions-in-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/35ed99e2833b2ac9f7b7493f6e464ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwigle</media:title>
		</media:content>
	</item>
		<item>
		<title>First contact with Refinery CMS</title>
		<link>http://pwigle.wordpress.com/2011/06/13/first-contact-with-refinery-cms/</link>
		<comments>http://pwigle.wordpress.com/2011/06/13/first-contact-with-refinery-cms/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 16:34:43 +0000</pubDate>
		<dc:creator>pwigle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">https://pwigle.wordpress.com/?p=133</guid>
		<description><![CDATA[I am about to finish my first CMS project based on the open source Ruby on Rails based CMS framework Refinery. It has been a pleasure to work with it and I will explain why in this post. I have some previous experience with the commercial CMS product EPiServer. It is a very polished product [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=133&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am about to finish my first CMS project based on the open source Ruby on Rails based CMS framework <a href="http://refinerycms.com/">Refinery</a>. It has been a pleasure to work with it and I will explain why in this post.</p>
<p>I have some previous experience with the commercial CMS product <a href="http://www.episerver.com/en/Products/Content/">EPiServer</a>. It is a very polished product packed with features. The problem with it is that it is developed to be attractive for editors and IT Management and not for developers. It looks really nice in demos, but the developer experience is far from perfect. I suspect that other commercial CMS systems have the same problem. Open source products on the other hand, are developed by developers for developers. This is certainly true for Refinery.</p>
<p>One thing I really like about Refinery is that it is designed “the Rails way”, which means that there is not much to learn if you’re already familiar with Rails.</p>
<h3>Setup</h3>
<p>Starting a new project is really simple. Just follow the simple steps in the <a href="http://refinerycms.com/guides/getting-started-with-refinery/">guide</a> and you are ready to go. When you start your new application the first time, you will be prompted to create the first user account.</p>
<h3>Basic customization</h3>
<p>Customizing the frontend is straightforward. There are Rake tasks defined for overriding defaults. The override task simply copies the file from the gem repository to your application directory. To override the default page view, for example, just issue the command:</p>
<pre>rake refinery:override view=pages/show</pre>
<p>You can override controllers, models and stylesheets in the same way. The override mechanism is not limited to the frontend, the admin interface can also be customized.</p>
<h3>Extending Refinery</h3>
<p>Extensions in Refinery are based on Rails Engines. A generator is provided that works like the Rails Scaffold generator. This makes it really easy to add your own functionality. This approach also makes it easy to reuse the extensions you build in other projects.</p>
<h3>Deployment</h3>
<p>Since your Refinery application is just a normal Rails app, you have the same deployment options available as with any Rack-based app. That includes <a href="http://www.heroku.com/">Heroku</a>, which allows you to get your app up and running in minutes. For a demo or test site you can probably use Heroku free of charge.</p>
<h3>Conclusion</h3>
<p>Refinery is lacking some advanced features available in commercial CMS products. Most notably it has no versioning support and the globalization support is rudimentary. Despite this I can really recommend it if you value its properties:</p>
<ul>
<li>Based on Ruby on Rails</li>
<li>Developer friendly</li>
<li>Easy to deploy</li>
<li>Easy to customize and extend</li>
</ul>
<p>If you are new to Rails, don’t worry. Very little knowledge of Ruby and Rails is necessary, at least to build a basic web site.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pwigle.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pwigle.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pwigle.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pwigle.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pwigle.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pwigle.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pwigle.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pwigle.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pwigle.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pwigle.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pwigle.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pwigle.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pwigle.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pwigle.wordpress.com/133/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=133&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://pwigle.wordpress.com/2011/06/13/first-contact-with-refinery-cms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/35ed99e2833b2ac9f7b7493f6e464ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwigle</media:title>
		</media:content>
	</item>
		<item>
		<title>Small Projects are no Excuse for Sloppy Process</title>
		<link>http://pwigle.wordpress.com/2011/02/01/small-projects-are-no-excuse-for-sloppy-process/</link>
		<comments>http://pwigle.wordpress.com/2011/02/01/small-projects-are-no-excuse-for-sloppy-process/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 20:19:30 +0000</pubDate>
		<dc:creator>pwigle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">https://pwigle.wordpress.com/?p=117</guid>
		<description><![CDATA[In the past few years I have been involved in a few small development projects. By small I mean a project with two or maybe three developers and a timeframe of four to eight weeks. Some of the projects have been very successful and others have been more troubled. In retrospect I found that the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=117&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the past few years I have been involved in a few small development projects. By small I mean a project with two or maybe three developers and a timeframe of four to eight weeks. Some of the projects have been very successful and others have been more troubled.</p>
<p>In retrospect I found that the in the more successful projects we applied a more strict agile process. The most troubled projects were those that were run in a sloppier fashion.</p>
<p>In a small project with a tight budget it is essential that you:</p>
<ul>
<li>Show continuous progress</li>
<li>Can respond to change quickly</li>
<li>Don’t waste time on things that don’t add value</li>
<li>Reduce defects</li>
</ul>
<p>To be successful in small projects, in my experience, you should at least do the following:</p>
<ul>
<li>Have a product backlog</li>
<li>Each product backlog item should be small enough to be completed in one day</li>
<li>Use a task board</li>
<li>Demonstrate your software one a week</li>
<li>Do test-driven development</li>
<li>Practice Continuous Integration</li>
<li>Automate build and deployment</li>
<li>Have retrospectives regularly</li>
<li>Daily stand-up meetings together with the customer</li>
<li>If you need estimates, use T-shirt sizes (S, M, L)</li>
<li>Pair-program as much as you can</li>
</ul>
<p>A consequence of the last point is that you should never be alone no matter how small the project is.</p>
<h3>What can be left out?</h3>
<p>In my experience you can safely in most cases skip the following practices:</p>
<ul>
<li>Break down of features into tasks</li>
<li>Detailed estimation</li>
<li>Burn-down charts</li>
<li>Velocity tracking</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pwigle.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pwigle.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pwigle.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pwigle.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pwigle.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pwigle.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pwigle.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pwigle.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pwigle.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pwigle.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pwigle.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pwigle.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pwigle.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pwigle.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=117&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://pwigle.wordpress.com/2011/02/01/small-projects-are-no-excuse-for-sloppy-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/35ed99e2833b2ac9f7b7493f6e464ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwigle</media:title>
		</media:content>
	</item>
		<item>
		<title>Migrating from Visual SourceSafe to Mercurial</title>
		<link>http://pwigle.wordpress.com/2010/12/03/migrating-from-visual-sourcesafe-to-mercurial/</link>
		<comments>http://pwigle.wordpress.com/2010/12/03/migrating-from-visual-sourcesafe-to-mercurial/#comments</comments>
		<pubDate>Fri, 03 Dec 2010 16:42:18 +0000</pubDate>
		<dc:creator>pwigle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Mercurial]]></category>
		<category><![CDATA[SourceControl]]></category>
		<category><![CDATA[SourceSafe]]></category>

		<guid isPermaLink="false">https://pwigle.wordpress.com/?p=110</guid>
		<description><![CDATA[If your organization use Microsoft SourceSafe as your version control tool, there are several reasons to stop doing that as pointed out in these blog posts: Visual SourceSafe Version Control: Unsafe at any Speed? Visual SourceSafe: Microsoft&#8217;s Source Destruction System Which version control system should you use instead? Well, there are a lot of tools [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=110&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If your organization use Microsoft SourceSafe as your version control tool, there are several reasons to stop doing that as pointed out in these blog posts:</p>
<ul>
<li><a href="http://www.developsense.com/testing/VSSDefects.html">Visual SourceSafe Version Control: Unsafe at any Speed?</a></li>
<li><a href="http://www.highprogrammer.com/alan/windev/sourcesafe.html">Visual SourceSafe: Microsoft&#8217;s Source Destruction System</a></li>
</ul>
<p>Which version control system should you use instead? Well, there are a lot of tools to choose from, both free and commercial. In my opinion the best choice for most organizations is a <a href="http://en.wikipedia.org/wiki/Distributed_revision_control">Distributed version control system</a> (DVCS). Popular tools are <a href="http://git-scm.com/">Git</a>, <a href="http://mercurial.selenic.com/">Mercurial</a> and <a href="http://bazaar.canonical.com/en/">Bazaar</a>. These are all excellent tools, which one to choose is very much a matter of taste. In this post I will describe how I did a migration from SourceSafe to Mercurial for a client.</p>
<h3>Migrating the repository</h3>
<p>I haven’t found any reliable tool to migrate directly from SourceSafe to Mercurial, but there are many tools to migrate from SourceSafe to Subversion and it is possible to migrate from Subversion to Mercurial.</p>
<p>I tried a few tools for the SourceSafe –&gt; Subversion conversion. I ended up using <a href="http://code.google.com/p/vss2svn/">Vss2Svn</a>, a tool with a simple command line interface. Vss2Svn creates a Subversion dump file, which can then be imported into Subversion. The following commands migrates the VSS repository into a new Subversion repository:</p>
<pre>vss2svn –vssdir &lt;path to your VSS database&gt;
svnadmin create C:\svn-repo
svnadmin load C:\svn-repo&lt; vss2svn-dumpfile.dat</pre>
<p>To migrate your new Subversion repo to Mercurial you can use the <a href="http://mercurial.selenic.com/wiki/ConvertExtension">convert</a><span style="font-family:'Courier New';"> </span>extension to Mercurial. If you have installed <a href="http://tortoisehg.bitbucket.org/">TortoiseHg</a>, you already have it. Just enable it from the Global Settings-&gt;Extensions page. Now start a local Subversion server with the command:</p>
<pre>svnserve -r C:\svn-repo –d</pre>
<p>If you would like to have each of your existing VSS project in a separate Mercurial repository, you will have to convert each one of them with a separate command, like so:</p>
<pre>hg convert svn://localhost/YourProject YourProject</pre>
<p>You will now have a new nice and warm home for your project!</p>
<p>One thing that was lost in translation was the labels from SourceSafe. I’m sure there is a way to keep them, but I didn’t have the time to investigate that.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pwigle.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pwigle.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pwigle.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pwigle.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pwigle.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pwigle.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pwigle.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pwigle.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pwigle.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pwigle.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pwigle.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pwigle.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pwigle.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pwigle.wordpress.com/110/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=110&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://pwigle.wordpress.com/2010/12/03/migrating-from-visual-sourcesafe-to-mercurial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/35ed99e2833b2ac9f7b7493f6e464ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwigle</media:title>
		</media:content>
	</item>
		<item>
		<title>NHibernate Session Handling Revisited</title>
		<link>http://pwigle.wordpress.com/2010/09/16/nhibernate-session-handling-revisited/</link>
		<comments>http://pwigle.wordpress.com/2010/09/16/nhibernate-session-handling-revisited/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 19:23:06 +0000</pubDate>
		<dc:creator>pwigle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">https://pwigle.wordpress.com/2010/09/16/nhibernate-session-handling-revisited/</guid>
		<description><![CDATA[In an old blog post I described how you can implement the Open Session in View pattern using Contextual Sessions. Since then I have discovered even easier way to handle the NHibernate sessions in an ASP.NET web application. The approach I have used recently is the one proposed by Ayende in this blog post. His [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=108&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In an old <a href="http://pwigle.wordpress.com/2008/11/21/nhibernate-session-handling-in-aspnet-the-easy-way/">blog post</a> I described how you can implement the <em>Open Session in View</em> pattern using <em>Contextual Sessions</em>. Since then I have discovered even easier way to handle the NHibernate sessions in an ASP.NET web application. The approach I have used recently is the one proposed by Ayende in this <a href="http://ayende.com/Blog/archive/2009/08/05/do-you-need-a-framework.aspx">blog post</a>. His approach is to store the reference to the current session in the current HttpContext and hooking in the session lifecycle management into the BeginRequest and EndRequest events.</p>
<p>Another approach that I haven’t used yet but I certainly will try in some upcoming project is to let your IoC container manage the sessions. <a href="http://www.kevinwilliampang.com/2010/04/06/setting-up-asp-net-mvc-with-fluent-nhibernate-and-structuremap/">Here</a> is an example of how to do that with StructureMap.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pwigle.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pwigle.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pwigle.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pwigle.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pwigle.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pwigle.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pwigle.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pwigle.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pwigle.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pwigle.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pwigle.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pwigle.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pwigle.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pwigle.wordpress.com/108/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=108&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://pwigle.wordpress.com/2010/09/16/nhibernate-session-handling-revisited/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/35ed99e2833b2ac9f7b7493f6e464ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwigle</media:title>
		</media:content>
	</item>
		<item>
		<title>Code Metrics Statistics with TeamCity</title>
		<link>http://pwigle.wordpress.com/2009/12/11/code-metrics-statistics-with-team-city/</link>
		<comments>http://pwigle.wordpress.com/2009/12/11/code-metrics-statistics-with-team-city/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 15:42:38 +0000</pubDate>
		<dc:creator>pwigle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Code-Quality]]></category>
		<category><![CDATA[Continuous-Integration]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[TeamCity]]></category>

		<guid isPermaLink="false">http://pwigle.wordpress.com/?p=70</guid>
		<description><![CDATA[Code metrics can be a very useful tool for monitoring some aspects of code quality. To get the most out of it you need to calculate the metrics on a regular basis in order to find trends. Code quality tend to go down during intense phases of a development project and also when a product [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=70&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Code metrics can be a very useful tool for monitoring some aspects of code quality. To get the most out of it you need to calculate the metrics on a regular basis in order to find trends. Code quality tend to go down during intense phases of a development project and also when a product is in low-intensity development, a.k.a the maintenance phase. The obvious thing to do for a modern developer is to integrate calculation of code metrics into the Continuous Integration process.</p>
<p>In this post I will demonstrate how you can calculate code metrics and display graphs of the evolution over time as part of your Continuous Integration process. There are a few tools available for calculating code metrics in .NET, the most capable is without doubt <a href="http://ndepend.com">NDepend</a>. Here I will use another tool, <a href="http://www.campwoodsw.com/sourcemonitor.html">SourceMonitor</a>, which is free of charge and very lightweight. We use <a href="http://www.jetbrains.com/teamcity/">Team City</a> at work, so that is the CI server that I will use here also, but you could probably implement this idea in the CI server you are using.</p>
<p>One of the goals I had when I started experimenting with code metrics statistics was that I wanted it to be easy to add statistics to any project, without changing anything in the project itself. All changes should be in the Team City configuration.</p>
<h3>Step 1: Create Metrics project in VCS</h3>
<p>The first step is to create a project in your version control system. This project should contain the following artifacts:</p>
<ul>
<li>The SourceMonitor executable</li>
<li>A SourceMonitor command file, SourceMonitorCommands.xml</li>
<li>A MSBuild script file, SourceMonitor.proj</li>
<li>MSBuild community tasks</li>
</ul>
<p>I put all the files in a directory called SourceMonitor.</p>
<h3>Step 2: Create a SourceMonitor command file</h3>
<p>I will not go into the details of working with SourceMonitor. If you are interested, you can read the documentation that is included in the download. Here is the command file that I used:</p>
<pre class="csharpcode"><span class="kwrd">&lt;?</span><span class="html">xml</span> <span class="attr">version</span><span class="kwrd">="1.0"</span> <span class="attr">encoding</span><span class="kwrd">="utf-8"</span>?<span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">sourcemonitor_commands</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">write_log</span><span class="kwrd">&gt;</span>true<span class="kwrd">&lt;/</span><span class="html">write_log</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">command</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">project_file</span><span class="kwrd">&gt;</span>MyProject.smp<span class="kwrd">&lt;/</span><span class="html">project_file</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">checkpoint_name</span><span class="kwrd">&gt;</span>Baseline<span class="kwrd">&lt;/</span><span class="html">checkpoint_name</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">project_language</span><span class="kwrd">&gt;</span>C#<span class="kwrd">&lt;/</span><span class="html">project_language</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">source_directory</span><span class="kwrd">&gt;</span>..<span class="kwrd">&lt;/</span><span class="html">source_directory</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">source_subdirectory_list</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">exclude_subdirectories</span><span class="kwrd">&gt;</span>true<span class="kwrd">&lt;/</span><span class="html">exclude_subdirectories</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">source_subtree</span><span class="kwrd">&gt;</span>bin\<span class="kwrd">&lt;/</span><span class="html">source_subtree</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">source_subdirectory</span><span class="kwrd">&gt;</span>obj\<span class="kwrd">&lt;/</span><span class="html">source_subdirectory</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">source_subdirectory_list</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">parse_utf8_files</span><span class="kwrd">&gt;</span>True<span class="kwrd">&lt;/</span><span class="html">parse_utf8_files</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">ignore_headers_footers</span><span class="kwrd">&gt;</span>True<span class="kwrd">&lt;/</span><span class="html">ignore_headers_footers</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">export</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">export_file</span><span class="kwrd">&gt;</span>SourceMonitor-details.xml<span class="kwrd">&lt;/</span><span class="html">export_file</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">export_type</span><span class="kwrd">&gt;</span>2<span class="kwrd">&lt;/</span><span class="html">export_type</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">export</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">command</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">command</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">project_file</span><span class="kwrd">&gt;</span>MyProject.smp<span class="kwrd">&lt;/</span><span class="html">project_file</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">checkpoint_name</span><span class="kwrd">&gt;</span>Baseline<span class="kwrd">&lt;/</span><span class="html">checkpoint_name</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">export</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">export_file</span><span class="kwrd">&gt;</span>SourceMonitor-summary.xml<span class="kwrd">&lt;/</span><span class="html">export_file</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">export_type</span><span class="kwrd">&gt;</span>1<span class="kwrd">&lt;/</span><span class="html">export_type</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">export</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">command</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">sourcemonitor_commands</span><span class="kwrd">&gt;</span></pre>
<p>This command file will create two xml-files: SourceMonitor-details.xml and SourceMonitor-summary.xml. It is from the latter that we will extract the values to publish to Team City.</p>
<h3>Step 3: Create a build script</h3>
<p>Here I have used MSBuild, but you can of course use NAnt, Rake or whatever. The build script will do the following:</p>
<ul>
<li>Run SourceMonitor on your source files</li>
<li>Extract the interesting values from the resulting xml-file</li>
<li>Publish these values to Team City</li>
</ul>
<p>The MSBuild community task XmlRead is used to extract the values from the xml-file. The Team City task TeamCityReportStatsValue is used to publish the values. The community tasks has to be explicitly imported, but the Team City tasks are imported automatically when the script is run by Team City. Here is my MSBuild script:</p>
<pre class="csharpcode"><span class="kwrd">&lt;?</span><span class="html">xml</span> <span class="attr">version</span><span class="kwrd">="1.0"</span> <span class="attr">encoding</span><span class="kwrd">="utf-8"</span>?<span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">Project</span> <span class="attr">ToolsVersion</span><span class="kwrd">="3.5"</span> <span class="attr">DefaultTargets</span><span class="kwrd">="Analyze"</span>
<span class="attr">xmlns</span><span class="kwrd">="http://schemas.microsoft.com/developer/msbuild/2003"</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">PropertyGroup</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">MSBuildCommunityTasksPath</span><span class="kwrd">&gt;</span>.<span class="kwrd">&lt;/</span><span class="html">MSBuildCommunityTasksPath</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">PropertyGroup</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">Import</span> <span class="attr">Project</span><span class="kwrd">="MSBuild.Community.Tasks.Targets"</span><span class="kwrd">/&gt;</span>

  <span class="kwrd">&lt;</span><span class="html">Target</span> <span class="attr">Name</span><span class="kwrd">="Analyze"</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">Exec</span> <span class="attr">Command</span><span class="kwrd">="SourceMonitor.exe /C SourceMonitorCommands.xml"</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">XmlRead</span> <span class="attr">XPath</span><span class="kwrd">="//*/metric[@id='M0']"</span> <span class="attr">XmlFileName</span><span class="kwrd">="SourceMonitor-summary.xml"</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">Output</span> <span class="attr">TaskParameter</span><span class="kwrd">="Value"</span> <span class="attr">PropertyName</span><span class="kwrd">="NumberOfLines"</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">XmlRead</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">TeamCityReportStatsValue</span> <span class="attr">Key</span><span class="kwrd">="NumberOfLines"</span> <span class="attr">Value</span><span class="kwrd">="$(NumberOfLines)"</span> <span class="kwrd">/&gt;</span>

    <span class="kwrd">&lt;</span><span class="html">XmlRead</span> <span class="attr">XPath</span><span class="kwrd">="//*/metric[@id='M5']"</span> <span class="attr">XmlFileName</span><span class="kwrd">="SourceMonitor-summary.xml"</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">Output</span> <span class="attr">TaskParameter</span><span class="kwrd">="Value"</span> <span class="attr">PropertyName</span><span class="kwrd">="MethodsPerClass"</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">XmlRead</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">TeamCityReportStatsValue</span> <span class="attr">Key</span><span class="kwrd">="MethodsPerClass"</span> <span class="attr">Value</span><span class="kwrd">="$(MethodsPerClass)"</span> <span class="kwrd">/&gt;</span>

    <span class="kwrd">&lt;</span><span class="html">XmlRead</span> <span class="attr">XPath</span><span class="kwrd">="//*/metric[@id='M7']"</span> <span class="attr">XmlFileName</span><span class="kwrd">="SourceMonitor-summary.xml"</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">Output</span> <span class="attr">TaskParameter</span><span class="kwrd">="Value"</span> <span class="attr">PropertyName</span><span class="kwrd">="StatementsPerMethod"</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">XmlRead</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">TeamCityReportStatsValue</span> <span class="attr">Key</span><span class="kwrd">="StatementsPerMethod"</span> <span class="attr">Value</span><span class="kwrd">="$(StatementsPerMethod)"</span> <span class="kwrd">/&gt;</span>

    <span class="kwrd">&lt;</span><span class="html">XmlRead</span> <span class="attr">XPath</span><span class="kwrd">="//*/metric[@id='M10']"</span> <span class="attr">XmlFileName</span><span class="kwrd">="SourceMonitor-summary.xml"</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">Output</span> <span class="attr">TaskParameter</span><span class="kwrd">="Value"</span> <span class="attr">PropertyName</span><span class="kwrd">="MaxComplexity"</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">XmlRead</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">TeamCityReportStatsValue</span> <span class="attr">Key</span><span class="kwrd">="MaxComplexity"</span> <span class="attr">Value</span><span class="kwrd">="$(MaxComplexity)"</span> <span class="kwrd">/&gt;</span>

    <span class="kwrd">&lt;</span><span class="html">XmlRead</span> <span class="attr">XPath</span><span class="kwrd">="//*/metric[@id='M14']"</span> <span class="attr">XmlFileName</span><span class="kwrd">="SourceMonitor-summary.xml"</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">Output</span> <span class="attr">TaskParameter</span><span class="kwrd">="Value"</span> <span class="attr">PropertyName</span><span class="kwrd">="AvgComplexity"</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">XmlRead</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">TeamCityReportStatsValue</span> <span class="attr">Key</span><span class="kwrd">="AvgComplexity"</span> <span class="attr">Value</span><span class="kwrd">="$(AvgComplexity)"</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Target</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Project</span><span class="kwrd">&gt;</span></pre>
<p><span class="kwrd">The build script above will extract the following metrics and publish them:</span></p>
<ul>
<li><span class="kwrd">Number of lines of code</span></li>
<li><span class="kwrd">Average number of methods per class</span></li>
<li><span class="kwrd">Average number of statements per method</span></li>
<li><span class="kwrd">Maximum cyclomatic complexity</span></li>
<li><span class="kwrd">Average cyclomatic complexity</span></li>
</ul>
<h3>Step 4: Create a build configuration in Team City</h3>
<p>The next step is to create a new build configuration for the project that you want to analyze and display statistics for.</p>
<p>Attach your VCS project root and the SourceMonitor root as well. Your version control settings will look like the example below.</p>
<div id="attachment_88" class="wp-caption alignnone" style="width: 660px"><a href="http://pwigle.files.wordpress.com/2009/12/vcs-settings.png"><img class="size-full wp-image-88" title="VCS Settings for Metrics" src="http://pwigle.files.wordpress.com/2009/12/vcs-settings.png?w=650&#038;h=120" alt="Version Control settings for Metrics" width="650" height="120" /></a><p class="wp-caption-text">Version Control Settings in Team City</p></div>
<p>Configure TeamCity to use the MSBuild runner for your build and specify the path to the build script that will run SourceMonitor. Also specify the target, in my case &#8220;Analyze&#8221;.</p>
<div id="attachment_91" class="wp-caption alignnone" style="width: 660px"><a href="http://pwigle.files.wordpress.com/2009/12/buildrunner.png"><img class="size-full wp-image-91" title="Build runner configuration in Team City" src="http://pwigle.files.wordpress.com/2009/12/buildrunner.png?w=650&#038;h=373" alt="" width="650" height="373" /></a><p class="wp-caption-text">Build runner configuration in Team City</p></div>
<p>Setup build triggering the way you like it, either as a dependent build or scheduled at some interval, for example every night.</p>
<h3>Step 5: Configure Team City to display statistics</h3>
<p>TeamCity has built in capablities to display statistics in graphs. You can easily add your own graphs to a project by adding configuration to the file plugin-settings.xml which is located in the folder: (TeamCity path)\.BuildServer\config\(project name). Note that you have to change the buildTypeId value to the Id of your Metrics build configuration. You can find the buildTypeId in the URL as a query parameter. Below is a sample plugin-settings file:</p>
<pre class="csharpcode"><span class="kwrd">&lt;?</span><span class="html">xml</span> <span class="attr">version</span><span class="kwrd">="1.0"</span> <span class="attr">encoding</span><span class="kwrd">="UTF-8"</span>?<span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">settings</span><span class="kwrd">&gt;</span>
 <span class="kwrd">&lt;</span><span class="html">custom-graphs</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">graph</span> <span class="attr">title</span><span class="kwrd">="Number of Lines"</span> <span class="attr">defaultFilters</span><span class="kwrd">=""</span> <span class="attr">hideFilters</span><span class="kwrd">="showFailed"</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">valueType</span> <span class="attr">key</span><span class="kwrd">="NumberOfLines"</span> <span class="attr">title</span><span class="kwrd">="Number Of Lines"</span> <span class="attr">buildTypeId</span><span class="kwrd">="bt61"</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">graph</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">graph</span> <span class="attr">title</span><span class="kwrd">="Methods per Class"</span> <span class="attr">defaultFilters</span><span class="kwrd">=""</span> <span class="attr">hideFilters</span><span class="kwrd">="showFailed"</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">valueType</span> <span class="attr">key</span><span class="kwrd">="MethodsPerClass"</span> <span class="attr">title</span><span class="kwrd">="Methods per Class"</span> <span class="attr">buildTypeId</span><span class="kwrd">="bt61"</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">graph</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">graph</span> <span class="attr">title</span><span class="kwrd">="Statements per Method"</span> <span class="attr">defaultFilters</span><span class="kwrd">=""</span> <span class="attr">hideFilters</span><span class="kwrd">="showFailed"</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">valueType</span> <span class="attr">key</span><span class="kwrd">="StatementsPerMethod"</span> <span class="attr">title</span><span class="kwrd">="Statements per Method"</span> <span class="attr">buildTypeId</span><span class="kwrd">="bt61"</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">graph</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">graph</span> <span class="attr">title</span><span class="kwrd">="Complexity"</span> <span class="attr">defaultFilters</span><span class="kwrd">=""</span> <span class="attr">hideFilters</span><span class="kwrd">="showFailed"</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">valueType</span> <span class="attr">key</span><span class="kwrd">="MaxComplexity"</span> <span class="attr">title</span><span class="kwrd">="Max Complexity"</span> <span class="attr">buildTypeId</span><span class="kwrd">="bt61"</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">valueType</span> <span class="attr">key</span><span class="kwrd">="AvgComplexity"</span> <span class="attr">title</span><span class="kwrd">="Average Complexity"</span> <span class="attr">buildTypeId</span><span class="kwrd">="bt61"</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">graph</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">custom-graphs</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">settings</span><span class="kwrd">&gt;</span></pre>
<p><span class="kwrd">Whenever the Metrics build is run, the graphs will be updated with the latest values. You will find them on the Statistics tab on the project overview page. It will look something like this after the first successful run:</span></p>
<p><span class="kwrd"> </span></p>
<div id="attachment_94" class="wp-caption alignnone" style="width: 660px"><a href="http://pwigle.files.wordpress.com/2009/12/graphs.png"><img class="size-full wp-image-94" title="TeamCity Metrics graphs" src="http://pwigle.files.wordpress.com/2009/12/graphs.png?w=650&#038;h=510" alt="" width="650" height="510" /></a><p class="wp-caption-text">Sample Metrics graphs</p></div>
<h3><span class="kwrd">Final remarks</span></h3>
<p>SourceMonitor only supports a few metrics, so if you want some more advanced metrics, like code cohesion, then go for NDepend.</p>
<p>In this post I haven&#8217;t explained how to display detailed reports from SourceMonitor in TeamCity. Maybe that will come in a later post.</p>
<p>Good luck with your metrics!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pwigle.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pwigle.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pwigle.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pwigle.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pwigle.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pwigle.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pwigle.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pwigle.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pwigle.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pwigle.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pwigle.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pwigle.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pwigle.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pwigle.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=70&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://pwigle.wordpress.com/2009/12/11/code-metrics-statistics-with-team-city/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/35ed99e2833b2ac9f7b7493f6e464ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwigle</media:title>
		</media:content>

		<media:content url="http://pwigle.files.wordpress.com/2009/12/vcs-settings.png" medium="image">
			<media:title type="html">VCS Settings for Metrics</media:title>
		</media:content>

		<media:content url="http://pwigle.files.wordpress.com/2009/12/buildrunner.png" medium="image">
			<media:title type="html">Build runner configuration in Team City</media:title>
		</media:content>

		<media:content url="http://pwigle.files.wordpress.com/2009/12/graphs.png" medium="image">
			<media:title type="html">TeamCity Metrics graphs</media:title>
		</media:content>
	</item>
		<item>
		<title>Test-Driven Developers have more fun</title>
		<link>http://pwigle.wordpress.com/2008/12/19/test-driven-developers-have-more-fun/</link>
		<comments>http://pwigle.wordpress.com/2008/12/19/test-driven-developers-have-more-fun/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 12:21:58 +0000</pubDate>
		<dc:creator>pwigle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://pwigle.wordpress.com/?p=54</guid>
		<description><![CDATA[I started using TDD a couple of months ago and what strikes me now is how much more fun it is to develop in this radically new way. There are several reasons for this. A common frustration when developing in the traditional way is that the progress is not immediately visible. This is particularly true [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=54&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I started using <a href="http://en.wikipedia.org/wiki/Test-driven_development">TDD</a> a couple of months ago and what strikes me now is how much more fun it is to develop in this radically new way. There are several reasons for this.</p>
<p>A common frustration when developing in the traditional way is that the progress is not immediately visible. This is particularly true in larger projects. You write a lot of code before you get something that is working and can be demonstrated. With TDD, every new passing test is a clear sign of a small step forward.</p>
<p>Another common cause for frustration and dissatisfaction for a professional developer is that many times you are not confident that your code is working as expected. If you apply TDD, allmost 100% of your code will be covered by tests and that will make you confident that the code is doing the right thing.</p>
<p>In the past I have sometimes suffered from &#8220;code writer&#8217;s block&#8221; when I&#8217;m trying so hard to get the design right from the beginning that I couldn&#8217;t produce any code at all. With TDD you don&#8217;t have to get it right from the start. The tests allows you to try out different designs and easily refactor the code without breaking it.</p>
<p>Every now and then I try to write some code for a hobby project, but I rarely got more than an hour or two free for coding at home. A TDD roundtrip of &#8220;red &#8211; green &#8211; refactor&#8221; typically takes less than two hours to complete, which means that even though I have very limited time I can still make som progress by adding at least one passing test every time I get a chance to write some code at home.</p>
<h3>Conclusion</h3>
<p>By applying TDD you will get greater job satisfaction as a developer. You will get feedback serveral times a day that you are making progress. You will be more confident that the code you are delivering is working as expected and you will find it easier to experiment with the design, thus giving you more freedom.</p>
<p>Feedback, confidence and freedom are factors that will make you enjoy your profession even more. Don&#8217;t miss an oppurtunity to have more fun at work and with your hobby projects &#8211; jump on the TDD bandwagon now!!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pwigle.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pwigle.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pwigle.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pwigle.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pwigle.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pwigle.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pwigle.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pwigle.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pwigle.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pwigle.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pwigle.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pwigle.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pwigle.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pwigle.wordpress.com/54/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=54&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://pwigle.wordpress.com/2008/12/19/test-driven-developers-have-more-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/35ed99e2833b2ac9f7b7493f6e464ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwigle</media:title>
		</media:content>
	</item>
		<item>
		<title>NHibernate Session handling in ASP.NET &#8211; the easy way</title>
		<link>http://pwigle.wordpress.com/2008/11/21/nhibernate-session-handling-in-aspnet-the-easy-way/</link>
		<comments>http://pwigle.wordpress.com/2008/11/21/nhibernate-session-handling-in-aspnet-the-easy-way/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 21:59:10 +0000</pubDate>
		<dc:creator>pwigle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://pwigle.wordpress.com/?p=10</guid>
		<description><![CDATA[EDIT: Take a look at a new blog post of mine on this subject. When I first started using the popular ORM framework NHibernate, I was a bit confused about the best way to manage NHibernate sessions in a web application. The official documentation did not provide much guidance, but I did find out that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=10&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>EDIT: Take a look at a <a href="http://pwigle.wordpress.com/2010/09/16/nhibernate-session-handling-revisited/">new blog post of mine</a> on this subject.</p>
<p>When I first started using the popular ORM framework <a href="http://www.nhibernate.org">NHibernate</a>, I was a bit confused about the best way to manage NHibernate sessions in a web application. The official documentation did not provide much guidance, but I did find out that the pattern <a href="http://www.hibernate.org/43.html">Open Session In View</a> was the way to go. The obvious question was: how do I implement this pattern in the context of an ASP.NET application?</p>
<p>The implementation that was proposed in the otherwise great article <a href="http://www.codeproject.com/KB/architecture/NHibernateBestPractices.aspx">NHibernate Best Practices</a> seemed overly complicated. There must be a simpler way to do this. After reading the documenation again I found that there is a feature in NHibernate called <a href="http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/architecture.html#architecture-current-session">Contextual Sessions</a>.</p>
<p>The basic idea with contextual sessions is that in order to get a reference to an instance of <code>ISession</code> you simply call the method <code>GetCurrentSession()</code> that is defined in the interface <code>ISessionFactory</code>. The call to <code>GetCurrentSession()</code> is delegated to a class specified by the configuration parameter <code>hibernate.current_session_context_class</code>. This class implements the interface <code>NHibernate.Context.ICurrentSessionContext</code>. Out-of-the-box NHibernate provides one implementation of this interface, <code>NHibernate.Context.ManagedWebSessionContext</code>, which tracks current sessions by <code>HttpContext</code>. That is exactly what we want in order to implement the Open Session In View pattern.</p>
<p>What we need to do in order to utilize the ManagedWebSessionContext is to bind the current <code>HttpContext</code> to an open session at the beginning of each request and then unbind the session to the context at the end of each request. The easiest way to do this is to use the <code>Application_BeginRequest</code> and <code>Application_EndRequest</code> event handlers in <code>Global.asax</code>. You could of course implement your own <code>HttpModule</code> and do the bindind and unbinding there, if you for some reason don&#8217;t want to use <code>Global.asax</code>.</p>
<p>Now it is time to show you some code! First of all you have to implement a session manager. I have implemented the session manager as a <a href="http://www.yoda.arachsys.com/csharp/singleton.html">lazy, lock-free, thread-safe singleton</a>:</p>
<pre class="csharpcode"><span class="kwrd">using</span> NHibernate;
<span class="kwrd">using</span> NHibernate.Cfg;

<span class="kwrd">namespace</span> DataAccess
{

    <span class="kwrd">public</span> <span class="kwrd">class</span> SessionManager
    {
        <span class="kwrd">private</span> <span class="kwrd">readonly</span> ISessionFactory sessionFactory;
        <span class="kwrd">public</span> <span class="kwrd">static</span> ISessionFactory SessionFactory
        {
            get { <span class="kwrd">return</span> Instance.sessionFactory; }
        }

        <span class="kwrd">private</span> ISessionFactory GetSessionFactory()
        {
            <span class="kwrd">return</span> sessionFactory;
        }

        <span class="kwrd">public</span> <span class="kwrd">static</span> SessionManager Instance
        {
            get {
                <span class="kwrd">return</span> NestedSessionManager.sessionManager; }
        }

        <span class="kwrd">public</span> <span class="kwrd">static</span> ISession OpenSession()
        {
            <span class="kwrd">return</span> Instance.GetSessionFactory().OpenSession();
        }

        <span class="kwrd">public</span> <span class="kwrd">static</span> ISession CurrentSession
        {
            get
            {
                <span class="kwrd">return</span> Instance.GetSessionFactory().GetCurrentSession();
            }
        }

        <span class="kwrd">private</span> SessionManager()
        {
            Configuration configuration = <span class="kwrd">new</span> Configuration().Configure();
            sessionFactory = configuration.BuildSessionFactory();
        }

        <span class="kwrd">class</span> NestedSessionManager
        {
            <span class="kwrd">internal</span> <span class="kwrd">static</span> <span class="kwrd">readonly</span> SessionManager sessionManager =
                <span class="kwrd">new</span> SessionManager();
        }
    }
}</pre>
<p>The binding and unbinding of the NHibernate session to the current HttpContext is done in Global.asax:</p>
<pre class="csharpcode">        <span class="kwrd">protected</span> <span class="kwrd">void</span> Application_BeginRequest(
            <span class="kwrd">object</span> sender, EventArgs e)
        {
            ManagedWebSessionContext.Bind(
                HttpContext.Current,
                SessionManager.SessionFactory.OpenSession());
        }

        <span class="kwrd">protected</span> <span class="kwrd">void</span> Application_EndRequest(
            <span class="kwrd">object</span> sender, EventArgs e)
        {
            ISession session = ManagedWebSessionContext.Unbind(
                HttpContext.Current, SessionManager.SessionFactory);
            <span class="kwrd">if</span> (session != <span class="kwrd">null</span>)
            {
                <span class="kwrd">if</span> (session.Transaction != <span class="kwrd">null</span> &amp;&amp;
                    session.Transaction.IsActive)
                {
                    session.Transaction.Rollback();
                }
                <span class="kwrd">else</span>
                    session.Flush();
                session.Close();
            }
        }</pre>
<p>The reason for the rollback of open transaction in <code>Application_EndRequest</code> is to ensure that the transaction is not committed in case of an uncaught exception.</p>
<p>Finally we have to configure NHibernate to use the <code>ManagedWebSessionContext</code>, by setting the parameter <code>current_session_context_class</code>. There is a short name that can be used, &#8220;managed_web&#8221;. In your web.config file you add the following property:</p>
<pre class="csharpcode">&lt;hibernate-configuration xmlns=<span class="str">"urn:nhibernate-configuration-2.2"</span>&gt;
    &lt;session-factory&gt;
        ...
        &lt;property name=<span class="str">"current_session_context_class"</span>&gt;
            managed_web
        &lt;/property&gt;
        ...
    &lt;/session-factory&gt;
&lt;/hibernate-configuration&gt;</pre>
<p>Now the property SessionManager.CurrentSession holds a reference to an open NHibernate session on every HTTP request. The usage is illustrated in the example code snippet below:</p>
<pre class="csharpcode">    ISession session = SessionManager.CurrentSession;
    session.BeginTransaction();
    Issue issue = <span class="kwrd">new</span> Issue();
    issue.Heading = txtHeading.Text;
    <span class="kwrd">int</span> id = (<span class="kwrd">int</span>)session.Save(issue);
    session.Transaction.Commit();
    lblCreated.Text = <span class="str">"Created issue with id: "</span> + id;</pre>
<p>As you can see this code snippet is taken from a code-behind file. In a real application you would of course put the code related to NHibernate into a DAO or Repository class.</p>
<h3>Conclusion</h3>
<p>What I have showed in this post is just one way of handling NHibernate sessions in an ASP.NET application. Another option which I haven&#8217;t investigated yet is to use the promising framework <a href="http://nhforge.org/media/p/9.aspx">NHibernate Burrow</a>. Maybe I will dig into that in another blog post.</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fpwigle.wordpress.com%2f2008%2f11%2f21%2fnhibernate-session-handling-in-aspnet-the-easy-way%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fpwigle.wordpress.com%2f2008%2f11%2f21%2fnhibernate-session-handling-in-aspnet-the-easy-way%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pwigle.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pwigle.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pwigle.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pwigle.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pwigle.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pwigle.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pwigle.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pwigle.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pwigle.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pwigle.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pwigle.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pwigle.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pwigle.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pwigle.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=10&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://pwigle.wordpress.com/2008/11/21/nhibernate-session-handling-in-aspnet-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/35ed99e2833b2ac9f7b7493f6e464ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwigle</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fpwigle.wordpress.com%2f2008%2f11%2f21%2fnhibernate-session-handling-in-aspnet-the-easy-way%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Deploying ASP.NET Web Applications using NAnt</title>
		<link>http://pwigle.wordpress.com/2008/11/21/deploying-aspnet-web-applications-using-nant/</link>
		<comments>http://pwigle.wordpress.com/2008/11/21/deploying-aspnet-web-applications-using-nant/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 21:57:56 +0000</pubDate>
		<dc:creator>pwigle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Continuous-Integration]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[NAnt]]></category>
		<category><![CDATA[TeamCity]]></category>

		<guid isPermaLink="false">http://pwigle.wordpress.com/?p=9</guid>
		<description><![CDATA[We have started implementing Contiuous Integration at our company. We began with Cruise Control.NET but have decided to try with TeamCity instead. One thing that we would like to do is to deploy ASP.NET web applications as part of our Continuous Integration process. We use the Web Application Project template in Visual Studio. One problem [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=9&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We have started implementing Contiuous Integration at our company. We began with Cruise Control.NET but have decided to try with <a href="http://www.jetbrains.com/teamcity/">TeamCity</a> instead. One thing that we would like to do is to deploy ASP.NET web applications as part of our Continuous Integration process. We use the Web Application Project template in Visual Studio. One problem that we faced was: How can we copy all the neccesary files to the web server? We didn&#8217;t want to specify the files explicitly nor did we want to copy all files with certain file name extensions. Those approaches seemed very error-prone.</p>
<p>The first approach we used with Cruise Control.NET was to use the MSBuild target <code>_CopyWebApplication</code> which is defined in Microsoft.WebApplication.targets. I was not very pleased with this solution, although it worked. My main concern that we didn&#8217;t have any control over the process. When we started with TeamCity it turned out that this approach was not working anymore. The <code>_CopyWebApplication</code> target copies all files needed for the web application to a directory called <code>_PublishedWebSites\&lt;web application project name&gt;</code>. For some reason (probably a good one), TeamCity mangles the name of the project file, with the effect that the name of the directory where the web application files were copied to had a different name than expected.</p>
<p>So I decided to try another approach. Since I like <a href="http://nant.sourceforge.net/">NAnt</a> much more than MSBuild, I started to explore if it was possible to use NAnt for this task. The main problem was that the valuable information on which content files were part of the application was buried in the project file. To utilize this information I used an XSL transformation to transform parts of the project file (which is an MSBuild script) into a NAnt script.</p>
<p>We would like to select all the files where the <em>Build Action</em> property is set to <em>Content</em>. Those files are listed in the project file as a Content element, like in this example:</p>
<pre class="csharpcode">  <span class="kwrd">&lt;</span><span class="html">ItemGroup</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Content</span> <span class="attr">Include</span><span class="kwrd">="Default.aspx"</span> <span class="kwrd">/&gt;</span></pre>
<p>Hence they can be selected with the XPath expression: <code>/Project/ItemGroup/Content</code>.</p>
<p>What I wanted my XSLT script to do was to create a NAnt script with the following content:</p>
<ol>
<li>A fileset with all the content files included
<li>A target which copies the files in the fileset to some directory defined by a property. </li>
</ol>
<p>This is what I came up with:</p>
<pre class="csharpcode"><span class="kwrd">&lt;?</span><span class="html">xml</span> <span class="attr">version</span><span class="kwrd">="1.0"</span> <span class="attr">encoding</span><span class="kwrd">="utf-8"</span>?<span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">xsl:stylesheet</span>
    <span class="attr">version</span><span class="kwrd">="1.0"</span>
    <span class="attr">xmlns:xsl</span><span class="kwrd">="http://www.w3.org/1999/XSL/Transform"</span>
    <span class="attr">xmlns:msxsl</span><span class="kwrd">="urn:schemas-microsoft-com:xslt"</span>
    <span class="attr">exclude-result-prefixes</span><span class="kwrd">="msxsl"</span>
    <span class="attr">xmlns:s</span><span class="kwrd">="http://schemas.microsoft.com/developer/
        msbuild/2003"<span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">xsl:output</span> <span class="attr">method</span><span class="kwrd">="xml"</span> <span class="attr">indent</span><span class="kwrd">="yes"</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">xsl:template</span> <span class="attr">match</span><span class="kwrd">="/"</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">project</span>
            <span class="attr">xmlns</span><span class="kwrd">="http://nant.sf.net/release/0.85/nant.xsd"</span>
            <span class="attr">name</span><span class="kwrd">="GeneratedFromMsbuild"</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">fileset</span> <span class="attr">id</span><span class="kwrd">="content.files"</span>
                <span class="attr">basedir</span><span class="kwrd">="${{project.root}}"</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">xsl:for-each</span> <span class="attr">select</span><span class="kwrd">=
                    "/s:Project/s:ItemGroup/s:Content"</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">include</span> <span class="attr">name</span><span class="kwrd">="{@Include}"</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">xsl:for-each</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">fileset</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">target</span> <span class="attr">name</span><span class="kwrd">="copy.content"</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">copy</span> <span class="attr">todir</span><span class="kwrd">="${{destination.dir}}"</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">fileset</span> <span class="attr">refid</span><span class="kwrd">="content.files"</span><span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">copy</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">target</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">project</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">xsl:template</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">xsl:stylesheet</span><span class="kwrd">&gt;</span></pre>
<p>The following excerpt from our main NAnt script shows how the XLS transformation is invoked and how the resulting script is used to copy the content files:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">target</span> <span class="attr">name</span><span class="kwrd">="deploy.web"</span> <span class="attr">depends</span><span class="kwrd">="generatenant"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">nant</span> <span class="attr">buildfile</span><span class="kwrd">="${generated.file}"</span> <span class="attr">target</span><span class="kwrd">="copy.content"</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">properties</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">property</span> <span class="attr">name</span><span class="kwrd">="project.root"</span>
                <span class="attr">value</span><span class="kwrd">="${web.projectrootdir}"</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">property</span> <span class="attr">name</span><span class="kwrd">="destination.dir"</span>
                <span class="attr">value</span><span class="kwrd">="${web.rootdir}"</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">properties</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">nant</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">copy</span>
       <span class="attr">todir</span><span class="kwrd">="${web.rootdir}\bin"</span><span class="kwrd">&gt;</span>
       <span class="kwrd">&lt;</span><span class="html">fileset</span> <span class="attr">basedir</span><span class="kwrd">="${web.projectrootdir}\bin"</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">include</span> <span class="attr">name</span> <span class="kwrd">="*.*"</span><span class="kwrd">/&gt;</span>
       <span class="kwrd">&lt;/</span><span class="html">fileset</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;/</span><span class="html">copy</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">target</span><span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">target</span> <span class="attr">name</span><span class="kwrd">="generatenant"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">delete</span> <span class="attr">file</span><span class="kwrd">="${generated.file}"</span> <span class="attr">failonerror</span><span class="kwrd">="false"</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">style</span> <span class="attr">style</span><span class="kwrd">="GenerateNantFromMSBuild.xslt"</span>
        <span class="attr">in</span><span class="kwrd">="${web.projectrootdir}/${web.projectfilename}"</span>
        <span class="attr">out</span><span class="kwrd">="${generated.file}"</span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">target</span><span class="kwrd">&gt;</span></pre>
<h3>Closing remarks</h3>
<p>Of course there are several other ways of accomplishing this, like using a Web Deployment Project, but I personally like having full control of what is going on and that can be achieved with NAnt.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pwigle.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pwigle.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pwigle.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pwigle.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pwigle.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pwigle.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pwigle.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pwigle.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pwigle.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pwigle.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pwigle.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pwigle.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pwigle.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pwigle.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=9&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://pwigle.wordpress.com/2008/11/21/deploying-aspnet-web-applications-using-nant/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/35ed99e2833b2ac9f7b7493f6e464ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwigle</media:title>
		</media:content>
	</item>
		<item>
		<title>Here is my blog</title>
		<link>http://pwigle.wordpress.com/2008/11/21/here-is-my-blog/</link>
		<comments>http://pwigle.wordpress.com/2008/11/21/here-is-my-blog/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 21:32:57 +0000</pubDate>
		<dc:creator>pwigle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://pwigle.wordpress.com/?p=5</guid>
		<description><![CDATA[After having thought about it for a long time, I finally decided to start my own blog. I will blog about things that are related to my work as a .NET developer, such as: Solutions to technical problems that I have encountered Technical books, blog posts and articles I have read Reports from conferences and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=5&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After having thought about it for a long time, I finally decided to start my own blog.</p>
<p>I will blog about things that are related to my work as a .NET developer, such as:</p>
<ul>
<li>Solutions to technical problems that I have encountered
<li>Technical books, blog posts and articles I have read
<li>Reports from conferences and training courses
<li>Development tools and frameworks
<li>Adoption of agile principles and practices </li>
</ul>
<p>I hope you will enjoy this blog and find it useful.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pwigle.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pwigle.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pwigle.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pwigle.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pwigle.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pwigle.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pwigle.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pwigle.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pwigle.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pwigle.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pwigle.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pwigle.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pwigle.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pwigle.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pwigle.wordpress.com&amp;blog=5596364&amp;post=5&amp;subd=pwigle&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy"></div>]]></content:encoded>
			<wfw:commentRss>http://pwigle.wordpress.com/2008/11/21/here-is-my-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/35ed99e2833b2ac9f7b7493f6e464ca2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pwigle</media:title>
		</media:content>
	</item>
	</channel>
</rss>
