<?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>Rash thoughts about .NET, C#, F# and Dynamics NAV. &#187; .NET</title>
	<atom:link href="http://www.navision-blog.de/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.navision-blog.de</link>
	<description>This Blog is about Microsoft Dynamics NAV (f.k.a Navision incl. C/SIDE and C/AL), C#, F# and .NET in general.</description>
	<lastBuildDate>Sun, 25 Mar 2012 18:34:07 +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>WPF Designer for F#</title>
		<link>http://www.navision-blog.de/2012/03/22/wpf-designer-for-f/</link>
		<comments>http://www.navision-blog.de/2012/03/22/wpf-designer-for-f/#comments</comments>
		<pubDate>Thu, 22 Mar 2012 19:19:10 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[FSharpx]]></category>
		<category><![CDATA[type providers]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/?p=1154</guid>
		<description><![CDATA[F# 3.0 brings the new type providers feature which enables a lot of different applications. Today I’m happy to announce that the FSharpx project brings you a WPF designer for F# in the Visual Studio 11 beta. A big kudos to Johann Deneux for writing the underlying XAML type provider. Create a new F# 3.0 [...]]]></description>
			<content:encoded><![CDATA[<p>F# 3.0 brings the new <a href="http://msdn.microsoft.com/en-us/library/hh156509(v=vs.110).aspx">type providers</a> feature which enables a lot of different applications. Today I’m happy to announce that the <a href="https://github.com/fsharp/fsharpx">FSharpx project</a> brings you a WPF designer for F# in the Visual Studio 11 beta.</p>
<p><a href="http://www.navision-blog.de/images/WPF-Designer-for-F_EDC7/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/WPF-Designer-for-F_EDC7/image_thumb.png" width="504" height="316" /></a></p>
<p>A big kudos to <a href="http://sharp-gamedev.blogspot.de/">Johann Deneux</a> for writing the underlying <a href="https://github.com/fsharp/fsharpx/blob/master/src/FSharpx.TypeProviders/XamlProvider.fs">XAML type provider</a>.</p>
<ol>
<li>Create a new F# 3.0 Console application project </li>
<li>Set the output type to “Windows Application” in the project settings </li>
<li>Use nuget and <em>install-package FSharpx.TypeProviders</em> </li>
<li>Add references to WindowsBase.dll, PresentationFramework.dll, System.Xaml.dll and PresentationCore.dll </li>
<li>Add a Xaml file to your project. Something like this: <script src="https://gist.github.com/2161484.js"> </script></li>
<li>Now you can access the Xaml in a typed way: <script src="https://gist.github.com/2161552.js"> </script></li>
<li>Start the project </li>
</ol>
<p>Enjoy!</p>
<p>BTW: No code generation needed is for this. No more nasty *.xaml.cs files.    <br />BTW2: Try to change the name of Button1 in the Xaml and press save. <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Zwinkerndes Smiley" src="http://www.navision-blog.de/images/WPF-Designer-for-F_112B0/wlEmoticon-winkingsmile.png" /></p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2012/03/22/wpf-designer-for-f/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Why do we need partial application? &#8211; Part 2 of n &#8211; Simulating type classes in C# and F#</title>
		<link>http://www.navision-blog.de/2012/01/31/why-do-we-need-partial-application-part-2-of-n-simulating-type-classes-in-c-and-f/</link>
		<comments>http://www.navision-blog.de/2012/01/31/why-do-we-need-partial-application-part-2-of-n-simulating-type-classes-in-c-and-f/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 16:48:58 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Currying]]></category>
		<category><![CDATA[partial  application]]></category>
		<category><![CDATA[type classes]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/?p=1149</guid>
		<description><![CDATA[This is yet another blog post in my Currying and Partial application series. This is what I have posted so far: Partial application in F# and C# Why do we need partial application? – Part 1 of n – Fluent interfaces and piping Currying and uncurrying in C# and F# In this post I want [...]]]></description>
			<content:encoded><![CDATA[<p>This is yet another blog post in my <a href="http://en.wikipedia.org/wiki/Currying">Currying</a> and <a href="http://en.wikipedia.org/wiki/Partial_application">Partial application</a> series. This is what I have posted so far:</p>
<ul>
<li><a href="http://www.navision-blog.de/2012/01/27/partial-application-if-f-and-c/">Partial application in F# and C#</a> </li>
<li><a href="http://www.navision-blog.de/2012/01/29/why-do-we-need-partial-application-part-1-of-n-fluent-interfaces-and-piping/">Why do we need partial application? – Part 1 of n – Fluent interfaces and piping</a> </li>
<li><a href="http://www.navision-blog.de/2012/01/30/currying-and-uncurrying-in-c-and-f/">Currying and uncurrying in C# and F#</a> </li>
</ul>
<p>In this post I want to show you a way to simulate <a href="http://en.wikipedia.org/wiki/Type_class">type classes</a> in C# and F#. Type classes are this wonderful feature in Haskell which allow you to specify constraints on your polymorphic types. We don’t have this in C# nor F#.</p>
<p>Let’s start with the following problem: We want to compute the sum of the squares of arbitrary numbers. We want to write something like this:</p>
<p><a href="http://www.navision-blog.de/images/Simulating-type-classes-in-C-and-F_F1D3/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/Simulating-type-classes-in-C-and-F_F1D3/image_thumb.png" width="489" height="169" /></a></p>
<p>The problem is we don’t have a generic * function and of course we’d also need a generic + operator and maybe a generic zero. Obviously we need a constraint on the generic parameter T since + might not be defined for any type. So let’s define an interface for numbers:</p>
<p> <script src="https://gist.github.com/1711425.js"> </script>
<p>Nothing special here, so let&#8217;s get straight to the implementation for integers and doubles:</p>
<p> <script src="https://gist.github.com/1711433.js"> </script>
<p>So far so good. With this in our pocket we rewrite SumOfSquares() into this:</p>
<p> <script src="https://gist.github.com/1711443.js"> </script>
<p>The trick is that we pass the concrete implementation as the first parameter into our function. This works exactly like a type constraint or as <a href="http://research.microsoft.com/en-us/people/simonpj/">Simon Peyton-Jones</a> would say: the <a href="http://en.wikipedia.org/wiki/Virtual_method_table">vtable</a> travels into the function. Notice that we don’t have access to the definition of in nor double. There is no way for us to express that int or double implement a number interface.</p>
<p>Now let’s try this out:</p>
<p> <script src="https://gist.github.com/1711474.js"> </script>
<p>As you can see, this is perfectly type safe. We now have a way for poor man’s type classes in C#. Yay!</p>
<p>Now what has this to do with partial application? Let’s look at the same thing in F#:</p>
<p> <script src="https://gist.github.com/1711508.js"> </script>
<p>We&#8217;re using a lot of partial application here. Exercise: Try to spot all the places.</p>
<p>Ok, you’re right. This post might be a little bit far away from the partial application stuff, but it’s still related. Somehow.</p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2012/01/31/why-do-we-need-partial-application-part-2-of-n-simulating-type-classes-in-c-and-f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Currying and uncurrying in C# and F#</title>
		<link>http://www.navision-blog.de/2012/01/30/currying-and-uncurrying-in-c-and-f/</link>
		<comments>http://www.navision-blog.de/2012/01/30/currying-and-uncurrying-in-c-and-f/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 17:00:29 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Currying]]></category>
		<category><![CDATA[partial  application]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/?p=1144</guid>
		<description><![CDATA[In the last couple of days I started to write some posts about Currying and Partial application: Partial application in F# and C# Why do we need partial application? – Part 1 of n – Fluent interfaces and piping This time I want to show you how we can write a higher-order function which allows [...]]]></description>
			<content:encoded><![CDATA[<p>In the last couple of days I started to write some posts about <a href="http://en.wikipedia.org/wiki/Currying">Currying</a> and <a href="http://en.wikipedia.org/wiki/Partial_application">Partial application</a>:</p>
<ul>
<li><a href="http://www.navision-blog.de/2012/01/27/partial-application-if-f-and-c/">Partial application in F# and C#</a> </li>
<li><a href="http://www.navision-blog.de/2012/01/29/why-do-we-need-partial-application-part-1-of-n-fluent-interfaces-and-piping/">Why do we need partial application? – Part 1 of n – Fluent interfaces and piping</a> </li>
</ul>
<p>This time I want to show you how we can write a <a href="http://en.wikipedia.org/wiki/Higher-order_function">higher-order function</a> which allows us to curry another function. Remember the multiplication function from the <a href="http://www.navision-blog.de/2012/01/27/partial-application-if-f-and-c/">first post</a> and it’s curried form:</p>
<p> <script src="https://gist.github.com/1705219.js"> </script><br />
<h5>Currying</h5>
<p>The question is: how can we automate this transformation process? Remember we want to have the curryied form for partial application:<script src="https://gist.github.com/1705245.js"> </script></p>
<p>Let’s look at the signature of the desired Curry-function: in our case it has to take <font color="#333333"><strong>Func&lt;int, int, int&gt;</strong></font> and returns <font color="#333333"><strong>Func&lt;int, Func&lt;int, int&gt;&gt;</strong></font>. </p>
<p>If we generalize the <strong>ints</strong> to generic parameters and fix the signature then the implementation is trivial (Compiler Driven Programming). There is exactly one way to make this work:</p>
<p> <script src="https://gist.github.com/1705277.js"> </script>
<p>The F# implementation does exactly the same, but without all the annoying the type hints:</p>
<p> <script src="https://gist.github.com/1705298.js"> </script><br />
<h5>Uncurrying</h5>
<p>Of course you can undo the currying by applying a generic Uncurry-function:</p>
<p> <script src="https://gist.github.com/1705371.js"> </script><script src="https://gist.github.com/1705372.js"> </script>
<p>And in F# this looks like this:</p>
<p> <script src="https://gist.github.com/1705380.js"> </script><br />
<h5>Libraries</h5>
<p>Currying and Uncurrying are two very important concepts in functional programming so they are included in a couple of libraries:</p>
<ul>
<li>You can find it at the top of the <a href="https://github.com/fsharp/fsharpx/blob/master/src/FSharpx.Core/Prelude.fs">Prelude</a> in FSharpx (<a href="http://bugsquash.blogspot.com/2011/10/introducing-fsharpx.html">read more</a>). </li>
<li>You can find it in the <a href="http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html">Haskell Prelude</a>. </li>
<li>You can find similar functions in <a href="https://github.com/scalaz/scalaz">Scalaz</a>. </li>
<li>Adrian Lang wrote a library called <a href="https://github.com/adrianlang/partial-js">partial-js</a> which allows to do something similar in JavaScript. </li>
</ul>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2012/01/30/currying-and-uncurrying-in-c-and-f/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Why do we need partial application? &#8211; Part 1 of n &#8211; Fluent interfaces and piping</title>
		<link>http://www.navision-blog.de/2012/01/29/why-do-we-need-partial-application-part-1-of-n-fluent-interfaces-and-piping/</link>
		<comments>http://www.navision-blog.de/2012/01/29/why-do-we-need-partial-application-part-1-of-n-fluent-interfaces-and-piping/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 10:34:35 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Currying]]></category>
		<category><![CDATA[partial  application]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/?p=1140</guid>
		<description><![CDATA[My last blog post was yet another introduction to Currying and Partial application. Now I want to put the focus more on the why part. Why do we want to have our functions in curryied form most of the time? This is the first part of a small blog post series and shows partial application [...]]]></description>
			<content:encoded><![CDATA[<p>My last <a href="http://www.navision-blog.de/2012/01/27/partial-application-if-f-and-c/">blog post</a> was yet another introduction to <a href="http://en.wikipedia.org/wiki/Currying">Currying</a> and <a href="http://en.wikipedia.org/wiki/Partial_application">Partial application</a>. Now I want to put the focus more on the <font color="#333333"><strong>why</strong></font> part. Why do we want to have our functions in curryied form most of the time? This is the first part of a small blog post series and shows partial application in F# pipelines.</p>
<p>Using “<a href="http://en.wikipedia.org/wiki/Fluent_interface">Fluent interfaces</a>” is a popular technique to write code in a more readable form. In languages like C# they also provide a way to create the code much faster. On every . we get IntelliSense and this gives us a “fluid” way of writing.</p>
<p>Let’s consider the following task: we want to compute the sum of the square roots of all odd numbers between 1 and 100. In C# we can use the LINQ method chaining approach in order to do something like this:</p>
<p><a href="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image_thumb.png" width="494" height="248" /></a></p>
<p>Now how does this look in F#? It’s basically the same. We replace every . with the |&gt; operator and use the analogous Seq.* functions:</p>
<p><a href="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image_3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image_thumb_3.png" width="494" height="85" /></a></p>
<p>Oups! What happened here? The F# compiler noticed a type error. <strong>Math.Sqrt</strong> needs a float as input but we gave it an int. C# uses implicit casts between int and float so we didn’t noticed the problem there. Implicit casts are a little bit problematic, at least if you want to have proper <a href="http://en.wikipedia.org/wiki/Type_inference">type inference</a> so F# doesn’t have this feature. No problem, we are programmers so let’s add the conversion manually:</p>
<p> <script src="https://gist.github.com/1697997.js"> </script>
<p>Notice that <strong>float</strong> is a function from int to float and not a cast. </p>
<p>Now you might ask: how does this all relate to partial application? The answer is simple: In every pipeline step we use a higher-order function (Seq.*) and apply the first parameter with a lambda. The second parameter is given via the |&gt; operator from the line above.</p>
<p><a href="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image_4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image_thumb_4.png" width="494" height="99" /></a></p>
<p>By applying our rule of thumb from the last post were are able to remove the x parameters:</p>
<p> <script src="https://gist.github.com/1698054.js"> </script>
<p>Now let’s step back to C#. Keeping this knowledge in mind we try to apply the same rule in order to get rid of the x parameters:</p>
<p><a href="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image_5.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image_thumb_5.png" width="494" height="302" /></a></p>
<p>Oups again! Now we see same error in C#. In this case it doesn’t know how to apply the implicit cast. As I said they are “problematic”, but we know how to fix this:</p>
<p> <script src="https://gist.github.com/1698185.js"> </script></p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2012/01/29/why-do-we-need-partial-application-part-1-of-n-fluent-interfaces-and-piping/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CodingDojo in TDD &#8211; Die einfachste L&#246;sung siegt</title>
		<link>http://www.navision-blog.de/2010/06/20/codingdojo-in-tdd-die-einfachste-loesung-siegt/</link>
		<comments>http://www.navision-blog.de/2010/06/20/codingdojo-in-tdd-die-einfachste-loesung-siegt/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 18:27:48 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Coding Dojo]]></category>
		<category><![CDATA[Kata]]></category>
		<category><![CDATA[.Net Open Space Süd]]></category>
		<category><![CDATA[CodingDojo]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/2010/06/20/codingdojo-in-tdd-die-einfachste-loesung-siegt/</guid>
		<description><![CDATA[Auf dem .NET OpenSpace S&#252;d in Karlsruhe hatte ich heute die Gelegenheit bei einem Coding Dojo mit Ilker Cetinkaya mitzumachen. Leider ist das Dojo nicht so richtig in Fahrt gekommen und wir haben es praktisch nicht geschafft auch nur eine einzige Regel der Kata.RomanNumerals zu implementieren. Der Grund daf&#252;r war (sicherlich nicht nur) aus meiner [...]]]></description>
			<content:encoded><![CDATA[<p>Auf dem <a href="http://karlsruhe.netopenspace.de">.NET OpenSpace S&#252;d</a> in Karlsruhe hatte ich heute die Gelegenheit bei einem Coding Dojo mit Ilker Cetinkaya mitzumachen. Leider ist das Dojo nicht so richtig in Fahrt gekommen und wir haben es praktisch nicht geschafft auch nur eine einzige Regel der Kata.RomanNumerals zu implementieren. Der Grund daf&#252;r war (sicherlich nicht nur) aus meiner Sicht, dass es zwei starke Fraktionen innerhalb des Teams gab. Auf der einen Seite “Coder”, die sich tats&#228;chlich von den Tests treiben lassen wollten und auf der anderen Seite eine Gruppe der “Knobler”, die sich nicht mit dem Test-first-Ansatz identifizieren k&#246;nnen und lieber am Board einen Algorithmus entwickeln.</p>
<p>Aus meiner Sicht sind beide Ans&#228;tze f&#252;r sich betrachtet auch v&#246;llig in Ordnung und k&#246;nnen zu sehr guten L&#246;sungen f&#252;hren.</p>
<p>Wer z.B. nicht glaubt, dass der strikte Test-first-Ansatz f&#252;r Kata.RomanNumerals funktioniert, der kann gern die Teilnehmer vom <a href="http://www.navision-blog.de/2010/06/18/bericht-vom-2-ten-net-coding-dojo-in-hamburg/">2.ten Hamburger Coding Dojo</a> fragen oder das <a href="http://github.com/forki/DojoHamburg/commits/master">github-Repository</a> dazu durch browsen und die Entwicklung der Commits verfolgen. </p>
<p>Was aber offensichtlich &#252;berhaupt nicht funktioniert ist der Mittelweg. Wenn sich beide Gruppen nicht auf das Vorgehen einigen und im Zweifel immer nur der “lauteste” &#196;nderungsvorschlag gewinnt, dann wird das Ergebnis mitunter unbefriedigend f&#252;r beide Seiten. Beim Karlsruher-Dojo hatten wir am Ende nach einer gescheiterten Implementierungsphase und abrupten Abbruch sogar nur 7 rote und einen gr&#252;nen Test vorzuweisen. Bei dem Gr&#252;nen frage ich momentan sogar immer noch warum ausgerechnet dieser Test &#252;berhaupt gelaufen ist.</p>
<p>Um also eine solche Situation zu vermeiden sollte man sich also am Anfang entscheiden wie man sein Dojo gemeinsam durchziehen will. Im weiteren werde ich jetzt eher auf die von mir favorisierte Variante mit striktem TDD eingehen, auch wenn mich eine Knobler-Session mit ausgepr&#228;gter Analysephase auch mal als Vergleichswert interessieren w&#252;rde. </p>
<p>Wie gesagt: Ich bin ausdr&#252;cklich davon &#252;berzeugt, dass beide L&#246;sungswege funktionieren k&#246;nnen – je nach Problem mal besser und mal schlechter.</p>
<h5>Striktes TDD und der einfachste L&#246;sungsvorschlag gewinnt</h5>
<p>Ein oft genanntes Argument der “Knobler”-Fraktion am TDD-Ansatz ist, dass nicht vorrausschauend entwickelt wird. Hey Jungs &#8211; das ist doch genau der Trick. Solange ich keine Anforderung f&#252;r irgendwelche Dinge habe (nicht im Kopf oder auf dem Papier, sondern als Test) wird keine Komplexit&#228;t hinzugef&#252;gt. Es wird dann behauptet, dass bei Test-first am Anfang sinnfreie Implementierungen gew&#228;hlt werden und dass man diesen Code am Ende ganz offensichtlich sowieso wieder wegschmei&#223;en w&#252;rde. Aber das stimmt einfach nicht. Auch wenn ich immer mehr Tests hinzunehme und meine Implementierung immer generischer wird, so wird die vorherige L&#246;sung letztlich immer ein Spezialfall der generischen Variante sein und geht somit nie verloren.</p>
<p>Gerade der Fokus auf diese minimal m&#246;gliche Generalsierung der aktuellen Implementierung sorgt daf&#252;r, dass der Algorithmus am Ende korrekt herausf&#228;llt. Das Knobeln kommt an dieser Stelle nat&#252;rlich wieder in den Ablauf herein. Allerdings knobeln wir so an wesentlich kleineren und damit leichteren Problemen&#160; – selbstverst&#228;ndlich nun viel &#246;fter und in k&#252;rzeren Zyklen.</p>
<p>Bei zuk&#252;nftigen Coding Dojos w&#252;rde ich also gern als Regel sehen, dass der einfachste Vorschlag, der zu Gr&#252;n f&#252;hrt implementiert wird.</p>
<h5>Temposteigerung durch gruppenweises Anlegen von roten Tests</h5>
<p>Zu bestimmten Zeitpunkten und insbesondere auch am Anfang von vielen Katas sieht man jedoch oft Implementierungsmuster die gleich eine ganze Klasse an Tests abdecken k&#246;nnten. Wenn man so eine Idee hat, dann sollte man die nat&#252;rlich auch nutzen und so das Tempo steigern. Anstatt aber diese Idee einfach zu programmieren w&#252;rde ich erst die komplette Gruppe von Tests schreiben und sicherstellen, dass alle neuen Tests auch wirklich &quot;rot sind. Dieser Shortcut ist aus meiner Sicht methodisch v&#246;llig unproblematisch, da zu diesem Zeitpunkt nur neue Anforderungen im System dokumentiert werden und diese dann als Begr&#252;ndung f&#252;r neue Komplexit&#228;t herangezogen werden k&#246;nnen.</p>
<p>Aber auch hier sollte die selbe Regel gelten: Die leichteste Implementierung gewinnt. Wenn also ein Teilnehmer eine einfachere L&#246;sung anbieten kann, dann wird die genommen.</p>
<h5>Training durch Wiederholung</h5>
<p>Wie Ilker in der Auswertung bereits gesagt hat, w&#252;rde ich auch gern nochmal in der selben Truppe ein Dojo machen. Vielleicht ergibt sich das ja sogar beim n&#228;chsten OpenSpace. Denn selbstverst&#228;ndlich geht es beim Coding Dojo nicht nur um Code sondern auch um die beteiligten Menschen.    <br />Obwohl wir am Ende keine L&#246;sung vorweisen konnten, habe ich in der kurzen Zeit sehr viel &#252;ber die Entwicklungsmethodik anderer Teilnehmer gelernt &#8211; ich denke das hat mir wirklich eine Menge gebracht.</p>
<h5>Training durch Wiederholung &#8211; Reloaded</h5>
<p>Da ein wichtiges Element bei Katas auch die Wiederholung ist (und mir im Zug langweilig ist), habe ich zus&#228;tzlich f&#252;r mich selbst und andere noch eine aufger&#228;umtere Variante der Kata mit minimalen Commits in das Repository hochgeladen. Unter <a title="http://github.com/forki/DojoHamburg/commits/Karlsruhe" href="http://github.com/forki/DojoHamburg/commits/Karlsruhe">http://github.com/forki/DojoHamburg/commits/Karlsruhe</a> kann man die &#196;nderungen von unten nach oben genau nachvollziehen. Wenn jemand ein Stelle findet wo ich zu viel implementiert habe oder wo die &#196;nderung nicht sinnvoll und einfach erscheint, dann w&#252;rde ich mich freuen dar&#252;ber diskutieren zu k&#246;nnen.</p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2010/06/20/codingdojo-in-tdd-die-einfachste-loesung-siegt/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Bericht vom 2.ten .NET Coding Dojo in Hamburg</title>
		<link>http://www.navision-blog.de/2010/06/18/bericht-vom-2-ten-net-coding-dojo-in-hamburg/</link>
		<comments>http://www.navision-blog.de/2010/06/18/bericht-vom-2-ten-net-coding-dojo-in-hamburg/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 18:52:37 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Coding Dojo]]></category>
		<category><![CDATA[Kata]]></category>
		<category><![CDATA[.NET User Group Hamburg]]></category>
		<category><![CDATA[CodingDojo]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/2010/06/18/bericht-vom-2-ten-net-coding-dojo-in-hamburg/</guid>
		<description><![CDATA[Am Mittwoch hat die .NET User Group Hamburg das zweite .NET Coding Dojo in wunderbarer Lage im Neuen Wall durchgef&#252;hrt. Der Dank gilt diesmal Computer Futures, die uns freundlicherweise Raum, Beamer und Getr&#228;nke zur Verf&#252;gung gestellt haben. Ablauf Nach einer kurzen Reflektion des letzten Treffens und Kl&#228;rung der aufgetretenen Syntaxprobleme hat sich das Team daf&#252;r [...]]]></description>
			<content:encoded><![CDATA[<p>Am Mittwoch hat die <a href="https://www.xing.com/net/pri44e1d5x/dotnetusergrouphamburg/">.NET User Group Hamburg</a> das zweite .NET Coding Dojo in wunderbarer Lage im Neuen Wall durchgef&#252;hrt. Der Dank gilt diesmal <a href="http://www.computerfutures.com/de/ ">Computer Futures</a>, die uns freundlicherweise Raum, Beamer und Getr&#228;nke zur Verf&#252;gung gestellt haben.</p>
<h5>Ablauf</h5>
<p>Nach einer kurzen Reflektion des letzten Treffens und Kl&#228;rung der aufgetretenen Syntaxprobleme hat sich das Team daf&#252;r entschieden, die <a href="http://codingdojo.org/cgi-bin/wiki.pl?KataRomanNumerals">Kata.RomanNumerals</a> zu implementieren. Wie beim <a href="http://www.navision-blog.de/2010/05/20/bericht-vom-ersten-net-coding-dojo-in-hamburg/">ersten Treffen</a> haben wir diese relativ einfache Kata auch wieder im Randori-Stil durchgef&#252;hrt. Da das Team relativ gleich geblieben ist, konnten wir den Ablauf jedoch leicht erweitern. Um etwas mehr Schwung in die Test-Phase zu bringen, habe ich vorgeschlagen immer in der Rot-Phase zu rotieren. Zus&#228;tzlich haben wir <a href="http://de.wikipedia.org/wiki/Git">git</a> als Versionskontrollsystem im Einsatz gehabt und bei jeder Gr&#252;n-Phase sowie nach Refactorings commited. Das Ergebnis kann auf meinem <a href="http://github.com/forki/DojoHamburg">Github-Account</a> bewundert werden.</p>
<h5>Kata</h5>
<p>Aus meiner Sicht bildet die Kata.RomanNumerals eine ideale Fortsetzung zur Kata.StringReplacer, die wir beim ersten Treffen hatten und ist praktisch perfekt mit Test-Driven Development l&#246;sbar. Insbesondere das nachtr&#228;gliche Implementieren der scheinbar komplizierten Subtraktionsregel ist wunderbar anhand von wenigen Sonderf&#228;llen (= UnitTests) l&#246;sbar.</p>
<h5>Was lief gut?</h5>
<ul>
<li>Die Rotation der Teilnehmer klappte wieder problemlos &#8211; Danke Jungs <img src='http://www.navision-blog.de/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </li>
<li>TDD wurde als sehr erfolgreich f&#252;r die Kata angesehen </li>
<li>Nahezu alle Teilnehmer waren &#252;berrascht wie einfach sich die Subtraktionsregel in TDD implementieren l&#228;sst </li>
<li>Die Randori-Form mit Rotation bei Rot sorgt f&#252;r Aktivit&#228;t </li>
<li>Es wurde immer versuchen die einfachste L&#246;sung zu w&#228;hlen </li>
<li>Die Rollen Driver, Co-Pilot und Publikum wurden klarer getrennt </li>
<li>Es wurde nach jedem implementierten Test in das git Repository commited </li>
<li>Ganz wichtig: Es hat wieder viel Spa&#223; gemacht! </li>
</ul>
<h5>Was wollen wir besser machen?</h5>
<ul>
<li>Noch mehr Wert auf das Naming legen </li>
<ul>
<li>&#220;berraschenderweise hat sich kein Team getraut die Namenskonvention des ersten Teams zu verbessern</li>
<li>Insbesondere auch die Commit-Kommentare sind noch nicht sehr aussagekr&#228;ftig</li>
</ul>
<li>In den Refactoring-Phasen sollten die Tools (Resharper) besser genutzt werden</li>
<li>Die Refactorings k&#246;nnten noch ausf&#252;hrlicher diskutiert werden</li>
<li>Von Anfang an externe Tastatur und Maus f&#252;r den Laptop bereit stellen </li>
<li>Internetverbindung um Syntaxfrage schneller kl&#228;ren zu k&#246;nnen</li>
<li>Parametrisierte Tests benutzen um weniger Test-Codierungsaufwand zu haben</li>
</ul>
<p>Vielen Dank an alle Teilnehmer – wir sehen uns dann beim n&#228;chsten Dojo.</p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2010/06/18/bericht-vom-2-ten-net-coding-dojo-in-hamburg/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bericht vom Ersten .NET Coding Dojo in Hamburg</title>
		<link>http://www.navision-blog.de/2010/05/20/bericht-vom-ersten-net-coding-dojo-in-hamburg/</link>
		<comments>http://www.navision-blog.de/2010/05/20/bericht-vom-ersten-net-coding-dojo-in-hamburg/#comments</comments>
		<pubDate>Thu, 20 May 2010 06:37:06 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Veranstaltungen]]></category>
		<category><![CDATA[.NET User Group Hamburg]]></category>
		<category><![CDATA[CodingDojo]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Test Driven Design]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/2010/05/20/bericht-vom-ersten-net-coding-dojo-in-hamburg/</guid>
		<description><![CDATA[Gestern fand das erste .NET Coding Dojo in Hamburg statt und es war aus meiner Sicht ein voller Erfolg. Als erstes m&#246;chte ich mich an dieser Stelle bei der Firma masters of arts f&#252;r die R&#228;umlichkeit und nat&#252;rlich bei allen Teilnehmer f&#252;r die aktive Mitarbeit bedanken. Durchgef&#252;hrt haben wir das Dojo im Randori-Stil, d.h. es [...]]]></description>
			<content:encoded><![CDATA[<p>Gestern fand das erste .NET Coding Dojo in Hamburg statt und es war aus meiner Sicht ein voller Erfolg. Als erstes m&#246;chte ich mich an dieser Stelle bei der Firma <a href="http://www.moaa.de">masters of arts</a> f&#252;r die R&#228;umlichkeit und nat&#252;rlich bei allen Teilnehmer f&#252;r die aktive Mitarbeit bedanken.</p>
<p><img style="border-right-width: 0px; margin: 0px 0px 10px 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Erkl&#228;rungen" border="0" alt="Erkl&#228;rungen" align="right" src="http://www.tbi-halle.de/wp-content/uploads/BerichtvomErsten.NETCodingDojoinHamburg_5870/image.png" width="181" height="244" /> </p>
<p>Durchgef&#252;hrt haben wir das Dojo im <a href="http://codingdojo.org/cgi-bin/wiki.pl?RandoriKata">Randori-Stil</a>, d.h. es gab einen Entwickler, einen “Co-Piloten” und das Publikum. Nach jeweils 5 Minuten bzw. jedem neuen Testfall wurden die Positionen mit neuen Teilnehmer aus dem Publikum getauscht.</p>
<p>Nach einer kurzen allgemeinen Einf&#252;hrung in das Thema “Coding Dojo” habe ich die Aufgabenstellungen der Kata.FizzBuzz und Kata.DictionaryReplacer vorgestellt. Durch kurze Abstimmung haben wir dann (vermutlich durch meine Wortwahl beeinflusst) die Kata.DictionaryReplacer gew&#228;hlt.</p>
<p>Mit der Wahl dieser Kata war ich nicht ganz ungl&#252;cklich, da wir DictionaryReplacer schon im Online Dojo durchgenommen haben und ich deshalb die Fallstricke schon etwas einsch&#228;tzen konnte.</p>
<blockquote><p><strong>Kata.DictionaryReplacer</strong></p>
<p>Create a method that takes a string and a dictionary,      <br />and replaces every key in the dictionary pre and suffixed with a dollar sign,       <br />with the corresponding value from the Dictionary. </p>
<p>Tests </p>
<p>input : &quot;&quot;,      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dict empty       <br />output: &quot;&quot; </p>
<p>input : &quot;$temp$&quot;,&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dict [&quot;temp&quot;, &quot;temporary&quot;]       <br />output: &quot;temporary&quot; </p>
<p>input : &quot;$temp$ here comes the name $name$&quot;,      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dict [&quot;temp&quot;, &quot;temporary&quot;] [&quot;name&quot;, &quot;John Doe&quot;]       <br />output : &quot;temporary here comes the name John Doe&quot;</p>
<p align="right">[<a href="http://codingdojo.org/cgi-bin/wiki.pl?KataDictionaryReplacer">codingdojo.org</a>]</p>
</blockquote>
<p>Nach kurzer Einf&#252;hrung in die Vorgehensweise des Test-Driven Developments (TDD) und Diskussion &#252;ber sinnvolles Naming ging es dann auch richtig in die Entwicklung. Die Kata eignet sich in dieser Form auch sehr sch&#246;n um tats&#228;chlich “Test first” zu arbeiten. Die Implementierung folgt quasi als logische Konsequenz.</p>
<p><img style="border-right-width: 0px; margin: 0px 10px 10px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Das Publikum" border="0" alt="Das Publikum" align="left" src="http://www.tbi-halle.de/wp-content/uploads/BerichtvomErsten.NETCodingDojoinHamburg_5870/image_3.png" width="244" height="164" /> </p>
<p>Interessant und ungleich komplizierter wurde es dann als wir eine zus&#228;tzliche Anforderung eingebaut haben. Da es sich bei der Kata um eine Art Templatesystem handelt liegt es nahe auch in den Values des W&#246;rterbuchs neue Keys zu erlauben und somit eine beliebige Ersetzungstiefe zu erreichen. Diese Anforderung ist ein wunderbares Beispiel daf&#252;r wie sehr man mit Aufwandsabsch&#228;tzungen daneben liegen kann. <img src='http://www.navision-blog.de/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><img style="border-right-width: 0px; margin: 0px 0px 10px 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Guter Rat ist teuer" border="0" alt="Guter Rat ist teuer" align="right" src="http://www.tbi-halle.de/wp-content/uploads/BerichtvomErsten.NETCodingDojoinHamburg_5870/image_4.png" width="244" height="156" /> </p>
<p>Die rekursive Ersetzung wurde noch sehr schnell gel&#246;st, aber richtig schwer haben wir uns dann mit der Erkennung von zyklischen Ersetzungen und der daraus folgenden Endlosschleife getan. Nach und nach wurden immer kompliziertere L&#246;sungsm&#246;glichkeiten genannt, die aber in der gegebenen Zeit nicht fehlerfrei umgesetzt werden konnten. Als Folge haben wir immer noch einen Test “rot”. Wer Lust hat kann sich also die Quellen vom <a href="http://github.com/forki/DojoHamburg">github Repository</a> ziehen und als Hausaufgabe den verbleibenden Test “gr&#252;n” machen.</p>
<p>In der Nachbetrachtung haben wir noch einige Sachen festgestellt:</p>
<h5>Was lief gut?</h5>
<ul>
<li>Die Rotation der Teilnehmer klappte problemlos </li>
<li>L&#246;sungsideen sprudelten f&#246;rmlich aus dem Publikum </li>
<li>Interessante Edge-Cases wurden gefunden </li>
<li>Viele kleine Tipps (z.B. Resharper Shortcuts) wurden ausgetauscht </li>
<li>TDD wurde als erfolgreich f&#252;r die Kata angesehen </li>
<li>Die Randori-Form sorgt f&#252;r Aktivit&#228;t </li>
<li>Ganz wichtig: Es hat Spa&#223; gemacht! </li>
</ul>
<h5>Was wollen wir besser machen?</h5>
<ul>
<li>Schneller den ersten Test schreiben </li>
<li>Intensivere Diskussion des Interfaces </li>
<li>Noch mehr Wert auf das Naming legen </li>
<li>Versuchen die einfachste L&#246;sung zu w&#228;hlen </li>
<li>Mehr Wert auf Refactoring legen
<ul>
<li>wurde etwas vernachl&#228;ssigt, da wir viel Zeit an der Endlosschleife verbraucht haben </li>
</ul>
</li>
<li>Die Rollen Driver, Co-Pilot und Publikum klarer trennen </li>
<li>Nach jedem implementierten Testcase bzw. jeder Rotation der Teilnehmer in das git Repository einchecken </li>
<li>Von Anfang an externe Tastatur und Maus f&#252;r den Laptop bereit stellen </li>
<li>Internetverbindung um Syntaxfrage schneller kl&#228;ren zu k&#246;nnen </li>
</ul>
<p>Als m&#246;glichen Termin f&#252;r das Dojo haben wir jetzt grob jeweils den 3. Mittwoch im Monat vorgeschlagen. &#220;ber die <a href="https://www.xing.com/net/pri2907edx/dotnetusergrouphamburg/">Xing-Gruppe der .NET User Group Hamburg</a> werden wir nat&#252;rlich auch wieder entsprechende Einladungen verschicken.</p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2010/05/20/bericht-vom-ersten-net-coding-dojo-in-hamburg/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8220;FAKE &#8211; F# Make&#8221; and NaturalSpec released</title>
		<link>http://www.navision-blog.de/2010/04/13/fake-f-sharp-make-and-naturalspec-released/</link>
		<comments>http://www.navision-blog.de/2010/04/13/fake-f-sharp-make-and-naturalspec-released/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 08:06:46 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[FAKE - F# Make]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[F-sharp Make]]></category>
		<category><![CDATA[NaturalSpec]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/2010/04/13/fake-f-make-and-naturalspec-released/</guid>
		<description><![CDATA[Yesterday Microsoft released the RTM versions of Visual Studio 2010, .NET Framework 4.0 and F# 2.0.0.0 and so it is time to announce the first official releases of “Fake – F# Make” and NaturalSpec. Both projects are now compatible with Visual Studio 2010 RC and RTM and the corresponding F# versions. Fake – F# Make [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday Microsoft released the RTM versions of <a href="http://www.microsoft.com/visualstudio/en-us/download">Visual Studio 2010</a>, .NET Framework 4.0 and <a href="http://msdn.microsoft.com/de-de/fsharp/cc835251%28en-us%29.aspx">F# 2.0.0.0</a> and so it is time to announce the first official releases of “<a href="http://bitbucket.org/forki/fake/wiki/Home">Fake – F# Make</a>” and <a href="http://bitbucket.org/forki/naturalspec/wiki/Home">NaturalSpec</a>. Both projects are now compatible with Visual Studio 2010 RC and RTM and the corresponding F# versions.</p>
<h5>Fake – F# Make version 1.0.0</h5>
<p>&quot;FAKE &#8211; F# Make&quot; is a build automation system, which is intended to provide a much better tooling support than XML-based build languages like MSBuild or NAnt. Due to its integration in F#, all benefits of the .NET Framework and functional programming can be used, including the extensive class library, powerful debuggers and integrated development environments like Visual Studio 2008, Visual Studio 2010 or SharpDevelop, which provide syntax highlighting and code completion.</p>
<p>Like F# itself the new build language was designed to be succinct, typed, declarative, extensible and easy to use.</p>
<ul>
<li><a href="http://bitbucket.org/forki/fake/wiki/Home">Project page</a> with samples and articles </li>
<li><a href="http://bitbucket.org/forki/fake/downloads/">Download page</a> </li>
<li><a href="http://github.com/forki/FAKE">Github repository</a> </li>
</ul>
<h5>NaturalSpec version 1.0.0</h5>
<p>NaturalSpec is a UnitTest framework based on <a href="http://www.nunit.org/">NUnit</a> and completely written in F# &#8211; but you don&#8217;t have to learn F# to use it. The idea is that you can write your spec mostly in a natural language like in the following sample:</p>
</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px">[&lt;Scenario&gt;]</p>
<p style="margin: 0px"><span style="color: blue">let</span> &#8220;When removing an element from a list it should not contain the element&#8220;() =</p>
<p style="margin: 0px">&#160; Given [1;2;3;4;5]&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// &quot;Arrange&quot; test context</span></p>
<p style="margin: 0px">&#160;&#160;&#160; |&gt; When removing 3&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// &quot;Act&quot;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; |&gt; It shouldn&#8217;t contain 3&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// &quot;Assert&quot;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; |&gt; It should contain 4&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// another assertion</span></p>
<p style="margin: 0px">&#160;&#160;&#160; |&gt; It should have (Length 4)&#160;&#160;&#160; <span style="color: green">// Assertion for length</span></p>
<p style="margin: 0px">&#160;&#160;&#160; |&gt; It shouldn&#8217;t have Duplicates <span style="color: green">// it contains duplicates ?</span></p>
<p style="margin: 0px">&#160;&#160;&#160; |&gt; Verify&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// Verify scenario</span></p>
</p></div>
</p>
<ul>
<li><a href="http://bitbucket.org/forki/naturalspec/wiki/Home">Project page</a> with samples and articles </li>
<li><a href="http://bitbucket.org/forki/naturalspec/downloads/">Download page</a> </li>
<li><a href="http://github.com/forki/NaturalSpec">Github repository</a> </li>
</ul>
<p>If you have any questions about the projects feel free to contact me.</p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2010/04/13/fake-f-sharp-make-and-naturalspec-released/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>&quot;Getting started&quot; with NaturalSpec &#8211; (Updated 08.11.2009)</title>
		<link>http://www.navision-blog.de/2009/11/08/getting-started-with-naturalspec/</link>
		<comments>http://www.navision-blog.de/2009/11/08/getting-started-with-naturalspec/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 09:48:00 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[NaturalSpec]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[nunit]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/2009/02/23/getting-started-with-naturalspec/</guid>
		<description><![CDATA[In my last article (Introducing NaturalSpec – A Domain-specific language (DSL) for testing) I used NaturalSpec in two small samples. This time I will show how we can set up a NaturalSpec environment to write our first automatically testable scenarios. 1. Choosing an IDE The first step is to choose an integrated development environment for [...]]]></description>
			<content:encoded><![CDATA[<p>In my last article (<a href="http://www.navision-blog.de/2009/02/23/introducing-naturalspec-a-dsl-for-testing-part-i/">Introducing NaturalSpec – A Domain-specific language (DSL) for testing</a>) I used NaturalSpec in two small samples. This time I will show how we can set up a <a href="http://code.google.com/p/natural/">NaturalSpec</a> environment to write our first automatically testable scenarios.</p>
<h5>1. Choosing an IDE</h5>
<p>The first step is to choose an integrated development environment for NaturalSpec. At the current project status you should be able to use NaturalSpec with Visual Studio 2008, Visual Studio 2010 beta 2, the freely available <a href="http://msdn.microsoft.com/en-us/vsx2008/products/bb933751.aspx">Visual Studio 2008 Shell</a> or the free IDE <a href="http://www.icsharpcode.net/OpenSource/SD/">SharpDevelop 3.0</a>.</p>
<h5>2. Installing the testing framework</h5>
<p>As NaturalSpec uses <a href="http://www.nunit.org/index.php">NUnit</a> as the underlying testing framework we have to install NUnit 2.5. I also recommend installing <a href="http://testdriven.net/default.aspx">TestDriven.Net</a> in order to get a Unit Test runner within Visual Studio.</p>
<h5>3. Installing F#</h5>
<p>NaturalSpec is completely written in <a href="http://en.wikipedia.org/wiki/F_Sharp_programming_language">F#</a> and all specs will also be written in F#. This doesn’t imply you have to learn programming in F# but we need the F# compiler to get things working. You can download the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=b55f0532-ac3c-4106-918c-5586a953a7da&amp;displaylang=en">F# October 2009 CTP</a> from the <a href="http://msdn.microsoft.com/en-us/fsharp/default.aspx">Microsoft F# Developer Center</a>.</p>
<h5>4. Downloading the latest version of NaturalSpec</h5>
<p>You can download a .zip with the <a href="http://code.google.com/p/natural/">latest NaturalSpec libraries from GoogleCode</a>.</p>
<h5>5. Creating a spec</h5>
<p>This part is written for using Visual Studio 2008. If you use SharpDevelop or Visual Studio 2008 Shell this might differ in some detail.</p>
<p>Start Visual Studio 2008 and create a new F# class library.</p>
<p><img class="bordered" title="Creating a spec project" border="0" alt="Creating a spec project" src="http://www.navision-blog.de/images/GettingstartedwithNaturalSpec_A7B1/image.png" width="500" height="354" /></p>
<p>Rename <em>Module1.fs</em> in <em>ListSpec.fs</em> and delete <em>script.fsx</em> from the project:</p>
<p><img class="bordered" title="Solution explorer" border="0" alt="Solution explorer" src="http://www.navision-blog.de/images/GettingstartedwithNaturalSpec_A7B1/image_3.png" width="248" height="146" /></p>
<p>Create a folder “Lib” and unzip the NaturalSpec libraries into it.</p>
<p>Add <em>NaturalSpec.dll</em> and <em>nunit.framework.dll</em> as references to your project:</p>
<p><img class="bordered" title="Adding project references" alt="Adding project references" src="http://www.navision-blog.de/images/GettingstartedwithNaturalSpec_A7B1/image_4.png" width="482" height="406" /></p>
<p>Copy the following code into ListSpec.fs:</p>
<pre class="code"><span style="color: blue">module </span>ListSpec</pre>
<pre class="code"><span style="color: blue">open </span>NaturalSpec

[&lt;Scenario&gt;]
<span style="color: blue">let </span>When_removing_an_3_from_a_small_list_it_should_not_contain_3() =
  Given [1;2;3;4;5]
    |&gt; When removing 3
    |&gt; It shouldn't contain 3
    |&gt; Verify</pre>
<p>If you have TestDriven.Net installed you can run your spec via right click in the solution explorer:</p>
<p><img class="bordered" title="Run spec with TestDriven.net" alt="Run spec with TestDriven.net" src="http://www.navision-blog.de/images/GettingstartedwithNaturalSpec_A7B1/image_5.png" width="295" /></p>
<p>If you don’t like the TestDriven.Net test runner you might want to use the NUnit GUI runner. The output should look like:</p>
<p><a href="http://www.navision-blog.de/images/GettingstartedwithNaturalSpec_A7B1/image_6.png"><img class="bordered" title="NUnit Gui runner" border="0" alt="NUnit Gui runner" src="http://www.navision-blog.de/images/GettingstartedwithNaturalSpec_A7B1/image_thumb.png" width="500" height="264" /></a></p>
<p>In addition the test runner should produce a Spec output file with the name “Spec.txt” within the same folder.</p>
<h5>Summary</h5>
<p>In a minimal environment you need <a href="http://www.icsharpcode.net/OpenSource/SD/">SharpDevelop</a>, the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=b55f0532-ac3c-4106-918c-5586a953a7da&amp;displaylang=en">F# compiler</a>, <a href="http://www.nunit.org/index.php">NUnit</a> and the <a href="http://code.google.com/p/natural/">NaturalSpec libraries</a> for using NaturalSpec. </p>
<p>In the next post I will show how you can <a href="http://www.navision-blog.de/2009/02/23/using-naturalspec-to-create-spec-for-c-projects/">use NaturalSpec to create a spec for C# projects</a>.</p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2009/11/08/getting-started-with-naturalspec/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Observing global hotkeys in C# / F#</title>
		<link>http://www.navision-blog.de/2009/11/06/observing-global-shortcuts/</link>
		<comments>http://www.navision-blog.de/2009/11/06/observing-global-shortcuts/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 10:08:05 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Hotkey]]></category>
		<category><![CDATA[PInvoke]]></category>
		<category><![CDATA[win32]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/2009/11/06/observing-global-shortcuts/</guid>
		<description><![CDATA[I recently had the problem to register a global hotkey, but my “old” Win32-API calls didn’t work with WPF. I looked around the web and found the “Managed Windows API”, but I didn’t want to add another external dependency to my project, so I extracted the core functions for registering hotkeys and condensed the code [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had the problem to register a global hotkey, but my “old” Win32-API calls didn’t work with WPF. I looked around the web and found the “<a href="http://mwinapi.sourceforge.net/">Managed Windows API</a>”, but I didn’t want to add another external dependency to my project, so I extracted the core functions for registering hotkeys and condensed the code to a new version. </p>
<p>As the original “Managed Windows API” is licensed by the GNU Lesser General Public License (LGPL) I want to provide my modifications here.</p>
<p>First we need a Window which can dispatch the window messages to our event handlers:</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> A Win32 native window that delegates window messages to </span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: green">handlers. So several</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> components can use the same native window to save </span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: green">&quot;USER resources&quot;. This class</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> is useful when writing your own components.</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">sealed</span> <span style="color: blue">class</span> <span style="color: #2b91af">EventDispatchingNativeWindow</span> : <span style="color: #2b91af">NativeWindow</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: blue">readonly</span> <span style="color: #2b91af">Object</span> MyLock = <span style="color: blue">new</span> <span style="color: #2b91af">Object</span>();</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: #2b91af">EventDispatchingNativeWindow</span> _instance;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Create your own event dispatching window.</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> EventDispatchingNativeWindow()</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; CreateHandle(<span style="color: blue">new</span> <span style="color: #2b91af">CreateParams</span>());</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> A global instance which can be used by components </span></p>
<p style="margin: 0px"><span style="color: green">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span>that do not need</span><span style="color: green"> their own window.</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: #2b91af">EventDispatchingNativeWindow</span> Instance</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">get</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">lock</span> (MyLock)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">return</span> </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _instance ?? </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (_instance = </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">new</span> <span style="color: #2b91af">EventDispatchingNativeWindow</span>());</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Attach your event handlers here.</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">event</span> <span style="color: #2b91af">WndProcEventHandler</span> EventHandler;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Parse messages passed to this window and send </span></p>
<p style="margin: 0px"><span style="color: gray">&#160;&#160;&#160; ///</span><span style="color: green"> </span><span style="color: green">them to the event handlers.</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;param name=&quot;m&quot;&gt;</span><span style="color: green">A System.Windows.Forms.Message </span></p>
<p style="margin: 0px"><span style="color: gray">&#160;&#160;&#160; ///</span><span style="color: green"> </span><span style="color: green">that is associated with the </span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> current Windows message.</span><span style="color: gray">&lt;/param&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">protected</span> <span style="color: blue">override</span> <span style="color: blue">void</span> WndProc(<span style="color: blue">ref</span> <span style="color: #2b91af">Message</span> m)</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">bool</span> handled = <span style="color: blue">false</span>;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (EventHandler != <span style="color: blue">null</span>)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; EventHandler(<span style="color: blue">ref</span> m, <span style="color: blue">ref</span> handled);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (!handled)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">base</span>.WndProc(<span style="color: blue">ref</span> m);</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">}</p>
</p></div>
<p>Now we can write our global hotkey handler class:</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> Specifies a class that creates a global keyboard hotkey.</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: #2b91af">GlobalHotkey</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: blue">readonly</span> <span style="color: #2b91af">Object</span> MyStaticLock = <span style="color: blue">new</span> <span style="color: #2b91af">Object</span>();</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: blue">int</span> _hotkeyCounter = 0xA000;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">readonly</span> <span style="color: blue">int</span> _hotkeyIndex;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">readonly</span> <span style="color: #2b91af">IntPtr</span> _hWnd;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Initializes a new instance of this class.</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;param name=&quot;keys&quot;&gt;</span><span style="color: green">The keys.</span><span style="color: gray">&lt;/param&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;param name=&quot;ctrl&quot;&gt;</span><span style="color: green">if </span><span style="color: gray">&lt;c&gt;</span><span style="color: green">true</span><span style="color: gray">&lt;/c&gt;</span><span style="color: green"> [CTRL].</span><span style="color: gray">&lt;/param&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;param name=&quot;alt&quot;&gt;</span><span style="color: green">if </span><span style="color: gray">&lt;c&gt;</span><span style="color: green">true</span><span style="color: gray">&lt;/c&gt;</span><span style="color: green"> [alt].</span><span style="color: gray">&lt;/param&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;param name=&quot;shift&quot;&gt;</span><span style="color: green">if </span><span style="color: gray">&lt;c&gt;</span><span style="color: green">true</span><span style="color: gray">&lt;/c&gt;</span><span style="color: green"> [shift].</span><span style="color: gray">&lt;/param&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;param name=&quot;winKey&quot;&gt;</span><span style="color: green">if </span><span style="color: gray">&lt;c&gt;</span><span style="color: green">true</span><span style="color: gray">&lt;/c&gt;</span><span style="color: green"> [win key].</span><span style="color: gray">&lt;/param&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> GlobalHotkey(<span style="color: #2b91af">Keys</span> keys, <span style="color: blue">bool</span> ctrl, </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">bool</span> alt, <span style="color: blue">bool</span> shift, <span style="color: blue">bool</span> winKey)</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; KeyCode = keys;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; Ctrl = ctrl;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; Alt = alt;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; Shift = shift;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; WindowsKey = winKey;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">EventDispatchingNativeWindow</span>.Instance.EventHandler </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; += NwEventHandler;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">lock</span> (MyStaticLock)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _hotkeyIndex = ++_hotkeyCounter;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; _hWnd = <span style="color: #2b91af">EventDispatchingNativeWindow</span>.Instance.Handle;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; Enable();</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> The key code of the hotkey.</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: #2b91af">Keys</span> KeyCode { <span style="color: blue">get</span>; <span style="color: blue">private</span> <span style="color: blue">set</span>; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Whether the shortcut includes the Control modifier.</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">bool</span> Ctrl { <span style="color: blue">get</span>; <span style="color: blue">private</span> <span style="color: blue">set</span>; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Whether this shortcut includes the Alt modifier.</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">bool</span> Alt { <span style="color: blue">get</span>; <span style="color: blue">private</span> <span style="color: blue">set</span>; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Whether this shortcut includes the shift modifier.</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">bool</span> Shift { <span style="color: blue">get</span>; <span style="color: blue">private</span> <span style="color: blue">set</span>; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Whether this shortcut includes the Windows key modifier.</span></p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: green"></span></p>
<p>&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span>
</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">bool</span> WindowsKey { <span style="color: blue">get</span>; <span style="color: blue">private</span> <span style="color: blue">set</span>; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; ~GlobalHotkey()</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; Disable();</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">EventDispatchingNativeWindow</span>.Instance.EventHandler </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; -= NwEventHandler;</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Enables the hotkey. When the hotkey is enabled, </span></p>
<p style="margin: 0px"><span style="color: gray">&#160;&#160;&#160; ///</span><span style="color: green"> </span><span style="color: green">pressing it causes a</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;c&gt;</span><span style="color: green">HotkeyPressed</span><span style="color: gray">&lt;/c&gt;</span><span style="color: green"> event instead of being </span></p>
<p style="margin: 0px"><span style="color: gray">&#160;&#160;&#160; ///</span><span style="color: green"> </span><span style="color: green">handled by the active</span><span style="color: green"> application.</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">void</span> Enable()</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// register hotkey</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">int</span> fsModifiers = 0;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (Shift) fsModifiers += ModShift;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (Ctrl) fsModifiers += ModControl;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (Alt) fsModifiers += ModAlt;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (WindowsKey) fsModifiers += ModWin;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">bool</span> success = </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; RegisterHotKey(_hWnd, _hotkeyIndex, </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; fsModifiers, (<span style="color: blue">int</span>) KeyCode);</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (!success)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">throw</span> <span style="color: blue">new</span> </p>
<p style="margin: 0px"><span style="color: #2b91af"><font color="#000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font>Exception</span>(</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #a31515">&quot;Could not register hotkey (already in use).&quot;</span>);</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Disables this instance.</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">void</span> Disable()</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// unregister hotkey</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; UnregisterHotKey(_hWnd, _hotkeyIndex);</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Occurs when the hotkey is pressed.</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">event</span> <span style="color: #2b91af">EventHandler</span> HotkeyPressed;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">void</span> NwEventHandler(<span style="color: blue">ref</span> <span style="color: #2b91af">Message</span> m, <span style="color: blue">ref</span> <span style="color: blue">bool</span> handled)</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (handled) <span style="color: blue">return</span>;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (m.Msg != WmHotkey || </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m.WParam.ToInt32() != _hotkeyIndex)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">return</span>;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (HotkeyPressed != <span style="color: blue">null</span>)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; HotkeyPressed(<span style="color: blue">this</span>, <span style="color: #2b91af">EventArgs</span>.Empty);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; handled = <span style="color: blue">true</span>;</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; #region</span> PInvoke Declarations</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">const</span> <span style="color: blue">int</span> ModAlt = 0&#215;0001;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">const</span> <span style="color: blue">int</span> ModControl = 0&#215;0002;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">const</span> <span style="color: blue">int</span> ModShift = 0&#215;0004;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">const</span> <span style="color: blue">int</span> ModWin = 0&#215;0008;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">const</span> <span style="color: blue">int</span> WmHotkey = 0&#215;0312;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; [<span style="color: #2b91af">DllImport</span>(<span style="color: #a31515">&quot;user32.dll&quot;</span>, SetLastError = <span style="color: blue">true</span>)]</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: blue">extern</span> <span style="color: blue">bool</span> RegisterHotKey(<span style="color: #2b91af">IntPtr</span> hWnd, </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">int</span> id, <span style="color: blue">int</span> fsModifiers, <span style="color: blue">int</span> vlc);</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; [<span style="color: #2b91af">DllImport</span>(<span style="color: #a31515">&quot;user32.dll&quot;</span>, SetLastError = <span style="color: blue">true</span>)]</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: blue">extern</span> <span style="color: blue">bool</span> UnregisterHotKey(<span style="color: #2b91af">IntPtr</span> hWnd, </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">int</span> id);</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; #endregion</span></p>
<p style="margin: 0px">}</p>
</p></div>
<p>Now we can easily register a global hotkey or use it as an observable in F#:</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: green">/// system-wide keyboard hook</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> hotkey = <span style="color: blue">new</span> GlobalHotkey(Keys.Q,<span style="color: blue">true</span>,<span style="color: blue">false</span>,<span style="color: blue">false</span>,<span style="color: blue">false</span>)</p>
<p style="margin: 0px"><span style="color: blue">let</span> hookObserver =</p>
<p style="margin: 0px">&#160; hotkey.HotkeyPressed&#160; </p>
<p style="margin: 0px">&#160;&#160;&#160; |&gt; Observable.subscribe (<span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span> printfn <span style="color: maroon">&quot;Hotkey pressed&quot;</span>)</p>
</p></div>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2009/11/06/observing-global-shortcuts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

