<?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>Christoph De Baene</title>
	<atom:link href="http://www.christophdebaene.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christophdebaene.com/blog</link>
	<description>daily date with the compiler</description>
	<lastBuildDate>Fri, 12 Apr 2013 20:07:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Building the source code of ASP.NET (Web API)</title>
		<link>http://www.christophdebaene.com/blog/2012/04/06/building-the-source-code-of-asp-net-web-api/</link>
		<comments>http://www.christophdebaene.com/blog/2012/04/06/building-the-source-code-of-asp-net-web-api/#comments</comments>
		<pubDate>Fri, 06 Apr 2012 00:18:43 +0000</pubDate>
		<dc:creator>Christoph De Baene</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET Web API]]></category>

		<guid isPermaLink="false">http://www.christophdebaene.com/blog/?p=1099</guid>
		<description><![CDATA[There is a lot of activity in the source code of ASP.NET on CodePlex. Because of some bug that has been fixed, I wanted to try out the latest build. Simply download the latest source code from CodePlex (I used changed set 88372a0b4ab9). Like it is mentioned on CodePlex you have to obtain the NuGet P...]]></description>
				<content:encoded><![CDATA[<p>There is a lot of activity in the <a href="http://aspnetwebstack.codeplex.com/SourceControl/list/changesets">source</a> code of <a href="http://aspnetwebstack.codeplex.com/">ASP.NET</a> on <a href="http://www.codeplex.com/">CodePlex</a>.<br />
Because of some <a href="http://aspnetwebstack.codeplex.com/workitem/10">bug</a> that has been fixed, I wanted to try out the latest build.</p>
<p>Simply download the latest source code from CodePlex (I used changed set <a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/88372a0b4ab9">88372a0b4ab9</a>).<br />
Like it is mentioned on CodePlex you have to obtain the <a href="http://aspnetwebstack.codeplex.com/wikipage?title=NuGet%20Packages">NuGet Packages</a> first and after that you can build.</p><pre class="crayon-plain-tag">build RestorePackages
build</pre><p>To test some things out I created a simple console application (inside the same solution) and added the following references with the following code</p>
<div class="shortcode-list arrow">
<ul>
<li>System.Net.Http</li>
<li>System.Web.Http</li>
<li>System.Web.Http.SelfHost</li>
</ul>
</div>
<p></p><pre class="crayon-plain-tag">static void Main(string[] args)
{
   var baseAddress = "http://localhost:7777/";
   var config = new HttpSelfHostConfiguration(baseAddress);
   config.Routes.MapHttpRoute(
      name: "DefaultApi",
      routeTemplate: "api/{controller}/{id}",
      defaults: new
      {
         id = RouteParameter.Optional
      });

   var server = new HttpSelfHostServer(config);
   server.OpenAsync().Wait();
   Console.WriteLine("The server is running...");
}</pre><p>When you have installed <a href="http://www.asp.net/mvc/mvc4">ASP.NET MVC4 Beta</a> you will get the following error</p>
<p><em id="__mceDel">
<div class="message-box-wrapper red">
<div class="message-box-title">Error</div>
<div class="message-box-content"></em>Could not load type &#8216;System.Web.Http.RouteParameter&#8217; from assembly &#8216;System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&#8242;.<em id="__mceDel"></div>
</div>
<p></em>Because the signed assembly has the same version it will always load the one that reside in the <a href="http://en.wikipedia.org/wiki/Global_Assembly_Cache">GAC</a>. There are breaking changes in the new version and it clearly doesn&#8217;t load the latest &#8216;System.Web.Http&#8217; assembly within the solution! This can be seen and monitored by using <a href="http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.100).aspx">Fuslogvw</a>.</p>
<p>To resolve this problem we can use <a href="http://msdn.microsoft.com/en-us/library/cskzh7h6.aspx">DEVPATH</a>. It&#8217;s an environment variable that you can set to a folder (typically you&#8217;re output folder). The runtime will use the DEVPATH folder for probing before looking into the GAC!<br />
After setting the DEVPATH environment variable (I had to restart my Visual Studio to take effect) you have to add the following in the config file and after that everything worked fine.</p><pre class="crayon-plain-tag">&lt;?xml version="1.0"?&gt;
&lt;configuration&gt;
  &lt;runtime&gt;
    &lt;developmentMode developerInstallation="true"/&gt;
  &lt;/runtime&gt;
&lt;/configuration&gt;</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdebaene.com/blog/2012/04/06/building-the-source-code-of-asp-net-web-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Roslyn &#8211; Formatting Code</title>
		<link>http://www.christophdebaene.com/blog/2011/10/26/roslyn-formatting-code/</link>
		<comments>http://www.christophdebaene.com/blog/2011/10/26/roslyn-formatting-code/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 23:41:34 +0000</pubDate>
		<dc:creator>Christoph De Baene</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code Generation]]></category>
		<category><![CDATA[Roslyn]]></category>

		<guid isPermaLink="false">http://www.christophdebaene.com/blog/?p=1083</guid>
		<description><![CDATA[Roslyn CTP is the implementation of a &#8216;compiler-as-a-service&#8217; for C# and VB.Net. Generally compilers are black boxes, the Roslyn project changes that by opening up APIs that you can use for code related tasks in your tools and applications. In this post we are investigating source code f...]]></description>
				<content:encoded><![CDATA[<p><a href="http://msdn.microsoft.com/en-us/roslyn">Roslyn CTP</a> is the implementation of a &#8216;compiler-as-a-service&#8217; for C# and VB.Net. Generally compilers are black boxes, the Roslyn project changes that by opening up APIs that you can use for code related tasks in your tools and applications.</p>
<p>In this post we are investigating <a href="http://en.wikipedia.org/wiki/Prettyprint">source code formatting</a>. Inside my projects I use as much as possible code generation and whether it is coming from T4 templates or some other mechanism, there is usually the need to format your code in a consistent way.</p>
<p>Inside Roslyn we can use the <em>SyntaxTree</em> class that resides in the <em>Roslyn.Compilers.CSharp</em> namespace to parse a text file (that contains C# of VB code). And after we can use the <em>Format</em> extension method that resides in the <em>CompilationUnitSyntax</em> class to reformat your code.</p><pre class="crayon-plain-tag">var code = File.ReadAllText("Sample.cs");

var tree = SyntaxTree.ParseCompilationUnit(code);
var root = (CompilationUnitSyntax)tree.Root;

var formattedCode = root.Format().GetFullText();</pre><p>Take for example the code fragment below (<em>Sample.cs</em>) which is totally unformatted.</p><pre class="crayon-plain-tag">namespace Domain
{
using System;
using System
.Collections
.Generic;
using System.ComponentModel.DataAnnotations;

public class BankAccount
:Entity,
IValidatableObject
{
public BankAccountNumber BankAccountNumber {
get;
set; }

public string Iban
{
get
{
return string
.Format("ES{0} {1} {2} {0}{3}",
this.BankAccountNumber.CheckDigits,
this.BankAccountNumber
.NationalBankCode,
this.BankAccountNumber
.OfficeNumber,
this.BankAccountNumber
.AccountNumber);
}
set {

}
}

public decimal Balance { get;
private set; }

public virtual ICollection
BankAccountActivity
{
get
{
if (_bankAccountActivity
== null)
_bankAccountActivity =
new HashSet();

return _bankAccountActivity;
}
set
{
_bankAccountActivity =
new HashSet(value);
}
}
}
}</pre><p>When passing the code fragment through the <em>SyntaxTree</em> and calling the <em>Format</em> extension method you get the following result which is formatted correctly.</p><pre class="crayon-plain-tag">namespace Domain
{
   using System;
   using System.Collections.Generic;
   using System.ComponentModel.DataAnnotations;

   public class BankAccount : Entity, IValidatableObject
   {
      public BankAccountNumber BankAccountNumber
      {   
         get;
         set;
      }

      public string Iban
      {
         get
         {
            return string.Format("ES{0} {1} {2} {0}{3}", this.BankAccountNumber.CheckDigits, this.BankAccountNumber.NationalBankCode, this.BankAccountNumber.OfficeNumber, this.BankAccountNumber.AccountNumber);
         }
         set
         {
         }
      }

      public decimal Balance
      {
         get;
         private set;
      }

      public virtual ICollection BankAccountActivity
      {
         get
         {
            if (_bankAccountActivity == null)
               _bankAccountActivity = new HashSet();
            return _bankAccountActivity;
         }
         set
         {
            _bankAccountActivity = new HashSet(value);
         }
     }   
   }
}</pre><p>Note that when you are using for example lambda expressions or delegates that the formatter will add unnecessary newlines and whitespaces. Take for example the following code fragment after calling the <em>Format</em> method.</p><pre class="crayon-plain-tag">public void SomeMethod()
{
   this.Click += (s, e) =&gt;
   {
      MessageBox.Show(((MouseEventArgs)e).Location.ToString());
   }
   ;
   treeView.AfterExpand += new TreeViewEventHandler(delegate (object o, TreeViewEventArgs t)
   {
      t.Node.ImageIndex = (int)FolderIconEnum.open;
      t.Node.SelectedImageIndex = (int)FolderIconEnum.open;
   }
);
}</pre><p>Thankfully we have everything in control through the APIs and we can rewrite the expression (like the <em>Format</em> extension method is doing).</p>
<p>For that we need to create a class inheriting from <em>SyntaxRewriter</em> that resides in the <em>Roslyn.Compilers.CSharp</em> namespace and implements the <a href="http://en.wikipedia.org/wiki/Visitor_pattern">Visitor pattern</a>.</p><pre class="crayon-plain-tag">public class CodeBeautifier: SyntaxRewriter
{
   protected override SyntaxToken VisitToken(SyntaxToken token)
   {
      switch (token.Kind)
      {
         case SyntaxKind.SemicolonToken:

         if (token.GetPreviousToken().Kind == SyntaxKind.CloseBraceToken ||
            token.GetPreviousToken().Kind == SyntaxKind.CloseParenToken)
         {
            return token
            .WithLeadingTrivia()
            .WithTrailingTrivia(Syntax.ElasticCarriageReturnLineFeed);
         }

         break;

      case SyntaxKind.CloseBraceToken:

         if (token.GetNextToken().Kind == SyntaxKind.CloseParenToken ||
            token.GetNextToken().Kind == SyntaxKind.SemicolonToken)
         {
             return token
             .WithTrailingTrivia();
         }

      break;

      case SyntaxKind.CloseParenToken:

         if (token.GetPreviousToken().Kind == SyntaxKind.CloseBraceToken)
         {
            return token
            .WithLeadingTrivia();
         }

      break;
   }

    return token;
}
}</pre><p>Note that I am visiting the syntax tokens, these are the terminals of the language grammar (representing the smallest syntactic fragments) and investigating the current kind of token with the next or previous kind of token. Syntax Trivia represents the parts such as whitespace, comments and preprocessor directives. Inside the <em>VisitToken</em> method I am replacing the syntax trivia parts.</p>
<p>To use the <em>CodeBeautifier </em>class you need to simply create an instance of it and using the <em>Visit</em> method to pass your node.</p><pre class="crayon-plain-tag">var code = File.ReadAllText("Sample.cs");

var tree = SyntaxTree.ParseCompilationUnit(code);
var root = (CompilationUnitSyntax)tree.Root;

var formattedCode = new CodeBeautifier().Visit(root.Format()).GetFullText();</pre><p>After the syntax rewriting you will see that the code now looks like below</p><pre class="crayon-plain-tag">public void SomeMethod()
{
this.Click += (s, e) =&gt;
{
MessageBox.Show(((MouseEventArgs)e).Location.ToString());
};
treeView.AfterExpand += new TreeViewEventHandler(delegate (object o, TreeViewEventArgs t)
{
t.Node.ImageIndex = (int)FolderIconEnum.open;
t.Node.SelectedImageIndex = (int)FolderIconEnum.open;
});
}</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdebaene.com/blog/2011/10/26/roslyn-formatting-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>0xc0000225 error when installing Win2008R2x64 on VirtualBox</title>
		<link>http://www.christophdebaene.com/blog/2011/10/04/0xc0000225-error-when-installing-win2008r2x64-on-virtualbox/</link>
		<comments>http://www.christophdebaene.com/blog/2011/10/04/0xc0000225-error-when-installing-win2008r2x64-on-virtualbox/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 19:28:32 +0000</pubDate>
		<dc:creator>Christoph De Baene</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.christophdebaene.com/blog/?p=1076</guid>
		<description><![CDATA[When trying to setup and install Windows Server 2008 R2 x64 on VirtualBox you may encounter the following error It turns out you need to enable the IO APIC setting, like below...]]></description>
				<content:encoded><![CDATA[<p>When trying to setup and install Windows Server 2008 R2 x64 on <a href="https://www.virtualbox.org/">VirtualBox</a> you may encounter the following error</p>
<p><a href="http://www.christophdebaene.com/blog/wp-content/uploads/2011/10/VirtualBoxWin2008R2X64.jpg"><img class="alignnone size-medium wp-image-1077" title="VirtualBoxWin2008R2X64" src="http://www.christophdebaene.com/blog/wp-content/uploads/2011/10/VirtualBoxWin2008R2X64-300x246.jpg" alt="" width="300" height="246" /></a></p>
<p>It turns out you need to enable the <a href="http://en.wikipedia.org/wiki/Intel_APIC_Architecture">IO APIC</a> setting, like below</p>
<p><a href="http://www.christophdebaene.com/blog/wp-content/uploads/2011/10/VirtualBoxSettings.jpg"><img class="alignnone size-full wp-image-1078" title="VirtualBoxSettings" src="http://www.christophdebaene.com/blog/wp-content/uploads/2011/10/VirtualBoxSettings.jpg" alt="" width="587" height="443" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdebaene.com/blog/2011/10/04/0xc0000225-error-when-installing-win2008r2x64-on-virtualbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Live Writer 2011 Tips</title>
		<link>http://www.christophdebaene.com/blog/2011/08/20/windows-live-writer-2011-tips/</link>
		<comments>http://www.christophdebaene.com/blog/2011/08/20/windows-live-writer-2011-tips/#comments</comments>
		<pubDate>Fri, 19 Aug 2011 23:18:52 +0000</pubDate>
		<dc:creator>Christoph De Baene</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Utils & Tools]]></category>
		<category><![CDATA[Windows Live]]></category>

		<guid isPermaLink="false">http://www.christophdebaene.com/blog/?p=1063</guid>
		<description><![CDATA[Windows Live Writer (WLW) is a great tool that enables you to edit and publish your blog posts. Below you find some tips about WLW. Make WLW portable I love portable applications, it enables you to store them on a USB drive or in the cloud without losing your settings and data. It turns out that it’...]]></description>
				<content:encoded><![CDATA[<p><a href="http://explore.live.com/windows-live-writer">Windows Live Writer</a> (WLW) is a great tool that enables you to edit and publish your blog posts.<br />
Below you find some tips about WLW.</p>
<h4>Make WLW portable</h4>
<p>I love <a href="http://en.wikipedia.org/wiki/Portable_application">portable applications</a>, it enables you to store them on a USB drive or in the cloud without losing your settings and data. It turns out that it’s pretty easy to make WLW portable, and thankfully the <a href="http://www.christophdebaene.com/blog/2008/10/30/how-to-make-your-windows-live-writer-portable/">investigation</a> I did 3 years ago is still valid for version 2011!</p>
<p>The steps are very simple</p>
<ol>
<li><strong>Copy</strong> all the contents of your installation folder (<em>C:\Program Files (x86)\Windows Live\Writer</em>) to your destination folder (e.g. USB stick)</li>
<li><strong>Create</strong> a <strong>folder</strong> called ‘<em>UserData</em>’ in your destination folder (same level with the folders <em>Dictionaries</em>, <em>Plugins</em>, …)</li>
</ol>
<p>You will see after launching WLW and configuring your blog site it will create all necessary files and folders for you settings and posts inside the <em>UserData</em> folder!</p>
<p><a href="http://www.christophdebaene.com/blog/wp-content/uploads/2011/08/WLWUserDataFolder.jpg" class="broken_link"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="WLWUserDataFolder" src="http://www.christophdebaene.com/blog/wp-content/uploads/2011/08/WLWUserDataFolder_thumb.jpg" alt="WLWUserDataFolder" width="505" height="127" border="0" /></a></p>
<h4>Edit existing posts</h4>
<p>With WLW it’s possible to edit existing posts (that originally were not posted with WLW) on your blog. It’s not directly clear from the user interface how to do that!</p>
<p>Click on the app menu in the ribbon bar en click on<em> <strong>Open recent post</strong></em>, not the items that appear on the right!</p>
<p><a href="http://www.christophdebaene.com/blog/wp-content/uploads/2011/08/WLWOpenRecentPostMenu.jpg" class="broken_link"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="WLWOpenRecentPostMenu" src="http://www.christophdebaene.com/blog/wp-content/uploads/2011/08/WLWOpenRecentPostMenu_thumb.jpg" alt="WLWOpenRecentPostMenu" width="234" height="239" border="0" /></a></p>
<p>After that you get a dialog where you can choose your blog site on the right. It retrieves all post items of your blog and you simply pick the one that you want to edit!</p>
<p><a href="http://www.christophdebaene.com/blog/wp-content/uploads/2011/08/WLWRecentPostDialog.jpg" class="broken_link"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="WLWRecentPostDialog" src="http://www.christophdebaene.com/blog/wp-content/uploads/2011/08/WLWRecentPostDialog_thumb.jpg" alt="WLWRecentPostDialog" width="580" height="439" border="0" /></a></p>
<h4>Use DropBox to sync your local drafts across computers</h4>
<p>I use <a href="http://www.dropbox.com/">DropBox</a> a lot, it’s a free hosting service that enables you to store and share files and folders across the internet. I use it to share my portable utilities and tools, and also WLW (after making it portable). This way I can always access my drafts and edit them when and where I want!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdebaene.com/blog/2011/08/20/windows-live-writer-2011-tips/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introducing Neo4jConnect</title>
		<link>http://www.christophdebaene.com/blog/2011/04/11/introducing-neo4jconnect/</link>
		<comments>http://www.christophdebaene.com/blog/2011/04/11/introducing-neo4jconnect/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 21:45:04 +0000</pubDate>
		<dc:creator>Christoph De Baene</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Neo4j]]></category>

		<guid isPermaLink="false">http://www.christophdebaene.com/blog/?p=1001</guid>
		<description><![CDATA[I started with an open-source project called Neo4jConnect that enables you to connect to Neo4j, which is a graph-database written in Java and accessible through the REST api. On this page you can find the several operations exposed by Neo4j through REST. Neo4jConnect exposes an object api to manipul...]]></description>
				<content:encoded><![CDATA[<p>I started with an open-source project called <a href="http://neo4jconnect.codeplex.com/">Neo4jConnect</a> that enables you to connect to <a href="http://neo4j.org/">Neo4j</a>, which is a graph-database written in Java and accessible through the <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a> api. On <a href="http://components.neo4j.org/neo4j-server/milestone/rest.html">this</a> page you can find the several operations exposed by Neo4j through REST. Neo4jConnect exposes an object api to manipulate the graph database.</p>
<p>More information and a quickstart can be found on the project <a href="http://neo4jconnect.codeplex.com/">site</a>.</p>
<p>In the next couple of weeks I will add more documentation and features!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdebaene.com/blog/2011/04/11/introducing-neo4jconnect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Archi(Mate): Architecture modeling language and tool</title>
		<link>http://www.christophdebaene.com/blog/2011/04/06/archimate-architecture-modeling-language-and-tool/</link>
		<comments>http://www.christophdebaene.com/blog/2011/04/06/archimate-architecture-modeling-language-and-tool/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 22:26:05 +0000</pubDate>
		<dc:creator>Christoph De Baene</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Modeling]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.christophdebaene.com/blog/?p=991</guid>
		<description><![CDATA[ArchiMate is an open and independent Enterprise Architecture modeling language that supports the description, analysis and visualization of architecture within and across business domains. ArchiMate is one of the open standards hosted by The Open Group and is based on the IEEE 1471 standard. The goa...]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.archimate.org/en/home/" class="broken_link">ArchiMate</a> is an open and independent Enterprise Architecture modeling language that supports the description, analysis and visualization of architecture within and across business domains. ArchiMate is one of the open standards hosted by <a href="http://www.opengroup.org/">The Open Group</a> and is based on the IEEE 1471 standard.</p>
<p>The goals of ArchiMate are</p>
<ul>
<li>To describe architectures and their <strong>relations</strong></li>
<li><strong>Communicate </strong>enterprise architectures with all stakeholders</li>
<li>Judge the impact of <strong>changes</strong></li>
<li><strong>Realise </strong>architecture by relating to existing standards, techniques and tools</li>
</ul>
<p><a href="http://archi.cetis.ac.uk/">Archi</a> is a free open source java application to create ArchiMate models.</p>
<p>[custom_frame_center]<br />
<a rel="wp-prettyPhoto" href="http://www.christophdebaene.com/blog/wp-content/uploads/2011/04/archi3_800.png"><img class="alignnone size-medium wp-image-992" title="archi3_800" src="http://www.christophdebaene.com/blog/wp-content/uploads/2011/04/archi3_800-300x199.png" alt="Archimate" width="300" height="199" /></a><br />
[/custom_frame_center]</p>
<p>You can also find a quick reference card of Archimate <a href="https://doc.novay.nl/dsweb/Get/Document-52048/">here</a> and you can also download <a href="https://doc.novay.nl/dsweb/Get/Document-32177/ArchiMate%20Visio%20stencils.zip">Archimate stencils</a> for Visio.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdebaene.com/blog/2011/04/06/archimate-architecture-modeling-language-and-tool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a .NET Windows Service in 5 steps with Topshelf</title>
		<link>http://www.christophdebaene.com/blog/2011/03/16/create-a-net-windows-service-in-5-steps-with-topshelf/</link>
		<comments>http://www.christophdebaene.com/blog/2011/03/16/create-a-net-windows-service-in-5-steps-with-topshelf/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 19:28:09 +0000</pubDate>
		<dc:creator>Christoph De Baene</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Services]]></category>

		<guid isPermaLink="false">http://www.christophdebaene.com/blog/?p=907</guid>
		<description><![CDATA[Topshelf is an open-source hosting framework for building Windows Services using .NET. With Topshelf you can create in a few lines of code your own windows service. It&#8217;s a kind of internal DSL for building windows services. I used version 2.2 of Topshelf and the binaries and sources can be fou...]]></description>
				<content:encoded><![CDATA[<p><a href="http://topshelf-project.com/">Topshelf</a> is an open-source hosting framework for building Windows Services using .NET. With Topshelf you can create in a few lines of code your own windows service. It&#8217;s a kind of internal <a href="http://martinfowler.com/bliki/DomainSpecificLanguage.html">DSL</a> for building windows services. I used version <strong>2.2</strong> of Topshelf and the binaries and sources can be found <a href="https://github.com/topshelf/topshelf">here</a> (GitHub).</p>
<p>First download Topshelf from GitHub, I used version 2.2 (<a href="https://github.com/downloads/Topshelf/Topshelf/Topshelf.v2.2.0.0.zip" class="broken_link">direct link</a>).</p>
<ol>
<li>Create a <strong>console application</strong> named &#8216;<em>SampleWindowsService</em>&#8216; inside Visual Studio<br />
[message type="info"]Be sure to change the target framework to &#8216;<em>.NET Framework 4</em>&#8216;[/message]</li>
<li><strong>Reference </strong>the <strong>binaries </strong><em>TopShelf.dll</em> and <em>log4net.dll </em>(included in Topshelf).</li>
<li><strong>Create </strong>a simple <strong>service </strong>called &#8216;SampleService&#8217; that simply write every 5 seconds to the log. Note that we create explicit a <em>Start </em>and <em>Stop </em>method which is conceptually the minimum that a windows service need.[csharp]<br />
public class SampleService<br />
{<br />
    private Timer _timer = null;<br />
    readonly ILog _log = LogManager.GetLogger(<br />
                                     typeof(SampleService));</p>
<p>    public SampleService()<br />
    {<br />
        double interval = 5000;<br />
        _timer = new Timer(interval);<br />
        _timer.Elapsed += new ElapsedEventHandler(OnTick);<br />
    }</p>
<p>    protected virtual void OnTick(object sender, ElapsedEventArgs e)<br />
    {<br />
        _log.Debug(&quot;Tick:&quot; + DateTime.Now.ToLongTimeString());<br />
    }</p>
<p>    public void Start()<br />
    {<br />
        _log.Info(&quot;SampleService is Started&quot;);</p>
<p>        _timer.AutoReset = true;<br />
        _timer.Enabled = true;<br />
        _timer.Start();<br />
    }</p>
<p>    public void Stop()<br />
    {<br />
        _log.Info(&quot;SampleService is Stopped&quot;);</p>
<p>        _timer.AutoReset = false;<br />
        _timer.Enabled = false;<br />
    }<br />
}<br />
[/csharp]</li>
<li>In the main method of our console application we will use Topshelf to <strong>host </strong>our <em>SampleService</em>.<br />
We we are telling Topshelf how to start and stop the service, what the service name is, etc.<br />
Note that we need to configure log4net for Topshelf and our service![csharp]<br />
static void Main(string[] args)<br />
{<br />
    XmlConfigurator.ConfigureAndWatch(<br />
        new FileInfo(&quot;.\\log4net.config&quot;));</p>
<p>    var host = HostFactory.New(x =&gt;<br />
    {<br />
        x.EnableDashboard();<br />
        x.Service(s =&gt;<br />
        {<br />
            s.SetServiceName(&quot;SampleService&quot;);<br />
            s.ConstructUsing(name =&gt; new SampleService());<br />
            s.WhenStarted(tc =&gt;<br />
            {<br />
                XmlConfigurator.ConfigureAndWatch(<br />
                    new FileInfo(&quot;.\\log4net.config&quot;));<br />
                tc.Start();<br />
            });<br />
            s.WhenStopped(tc =&gt; tc.Stop());<br />
        });</p>
<p>        x.RunAsLocalSystem();<br />
        x.SetDescription(&quot;SampleService Description&quot;);<br />
        x.SetDisplayName(&quot;SampleService&quot;);<br />
        x.SetServiceName(&quot;SampleService&quot;);<br />
    });</p>
<p>    host.Run();<br />
}<br />
[/csharp]</li>
<li>The only thing we have to do now is to <strong>configure </strong>log4net. Create a file called &#8216;<em>log4net.config</em>&#8216; with the following configuration.[xml]<br />
&lt;!&#8211;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&#8211;&gt;</p>
<p>[/xml]</p>
<p>This configuration enables to output to the console and through a <a href="http://en.wikipedia.org/wiki/User_Datagram_Protocol">UDP</a> network protocol so that we can easily monitor the log statements when installed as a windows service. I used <a href="http://log2console.codeplex.com/">Log2Console</a> (Codeplex) to monitor my log statements through UDP.<br />
[message type="info"]Make sure the output directory of <em>log4net.config</em> is set to &#8216;Copy always&#8217;[/message] [message type="warning"]Note that there is an <a href="http://www.alteridem.net/2010/07/09/log4net-udpappender-with-ipv6-on-windows-vista-and-7/">issue</a> with log4net related to IPv6 and Windows Vista/7. You can fix it by adding the following &#8217;127.0.0.1 log4view-local&#8217; to your hosts file which can be found in folder <em>C:\Windows\System32\drivers\etc\hosts</em>.[/message]</li>
</ol>
<p>When you fit F5 you will see that Topshelf outputs some log statements and you will see that the log statements of our SampleService is included and everything is working properly.</p>
<p><a href="http://www.christophdebaene.com/blog/wp-content/uploads/2011/03/TopshelfConsole.jpg"><img class="alignnone size-medium wp-image-958" title="TopshelfConsole" src="http://www.christophdebaene.com/blog/wp-content/uploads/2011/03/TopshelfConsole-300x199.jpg" alt="" width="300" height="199" /></a></p>
<p>In order to install SampleService as a Windows Service you simply need to do the following through the command prompt.</p>
<p>[message type="info"]Be sure to launch the command prompt as an administrator![/message]</p>
<p>[text]SampleWindowsService.exe install[/text]</p>
<p>After that when the windows service has been installed successfully we can start the service through <em>services.msc</em> or simply by typing</p>
<p>[text]SampleWindowsService.exe start[/text]</p>
<p>Now we can open Log2Console to monitor our log files that is send through the UDP appender.</p>
<p><a href="http://www.christophdebaene.com/blog/wp-content/uploads/2011/03/Log2Console.jpg"><img class="alignnone size-medium wp-image-966" title="Log2Console" src="http://www.christophdebaene.com/blog/wp-content/uploads/2011/03/Log2Console-300x232.jpg" alt="" width="300" height="232" /></a><br />
To uninstall the service we simply write</p>
<p>[text]SampleWindowsService.exe uninstall[/text]</p>
<p>The sources can be found <a href="https://bitbucket.org/delarou/blogsamples/src/482fbab1bcbe/TopshelfSample/">here</a> (BitBucket)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdebaene.com/blog/2011/03/16/create-a-net-windows-service-in-5-steps-with-topshelf/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code coverage with Visual Studio</title>
		<link>http://www.christophdebaene.com/blog/2009/07/13/code-coverage-with-visual-studio-2/</link>
		<comments>http://www.christophdebaene.com/blog/2009/07/13/code-coverage-with-visual-studio-2/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 22:51:31 +0000</pubDate>
		<dc:creator>Christoph De Baene</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Visual studio]]></category>

		<guid isPermaLink="false">http://christophdebaene.com/blog/?p=629</guid>
		<description><![CDATA[Code coverage is used to determine how effectively your tests exercise the code in your application. This way you can identify sections of code that are covered, not covered or partially covered by your tests. Visual Studio uses 2 different types of analysis, block-based statement coverage (C1 cover...]]></description>
				<content:encoded><![CDATA[<p>Code coverage is used to determine how effectively your tests exercise the code in your application. This way you can identify sections of code that are covered, not covered or partially covered by your tests.</p>
<p>Visual Studio uses 2 different types of analysis, block-based statement coverage (C1 coverage) and line-based coverage.</p>
<ul>
<li><strong>Block-based statement coverage</strong>
<p>A block is defined as a sequence of instructions that have a single entry point and a single exit point. Exit points include branch instructions, a function call, a return instruction, or, for managed code, a throw instruction.</li>
<li><strong>Line-based coverage</strong>
<p>For line-based coverage, the tools identify all of the blocks that make up a line and then use this information to determine the level of coverage for the line. If all of the blocks that make up the line are covered, then the tools report that the line is covered. If no blocks in the line are covered, then the tools report that the line is not covered. If some, but not all, of the blocks in the line are covered, then the tools report that the line is partially covered.</li>
</ul>
<p>Take for example the following class that reside in MyProject.BusinessLogic assembly</p>
<p>[csharp]<br />
public class Foo<br />
{<br />
    public int Calculate(int x, int y)<br />
    {<br />
        if (x &gt; 0 &amp;&amp; y &lt; 0)<br />
        {<br />
            return -1;<br />
        }<br />
        else<br />
        {<br />
            return 1;<br />
        }<br />
}<br />
[/csharp]</p>
<p>And a unit test that reside in <em>MyProject.BusinessLogic.Test</em> assembly</p>
<p>[csharp]<br />
[TestClass]<br />
public class FooTest<br />
{<br />
    [TestMethod]<br />
    public void Calculate()<br />
    {<br />
        Foo foo = new Foo();<br />
        Assert.AreEqual(1, foo.Calculate(3, 4));<br />
    }<br />
}<br />
[/csharp]</p>
<p>To enable code coverage you need to double-lick on the LocalTestRun.testrunconfig file that is located in the &#8216;Solution Items&#8217; folder.</p>
<p><a href="http://christophdebaene.com/blog/wp-content/uploads/2009/07/testrunconfig_2.jpg"><img class="alignnone size-full wp-image-631" title="testrunconfig_2" src="http://christophdebaene.com/blog/wp-content/uploads/2009/07/testrunconfig_2.jpg" alt="" width="294" height="146" /></a></p>
<p>Inside the &#8216;Code Coverage&#8217; tab you select the assembly that you want to instrument. In this case we select <em>MyProject.BusinessLogic.dll</em> assembly.</p>
<p><a href="http://christophdebaene.com/blog/wp-content/uploads/2009/07/codecoverage_1.jpg"><img class="alignnone size-full wp-image-632" title="codecoverage_1" src="http://christophdebaene.com/blog/wp-content/uploads/2009/07/codecoverage_1.jpg" alt="" width="593" height="432" /></a></p>
<p>Now you will need to run your unit tests again. Note that code coverage doesn&#8217;t work when you debug your unit tests, so you will need to run your unit tests through the menu &#8216;Test –&gt; Run –&gt; All Tests in Solution (CTRL+R, A)&#8217;. After that you can view a report about the code coverage results through the menu &#8216;Test –&gt; Windows –&gt; Code Coverage Results&#8217;.</p>
<p><a href="http://christophdebaene.com/blog/wp-content/uploads/2009/07/codecoverageresults_4.jpg"><img class="alignnone size-full wp-image-634" title="codecoverageresults_4" src="http://christophdebaene.com/blog/wp-content/uploads/2009/07/codecoverageresults_4.jpg" alt="" width="640" height="130" /></a></p>
<p>From the results we notice that we don&#8217;t have 100% code coverage because our unit test only reached one part of the condition inside the Calculate method. If you open the Foo class and enable the code coloring you see the parts that are covered, not covered or partially covered.</p>
<p><a href="http://christophdebaene.com/blog/wp-content/uploads/2009/07/CodeCoverageColoring_2.jpg"><img class="alignnone size-full wp-image-635" title="CodeCoverageColoring_2" src="http://christophdebaene.com/blog/wp-content/uploads/2009/07/CodeCoverageColoring_2.jpg" alt="" width="380" height="301" /></a></p>
<ul>
<li>Light Blue: Indicates that the entire line of code was exercised in the test run.</li>
<li>Beige: Indicates that only a portion of the code blocks within the line of code were exercised in the test run.</li>
<li>Reddish Brown: Indicates that the line was not exercised in the test run.</li>
</ul>
<p>Code coverage inside Visual Studio uses <a href="http://en.wikipedia.org/wiki/Code_coverage">statement coverage</a> and in this case the number of IL instructions reached is taken into account. If we add some statements in the Foo class and run again our code coverage we notice that the coverage has been raised form 71,43% to 92,59%. It&#8217;s important to notice, that when you refactor your class it influences the code coverage even when the contract of the class is the same! This is very different from <a href="http://en.wikipedia.org/wiki/Code_coverage">Branch coverage</a> where each control structure is evaluated to true and false. In this case we would have 50% code coverage.</p>
<p>[csharp]<br />
public class Foo<br />
{<br />
    public int Calculate(int x, int y)<br />
    {<br />
        if (x &gt; 0 &amp;&amp; y &lt; 0)<br />
        {<br />
            return -1;<br />
        }<br />
        else<br />
        {<br />
            Console.WriteLine(x.ToString());<br />
            Console.WriteLine(x.ToString());<br />
            Console.WriteLine(x.ToString());<br />
            Console.WriteLine(x.ToString());<br />
            Console.WriteLine(x.ToString());<br />
            Console.WriteLine(x.ToString());<br />
            Console.WriteLine(x.ToString());<br />
            Console.WriteLine(x.ToString());<br />
            Console.WriteLine(x.ToString());<br />
            Console.WriteLine(x.ToString());</p>
<p>            return 1;<br />
        }<br />
    }<br />
}<br />
[/csharp]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdebaene.com/blog/2009/07/13/code-coverage-with-visual-studio-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enumerating project items in a Visual Studio solution</title>
		<link>http://www.christophdebaene.com/blog/2009/07/08/enumerating-project-items-in-a-visual-studio-solution-2/</link>
		<comments>http://www.christophdebaene.com/blog/2009/07/08/enumerating-project-items-in-a-visual-studio-solution-2/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 16:25:43 +0000</pubDate>
		<dc:creator>Christoph De Baene</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Visual studio]]></category>

		<guid isPermaLink="false">http://christophdebaene.com/blog/?p=637</guid>
		<description><![CDATA[Often you have the need to iterate through a collection and most of the time the iteration logic is weaved with the action that need to be done. This is because we are used to program in an imperative approach. In some scenarios it&#8217;s better to use a functional approach and let other functions ...]]></description>
				<content:encoded><![CDATA[<p>Often you have the need to iterate through a collection and most of the time the iteration logic is weaved with the action that need to be done. This is because we are used to program in an <a href="http://en.wikipedia.org/wiki/Imperative_programming">imperative</a> approach. In some scenarios it&#8217;s better to use a <a href="http://msdn.microsoft.com/en-us/library/bb669144.aspx">functional</a> approach and let other functions decide which action need to be applied. This way we can for example reuse our iteration logic.</p>
<p>Below is an iterator that starts from a solution or project and iterates through all project items inside the solution.</p>
<p>[csharp]<br />
public class ProjectItemIterator : IEnumerable&lt;EnvDTE.ProjectItem&gt;<br />
{<br />
    IEnumerable&lt;EnvDTE.Project&gt; projects;</p>
<p>    public ProjectItemIterator(EnvDTE.Solution solution)<br />
    {<br />
        if (solution == null)<br />
            throw new ArgumentNullException(&quot;solution&quot;);</p>
<p>        projects = solution.Projects.Cast&lt;EnvDTE.Project&gt;();<br />
    }</p>
<p>    public ProjectItemIterator(IEnumerable&lt;EnvDTE.Project&gt; projects)<br />
    {<br />
        if (projects == null)<br />
            throw new ArgumentNullException(&quot;projects&quot;);</p>
<p>        this.projects = projects;<br />
    }</p>
<p>    public IEnumerator&lt;EnvDTE.ProjectItem&gt; GetEnumerator()<br />
    {<br />
        foreach (EnvDTE.Project currentProject in projects)<br />
            foreach (var currentProjectItem in Enumerate(currentProject.ProjectItems))<br />
                yield return currentProjectItem;<br />
    }</p>
<p>    IEnumerable&lt;EnvDTE.ProjectItem&gt; Enumerate(EnvDTE.ProjectItems projectItems)<br />
    {<br />
        foreach (EnvDTE.ProjectItem item in projectItems)<br />
        {<br />
            yield return item;</p>
<p>            if (item.SubProject != null)<br />
            {<br />
                foreach (EnvDTE.ProjectItem childItem in Enumerate(item.SubProject.ProjectItems))<br />
                    yield return childItem;<br />
            }<br />
            else<br />
            {<br />
                foreach (EnvDTE.ProjectItem childItem in Enumerate(item.ProjectItems))<br />
                    yield return childItem;<br />
            }<br />
        }<br />
    }</p>
<p>    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()<br />
    {<br />
        return GetEnumerator();<br />
    }<br />
}<br />
[/csharp]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdebaene.com/blog/2009/07/08/enumerating-project-items-in-a-visual-studio-solution-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Customize code generation in .NET RIA Services</title>
		<link>http://www.christophdebaene.com/blog/2009/03/31/customize-code-generation-in-net-ria-services-2/</link>
		<comments>http://www.christophdebaene.com/blog/2009/03/31/customize-code-generation-in-net-ria-services-2/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 01:17:23 +0000</pubDate>
		<dc:creator>Christoph De Baene</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Services]]></category>

		<guid isPermaLink="false">http://christophdebaene.com/blog/?p=626</guid>
		<description><![CDATA[Microsoft .NET RIA Services simplifies the traditional n-tier application pattern by bringing together the ASP.NET and Silverlight platforms. RIA Services provides a pattern to write application logic that runs on the mid-tier and controls access to data for queries, changes and custom operations. I...]]></description>
				<content:encoded><![CDATA[<p><em>Microsoft .NET RIA Services simplifies the traditional n-tier application pattern by bringing together the ASP.NET and Silverlight platforms. RIA Services provides a pattern to write application logic that runs on the mid-tier and controls access to data for queries, changes and custom operations. It also provides end-to-end support for common tasks such as data validation, authentication and roles by integrating with Silverlight components on the client and ASP.NET on the mid-tier.</em></p>
<p>To get started with .NET RIA Services you need Visual Studio 2008 SP1 and you need to install the following packages</p>
<ul>
<li>Microsoft Silverlight 3 Tools Beta 1 for Visual Studio 2008 SP1</li>
<li>Microsoft .NET RIA Services March &#8217;09 Preview</li>
</ul>
<p>On the download page of .NET RIA Services there is a great PDF document (riaservicesoverviewpreview.pdf) that gives you a step-by-step guide.</p>
<p>Every time you compile a solution with .NET RIA Services, an MSBuild task is executed that generates code in your Silverlight project from the domain services (DomainService class) that reside in your ASP.NET server. After some investigation through reflector, you can actually modify or extend the code generation using <a href="http://msdn.microsoft.com/en-us/library/y2k85ax6.aspx">CodeDom</a>! For this you need to add an attribute called DomainIdentifier where you specify a type that inherits from CodeProcessor. Both classes reside in the System.Web.Ria.Data namespace.</p>
<p>[csharp]<br />
[EnableClientAccess()]<br />
[DomainIdentifier(&quot;Comment&quot;, CodeProcessor = typeof(CommentCodeProcessor))]<br />
public class CityService : DomainService<br />
{<br />
   //&#8230;<br />
}<br />
[/csharp]</p>
<p>In this example, we simply add some documentation in the summary tag.</p>
<p>[csharp]<br />
public class CommentCodeProcessor : CodeProcessor<br />
{<br />
    public CommentCodeProcessor(CodeDomProvider codeDomProvider)<br />
        : base(codeDomProvider)<br />
    {<br />
    }</p>
<p>    public override void ProcessGeneratedCode(<br />
        DomainServiceDescription domainServiceDescription,<br />
        System.CodeDom.CodeCompileUnit codeCompileUnit,<br />
        IDictionary&lt;Type, System.CodeDom.CodeTypeDeclaration&gt; typeMapping)<br />
    {<br />
        Type domainServiceType = domainServiceDescription.DomainServiceType;<br />
        CodeTypeDeclaration declaration = typeMapping[domainServiceType];</p>
<p>        declaration.Comments.Add(new CodeCommentStatement(&quot;&lt;summary&gt;&quot;, true));</p>
<p>        foreach (var entityType in domainServiceDescription.EntityTypes)<br />
        {<br />
            declaration.Comments.Add(<br />
                new CodeCommentStatement(<br />
                    string.Format(&quot;Entity Type: {0}&quot;, entityType.FullName), true));<br />
        }</p>
<p>        foreach (var operationEntry in domainServiceDescription.DomainOperationEntries)<br />
        {<br />
            declaration.Comments.Add(<br />
                new CodeCommentStatement(<br />
                    string.Format(&quot;Operation Entry: {0}&quot;, operationEntry.MethodInfo.Name), true));<br />
        }</p>
<p>        declaration.Comments.Add(new CodeCommentStatement(&quot;&lt;/summary&gt;&quot;, true));<br />
    }<br />
}<br />
[/csharp]</p>
<p>Below you find a sample of the generated file using the <em>CommentCodeProcessor</em></p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
/// Entity Type: SilverlightApplication.Web.DataModels.City<br />
/// Operation Entry: GetCities<br />
/// Operation Entry: ReturnAllCities<br />
/// &lt;/summary&gt;<br />
[DomainIdentifier(&quot;Comment&quot;)]<br />
public sealed partial class CityContext : DomainContext<br />
{<br />
   //&#8230;<br />
}<br />
[/csharp]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdebaene.com/blog/2009/03/31/customize-code-generation-in-net-ria-services-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
