<?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/"
	>

<channel>
	<title>Ola Kodar</title>
	<atom:link href="http://ola.kodar.se/feed/" rel="self" type="application/rss+xml" />
	<link>http://ola.kodar.se</link>
	<description>Sharing is caring</description>
	<lastBuildDate>Sun, 13 Nov 2011 19:54:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Document based sagas for dummies</title>
		<link>http://ola.kodar.se/2011/11/13/document-based-sagas-for-dummies/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=document-based-sagas-for-dummies</link>
		<comments>http://ola.kodar.se/2011/11/13/document-based-sagas-for-dummies/#comments</comments>
		<pubDate>Sun, 13 Nov 2011 19:54:28 +0000</pubDate>
		<dc:creator>Ola Herrdahl</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ola.kodar.se/?p=347</guid>
		<description><![CDATA[In previous two post, CQRS for dummies and CQRS for developers we saw how to derive our target architecture from an ordinary night at the bar. However in those to post we only considered things going on in our own head. This post will be about all the things going on around us, about how [...]]]></description>
			<content:encoded><![CDATA[<p>In previous two post, <a href="http://ola.kodar.se/2011/11/13/cqrs-for-dummies/">CQRS for dummies</a> and <a href="http://ola.kodar.se/2011/11/13/cqrs-for-developers/">CQRS for developers</a> we saw how to derive our target architecture from an ordinary night at the bar. However in those to post we only considered things going on in our own head. This post will be about all the things going on around us, about how we interact with other people to complete tasks in a collaborative manor.</p>
<p>Now, how do we usually go about solving things collaboratively?</p>
<p>We create a <a href="http://en.wikipedia.org/wiki/Form_(document)">form/document</a> for it!</p>
<p>Forms are simple documents with some basic guidance built into them telling the current actor how to completing it. E.g. sections that state <em>to be filled in by applicant</em> so that the applicant know which part of the form he or she need to sign without any additional information. But it also contains information on where to send the document so that the process can continue.<br />
(See real world example <a href="http://www.kth.se/polopoly_fs/1.171958!/Menu/general/column-content/attachment/Degree%20Project%20090423.pdf">here</a>.)</p>
<p>These documents can be copied, completed in partial and later merged by different actors.<br />
A better example of a more complex process is the <a href="http://ola.kodar.se/docs/DegreeForm.htm">degree project form</a> that contains lots of steps that involve many different actors.</p>
<p>Now start applying this way of modeling your processes in software too.</p>
]]></content:encoded>
			<wfw:commentRss>http://ola.kodar.se/2011/11/13/document-based-sagas-for-dummies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CQRS for developers</title>
		<link>http://ola.kodar.se/2011/11/13/cqrs-for-developers/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cqrs-for-developers</link>
		<comments>http://ola.kodar.se/2011/11/13/cqrs-for-developers/#comments</comments>
		<pubDate>Sun, 13 Nov 2011 17:46:44 +0000</pubDate>
		<dc:creator>Ola Herrdahl</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[CQRS]]></category>

		<guid isPermaLink="false">http://ola.kodar.se/?p=342</guid>
		<description><![CDATA[From the CQRS for dummies post we can extract a couple of important concepts. Non blocking operations, we can continue to speak even when our conscience is gone. Eventual consistency due to persistent storage of past events, the conscience was able to get back in synch without missing that we did break some of it [...]]]></description>
			<content:encoded><![CDATA[<p>From the <a href="http://ola.kodar.se/2011/11/13/cqrs-for-dummies/">CQRS for dummies</a> post we can extract a couple of important concepts.</p>
<p>Non blocking operations, we can continue to speak even when our conscience is gone.</p>
<p>Eventual consistency due to persistent storage of past events, the conscience was able to get back in synch without missing that we did break some of it rules.</p>
<p>Compensating actions do not have to put the system back in a consistent state. Your flowers might not be enough. Some events can simple not be compensated.</p>
<p>Building systems that meet these requirements are hard.<br />
Applying <em>Forget it ever happened</em> is typical in conflict with persistent storage of past events.</p>
<p>A perfectly valid real world example of when we need <em>Forget it ever happened</em> is when, by mistake, we associate a person’s new hidden identity with his old identity in our database. Do you know how much fun it is building a bullet proof auditing system just to realize we need to erase a record in it?</p>
<p>Every time we by mistake reveal a secret; we would love to have the ability to forget that the thing ever happened.</p>
]]></content:encoded>
			<wfw:commentRss>http://ola.kodar.se/2011/11/13/cqrs-for-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CQRS for dummies</title>
		<link>http://ola.kodar.se/2011/11/13/cqrs-for-dummies/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cqrs-for-dummies</link>
		<comments>http://ola.kodar.se/2011/11/13/cqrs-for-dummies/#comments</comments>
		<pubDate>Sun, 13 Nov 2011 16:25:52 +0000</pubDate>
		<dc:creator>Ola Herrdahl</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[CQRS]]></category>

		<guid isPermaLink="false">http://ola.kodar.se/?p=339</guid>
		<description><![CDATA[Most of us have been in situations where a part of our self starts acting on its own. One example of this is the common situation when we open our mouth and starts speaking before thinking. Somewhere in our brains there is a process (our conscience) that will stop us from saying dumb things.  If [...]]]></description>
			<content:encoded><![CDATA[<p>Most of us have been in situations where a part of our self starts acting on its own.<br />
One example of this is the common situation when we open our mouth and starts speaking before thinking.</p>
<p>Somewhere in our brains there is a process (our conscience) that will stop us from saying dumb things.  If this process is operating in a degraded mode, it won’t be able to keep up the pace with the process currently in charge of “the speaking”. Instead of blocking your ability to speak at all it will just let you continue the conversation but without the ability for you to double check every sentence you are about to speak in your mind (e.g. we have lost contact with our conscience).</p>
<p>After each of these accidents we typically start feeling guilty after a while. This feeling typically occurs when our conscience has gotten back to speed and realized what just had happen a couple of moments (or hours) ago. Our conscience obviously has the ability to queue up work for later processing.</p>
<p>The guilt you are now feeling is most probably telling you that you need to correct yourself by performing an excuse. This action is called a compensating action. Whenever we realized that we were wrong we get this urge of doing something to compensate for it.</p>
<p>But there are many ways of performing these actions. An excuse can be delivered on a card along with flowers. Or we could just apply a quite popular pattern called <em>Forget it ever happened</em>. Either way, we have performed some sort of compensating action due to the fact that our conscience was unable to operate there for a moment.</p>
<p>Now, instead of applying this to yourself on a typical Friday night, apply it to your system!</p>
]]></content:encoded>
			<wfw:commentRss>http://ola.kodar.se/2011/11/13/cqrs-for-dummies/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Access a Mercurial (BitBucket) repository using SSH key from TeamCity</title>
		<link>http://ola.kodar.se/2011/09/15/using-ssh-teamcity-mercurial/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-ssh-teamcity-mercurial</link>
		<comments>http://ola.kodar.se/2011/09/15/using-ssh-teamcity-mercurial/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 15:21:02 +0000</pubDate>
		<dc:creator>Ola Herrdahl</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[bitbucket]]></category>
		<category><![CDATA[hg]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://ola.kodar.se/?p=323</guid>
		<description><![CDATA[This post outlines the problem pretty well as wall as part of the solution: http://weichhold.com/2010/08/12/using-mercurial-over-ssh-with-private-key-in-teamcity-ci/ However our build server did not read the mecurial.ini file when placed in the SysWOW64/config/systemprofile folder. (You can test this by running hg showconfig from the console running under the systems account.) Instead we had to place it in the [...]]]></description>
			<content:encoded><![CDATA[<p>This post outlines the problem pretty well as wall as part of the solution:<br />
<a href="http://weichhold.com/2010/08/12/using-mercurial-over-ssh-with-private-key-in-teamcity-ci/">http://weichhold.com/2010/08/12/using-mercurial-over-ssh-with-private-key-in-teamcity-ci/</a></p>
<p>However our build server did not read the mecurial.ini file when placed in the SysWOW64/config/systemprofile folder.<br />
(You can test this by running <em>hg showconfig</em> from the console running under the systems account.)</p>
<p>Instead we had to place it in the TortoiseHG installation folder.<br />
We also tweaked it a bit according to the <a href="http://confluence.atlassian.com/display/BITBUCKET/Using+SSH+to+Access+your+Bitbucket+Repository">BitBucket documentation on SSH</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="cmd" style="font-family:monospace;">[ui]
ssh = &quot;TortoisePlink.exe&quot; -ssh -2 -batch -C -i &quot;c:\path\to\key.ppk&quot;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ola.kodar.se/2011/09/15/using-ssh-teamcity-mercurial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up kdiff3 for git on windows</title>
		<link>http://ola.kodar.se/2011/06/22/setting-up-kdiff3-for-git-on-windows/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=setting-up-kdiff3-for-git-on-windows</link>
		<comments>http://ola.kodar.se/2011/06/22/setting-up-kdiff3-for-git-on-windows/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 16:09:44 +0000</pubDate>
		<dc:creator>Ola Herrdahl</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[kdiff3]]></category>
		<category><![CDATA[merge]]></category>
		<category><![CDATA[mergetool]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://ola.kodar.se/?p=302</guid>
		<description><![CDATA[Install kdiff3 (I use the version bundled with TortoiseHg). run the following commands in the git bash: git config --global merge.tool kdiff3 git config --global mergetool.kdiff3.path &#34;C:\Program Files\TortoiseHg\kdiff3.exe&#34; merge! git mergetool]]></description>
			<content:encoded><![CDATA[<ol>
<li>Install kdiff3 (I use the version bundled with TortoiseHg).</li>
<li>run the following commands in the git bash:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> config <span style="color: #660033;">--global</span> merge.tool kdiff3
<span style="color: #c20cb9; font-weight: bold;">git</span> config <span style="color: #660033;">--global</span> mergetool.kdiff3.path <span style="color: #ff0000;">&quot;C:\Program Files<span style="color: #000099; font-weight: bold;">\T</span>ortoiseHg\kdiff3.exe&quot;</span></pre></div></div>

</li>
<li>merge!

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> mergetool</pre></div></div>

</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://ola.kodar.se/2011/06/22/setting-up-kdiff3-for-git-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Never version things by date</title>
		<link>http://ola.kodar.se/2011/05/31/never-version-things-by-date/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=never-version-things-by-date</link>
		<comments>http://ola.kodar.se/2011/05/31/never-version-things-by-date/#comments</comments>
		<pubDate>Tue, 31 May 2011 15:57:46 +0000</pubDate>
		<dc:creator>Ola Herrdahl</dc:creator>
				<category><![CDATA[Error of the Day]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[version]]></category>

		<guid isPermaLink="false">http://ola.kodar.se/?p=292</guid>
		<description><![CDATA[Suddenly our CI-machine started to fail on code that we had not touched for ages. Test(s) failed. Expected string length 6 but was 4. Strings differ at index 0. Expected: &#8220;foobar&#8221; But was: &#8220;test&#8221; The test that broke the build was very straight forward: &#91;Test&#93; public void SettingsShouldSupportCRUD&#40;&#41; &#123; ApplicationSetting.Delete&#40;&#34;Test.ABC&#34;&#41;; &#160; var setting = ApplicationSetting.Get&#40;&#34;Test.ABC&#34;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Suddenly our CI-machine started to fail on code that we had not touched for ages.</p>
<blockquote><p>
Test(s) failed.   Expected string length 6 but was 4. Strings differ at index 0.<br />
  Expected: &#8220;foobar&#8221;<br />
  But was:  &#8220;test&#8221;
</p></blockquote>
<p>The test that broke the build was very straight forward:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> SettingsShouldSupportCRUD<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            ApplicationSetting<span style="color: #008000;">.</span><span style="color: #0000FF;">Delete</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Test.ABC&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            var setting <span style="color: #008000;">=</span> ApplicationSetting<span style="color: #008000;">.</span><span style="color: #0000FF;">Get</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Test.ABC&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">IsNull</span><span style="color: #008000;">&#40;</span>setting<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            ApplicationSetting<span style="color: #008000;">.</span><span style="color: #0000FF;">Set</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Test.ABC&quot;</span>, <span style="color: #666666;">&quot;test&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Create</span>
&nbsp;
            setting <span style="color: #008000;">=</span> ApplicationSetting<span style="color: #008000;">.</span><span style="color: #0000FF;">Get</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Test.ABC&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Read</span>
&nbsp;
            Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;test&quot;</span>, setting<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            ApplicationSetting<span style="color: #008000;">.</span><span style="color: #0000FF;">Set</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Test.ABC&quot;</span>, <span style="color: #666666;">&quot;foobar&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Update</span>
&nbsp;
            setting <span style="color: #008000;">=</span> ApplicationSetting<span style="color: #008000;">.</span><span style="color: #0000FF;">Get</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Test.ABC&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;foobar&quot;</span>, setting<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            ApplicationSetting<span style="color: #008000;">.</span><span style="color: #0000FF;">Delete</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Test.ABC&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Delete</span>
&nbsp;
            setting <span style="color: #008000;">=</span> ApplicationSetting<span style="color: #008000;">.</span><span style="color: #0000FF;">Get</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Test.ABC&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">IsNull</span><span style="color: #008000;">&#40;</span>setting<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

<p>Notice how we do the update here.<br />
A setting is an immutable object in this system so we use the same semantics as when creating.</p>
<p>So instead of modifying the old object, we just bind the key to the new value using the set method and make sure we always return the latest object upon get.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> Get<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> key<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            var result <span style="color: #008000;">=</span> ActiveRecordMediator<span style="color: #008000;">&lt;</span>ApplicationSetting<span style="color: #008000;">&gt;.</span><span style="color: #0000FF;">FindAllByProperty</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Date&quot;</span>, <span style="color: #666666;">&quot;Name&quot;</span>, key<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>result<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> result<span style="color: #008000;">.</span><span style="color: #0000FF;">Last</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

<p>As you can see, the get method is pretty trivial as well, just fetch all the settings for a given key ordered by date and return the youngest.</p>
<p>So why is this code broken?</p>
<p>I had to dig into the database to see what was going on here.<br />
By putting a breakpoint in the test just before the last call to Delete I could dump the data before it was deleted.</p>
<pre>
(1, 'application', '2011-05-31 16:54:04', 'Test.ABC', 'test')
(2, 'application', '2011-05-31 16:54:04', 'Test.ABC', 'foobar')
</pre>
<p>According the time-stamp the two settings where both created at the same time and obviously that was bad.<br />
(And what makes it extra bad is that <a href="http://bugs.mysql.com/bug.php?id=8523">MySQL only supports precision down to a second</a>.)</p>
<p>The assumption when writing this code was that such ordering still would be deterministic (e.g. by falling back to using the primary key) but no.<br />
Our failing test just proved that the order might change at any given time.</p>
<p>We solved this by switching to sorting by primary key instead (which is what we should have done from the beginning anyway).<br />
(Here <a href="http://ayende.com/blog/4643/createsequetialuuid-answer">sequential UUIDs</a> come into handy.)</p>
]]></content:encoded>
			<wfw:commentRss>http://ola.kodar.se/2011/05/31/never-version-things-by-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Watin and portable Firefox</title>
		<link>http://ola.kodar.se/2011/03/15/watin-and-portable-firefox/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=watin-and-portable-firefox</link>
		<comments>http://ola.kodar.se/2011/03/15/watin-and-portable-firefox/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 15:40:44 +0000</pubDate>
		<dc:creator>Ola Herrdahl</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://ola.kodar.se/?p=272</guid>
		<description><![CDATA[I stumbled over this thread in the Watin archives and thought that it sounded like a great idea to use a portable bundle of Firefox for our acceptance tests. However it took some more effort in getting this thing to work than just changing the FireFox.PathToExe property. Changing just the property will just make Watin [...]]]></description>
			<content:encoded><![CDATA[<p>I stumbled over <a href="http://sourceforge.net/mailarchive/forum.php?thread_name=AANLkTik6JARc6LphU0hrTePz3zbb5VaI-TqjCEMJMiRs%40mail.gmail.com&#038;forum_name=watin-development">this</a> thread in the Watin archives and thought that it sounded like a great idea to use a <a href="http://PortableApps.com/FirefoxPortable">portable bundle of Firefox</a> for our acceptance tests.</p>
<p>However it took some more effort in getting this thing to work than just changing the <em>FireFox.PathToExe</em> property.<br />
Changing just the property will just make Watin start the portable apps launcher process.<br />
And just because the launcher process is started it does not mean that Firefox has been started yet so here we have a race condition.<br />
Depending on your setup you could get it to work sometimes but must of my tests always failed.</p>
<p>I began by playing around with the portable launcher configuration (FirefoxPortable.ini) for a while but it seemed impossible to get it to work that way so I gave up and downloaded the source for Watin.</p>
<p>I followed the stack trace back to the broken method.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">System.NullReferenceException : Object reference not set to an instance of an object.
at WatiN.Core.Native.Mozilla.FireFoxClientPort.CreateNewFireFoxInstance(String url)
at WatiN.Core.Native.Mozilla.FireFoxClientPort.Connect(String url, Boolean createNewFireFoxInstance)
at WatiN.Core.FireFox.CreateFireFoxInstance(String url)</pre></div></div>

<p>And eventually found the problem in the <em>Firefox.CreateProcess(string arguments, bool waitForMainWindow)</em> method.<br />
After it had created the new process it used this piece of code to halt until the process had been started.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">var result <span style="color: #008000;">=</span> action<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Try</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span>
<span style="color: #008000;">&#123;</span>
    ffProcess<span style="color: #008000;">.</span><span style="color: #0000FF;">Refresh</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>ffProcess<span style="color: #008000;">.</span><span style="color: #0000FF;">HasExited</span> <span style="color: #008000;">&amp;&amp;</span> ffProcess<span style="color: #008000;">.</span><span style="color: #0000FF;">MainWindowHandle</span> <span style="color: #008000;">!=</span> IntPtr<span style="color: #008000;">.</span><span style="color: #0000FF;">Zero</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Logger<span style="color: #008000;">.</span><span style="color: #0000FF;">LogAction</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Waited for FireFox, main window handle found.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>But that piece of code just checks if new process has been started, not if it is the correct process.</p>
<p>Luckily while looking for the issue I notice this property:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #0600FF; font-weight: bold;">static</span> Process CurrentProcess <span style="color: #008000;">&#123;</span>
    get <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>var process <span style="color: #0600FF; font-weight: bold;">in</span> Process<span style="color: #008000;">.</span><span style="color: #0000FF;">GetProcesses</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>  <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>process<span style="color: #008000;">.</span><span style="color: #0000FF;">ProcessName</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;firefox&quot;</span>, StringComparison<span style="color: #008000;">.</span><span style="color: #0000FF;">OrdinalIgnoreCase</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>  <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> process<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The CurrentProcess property will return null if there are no processes named firefox running so it could be used to tell whether or not it is the correct process that has been started.<br />
So I fixed the issue by replacing the <em>ffProcess.MainWindowHandle != IntPtr.Zero</em> condition with a check if the current process is null or not:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">var result <span style="color: #008000;">=</span> action<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Try</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span>
<span style="color: #008000;">&#123;</span>
    ffProcess<span style="color: #008000;">.</span><span style="color: #0000FF;">Refresh</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>ffProcess<span style="color: #008000;">.</span><span style="color: #0000FF;">HasExited</span> <span style="color: #008000;">&amp;&amp;</span> CurrentProcess <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Logger<span style="color: #008000;">.</span><span style="color: #0000FF;">LogAction</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Waited for FireFox, process found.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>(If the Portable Firefox Launcher is started without a splash screen the ffProcess will never have a MainWindowHandle&#8230;)</p>
]]></content:encoded>
			<wfw:commentRss>http://ola.kodar.se/2011/03/15/watin-and-portable-firefox/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Accessing Ubuntu running on Hyper-V over Remote Desktop</title>
		<link>http://ola.kodar.se/2010/11/20/accessing-ubuntu-running-on-hyper-v-over-remote-desktop/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=accessing-ubuntu-running-on-hyper-v-over-remote-desktop</link>
		<comments>http://ola.kodar.se/2010/11/20/accessing-ubuntu-running-on-hyper-v-over-remote-desktop/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 16:54:08 +0000</pubDate>
		<dc:creator>Ola Herrdahl</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Hyper-V]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://ola.kodar.se/?p=257</guid>
		<description><![CDATA[This is a note to self (and anyone else who tries to access a virtual Ubuntu guest on Hyper-V from a RDP-session). Mouse capture does not work in Hyper-V when accessing it from a RDP-session unless you have installed the integration services in the guest OS. (MS does not provide integration services for Ubuntu&#8230;) In [...]]]></description>
			<content:encoded><![CDATA[<p>This is a note to self (and anyone else who tries to access a virtual Ubuntu guest on Hyper-V from a RDP-session).</p>
<p>Mouse capture does not work in Hyper-V when accessing it from a RDP-session unless you have installed the integration services in the guest OS.<br />
(MS does not provide integration services for Ubuntu&#8230;)</p>
<p>In order to work effeciently without the mouse, these two guides will come in handy:</p>
<ol style="list-style: upper-roman outside;">
<li><a href="http://blogs.technet.com/b/jhoward/archive/2008/03/23/controlling-vms-under-hyper-v-without-the-mouse.aspx">Controlling Hyper-V VMs in Virtual Machine Connection over TS/Remote Desktop without a mouse</a></li>
<li><a href="https://help.ubuntu.com/community/KeyboardShortcuts">Keyboard Shortcuts in Ubuntu</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://ola.kodar.se/2010/11/20/accessing-ubuntu-running-on-hyper-v-over-remote-desktop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AuthenticateRequest not raised when doing a Server.Transfer</title>
		<link>http://ola.kodar.se/2010/10/23/authenticaterequest-not-raised-when-doing-a-server-transfer/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=authenticaterequest-not-raised-when-doing-a-server-transfer</link>
		<comments>http://ola.kodar.se/2010/10/23/authenticaterequest-not-raised-when-doing-a-server-transfer/#comments</comments>
		<pubDate>Sat, 23 Oct 2010 16:27:08 +0000</pubDate>
		<dc:creator>Ola Herrdahl</dc:creator>
				<category><![CDATA[Error of the Day]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[csharp]]></category>

		<guid isPermaLink="false">http://ola.kodar.se/?p=246</guid>
		<description><![CDATA[I've recently enhanced a legacy product with support for "custom links" by writing a simple HttpModule. 

The module is very simple, it hooks in to each request and check if a mapping exists for the current path. 
In order to do this all it needs is a simple map of new to old (legacy) paths. 

If a mapping is found, a call to Server.Transfer is done to transfer the request the the correct page.

This worked like a charm until I realized that the AuthenticateRequest was no longer raised when visiting a link that was served using my new module.]]></description>
			<content:encoded><![CDATA[<p><strong>Background</strong><br />
I&#8217;ve recently enhanced a legacy product with support for &#8220;custom links&#8221; by writing a simple HttpModule. (Similar to the <a href="http://msdn.microsoft.com/en-us/library/ms228302.aspx">built in UrlMapping-support</a>, just a little bit more flexible.)</p>
<p>The module is very simple, it hooks in to each request and check if a mapping exists for the current path.<br />
In order to do this all it needs is a simple map of new to old (legacy) paths.<br />
E.g. {/Home => /Page/1/, /About => /Page/24/Article/2}</p>
<p>If a mapping is found, a call to Server.Transfer is done to transfer the request the the correct page.<br />
This worked like a charm and I did not have to touch the legacy application on order to get it working.</p>
<p><strong>The problem</strong><br />
Yesterday I needed to do some minor tweaking in the the legacy application and all when pretty smooth until I hit a page that was served using my module above.</p>
<p>The log output of a working request looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[10] INFO  ASP.global_asax [(null)] - /########################################\
[10] INFO  ASP.global_asax [(null)] - ### Begin Request ########################
[10] INFO  ASP.global_asax [(null)] - /default.aspx
[10] DEBUG ASP.global_asax [(null)] - User IS authenticated.
[10] DEBUG MyProject.Impl.AdminService [(null)] - LoadUserFindUserById(http://ola.kodar.se/)
[10] DEBUG MyProject.Impl.NHibernate.NHibernateHelper [(null)] - Opening a new session [
[10] DEBUG MyProject.Impl.NHibernate.NHibernateHelper [(null)] - 	session: 16143157
[10] DEBUG MyProject.Impl.NHibernate.NHibernateHelper [(null)] - ]
[10] DEBUG MyProject.Impl.NHibernate.GenericManager [(null)] - Executing criteria [
[10] DEBUG MyProject.Impl.NHibernate.GenericManager [(null)] - 	UserId = http://ola.kodar.se
[10] DEBUG MyProject.Impl.NHibernate.GenericManager [(null)] - ]
[10] DEBUG MyProject.Impl.AdminService [(null)] - User found: UserId: http://ola.kodar.se, Name: Ola Herrdahl
...
[10] DEBUG MyProject.Impl.NHibernate.NHibernateHelper [(null)] - Closing session [
[10] DEBUG MyProject.Impl.NHibernate.NHibernateHelper [(null)] - 	session: 16143157
[10] DEBUG MyProject.Impl.NHibernate.NHibernateHelper [(null)] - ]
[10] INFO  ASP.global_asax [(null)] - ### End Request ##########################
[10] INFO  ASP.global_asax [(null)] - /default.aspx
[10] INFO  ASP.global_asax [(null)] - \########################################/</pre></div></div>

<p>But a request that passed my fancy custom http module would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[7] DEBUG MyProject.Web.UrlMappingModule [(null)] - Checking url:/seo-friendly-url
[7] DEBUG MyProject.Web.HttpHandler [(null)] - Processing request [
[7] DEBUG MyProject.Web.HttpHandler [(null)] - 	path: /
[7] DEBUG MyProject.Web.HttpHandler [(null)] - 	name: Page.aspx
[7] DEBUG MyProject.Web.HttpHandler [(null)] - 	AbsolutePath: /Pages/215
[7] DEBUG MyProject.Web.HttpHandler [(null)] - ]
[7] DEBUG MyProject.Web.HttpHandler [(null)] - Transfering user to: /Page.aspx?Pages=215&amp;
[7] DEBUG MyProject.Impl.NHibernate.NHibernateHelper [(null)] - Opening a new session [
[7] DEBUG MyProject.Impl.NHibernate.NHibernateHelper [(null)] - 	session: 21943666
[7] DEBUG MyProject.Impl.NHibernate.NHibernateHelper [(null)] - ]
...
[7] DEBUG MyProject.Impl.NHibernate.NHibernateHelper [(null)] - Closing session [
[7] DEBUG MyProject.Impl.NHibernate.NHibernateHelper [(null)] - 	session: 21943666
[7] DEBUG MyProject.Impl.NHibernate.NHibernateHelper [(null)] - ]
[7] INFO  ASP.global_asax [(null)] - ### End Request ##########################
[7] INFO  ASP.global_asax [(null)] - /seo-friendly-url
[7] INFO  ASP.global_asax [(null)] - \########################################/</pre></div></div>

<p>I noticed that the neither Application_BeginRequest nor Application_AuthenticateRequest (in global.asax) seemed to be called when the request was handled by my UrlMappingModule.<br />
But strangely Application_EndRequest was executed as expected&#8230;</p>
<p>Obviously, my UrlMappingModule was not so unobtrusive as I first thought&#8230;</p>
<p><strong>The investigation</strong><br />
In the custom module I did all the magic upon the BeginRequest event.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Init<span style="color: #008000;">&#40;</span>HttpApplication context<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            context<span style="color: #008000;">.</span><span style="color: #0000FF;">BeginRequest</span> <span style="color: #008000;">+=</span> OnBeginRequest<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>initialized<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                initialized <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                LoadMappings<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

<p>But looking at this again, I realized that doing a Server.Transfer so early in the pipeline was probably a bad idea.<br />
However the <a href="http://msdn.microsoft.com/en-us/library/y4k58xk7(v=VS.100).aspx">HttpServerUtility.Transfer</a> documentation states that:</p>
<blockquote><p>For the current request, terminates execution of the current page and starts execution of a new page by using the specified URL path of the page.</p></blockquote>
<p>This seemed to be ok until I read the remarks:</p>
<blockquote><p>ASP.NET does not verify that the current user is authorized to view the resource delivered by the Transfer method. Although the ASP.NET authorization and authentication logic runs before the original resource handler is called, ASP.NET directly calls the handler indicated by the Transfer method and does not rerun authentication and authorization logic for the new resource. If your application&#8217;s security policy requires clients to have appropriate authorization to access the resource, the application should force reauthorization or provide a custom access-control mechanism.</p></blockquote>
<p>So obviously the <a href="http://msdn.microsoft.com/en-us/library/bb470252.aspx#Stages">request pipeline events</a> are not raised as one might excepted them to be in the page that one is transferring to. </p>
<p><strong>The solution</strong><br />
When doing a server transfer one should probably aim at doing it as late as possible in the HttpApplication pipeline.<br />
In this case, I changed my module to do the transfer call upon the PostAuthenticateRequest event instead of on BeginRequest and everything started working as expected.</p>
]]></content:encoded>
			<wfw:commentRss>http://ola.kodar.se/2010/10/23/authenticaterequest-not-raised-when-doing-a-server-transfer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C programming sucks</title>
		<link>http://ola.kodar.se/2010/09/28/c-programming-sucks/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=c-programming-sucks</link>
		<comments>http://ola.kodar.se/2010/09/28/c-programming-sucks/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 09:51:56 +0000</pubDate>
		<dc:creator>Ola Herrdahl</dc:creator>
				<category><![CDATA[Error of the Day]]></category>
		<category><![CDATA[c/c++]]></category>

		<guid isPermaLink="false">http://ola.kodar.se/?p=239</guid>
		<description><![CDATA[I really love all the cryptic errors you can run into in this fantastic language. void replayAllPastEvents&#40;DumbThing *dumbThing&#41;&#123; // read events from disk, bla bla bla apply&#40;dumbthing, event&#41;; // &#60;- explosion in this call // ... &#125; The code did compile but crashed due to a segmentation fault in the apply function. Can you spot [...]]]></description>
			<content:encoded><![CDATA[<p>I really love all the cryptic errors you can run into in this fantastic language.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> replayAllPastEvents<span style="color: #009900;">&#40;</span>DumbThing <span style="color: #339933;">*</span>dumbThing<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">// read events from disk, bla bla bla</span>
     apply<span style="color: #009900;">&#40;</span>dumbthing<span style="color: #339933;">,</span> event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// &lt;- explosion in this call</span>
     <span style="color: #666666; font-style: italic;">// ...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The code did compile but crashed due to a segmentation fault in the apply function.<br />
Can you spot the error?</p>
<p>It is a minor typo on the apply line. Even when I have removed all the code above that line it is still quite hard to detect. </p>
<p>But why on earth did not the compiler throw an error on this?</p>
<p>It turned out that I had a function called dumbthing defined elsewhere and for some reason, the c-compiler forgot to warn me about this type error here since it was to busy warning about an implicit function declaration instead. It was not until I got tired of debugging this issue and went on to fixing that warning that the real reason behind the crash was revealed.</p>
<p>(And yes I know, fault was all mine in the end, but still, feels lot better blaming somebody else&#8230;)</p>
]]></content:encoded>
			<wfw:commentRss>http://ola.kodar.se/2010/09/28/c-programming-sucks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

