<?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>Lars Wilhelmsen &#187; .NET</title>
	<atom:link href="http://www.larswilhelmsen.com/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.larswilhelmsen.com</link>
	<description>Microsoft Connected Systems MVP</description>
	<lastBuildDate>Tue, 22 Jun 2010 08:24:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Easier Unit Testing of WCF Services with ServiceTestContext</title>
		<link>http://www.larswilhelmsen.com/2009/09/08/easier-unit-testing-of-wcf-services-with-servicetestcontext/</link>
		<comments>http://www.larswilhelmsen.com/2009/09/08/easier-unit-testing-of-wcf-services-with-servicetestcontext/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 08:42:13 +0000</pubDate>
		<dc:creator>larsw</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://www.larswilhelmsen.com/2009/09/08/easier-unit-testing-of-wcf-services-with-servicetestcontext/</guid>
		<description><![CDATA[Hi, and apologies for being so awfully quiet the last couple of months. Expect the traffic to pick up again (I’ll explain the silence in a blog post later). Now, when unit testing WCF Services, I’ve often ended up with cluttering my tests with a lot of plumbing code to wire up the SUT; that is [...]]]></description>
			<content:encoded><![CDATA[<p>Hi, and apologies for being so awfully quiet the last couple of months. Expect the traffic to pick up again (I’ll explain the silence in a blog post later).</p>
<p>Now, when unit testing WCF Services, I’ve often ended up with cluttering my tests with a lot of plumbing code to wire up the SUT; that is – the WCF service I want to exercise.</p>
<p>Now, being a lazy guy, wiring up (redundant) plumbing code again and again, I often end up trying to extract the essence and put together a tool or helper class.</p>
<p>So, this is my first shot of a fluent helper class that lets you test your WCF services.</p>
<p>The screenshot below pretty much sums up the functionality. It should be pretty self explaining; You end up writing an <em>Action&lt;TContract&gt;</em> implementation that acts as the client.</p>
<p>It will wire up an OperationContextScope automatically, but it can be disabled if you don’t need it.</p>
<p><a href="http://www.larswilhelmsen.com/wp-content/uploads/2009/09/ShouldReturnHttp2001.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="ShouldReturnHttp200" src="http://www.larswilhelmsen.com/wp-content/uploads/2009/09/ShouldReturnHttp200_thumb1.png" border="0" alt="ShouldReturnHttp200" width="505" height="455" /></a></p>
<p>The state/quality of the code is “Proof of Concept” and can be found <a href="http://www.larswilhelmsen.com/wp-content/uploads/2009/09/ServiceTestContext.cs">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.larswilhelmsen.com/2009/09/08/easier-unit-testing-of-wcf-services-with-servicetestcontext/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The book shelf of a Connected Systems MVP</title>
		<link>http://www.larswilhelmsen.com/2009/05/12/the-book-shelf-of-a-connected-systems-mvp/</link>
		<comments>http://www.larswilhelmsen.com/2009/05/12/the-book-shelf-of-a-connected-systems-mvp/#comments</comments>
		<pubDate>Tue, 12 May 2009 18:14:15 +0000</pubDate>
		<dc:creator>larsw</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Software+Craftmanship]]></category>

		<guid isPermaLink="false">http://larsw.wordpress.com/2009/05/12/the-book-shelf-of-a-connected-systems-mvp/</guid>
		<description><![CDATA[A few days ago, Gøran Hansen of Capgemini and a an active member of the Norwegian Microsoft scene – as well as active in the Twittersphere, wrote a blog post called “A Software Craftsman’s Bookshelf” containing a picture of his book shelf with Software Development-related books, as well as a brief review of the titles. [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago, <a href="http://blog.goeran.no/" target="_blank">Gøran Hansen of Capgemini</a> and a an active member of the Norwegian Microsoft scene – as well as active in the <a href="http://www.twitter.com/goeran" target="_blank">Twittersphere</a>, wrote a blog post called “<a href="http://blog.goeran.no/PermaLink,guid,b0df5924-fb90-4506-b2e7-1e15a5e981c6.aspx">A Software Craftsman’s Bookshelf</a>” containing a picture of his book shelf with Software Development-related books, as well as a brief review of the titles. He tagged a bunch of other people – including me, so here’s my contribution to this book shelf meme</p>
<p>(I actually wonder why a UI-geek like Gøran chose a dull jpeg for visualizing his book shelf, so I’m stepping up &#8211; to show off that <em>Mr. Non-UI guy</em> can use the Stitch functionality in <a href="http://www.microsoft.com/downloads/details.aspx?familyid=457b17b7-52bf-4bda-87a3-fa8a4673f8bf&amp;displaylang=en" target="_blank">Deep Zoom Composer</a>. The final product is hosted on <a href="http://www.deepzoompix.com/" target="_blank">DeepZoomPix</a> – a Microsoft site for hosting Deep Zoom pictures.)</p>
<p>Update: Seems like the stupid wordpress.com blog hosting strips javascripts and object tags, so until I’ll get around to move this blog to a more sane hosting provider, I’ll have to put up a preview picture that hyperlinks to the <a href="http://www.deepzoompix.com/" target="_blank">DeepZoomPix</a> site <img src='http://www.larswilhelmsen.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
<p><a title="My book shelf" href="http://deepzoompix.com/DZApp/IFrame.aspx?alias=larsw&amp;album=1"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="bookshelf_preview" border="0" alt="bookshelf_preview" src="http://larsw.files.wordpress.com/2009/05/bookshelf_preview.jpg" width="550" height="457" /></a> </p>
<p>(A click on the image will bring you to the real Deep Zoom image)</p>
<p><strike>I actually thought about rotating the stitched picture counter-clockwise, so that the titles of the books would be easier to read, but I postphoned it to a moment when I have more time to stuff like this <img src='http://www.larswilhelmsen.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </strike> </p>
<p>A description of the books + Amazon links, as well as a list of people I&#8217;d like to tag will be added later. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.larswilhelmsen.com/2009/05/12/the-book-shelf-of-a-connected-systems-mvp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Syntax highlighting with MGrammar</title>
		<link>http://www.larswilhelmsen.com/2009/03/31/syntax-highlighting-with-mgrammar/</link>
		<comments>http://www.larswilhelmsen.com/2009/03/31/syntax-highlighting-with-mgrammar/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 20:37:54 +0000</pubDate>
		<dc:creator>larsw</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Codename+Oslo]]></category>
		<category><![CDATA[MGrammar]]></category>
		<category><![CDATA[Syntax+Highlighting]]></category>

		<guid isPermaLink="false">http://larsw.wordpress.com/2009/03/31/syntax-highlighting-with-mgrammar/</guid>
		<description><![CDATA[Since I started exploring the possibilities of the various bits of codename “Oslo”, there has been one thing that has really annoyed me (and this is not Oslo’s fault). The lack of a decent tool to do syntax highlighting of M, MGrammar &#38; custom DSLs is vital to be able to communicate the intentions of [...]]]></description>
			<content:encoded><![CDATA[<p>Since I started exploring the possibilities of the various bits of codename “Oslo”, there has been one thing that has really annoyed me (and this is not Oslo’s fault). The lack of a decent tool to do syntax highlighting of <em>M</em>, <em>MGrammar</em> &amp; custom DSLs is vital to be able to communicate the intentions of a bit of source code when you blog about it.</p>
<p>Since I’ve been using the bits in <em>System.Dataflow</em> in a couple of projects now, I knew of the existence of the <em>Lexer</em> etc. in the assembly. I started to investigate further with .NET Reflector and found one class that seemed quite relevant for the tool I wanted to write; <em>System.Dataflow.LexerReader</em>. You initialize the <em>LexerReader</em> with a <em>ParserContext</em> and a stream of input data (typically the source code) and iterate over the tokens that the <em>Lexer</em> discover.</p>
<p>So, the basic requirements for the utility I wanted to create were:</p>
<ul>
<li>Take a compiled <em>MGrammar</em> (<em>Mgx</em>) as input. </li>
<li>Take a piece of source code that complies to the MGrammar as input. </li>
<li>Output a HTML fragment with syntax highlighted source code. </li>
</ul>
<p>Since the <em>MGrammar</em> language has a notion of attributes, and more specific; supports the <em>@{Classification}</em> attribute that lets the language developer classify/group the different tokens into <strong>Keywords</strong>, <strong>Literals</strong>, <strong>Strings</strong>, <strong>Numerics</strong> etc., I started digging into the System.Dataflow to hopefully find a mechanism to retrieve the metadata during the Lexing phase.</p>
<p>After some hours of intensive searching with .NET Reflector and the Visual Studio debugger, I found the solution; when you iterate over the <em>LexerReader</em> instance, you end up with <em>ParseTokenReference</em> instances that both describes the token and its content. It doesn’t contain the classification information directly, and that was the big puzzle I had to solve. It turned out that the <em>DynamicParser</em> instance, that I used to load up the <em>Mgx</em> file and build the <em>ParseContext</em> had a <em>GetTokenInfo()</em> method that took an integer as the only parameter; <em>tokenTag</em> – and the <em>ParseTokenReference</em> instance had a .Tag property. Bingo!</p>
<p>So, I’ve put together a small spike that I’m intending to clean up – it’s located <a href="http://github.com/larsw/larsw.msyntaxhighlighter/tree/master" target="_blank">here</a> at the moment and will be licensed under the Apache License.</p>
<p>Below is a sample output&#160; from the utility – the input is a MGrammar that I wrote for a answer to a thread in the Oslo/MSDN forum.</p>
<p>For the first version it will probably be a command line tool – but it would probably be a good idea to create both a ASP.NET frontend and a Windows Live Writer addin for it.</p>
<div style="font-family:consolas, courier, monospace;"><span class="Keyword">module</span> LarsW.Languages     <br /><span class="Delimiter">{</span>     <br />&#160;&#160;&#160; <span class="Keyword">language</span> nnnAuthLang     <br />&#160;&#160;&#160; <span class="Delimiter">{</span>     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Keyword">syntax</span> Main = ar:AuthRule* =&gt; Rules <span class="Delimiter">{</span>&#160;<span class="Keyword">valuesof</span><span class="Delimiter">(</span>ar<span class="Delimiter">)</span>&#160;<span class="Delimiter">}</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Keyword">syntax</span> AuthRule = ad:AllowDeny av:AuthVerb     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; tOpenParen rl:RoleList tCloseParen tSemiColon     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; =&gt; AuthRule <span class="Delimiter">{</span> Type <span class="Delimiter">{</span>ad<span class="Delimiter">}</span>, AuthType<span class="Delimiter">{</span>av<span class="Delimiter">}</span>, Roles    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Delimiter">{</span> <span class="Keyword">valuesof</span><span class="Delimiter">(</span>rl<span class="Delimiter">)</span><span class="Delimiter">}</span>&#160;<span class="Delimiter">}</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Keyword">syntax</span> RoleList = ri:RoleItem&#160; =&gt; List <span class="Delimiter">{</span> ri <span class="Delimiter">}</span>     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; | ri:RoleItem tComma rl:RoleList     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; =&gt; List <span class="Delimiter">{</span> ri, <span class="Keyword">valuesof</span><span class="Delimiter">(</span>rl<span class="Delimiter">)</span>&#160;<span class="Delimiter">}</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Keyword">syntax</span> RoleItem = tRoleName;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Keyword">syntax</span> AllowDeny = a:tAllow =&gt; a     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; | d:tDeny =&gt; d;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Keyword">syntax</span> AuthVerb = tText;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Keyword">token</span> tText = <span class="Delimiter">(</span><span class="Literal">&quot;a&quot;</span>..<span class="Literal">&quot;z&quot;</span>|<span class="Literal">&quot;A&quot;</span>..<span class="Literal">&quot;Z&quot;</span><span class="Delimiter">)</span>+;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; @{Classification<span class="Delimiter">[</span><span class="Literal">&quot;Keyword&quot;</span><span class="Delimiter">]</span><span class="Delimiter">}</span><span class="Keyword">token</span> tAllow = <span class="Literal">&quot;Allow&quot;</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; @{Classification<span class="Delimiter">[</span><span class="Literal">&quot;Keyword&quot;</span><span class="Delimiter">]</span><span class="Delimiter">}</span><span class="Keyword">token</span> tDeny = <span class="Literal">&quot;Deny&quot;</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Keyword">token</span> tOpenParen = <span class="Literal">&quot;(&quot;</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Keyword">token</span> tCloseParen = <span class="Literal">&quot;)&quot;</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Keyword">token</span> tSemiColon = <span class="Literal">&quot;;&quot;</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Keyword">token</span> tComma = <span class="Literal">&quot;,&quot;</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Keyword">token</span> Whitespace = <span class="Literal">&quot; &quot;</span>|<span class="Literal">&quot;\t&quot;</span>|<span class="Literal">&quot;\r&quot;</span>|<span class="Literal">&quot;\n&quot;</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Keyword">token</span> tRoleName = Language.Grammar.TextLiteral;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Keyword">interleave</span> Skippable = Whitespace;     <br />&#160;&#160;&#160; <span class="Delimiter">}</span>     <br /><span class="Delimiter">}</span></div>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2flarswilhelmsen.com%2f2009%2f03%2f31%2fsyntax-highlighting-with-mgrammar%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2flarswilhelmsen.com%2f2009%2f03%2f31%2fsyntax-highlighting-with-mgrammar%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larswilhelmsen.com/2009/03/31/syntax-highlighting-with-mgrammar/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Parsing the command line with MGrammar &#8211; part 2</title>
		<link>http://www.larswilhelmsen.com/2009/03/19/parsing-the-command-line-with-mgrammar-part-2/</link>
		<comments>http://www.larswilhelmsen.com/2009/03/19/parsing-the-command-line-with-mgrammar-part-2/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 11:39:30 +0000</pubDate>
		<dc:creator>larsw</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Codename+Oslo]]></category>
		<category><![CDATA[DSLs]]></category>
		<category><![CDATA[MGrammar]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://larsw.wordpress.com/?p=177</guid>
		<description><![CDATA[In the first installment of this series we took a look at the basic grammar for parsing the command line with MGrammar. In this part I’ll show you how we can load in a compiled version of the MGrammar and parse the input (i.e. the command line) to produce a valid MGraph that we in [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://larswilhelmsen.com/2009/03/16/parsing-the-command-line-with-mgrammar-part-1/" target="_blank">the first installment</a> of this series we took a look at the basic grammar for parsing the command line with MGrammar. In this part I’ll show you how we can load in a compiled version of the MGrammar and parse the input (i.e. the command line) to produce a valid MGraph that we in turn can process in the backend code.</p>
<p>A quick reminder from part 1; the code is located here:    <br /><a title="http://github.com/larsw/larsw.commandlineparser" href="http://github.com/larsw/larsw.commandlineparser">http://github.com/larsw/larsw.commandlineparser</a></p>
<p>You can download the code either by using git or downloading it as an archive. Once you’ve done that, open the solution LarsW.CommandLineParser.sln in Visual Studio 2008.</p>
<p align="justify"><a href="http://larsw.files.wordpress.com/2009/03/image2.png"><img title="image" style="display:inline;border-width:0;margin:4px 0 0 8px;" height="169" alt="image" src="http://larsw.files.wordpress.com/2009/03/image-thumb2.png" width="240" align="right" border="0" /></a>Most likely you will be presented with the following dialog box, informing you that opening the solution (or more correct the LarsW.CommandLineParser C# project inside) can pose a security risk. The reason for this is that I’ve included the a MSBuild task for compiling MGrammar files (.mg) into .mgx is that included in the Oslo SDK. Select the <strong>“Load project normally”</strong> and press <strong>OK</strong>.</p>
<p align="justify">We can first take a look at the extra plumbing I’ve added to the project to get the .mg file to compile. Right-click the LarsW.CommandLineParser project in the Solution Explorer, and choose <em>Unload Project</em>. Next, right-click it again, and choose <em>Edit LarsW.CommandLineparser.csproj. This should bring up the </em>project file will be shown as raw XML in the editor window.</p>
<p align="justify">In the first &lt;PropertyGroup&gt; I’ve added seven lines that I borrowed from a project created with the “M” template. They basically set’s up the path to various M-specific tools and auxiliary files.</p>
<p align="justify">The only line of these that really matter and that I had to tweak in order to get this right is the <strong>&lt;MgTarget&gt;</strong> element. Out of the box this is set to Mgx, that instructs the Mg compiler to spit out the result of the compilation as a <strong>.mgx</strong> file. As we will see later, the value needs to be set to MgResource in order to get the DynamicParser to load the <strong>.mgx</strong> as a resource.</p>
<p>If you navigate to the end of the project file, I’ve also added an &lt;Import&gt; element that imports some MGrammar specific MSBuild tasks and the most important thing; in the last <strong>&lt;ItemGroup&gt;</strong> section I’ve changed the element type from &lt;None&gt; to &lt;MgCompile&gt; for the <strong>cmd.mg</strong> file.</p>
<p>Well, we’ve been mucking around in the MSBuild plumbing too long now, haven’t we? Right-click the project again and choose <em>Reload Project</em>. When the project has loaded up again, build to ensure that everything is fine and dandy. Even though I haven’t stated it before, it should be obvious that the project depends on the latest (as of now that is the January 2009 CTP Refresh) Oslo SDK.</p>
<p>The core component is the <strong>CommandLineProcessor</strong> class.</p>
<p>It loads up the language (the compiled version of the <em>cmd.mg</em>) with <strong>DynamicParser.LoadFromResource()</strong>. The reason why we had to specify <strong>MgxResource</strong> as the <strong>MgTarget</strong> earlier is that if we don’t, and add the compiled .mgx file as a plain resource, the <strong>.LoadFromResource()</strong> method won’t find it. As of now, it seems that it will only look for resources with the <em>.resource</em> extension.</p>
<p>We then pass in the command line with a <strong>StringReader</strong> instance to the <strong>.Parse&lt;T&gt;</strong>() method on the <strong>DynamicParser</strong> instance. Even though it’s not specified, the T has to be object or a type that implements <strong>System.Dataflow.ISourceInfo</strong>. The internal/inner Node classes in GraphBuilder is what that will be handed out per default, but you can also create your own GraphBuilder and produce nodes from your own domain model.</p>
<p>So, by calling parser.Parse&lt;object&gt;(null, commandLineReader, ErrorReporter.Standard) we will get an instance to the root of the Abstract Syntax Tree (AST) returned if the input matches the grammar. The AST is basically a representation of the MGraph.</p>
<p>The next step is to traverse the AST and act upon the different node types. The grammar for this project is quite trivial and is mostly done by the private <strong>ProcessParameter()</strong> method in the <strong>CommandLineProcessor</strong> class. I suggest that you take a look at it if you’re interested in doing something similar.</p>
<p>So, just create an instance of the <strong>CommandLineProcessor</strong> and pass in an instance of an arbitrary class that contains method that will handle the command line arguments. To specify that a method is a argument handler, decorate it with the <strong>CommandLineArgumentHandler</strong> attribute. It will take in three parameters; short form &amp; long form of the argument keyword and a description. For now the description isn’t used for anything but the idea is that the command line processor can auto generate a usage screen for you (typically shown with –?).</p>
<p>That’s about it – if you find it useful or modify the code, please let me know. With git you can push me a change set and I will try to merge it if you’ve come up with a cool feature.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.larswilhelmsen.com/2009/03/19/parsing-the-command-line-with-mgrammar-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Configurable PrincipalPermission attribute</title>
		<link>http://www.larswilhelmsen.com/2008/12/17/configurable-principalpermission-attribute/</link>
		<comments>http://www.larswilhelmsen.com/2008/12/17/configurable-principalpermission-attribute/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 13:50:11 +0000</pubDate>
		<dc:creator>larsw</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://larsw.wordpress.com/2008/12/17/configurable-principalpermission-attribute/</guid>
		<description><![CDATA[I while ago, a question came up in the WCF Forum about configuring the role and/or user name properties of the PrincipalPermission attribute. As I answered, it is possible to create a custom version of the attribute (deriving from the CodeAccessSecurityAttribute, since the PrincipalPermission attribute is sealed) and pull the property values from the {web&#124;app}.config [...]]]></description>
			<content:encoded><![CDATA[<p>I while ago, <a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/aa2adc6a-db26-4604-b214-d575cf8e27c8" target="_blank">a question came up</a> in the WCF Forum about configuring the role and/or user name properties of the <a href="http://msdn2.microsoft.com/7skx7sw2.aspx" target="_blank">PrincipalPermission</a> attribute. As I answered, it is possible to create a custom version of the attribute (deriving from the <a href="http://msdn2.microsoft.com/w91w8a2b.aspx" target="_blank">CodeAccessSecurityAttribute</a>, since the PrincipalPermission attribute is sealed) and pull the property values from the {web|app}.config file.</p>
<p>I implemented a solution for this about a year ago and planned to put up a blog post about it, but it never made it out to the public (the main cause is probably that I experienced a blog-block period of my life <img src='http://www.larswilhelmsen.com/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> ).</p>
<p>The same requirement may be a viable solution i system I’m currently working on for a customer, so I dug through my archives and found the old code.</p>
<p>I’ve polished it a bit made it available <a href="http://larsw-public.s3.amazonaws.com/LarsW.Security-1.0.0.zip" target="_blank">here</a> under the Apache License 2.0.</p>
<p>The extended version, PrincipalPermissionEx can be used in two modes; either as a “normal” derivable PrincipalPermission attribute or an attribute that uses the configuration system (or a combination of both).</p>
<p>Instead of using the generic PrincipalPermission attribute, you’ll make derived version for each system role with a sensible name – making it more reliable and resistant to typos; e.g. </p>
<pre>[MustHaveSuperUserPrivilegesPermission]
public void PrivilegedOperation(…)
{
}</pre>
<p>instead of:</p>
<pre>[PrincipalPermission(Role = &quot;MYDOMAIN\SuperUsers&quot;)]
public void PrivilegedOperation(…)
{
}</pre>
<p>
  <br />Take a look at the supplied sample code to see how this is implemented.</p>
<p>The usage of PrincipalPermission-based authorization is useful in a variety of scenarios; it can be applied to WCF services, ASP.NET &amp; Smart Client applications. Note that if you put the user name/role in the configuration file, you will need to ensure that the file is locked down with an appropriate ACL to prevent tampering by malicious users. This might not apply to solutions hosted on a locked down server (i.e. IIS-hosted web applications and services) but for smart / desktop clients where the user might have higher privileges to files on the local file system it is necessary to be aware of this.</p>
<p>As always, feedback is welcome <img src='http://www.larswilhelmsen.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2flarswilhelmsen.com%2f2008%2f12%2f17%2fconfigurable-principalpermission-attribute%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2flarswilhelmsen.com%2f2008%2f12%2f17%2fconfigurable-principalpermission-attribute%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larswilhelmsen.com/2008/12/17/configurable-principalpermission-attribute/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>LINQ to XML: XPathSelectElement Annoyance</title>
		<link>http://www.larswilhelmsen.com/2008/12/12/linq-to-xml-xpathselectelement-annoyance/</link>
		<comments>http://www.larswilhelmsen.com/2008/12/12/linq-to-xml-xpathselectelement-annoyance/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 14:08:23 +0000</pubDate>
		<dc:creator>larsw</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Annoyance]]></category>
		<category><![CDATA[Bug?]]></category>
		<category><![CDATA[LINQ to XML]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[XPath]]></category>

		<guid isPermaLink="false">http://larsw.wordpress.com/2008/12/12/linq-to-xml-xpathselectelement-annoyance/</guid>
		<description><![CDATA[It may be me – since I’m no XPath (or XSLT) pro, but the following is in my book a bug – or at least an annoyance category 3: Given the following XML document loaded into an XDocument: &#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62; &#60;Elements&#62; &#60;Element Id=&#34;1&#34; /&#62; &#60;Element Id=&#34;2&#34; /&#62; &#60;Element Id=&#34;3&#34; /&#62; &#60;Element Id=&#34;4&#34; /&#62; &#60;Element [...]]]></description>
			<content:encoded><![CDATA[<p>It may be me – since I’m no XPath (or XSLT) pro, but the following is in my book a bug – or at least an annoyance category 3:</p>
<p>Given the following XML document loaded into an XDocument:</p>
<pre style="background:#222222;"><span style="background:#222222;color:#66bfff;">&lt;?xml </span><span style="background:#222222;color:white;">version</span><span style="background:#222222;color:#66bfff;">=</span><span style="background:#222222;color:#d282a6;">&quot;1.0&quot; </span><span style="background:#222222;color:white;">encoding</span><span style="background:#222222;color:#66bfff;">=</span><span style="background:#222222;color:#d282a6;">&quot;utf-8&quot;</span><span style="background:#222222;color:#66bfff;">?&gt;
&lt;Elements&gt;
  &lt;Element </span><span style="background:#222222;color:white;">Id</span><span style="background:#222222;color:#66bfff;">=</span><span style="background:#222222;color:#d282a6;">&quot;1&quot; </span><span style="background:#222222;color:#66bfff;">/&gt;
  &lt;Element </span><span style="background:#222222;color:white;">Id</span><span style="background:#222222;color:#66bfff;">=</span><span style="background:#222222;color:#d282a6;">&quot;2&quot; </span><span style="background:#222222;color:#66bfff;">/&gt;
  &lt;Element </span><span style="background:#222222;color:white;">Id</span><span style="background:#222222;color:#66bfff;">=</span><span style="background:#222222;color:#d282a6;">&quot;3&quot; </span><span style="background:#222222;color:#66bfff;">/&gt;
  &lt;Element </span><span style="background:#222222;color:white;">Id</span><span style="background:#222222;color:#66bfff;">=</span><span style="background:#222222;color:#d282a6;">&quot;4&quot; </span><span style="background:#222222;color:#66bfff;">/&gt;
  &lt;Element </span><span style="background:#222222;color:white;">Id</span><span style="background:#222222;color:#66bfff;">=</span><span style="background:#222222;color:#d282a6;">&quot;5&quot; </span><span style="background:#222222;color:#66bfff;">/&gt;
&lt;/Elements&gt;</span></pre>
<p>The following XPath should&#160; yield the first element of the list:</p>
<pre style="background:#222222;"><span style="background:#222222;color:#bac794;">&quot;//Element[@Id = '1']&quot;</span></pre>
<p>
  <br />Guess what? If use the .XPathSelectElement() extension method, the result will be null – nada!</p>
</p>
<pre style="background:#222222;"><span style="background:#222222;color:#bac794;">&quot;//Element[@Id='1']&quot;</span></pre>
<p>
  <br />The same query without the whitespace around the equal sign will give you the right result.</p>
<p>If you’re an XPath pro I would like your opinion on the matter – or else I’m turning this issue over to <a href="http://connect.microsoft.com/" target="_blank">http://connect.microsoft.com/</a></p>
<p><em>Sigh.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larswilhelmsen.com/2008/12/12/linq-to-xml-xpathselectelement-annoyance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Codename &#8220;Velocity&#8221; WF/WCF Persistence Provider</title>
		<link>http://www.larswilhelmsen.com/2008/12/11/codename-velocity-wfwcf-persistence-provider/</link>
		<comments>http://www.larswilhelmsen.com/2008/12/11/codename-velocity-wfwcf-persistence-provider/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 20:24:24 +0000</pubDate>
		<dc:creator>larsw</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Persistence Provider]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[WF]]></category>

		<guid isPermaLink="false">http://larsw.wordpress.com/2008/12/11/codename-velocity-wfwcf-persistence-provider/</guid>
		<description><![CDATA[So, it’s been a bit quiet here lately. The natural cause of it is (in no particular order): A lot of work Spending quality time with my son Hacking on different kinds of technology bits (mainly pieces released at the PDC 2008) I’ve also tried to get a clear picture of my “blind spots” when [...]]]></description>
			<content:encoded><![CDATA[<p>So, it’s been a bit quiet here lately. The natural cause of it is (in no particular order):</p>
<ul>
<li>A lot of work</li>
<li>Spending quality time with my son</li>
<li>Hacking on different kinds of technology bits (mainly pieces released at the PDC 2008)</li>
</ul>
<p>I’ve also tried to get a clear picture of my “blind spots” when it comes to WCF. Even though I feel quite competent, there are still tons of stuff that I don’t touch daily so I still have to “rehearse”.</p>
<p>Since I have “Get to know Workflow Foundation – for real” on my TODO list I spent some time playing with durable services.</p>
<p>The persistence provider mechanism that is located in <strong>System.WorkflowServices</strong> is not exclusive to to Workflows / Workflow services. It can also be used with “vanilla” WCF Services.</p>
<p>The idea is that the framework can persist the service instance after you have invoked a method and when a future method invocation comes down the wire, it can pull it from the persistence store – revive it and pass the call to the “same” instance. A perfect fit for the scenario of long running services.</p>
<p>So how do you enable durable services? It is quite easy. First, you decorate your service implementation with <strong>[DurableService]</strong> and one of the mechanisms that specifies that the type is <em>serializable</em> (I chose <strong>[Serializable]</strong> for the sake of simplicity).</p>
<p><img style="display:inline;" title="image" src="http://larsw.files.wordpress.com/2008/12/image.png" alt="image" width="352" height="543" /></p>
<p>In this code snippet we also see that there is another attribute that can be used to tell the persistence mechanism that a call to an operation creates the instance or tears it down; <a href="http://msdn.microsoft.com/en-us/system.servicemodel.description.durableoperationattribute.aspx" target="_blank">[DurableOperation]</a>.</p>
<p>The next thing you have to do is to wire up a persistence provider using either configuration or programmatically.</p>
<p>Out of the box there exists only one Persistence Provider; One suited for persisting the service instances to SQL Server – <em>System.ServiceModel.Persistence.SqlPersistenceProviderFactory.</em> You will have to set up a SQL Server Database instance with the schema located in <em>C:\Windows\Microsoft.NET\Framework\v3.5\SQL\EN</em>.</p>
<p>But that was a digression – now back to my custom “Velocity” Persistence Provider. If you don’t know what Codename “Velocity” is, I suggest that you head over <a href="http://blogs.msdn.com/velocity/" target="_blank">here</a> and read more about it. The short description:</p>
<p>It is Microsoft’s attempt to create an in-memory, high-performance, distributed caching supporting different scenarios that can suite many needs in both a web farm or other places where caching is needed. The current version that is publicly available is CTP2. We should expect a new CTP in March (around the time of MIX’09) and the RTW/RTM in the mid of 2009.</p>
<p>To implement a custom persistence provider, you will have to create two classes; the persistence provider implementation and its factory. It is the fully qualified type name of the factory that is specified when you set up the configuration.</p>
<p>The following configuration snippet shows how a custom service behavior is set up. You will have to set the <em>behaviorConfiguration</em> attribute on the service element to <strong>“defaultServiceBehavior”</strong> in this case.</p>
<p><img style="display:inline;" title="image" src="http://larsw.files.wordpress.com/2008/12/image1.png" alt="image" width="497" height="161" /></p>
<p>The code for the provider is available <a href="http://larsw-public.s3.amazonaws.com/LarsW.VelocityPersistenceProvider-1.0.0.zip" target="_blank">here</a> (Licensed under the <em>Apache License 2.0</em>).</p>
<p>Cheers <img src='http://www.larswilhelmsen.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> <br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2flarswilhelmsen.com%2f2008%2f12%2f11%2fcodename-velocity-wfwcf-persistence-provider%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2flarswilhelmsen.com%2f2008%2f12%2f11%2fcodename-velocity-wfwcf-persistence-provider%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larswilhelmsen.com/2008/12/11/codename-velocity-wfwcf-persistence-provider/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>What&#8217;s new in WCF 4.0</title>
		<link>http://www.larswilhelmsen.com/2008/11/25/whats-new-in-wcf-40/</link>
		<comments>http://www.larswilhelmsen.com/2008/11/25/whats-new-in-wcf-40/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 20:54:13 +0000</pubDate>
		<dc:creator>larsw</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[NNUG]]></category>
		<category><![CDATA[Talks]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://larsw.wordpress.com/2008/11/25/whats-new-in-wcf-40/</guid>
		<description><![CDATA[Tonight I held a talk for the Norwegian .NET User Group Oslo on “What’s new in WCF 4.0”. The feedback was good and I think it went fairly well, especially considered the time I’ve had to prepare. There should probably have been more time allocated for demonstrations but to cover all the areas of improvements [...]]]></description>
			<content:encoded><![CDATA[<p>Tonight I held a talk for the Norwegian .NET User Group Oslo on “What’s new in WCF 4.0”. The feedback was good and I think it went fairly well, especially considered the time I’ve had to prepare.</p>
<p>There should probably have been more time allocated for demonstrations but to cover all the areas of improvements in WCF (and related technologies) I really need (at least) 45 minutes. If I’m asked to do this talk for other NNUG chapters (or internal for other companies/clients) I think it would be wise to either cut down on the content – and only mention the left out parts briefly – or extend it to a two hour talk.</p>
<p>If you attended the talk, I would love feedback (both positive &amp; negative), comments, questions, speaking &amp; consultancy offers. Contact me at lw at miles dot no </p>
<p>You can download the slides <a href="http://larsw-public.s3.amazonaws.com/What%20is%20new%20in%20WCF%204.0.pdf" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.larswilhelmsen.com/2008/11/25/whats-new-in-wcf-40/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Where are the System.ServiceModel .Discovery bits?</title>
		<link>http://www.larswilhelmsen.com/2008/11/21/where-are-the-systemservicemodeldiscovery-bits/</link>
		<comments>http://www.larswilhelmsen.com/2008/11/21/where-are-the-systemservicemodeldiscovery-bits/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 10:51:14 +0000</pubDate>
		<dc:creator>larsw</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[NNUG]]></category>
		<category><![CDATA[System.ServiceModel.Discovery]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[WS-Discovery]]></category>

		<guid isPermaLink="false">http://larsw.wordpress.com/2008/11/21/where-are-the-systemservicemodeldiscovery-bits/</guid>
		<description><![CDATA[I’m currently preparing my talk for next Tuesday &#8211; “What’s new in WCF 4.0” and one of the features I want to talk about is the new WS-Discovery implementation. My only problem so far (until today) was that I couldn’t find the bits on the Virtual PC Image! I have been searching high and low [...]]]></description>
			<content:encoded><![CDATA[<p>I’m currently preparing my talk for next Tuesday &#8211; “<em>What’s new in WCF 4.</em>0” and one of the features I want to talk about is the new <em>WS-Discovery</em> implementation. My only problem so far (until today) was that I couldn’t find the bits on the Virtual PC Image! I have been searching high and low with .NET Reflector – to no luck.</p>
<p>So I wrote a post in the WCF forum and asked if anyone knew where I could find it. No good answers, so I sent the question to a couple of the PM’s in Connected Systems Division that I know work with WCF. No answer. Finally I turned to the Email form on <a href="http://blogs.msdn.com/drnick/" target="_blank">Nicholas Allen’s blog</a> – and he was kind enough to mail me back.</p>
<p>Turn out that the bits is in the <strong>System.WorkflowServiceModel</strong> – one of the assemblies I didn’t bother to search since I thought they only contained Workflow-specific bits…</p>
<p>The invitation to the talk on Tuesday can be found <a href="http://www.nnug.no/Avdelinger/Oslo/Moter/Brukergruppemote-november-2008/" target="_blank">here</a> (In Norwegian). I’m hoping for at least 70-80 attendees.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.larswilhelmsen.com/2008/11/21/where-are-the-systemservicemodeldiscovery-bits/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft PDC &#039;08 &amp; Los Angeles; here I come!</title>
		<link>http://www.larswilhelmsen.com/2008/08/15/microsoft-pdc-08-los-angeles-here-i-come/</link>
		<comments>http://www.larswilhelmsen.com/2008/08/15/microsoft-pdc-08-los-angeles-here-i-come/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 18:20:47 +0000</pubDate>
		<dc:creator>larsw</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PDC'08]]></category>

		<guid isPermaLink="false">http://larsw.wordpress.com/2008/08/15/microsoft-pdc-08-los-angeles-here-i-come/</guid>
		<description><![CDATA[Today, August 15th, is the last day you get a discount when you sign up for the Microsoft Professional Developer Conference 2008, held in&#160; Los Angeles, CA. I have not been sure if I was going to make it to the PDC this year, giving that I&#8217;ve just started in a new company and I [...]]]></description>
			<content:encoded><![CDATA[<p>Today, August 15th, is the last day you get a discount when you sign up for the <a href="http://www.microsoftpdc.com/" target="_blank">Microsoft Professional Developer Conference 2008</a>, held in&#160; <a href="http://en.wikipedia.org/wiki/Los_Angeles" target="_blank">Los Angeles, CA</a>.</p>
<p>I have not been sure if I was going to make it to the PDC this year, giving that I&#8217;ve just started in a new company and I didn&#8217;t know on beforehand if the customer&#8217;s project manager would approve. I really thought TechEd EMEA would be more realistic, but today I actually managed to pull it off.</p>
<p>The answers was:</p>
<ul>
<li>Miles: Of course, Lars! Go to the PDC.</li>
<li>Customer&#8217;s PM: Of course Lars! Go to the PDC.</li>
<li>@ home: Of course Lars! Go to the PDC.</li>
</ul>
<p>So today I have signed up! Reserved a hotel room at the <a href="http://www.miyakoinn.com/">Miyako Hotel</a> and ordered plane tickets through <a href="http://www.seat24.no/" target="_blank">Seat24</a> with <a href="https://www.continental.com/" target="_blank">Continental Airlines</a>. There&#8217;s a stop in <a href="http://en.wikipedia.org/wiki/Newark,_New_Jersey" target="_blank">Newark, NJ</a> both to &amp; from, but hopefully I&#8217;ll manage.</p>
<p>So, the thing to do now is to get an overview over the sessions that Microsoft has been announced.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.larswilhelmsen.com/2008/08/15/microsoft-pdc-08-los-angeles-here-i-come/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
