<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blog.irm.se/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Blogs @ IRM</title><link>http://blog.irm.se/blogs/default.aspx</link><description /><dc:language>en-US</dc:language><generator>CommunityServer 2.1 (Build: 60809.935)</generator><item><title>SlowCheetah XML Transforms as part of a TFS Build</title><link>http://blog.irm.se/blogs/eric/archive/2012/05/15/SlowCheetah-XML-Transforms-as-part-of-a-TFS-Build.aspx</link><pubDate>Tue, 15 May 2012 12:46:00 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48823</guid><dc:creator>ericqu</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;A half year ago I blogged about “&lt;a href="http://blog.irm.se/blogs/eric/archive/2011/09/14/Deploying-ClickOnce-to-Multiple-Environments.aspx"&gt;Deploying ClickOnce to Multiple Environments&lt;/a&gt;”, but now I want to take this a couple of steps further and use a build server to automate the deploys. The first thing that I looked into was how to get SlowCheetah XML Transformations to work on our build server and this is the steps I took:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;First of all I added the files the SlowCheetah installed to a place relative to my project files. You can find the files in you profile folder under “AppData\Local\Microsoft\MSBuild\SlowCheetah\v1”, so I copied them to our packages folder and checked them in to TFS Source Control.&lt;/li&gt;    &lt;li&gt;After this I right-clicked on my project in Solution Explorer and choose “Edit Project File”. Search for SlowCheetahTargets and replace “$(LOCALAPPDATA)\Microsoft\MSBuild\SlowCheetah\v1\SlowCheetah.Transforms.targets” with the relative path to the targets file. In my case I replaced it with “..\packages\SlowCheetah.Transforms.targets”.&lt;/li&gt;    &lt;li&gt;Now when you create a new Build definition in TFS you can set “Configurations to Build” (under “Build process parameters” and “Items to Build”) to the configuration that you want to build and the transformations will be applied on the build server too.&lt;/li&gt; &lt;/ol&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48823" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/eric/archive/tags/Windows+Forms/default.aspx">Windows Forms</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/Tools/default.aspx">Tools</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category></item><item><title>EA Principles–a way to overcome complexity and create simplicity</title><link>http://blog.irm.se/blogs/eskil/archive/2012/05/10/EA-Principles_1320_a-way-to-overcome-complexity-and-create-simplicity.aspx</link><pubDate>Thu, 10 May 2012 10:01:47 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48822</guid><dc:creator>eskil</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;b&gt;Eskil Swende starts a discussion on EA Principles. He will discuss a number of hypotheses how to overcome complexity and create simplicity. &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Our enterprises evolve continuously. As a result, their architectural structures are transformed and extended continuously. Without control such changes are bound to lead to an overly complex and uncoordinated environment. Such a structure is hard to manage and may resist future changes in the desired direction.&lt;/p&gt;  &lt;p&gt;Enterprise Architecture (EA) aims to proactively manage and share this structure. One main purpose of EA is to simplify the structure to make the enterprise agile and prepared for change and transformation. The other main purpose of EA is to simplify IT solutions and the system architecture.&lt;/p&gt;  &lt;p&gt;A number of Architecture Principles form the cornerstone of EA. These principles provide a means to direct a successful transformation of the enterprise and achieve simplicity beyond the complexity.&lt;/p&gt;  &lt;h4&gt;&lt;a name="_Toc317251392"&gt;Introduction&lt;/a&gt;&lt;/h4&gt;  &lt;h5&gt;&lt;a name="_Toc317251393"&gt;Background&lt;/a&gt;&lt;/h5&gt;  &lt;p&gt;EA has been around since Zachman introduced his Framework in the 1980s. EA was introduced to management by “Enterprise Architecture as Strategy” written by Ross, Weill and Robertson, published in 2006. Today the Open Group is introducing EA globally with their TOGAF Framework.&lt;/p&gt;  &lt;p&gt;In Scandinavia more than 150 Architecture Plans have been developed since 1982, starting at SAS and SKF and recently at Scania, Statoil and IKEA to mention a few important examples. More than 800 Enterprise Architects have been certified at an academic level since 1994.&lt;/p&gt;  &lt;h4&gt;&lt;a name="_Toc317251394"&gt;Contribution&lt;/a&gt;&lt;/h4&gt;  &lt;p&gt;A large number of global experts have been visiting us in Sweden and generously shared their knowledge and experience contributing to these EA Principles. Among them are Michael Brackett, Chris Bradley, Malcolm Chisholm, Steve Conway, Larry English, Thomas Erl, Danny Greefhorst, Steve Hoberman, Dirk Krafzig, Rick van der Lans, Stuart MacGregor, Jan Henderyckx, Dave McComb, Daniel Moody, Alexander Osterwalder, David Robertson, Jaap Schekkerman, Bob Seiner, Len Silverstone, Graeme Simsion and John Zachman.&lt;/p&gt;  &lt;p&gt;A number of very professional certified enterprise architects in the DAMA Scandinavia network have been very supportive with helpful proposals and criticism.&lt;/p&gt;  &lt;p&gt;A special thanks to Len Fehskens and his very inspiring thoughts in “Re-thinking Architecture”.&lt;/p&gt;  &lt;h5&gt;&lt;a name="_Toc317251395"&gt;What is a principle?&lt;/a&gt;&lt;/h5&gt;  &lt;p&gt;“A principle is a &lt;a href="http://en.wikipedia.org/wiki/Law"&gt;law&lt;/a&gt; or &lt;a href="http://en.wikipedia.org/wiki/Rule"&gt;rule&lt;/a&gt; that has to be, or usually is to be followed, or can be desirably followed, or is an inevitable consequence of something, such as the laws observed in nature or the way that a system is constructed.” (Wikipedia).&lt;/p&gt;  &lt;h5&gt;&lt;a name="_Toc317251396"&gt;Why EA Principles?&lt;/a&gt;&lt;/h5&gt;  &lt;p&gt;Now when EA is globally accepted we may continue our effort to reach maturity. We all know that adding complexity is a short term solution to many problems. On the other hand creating simplicity is a long term solution, which requires a lot of knowledge, experience and resources. &lt;/p&gt;  &lt;p&gt;Is there any way where we can work proactively towards long term solutions when we solve our short term problems? Yes, we think so. Reusing or creating simple solutions is often easier than adding complexity.&lt;/p&gt;  &lt;p&gt;The EA Principles I want to discuss in this column aim at finding more long term simplicity when finding solutions to our problems.&lt;/p&gt;  &lt;p&gt;“EA must include everything you need and nothing you don´t need” is one of the most important thoughts from Len Fehskens. “Simplicity is a virtue” is stated by Ingvar Kamprad, the founder of IKEA.&lt;/p&gt;  &lt;h4&gt;&lt;a name="_Toc317251397"&gt;List of EA Principles&lt;/a&gt;&lt;/h4&gt;  &lt;h5&gt;&lt;a name="_Toc317251398"&gt;The overall EA Principles&lt;/a&gt;&lt;/h5&gt;  &lt;ol&gt;   &lt;li&gt;Manage Information as a Resource and capture data once only &lt;/li&gt;    &lt;li&gt;Create simplicity to overcome the complexity &lt;/li&gt; &lt;/ol&gt;  &lt;h5&gt;&lt;a name="_Toc317251399"&gt;EA Principles&lt;/a&gt;&lt;/h5&gt;  &lt;ol&gt;   &lt;li&gt;Create a Business Driven Architecture &lt;/li&gt;    &lt;li&gt;Develop and manage an Overall Business Information Model &lt;/li&gt;    &lt;li&gt;Develop and manage an Overall Business Process Architecture &lt;/li&gt;    &lt;li&gt;Achieve traceability from the overall architecture to the solution details and vice versa &lt;/li&gt;    &lt;li&gt;Start at the top and keep the overview &lt;/li&gt;    &lt;li&gt;Support transformation, give assistance and share the EA knowledge &lt;/li&gt;    &lt;li&gt;Relate EA to the Business Innovation Models &lt;/li&gt;    &lt;li&gt;Invest in reusable Components &lt;/li&gt;    &lt;li&gt;Develop and manage an EA – Project agreement for new IT Solutions &lt;/li&gt;    &lt;li&gt;Establish EA Governance supporting the desired transformations &lt;/li&gt; &lt;/ol&gt;  &lt;h4&gt;&lt;a name="_Toc317251400"&gt;Overall EA Principle 1 – Managing Information as a Resource and capture data once only &lt;/a&gt;&lt;/h4&gt;  &lt;p&gt;Information is a unique resource because you don’t consume it when using it. But it is also a very difficult resource to manage. Ted Codd, an English mathematician, made 1970 a ground-breaking development with his “Normalization theory” published and spread around the world by Chris Date.&lt;/p&gt;  &lt;p&gt;In Scandinavia Bo Sundgren, a Swedish IM-professor, has made it operational and created a workshop approach. A number of business experts together with a professional facilitator can achieve a high quality Information Model; often named Data Model by IT professionals.&lt;/p&gt;  &lt;p&gt;At architecture level we want to find a number of overall Information Groups, where an entity is only allowed in one single information group. Normally we find 25 – 40 Information Groups. These groups are gradually detailed when developing new IT solutions. This is a way to create reusable components in the business creating simplicity and reducing complexity. Read more at &lt;a href="http://www.tdan.com/view-articles/12655"&gt;http://www.tdan.com/view-articles/12655&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Still this requires knowledge and experience and many enterprises have not yet made this investment. Let us compare with the car and truck industry. Today this industry has invested heavily in modularity, but it has taken them more than 50 years to reach this maturity stage. Volkswagen calculate savings around 5 billion Euros yearly, since many car models use the same components or platform. When Scania or Volvo deliver a truck it is often unique, but it is built only using standard modules. In EA we have only just started such a journey.&lt;/p&gt;  &lt;h4&gt;&lt;a name="_Toc317251401"&gt;Overall EA Principle 2 – Create simplicity to overcome the complexity&lt;/a&gt;&lt;/h4&gt;  &lt;p&gt;Our world is growing more and more complex. We have many driving forces adding to this complexity and very few creating simplicity. Companies like IKEA, where “simplicity is a virtue”, are very rare.&lt;/p&gt;  &lt;p&gt;In a new book “Managing Complexity in our Organizations” Ulrich Steger at IMD in Lausanne tells us a lot about how complexity is still driving us away from a useful simplicity. Standardization of core processes is important when reducing complexity. There is a diversity of systems within a company that are often incompatible and resemble a patchwork of undisciplined IT-enabled business processes and redundant databases. The information itself is often quite diverse and is an important complexity driver. The complexity drivers in the innovation process are described in detail and are shown in a case study from LEGO, by Robert Davidson.&lt;/p&gt;  &lt;p&gt;Our experience is that creating simplicity may start with the overall information modeling and the development of common definitions of important entities. The information structure and the common definitions are very useful when developing the overall business process architecture. It is a good way to reduce complexity in the enterprise structure. To start with the processes avoiding the information itself is attractive, but a short cut is often the longest way around!&lt;/p&gt;  &lt;p&gt;&lt;i&gt;”It seems that perfection is reached,      &lt;br /&gt;not when there is nothing left to add,       &lt;br /&gt;but when there is nothing left to take away” &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;by Antoine de Saint Exupéry, French author and pilot, 1900 – 1944.&lt;/p&gt;  &lt;h4&gt;&lt;a name="_Toc317251402"&gt;Introducing the EA Principle approach&lt;/a&gt;&lt;/h4&gt;  &lt;p&gt;&lt;img src="http://blog.irm.se/photos/eskil/images/48817/original.aspx" width="600" height="450" /&gt;     &lt;br /&gt;Fig 1. In the center we have the City Plan (EA) describing the structure of the enterprise, mainly the business processes and the information resource. To the left we may have a number of Business Model Canvases, where we have a binary alignment to the City Plan. Like a sun up to the right we have the reusable components (modules) also binary aligned with the information resource in the City Plan. To the right we may have a number of development projects based on the structure in the City Plan and giving feedback to the architectural structure. &lt;/p&gt;  &lt;h4&gt;&lt;a name="_Toc317251403"&gt;Overview of the EA Principles&lt;/a&gt;&lt;/h4&gt;  &lt;p&gt;&lt;img src="http://blog.irm.se/photos/eskil/images/48821/original.aspx" width="600" height="450" /&gt;&lt;/p&gt;  &lt;p&gt;Fig 2. The EA Principles No 1-6 are guiding the development of the Enterprise Architecture to make it fulfil the EA purpose. No 7 is the binary alignment to the Business Innovation Model. No 8 is about how to develop reusable components. No 9 is the agreement between EA and Projects guiding the implementation of the Architecture. No 10 is the EA Governance needed to manage the transformation to the desired structure.&lt;/p&gt;  &lt;h4&gt;&lt;a name="_Toc317251404"&gt;Please give your feedback!&lt;/a&gt;&lt;/h4&gt;  &lt;p&gt;Please give your feedback about these hypotheses. Have we included everything you need and nothing more? Read more about it in the book “Architecture Principles - the cornerstones of EA”, by Danny Greefhorst.&lt;/p&gt;  &lt;h3&gt;EA Forum in Venice on the 21st – 22nd of August 2012&lt;/h3&gt;  &lt;p&gt;Learn more and discuss with experts and architects at the EA Forum in Venice on the 21st – 22nd of August 2012. &lt;/p&gt;  &lt;p&gt;Read more at &lt;a title="http://www.irm.se/ea-forum-in-venice" href="http://www.irm.se/ea-forum-in-venice"&gt;http://www.irm.se/ea-forum-in-venice&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In upcoming articles I will present and discuss each EA Principle in detail. &lt;/p&gt;  &lt;p&gt;Next article will discuss the pros and cons of creating an agile Business Driven Enterprise Architecture, where the architects facilitate a group of business experts covering the overall enterprise structure. &lt;/p&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48822" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/eskil/archive/tags/EA+Principles/default.aspx">EA Principles</category><category domain="http://blog.irm.se/blogs/eskil/archive/tags/Enterprise+Architecture/default.aspx">Enterprise Architecture</category></item><item><title>How to do Custom Event Logging and Trace Writing in Azure</title><link>http://blog.irm.se/blogs/johan/archive/2012/02/24/How-to-do-Custom-Event-Logging-and-Trace-Writing-in-Azure.aspx</link><pubDate>Fri, 24 Feb 2012 14:56:00 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48805</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;We&amp;rsquo;re about to begin our first &amp;ldquo;real&amp;rdquo; Azure project and I needed to wrap my head around event logging and trace writing in the cloud. Any proper application running in any cloud needs this sooner or later.&lt;/p&gt;  &lt;p&gt;I quickly noticed that the information around Azure diagnostics was all over the place, and some things seems to have been changed in newer versions of the Azure SDK. So, something I thought was going to take me just a few minutes to figure out took about a day, but I think I got it sorted in the end and here&amp;rsquo;s what I did to get simple event logging and trace writing to work for our web role. &lt;/p&gt;  &lt;p&gt;First thing I had to understand was how data for all kinds of diagnostics is handled and stored in Azure. You need to define which kinds of diagnostics data you want to capture, and you need to define where Azure should transfer the data captured so that you can download them or look at then with various tools. You also need to define how often these values should be transferred. I&amp;rsquo;ll get back to that a bit later.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Create a Custom Event Source&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;First thing I wanted to have was a custom event source to write to for warnings and errors. To do this I created a simple cmd-file which I placed inside the web role project and uploaded with the packed deployment. Now when the web role is deployed, you define startup task which runs in elevated mode (to be able to create the event source) and points to this cmd-file. So, create a file inside your project&amp;rsquo;s root called &lt;strong&gt;CreateEventSource.cmd&lt;/strong&gt; and put this inside it:&lt;/p&gt;  &lt;pre style="background:white;color:black;font-family:consolas;font-size:13px;"&gt;&lt;strong&gt;EventCreate /L Application /T Information /ID 900 /SO &amp;quot;MySource&amp;quot; /D &amp;quot;my custom source&amp;quot;&lt;/strong&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="background:white;color:black;font-family:consolas;font-size:13px;"&gt;&lt;font face="Verdana"&gt;&lt;strong&gt;NOTE! &lt;/strong&gt;Make sure the cmd-file property for &amp;ldquo;copy to output directory&amp;rdquo; is set to &amp;ldquo;copy always&amp;rdquo; or &amp;ldquo;copy if newer&amp;rdquo;.&lt;/font&gt;&lt;/pre&gt;

&lt;pre style="background:white;color:black;font-family:consolas;font-size:13px;"&gt;&lt;font face="Verdana"&gt;Then open up your service definition file, &lt;strong&gt;ServiceDefinition.csdef&lt;/strong&gt;, and add a startup task to it:&lt;/font&gt;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt;?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ServiceDefinition&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;MyWeb&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;WebRole&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;MyWebRole&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;vmsize&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ExtraSmall&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;strong&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Startup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Task&lt;/span&gt; &lt;span class="attr"&gt;commandLine&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;CreateEventSource.cmd&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;executionContext&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;elevated&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;taskType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;simple&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Startup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/strong&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Sites&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&amp;hellip; and so on&amp;hellip;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ServiceDefinition&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;p&gt;So now when your application is deployed the cmd-file should be executed with elevated permission and create the event log source you specified. &lt;strong&gt;EventCreate&lt;/strong&gt; is a tool which is available on the Azure server so it&amp;rsquo;s nothing you need to worry about. Same thing should work well on your local dev machine too.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Storage Location for Diagnostics Data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You need a place for the diagnostics data to be transferred to. This is number of Azure Storage tables so you need to create an Azure Storage Account where Azure can create these specific tables and transfer the captured data. So you basically go to the Azure Management Portal and create a new Storage Account and copy the access key. Then paste the storage account name and key into the Service Configuration:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/image_766969F9.png"&gt;&lt;img alt="image" border="0" height="216" src="http://weblogs.asp.net/blogs/jdanforth/image_thumb_231223D3.png" style="border:0px currentColor;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" width="642" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now when Azure starts to transfer data from event log and trace writes, they will be written to these two tables; WADLogsTable and WADWindowsEventLogsTable:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/image_33AA1EC1.png"&gt;&lt;img alt="image" border="0" height="114" src="http://weblogs.asp.net/blogs/jdanforth/image_thumb_6BE895D9.png" style="border:0px currentColor;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" width="242" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you capture performance counters and such, these will be written to other tables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Diagnostics Configuration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next thing to do is to configure which diagnostics to capture for your application. This is done in the &lt;strong&gt;OnStart()&lt;/strong&gt; method of your &lt;strong&gt;WebRole.cs&lt;/strong&gt; file. What I wanted to test initially was event logging to my custom source and also some trace writings for information, warning and errors. I also specified how frequently I wanted these diagnostics to be written to the storage tables:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; OnStart()
{
    var diag = DiagnosticMonitor.GetDefaultInitialConfiguration();
            
    diag.Logs.ScheduledTransferLogLevelFilter = LogLevel.Information;
    diag.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(30);

    diag.WindowsEventLog.DataSources.Add(&lt;span class="str"&gt;&amp;quot;Application!*[System[Provider[@Name=&amp;#39;MySource&amp;#39;]]]&amp;quot;&lt;/span&gt;); 
    diag.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromSeconds(30);

    DiagnosticMonitor.Start(&lt;span class="str"&gt;&amp;quot;Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString&amp;quot;&lt;/span&gt;, diag); 

    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;base&lt;/span&gt;.OnStart();
}&lt;/pre&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;p&gt;Note a few things about this code &amp;ndash; The transfer schedule is set to 30 seconds and you may want to set this one a bit higher and also look at the buffer quotas. The sample code is also only capturing and transferring event logs from the &amp;ldquo;Application&amp;rdquo; logs, and I&amp;rsquo;ve added an xpath expression to only transfer logs from the &amp;ldquo;MySource&amp;rdquo; event source we specified in the cmd-file earlier. You may want to grab all application events as well as all system logs too, in that case:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;diag.WindowsEventLog.DataSources.Add(&lt;span class="str"&gt;&amp;quot;System!*&amp;quot;&lt;/span&gt;);
diag.WindowsEventLog.DataSources.Add(&lt;span class="str"&gt;&amp;quot;Application!*&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;p&gt;&lt;strong&gt;Writing to Event and Trace Logs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The simplest thing is then to add some code to write to the event log and trace logs in your code, for example:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Trace.TraceError(&lt;span class="str"&gt;&amp;quot;Invalid login&amp;quot;&lt;/span&gt;);
EventLog.WriteEntry(&lt;span class="str"&gt;&amp;quot;MySource&amp;quot;&lt;/span&gt;,&lt;span class="str"&gt;&amp;quot;Invalid login&amp;quot;&lt;/span&gt;,EventLogEntryType.Error);&lt;/pre&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;p&gt;&lt;strong&gt;Looking at the Data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To actually see what&amp;rsquo;s been written to these tables, you need to either download the data from the storage tables via APIs, use the server explorer or some tool, like the one from Cerebrata &amp;ndash; &amp;ldquo;Azure Diagnostics Manager&amp;rdquo; &amp;ndash; which seems to do the job pretty well. As far as I know, there is no proper tool available from Microsoft. Be that as it may. &lt;/p&gt;

&lt;p&gt;Please, feel free to write comments below and add tips and tricks about handling diagnostics in your Azure application. I&amp;rsquo;d like to know more about the Transfer Period and Buffer Quotas and how they may affect the application and maybe also the billing&amp;hellip; I&amp;rsquo;m sure there are loads to learn about this &lt;img alt="Ler" class="wlEmoticon wlEmoticon-smile" src="http://weblogs.asp.net/blogs/jdanforth/wlEmoticon-smile_31F952ED.png" /&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;em&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/em&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48805" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/Azure/default.aspx">Azure</category></item><item><title>When the Test Agent Fails on the Build Server</title><link>http://blog.irm.se/blogs/eric/archive/2012/02/16/When-the-Test-Agent-Fails-on-the-Build-Server.aspx</link><pubDate>Thu, 16 Feb 2012 20:23:46 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48804</guid><dc:creator>ericqu</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;When I set up a continues integration build on our new build-server, I got “The agent process was stopped while the test was running.” when the test ran. This is not a very helpful error message and the troubleshooting is hard when all test succeeds locally. Fortunately I have the possibility to read the event log on the build server and there were more details. In my case the problem was that the &lt;a href="http://msdn.microsoft.com/en-us/devlabs/dd491992"&gt;code contracts&lt;/a&gt; wasn’t installed on the server.&lt;/p&gt;  &lt;p&gt;Once again the lesson is to read the event log. Am I the only one that often forgets to do that initially?&lt;/p&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48804" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+3.0/default.aspx">.NET 3.0</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+3.5/default.aspx">.NET 3.5</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category></item><item><title>How to Force Comments When Doing Check-In in TFS</title><link>http://blog.irm.se/blogs/johan/archive/2012/02/08/How-to-Force-Comments-When-Doing-Check_2D00_In-in-TFS.aspx</link><pubDate>Wed, 08 Feb 2012 09:35:52 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48800</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I was looking for a policy like this, and found this blog article by Claus Konrad:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://blog.clauskonrad.net/2010/08/tfs-2010-how-to-force-comments-when.html" href="http://blog.clauskonrad.net/2010/08/tfs-2010-how-to-force-comments-when.html"&gt;http://blog.clauskonrad.net/2010/08/tfs-2010-how-to-force-comments-when.html&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now, unfortunately everyone in the project has to have the TFS Power Tools installed to make this work.&lt;/p&gt;  &lt;p&gt;The power tools can be downloaded from the Visual Studio Gallery, this is a direct link to it: &lt;/p&gt;  &lt;p&gt;&lt;a title="http://visualstudiogallery.msdn.microsoft.com/c255a1e4-04ba-4f68-8f4e-cd473d6b971f?SRC=VSIDE" href="http://visualstudiogallery.msdn.microsoft.com/c255a1e4-04ba-4f68-8f4e-cd473d6b971f?SRC=VSIDE"&gt;http://visualstudiogallery.msdn.microsoft.com/c255a1e4-04ba-4f68-8f4e-cd473d6b971f?SRC=VSIDE&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Whish this was in the box from start.&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48800" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/TFS/default.aspx">TFS</category></item><item><title>MSTest and Calling Exe with Sample Data Files</title><link>http://blog.irm.se/blogs/johan/archive/2012/02/07/MSTest-and-Calling-Exe-with-Sample-Data-Files.aspx</link><pubDate>Tue, 07 Feb 2012 08:52:59 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48799</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;For various reasons I’m using MSTest for my unit tests and I have this console app which generates a PDF file from an XML file that needed some tests.&lt;/p&gt;  &lt;p&gt;So, when moving the unit tests over to a TFS build server, having hard coded paths to test data files is not a good idea. The recommended way of doing it is to use the DeploymentItem attribute.&lt;/p&gt;  &lt;p&gt;Also, when calling an exe-file which does Environment.Exit() and catching the exit code from the unit test is pretty straight forward by using Process.Start() and checking the ExitCode property.&lt;/p&gt;  &lt;p&gt;A small sample:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;[TestMethod]
[DeploymentItem(&lt;span class="str"&gt;@&amp;quot;TestData\arbetsorder.xml&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;TestData&amp;quot;&lt;/span&gt;)]
[DeploymentItem(&lt;span class="str"&gt;@&amp;quot;TestData\arbetsorderReport.rdlc&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;TestData&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; GeneratorShouldReturnWithExitCode0()
{
    Process proc;
    &lt;span class="kwrd"&gt;try&lt;/span&gt;
    {
        proc = Process.Start(&lt;span class="str"&gt;&amp;quot;PdfGenerator.exe&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;\&amp;quot;&amp;quot;&lt;/span&gt; + Directory.GetCurrentDirectory() + &lt;span class="str"&gt;&amp;quot;/TestData/arbetsorderReport.rdlc\&amp;quot; \&amp;quot;&amp;quot;&lt;/span&gt; +
            Directory.GetCurrentDirectory() + &lt;span class="str"&gt;&amp;quot;/arbetsorder.pdf\&amp;quot; \&amp;quot;&amp;quot;&lt;/span&gt; + Directory.GetCurrentDirectory() + &lt;span class="str"&gt;&amp;quot;/TestData/arbetsorder.xml\&amp;quot;&amp;quot;&lt;/span&gt;);
    }
    &lt;span class="kwrd"&gt;catch&lt;/span&gt; (System.ComponentModel.Win32Exception ex)
    {
        proc = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
        Assert.Fail(ex.Message);
    }

    Assert.IsNotNull(proc);
    proc.WaitForExit(10000);
    Assert.IsTrue(proc.HasExited);
    Assert.AreEqual(0, proc.ExitCode, &lt;span class="str"&gt;&amp;quot;Expected 0, got &amp;quot;&lt;/span&gt; + proc.ExitCode);
}&lt;/pre&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;p&gt;But, there’s a small caveat to get the DeploymentItem argument working properly! First you have to open up the test settings of your .testsettings file, select the Deployment settings and make sure the “Enable deployment” checkbox is checked:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/image_69D77233.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/jdanforth/image_thumb_369B38CA.png" width="644" height="475" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s all you need to do. And &lt;em&gt;note that you may actually have to exit and restart Visual Studio to make it work&lt;/em&gt;. I never got the files deployed until I did that restart.&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48799" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/Unit+Testing/default.aspx">Unit Testing</category></item><item><title>Information and Events are Stable Parts of Business</title><link>http://blog.irm.se/blogs/eric/archive/2012/01/13/Information-and-Events-are-Stable-Parts-of-Business.aspx</link><pubDate>Fri, 13 Jan 2012 09:32:51 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48793</guid><dc:creator>ericqu</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;&lt;img src="http://blog.irm.se/photos/eric/images/48792/original.aspx" /&gt;&lt;/p&gt;  &lt;p&gt;At IRM we often use this picture to talk about the stable parts of the business. Actually we have used it at least during the eight years I‘ve been working here.&lt;/p&gt;  &lt;p&gt;The least stable part is the &lt;strong&gt;organisation&lt;/strong&gt; itself. Many of us have been affected by organisational changes during the last year and just as many of us will be affected by a change this year. Since it changes all the time it would be unwise to base any software architecture on the current organisation.     &lt;br /&gt;As a side note: This is one reason to why I often talk about (user) roles as a bad thing to base the security checks on for a system, even though it is often well supported by the platform.&lt;/p&gt;  &lt;p&gt;The most stable part of the business is the structure of the &lt;strong&gt;information&lt;/strong&gt; we need. As long as IRM have been a consultancy firm we have provided &lt;em&gt;services &lt;/em&gt;to our &lt;em&gt;customers&lt;/em&gt; in &lt;em&gt;projects &lt;/em&gt;for which we have always tracked the hours (&lt;em&gt;time&lt;/em&gt;) each &lt;em&gt;employee&lt;/em&gt; have worked. Surely the information changes too, for example we have for many years educated other in both internal and open &lt;em&gt;courses&lt;/em&gt;, but this was not part of the business when IRM started back in 1982. The content changes (hopefully) rapidly with new customers and projects all the time, but not what information we need to track. &lt;/p&gt;  &lt;p&gt;How we have performed our services and the internal work have changed over time. It is the &lt;strong&gt;process&lt;/strong&gt; we try to improve all the time. Since the process itself is something that we want to change this is also unwise to base the software architecture on. Still this was a very common advise when SOA was hitting the hype curve, but I believe that is a mistake that happened because we so eagerly wanted to align our solutions better to the business process (of course the system need to support the processes very well, but it shouldn’t be the part that we base our architecture on).     &lt;br /&gt;If we dig a little bit deeper into processes they are a series of &lt;u&gt;activities&lt;/u&gt;, triggered by an &lt;u&gt;event&lt;/u&gt;, that are performed to deliver a &lt;u&gt;value&lt;/u&gt; for a &lt;u&gt;customer&lt;/u&gt;. The activities are more stable than the process itself, but even more stable are the events. Actually there is an event after each activity that triggers the next activity. An event can also be found when studying the state transitions of the information, for example visualized in an UML State Diagram. This have lead me to talk about the events as the line between Process and Information in the stability diagram above.&lt;/p&gt;  &lt;p&gt;I would say that information and events are two important artifacts to pay special attention to when designing software. This spans from defining the correct aggregates (in DDD) to defining service boundary (in SOA) or Bounded Context (in DDD) to integration between systems. I haven’t written about business capabilities in this post, but also when using capabilities for example to define services, you need to make sure that information which must be consistent (not eventually consistent) belongs to the same capability and the most important way of communication between services are based on events.&lt;/p&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48793" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/eric/archive/tags/Architecture/default.aspx">Architecture</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/Event+Sourcing/default.aspx">Event Sourcing</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/CQRS/default.aspx">CQRS</category></item><item><title>Deploying ClickOnce to Multiple Environments</title><link>http://blog.irm.se/blogs/eric/archive/2011/09/14/Deploying-ClickOnce-to-Multiple-Environments.aspx</link><pubDate>Wed, 14 Sep 2011 13:05:20 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48779</guid><dc:creator>ericqu</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;So in my struggling to get a lean and effective way to roll out new versions of an application for two of my clients, I have some more to share with you. I want it to be extremely easy for me to create a new ClickOnce installer for my clients and I have identified three things that I need to solve:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The installations will be run from different installation URL:s.&lt;/li&gt;    &lt;li&gt;Getting unique config-files packed with the ClickOnce publish. I have 2 clients, each with a test and a production environment, and I need to handle my own test environment too.&lt;/li&gt;    &lt;li&gt;A client machine needs to be able to run installations for both test and production on a single machine. This means that ClickOnce must see my applications as different applications even though it is only one.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I have solved the last two, so lets start with the last one.&lt;/p&gt;  &lt;h4&gt;Running both test and production environments on the same client&lt;/h4&gt;  &lt;p&gt;There are more than one way to solve this, but for me the easiest solution was to create two Visual Studio projects. Originally I had a single Windows Forms exe project in Visual Studio, but I changed this to be just a DLL-project (Output type in Application settings). Then I created two new projects with the names Application and Application.Test and for both of them I configured ClickOnce as usual. There is only a single line of code in each of these projects and that’s to call the original entry point in my old exe-project:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;Program&lt;/span&gt;.Main(args);&lt;/pre&gt;

&lt;p&gt;With this solved I still needed to handle the differences in configurations.&lt;/p&gt;

&lt;h4&gt;Different config for each environment&lt;/h4&gt;

&lt;p&gt;Visual Studio 2010 has support for transforming configuration files when deploying a web project, but only when deploying and that is only supported for web projects. &lt;a href="http://sedodream.com/2011/08/17/AppconfigTransformVisualStudioAddIn.aspx"&gt;Luckily Sayed Ibrahim Hashimi and Chuck England have created a small VSiX&lt;/a&gt; called &lt;a href="http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5"&gt;SlowCheetah XML Transforms&lt;/a&gt; that do the same thing, but when you build your project. So naturally the first step is to install the add-in. Next up is to create new project configurations in configuration manager (I created CustomerATest, CustomerAProd, CustomerBTest and CustomerBTest). With this in place you can right-click on the config-file in you project and select Add Transform, which adds a sub-config file for each configuration. In these config files you then &lt;a href="http://msdn.microsoft.com/en-us/library/dd465326(VS.100).aspx"&gt;apply the transformations for the changes you want to do&lt;/a&gt; in the config file.&lt;/p&gt;

&lt;p&gt;This is so useful in many more scenarios than just for deploying with ClickOnce.&lt;/p&gt;

&lt;p&gt;
  &lt;br /&gt;Unfortunately I haven’t solved the problem of having different installation URL:s for each configuration, but maybe someone has a tip? I have tried to edit the project file and move the installation url element to respective configuration. This works if I remember to reload the project each time I select another configuration (which I of course don’t), but if I don’t reload the settings will be overwritten with the value from the configuration that was used when the project was loaded so that won’t work. The best thing would of course be if Visual Studio could start to support different installation URL for each configuration.&lt;/p&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48779" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/eric/archive/tags/Windows+Forms/default.aspx">Windows Forms</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+3.0/default.aspx">.NET 3.0</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+3.5/default.aspx">.NET 3.5</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category></item><item><title>Command Handling the Nancy Way</title><link>http://blog.irm.se/blogs/johan/archive/2011/09/08/Command-Handling-the-Nancy-Way.aspx</link><pubDate>Thu, 08 Sep 2011 13:50:55 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48776</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/minibuss_small_thumb1_thumb_thumb_353836CC.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="minibuss_small_thumb1_thumb_thumb" border="0" alt="minibuss_small_thumb1_thumb_thumb" src="http://weblogs.asp.net/blogs/jdanforth/minibuss_small_thumb1_thumb_thumb_thumb_5FA467E9.png" width="36" height="28" /&gt;&lt;/a&gt; MiniBuss is a micro service bus framework over msmq which consists of less than 400 lines of code, sitting inside one single source file. The project is hosted over at &lt;a href="http://minibuss.codeplex.com"&gt;http://minibuss.codeplex.com&lt;/a&gt; and the source code is maintained at &lt;a title="https://github.com/johandanforth/MiniBuss" href="https://github.com/johandanforth/MiniBuss"&gt;https://github.com/johandanforth/MiniBuss&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I’ve been a fan of &lt;a href="https://github.com/NancyFx/Nancy" target="_blank"&gt;the Sinatra inspired web framework called Nancy&lt;/a&gt;, especially the neat way of setting up handlers for routes. The simplest sample on their site is this:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Module : NancyModule
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Module()
    {
        Get[&lt;span class="str"&gt;&amp;quot;/greet/{name}&amp;quot;&lt;/span&gt;] = x =&amp;gt; {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;.Concat(&lt;span class="str"&gt;&amp;quot;Hello &amp;quot;&lt;/span&gt;, x.name);
        };
    }
}&lt;/pre&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;p&gt;So, I shamelessly dug into the Nancy code and borrowed some 20-30 lines of code and came up with something like this for registering handlers for certain incoming commands on the minibus, what do you think?&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CommandHandler : MessageHandler
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; CommandHandler()
    {
        WhenReceiving[&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(SampleMessage1)] = x =&amp;gt;
        {
            Console.WriteLine(&lt;span class="str"&gt;&amp;quot;sample 1 message: &amp;quot;&lt;/span&gt; + x.Text);
        };

        WhenReceiving[&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(SampleMessage2)] = x =&amp;gt;
        {
            Console.WriteLine(&lt;span class="str"&gt;&amp;quot;sample 2 message: &amp;quot;&lt;/span&gt; + x.Text);
        };
    }
}&lt;/pre&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;p&gt;It’s a bit more code but it helps/enforces you to move the handlers off to a certain module. Thoughts?&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48776" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/Open+Source/default.aspx">Open Source</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Service+Bus/default.aspx">Service Bus</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/MiniBuss/default.aspx">MiniBuss</category></item><item><title>More MiniBuss Updates</title><link>http://blog.irm.se/blogs/johan/archive/2011/09/02/More-MiniBuss-Updates.aspx</link><pubDate>Fri, 02 Sep 2011 20:23:23 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48775</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/minibuss_small_thumb1_thumb_51B22E2D.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="minibuss_small_thumb1_thumb" border="0" alt="minibuss_small_thumb1_thumb" src="http://weblogs.asp.net/blogs/jdanforth/minibuss_small_thumb1_thumb_thumb_02D168CE.png" width="36" height="28" /&gt;&lt;/a&gt; MiniBuss is a micro service bus framework over msmq which consists of less than 400 lines of code, sitting inside one single source file. The project is hosted over at &lt;a href="http://minibuss.codeplex.com"&gt;http://minibuss.codeplex.com&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Thanks to @CodingInsomnia for testing out the MiniBuss stuff a bit more than I did &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://weblogs.asp.net/blogs/jdanforth/wlEmoticon-winkingsmile_61DDF626.png" /&gt; For the samples, and for my initial testing code, I used a shared assembly with messages (events and commands), which shouldn’t be necessary. So I made a few simple changes and now you can choose to either share messages in an assembly between your sender/receiver and publisher/subscribers OR you can declare local message classes &lt;strong&gt;as long as those classes use the same class name and properties&lt;/strong&gt; it should work.&lt;/p&gt;  &lt;p&gt;The &lt;strong&gt;NuGet package has been updated&lt;/strong&gt;, and the new code is in package version 1.0.2.0.&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48775" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/.NET/default.aspx">.NET</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Open+Source/default.aspx">Open Source</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Codeplex/default.aspx">Codeplex</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Service+Bus/default.aspx">Service Bus</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/CQRS/default.aspx">CQRS</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/msmq/default.aspx">msmq</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/MiniBuss/default.aspx">MiniBuss</category></item><item><title>MiniBuss Updates</title><link>http://blog.irm.se/blogs/johan/archive/2011/09/01/MiniBuss-Updates.aspx</link><pubDate>Thu, 01 Sep 2011 09:35:31 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48774</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/minibuss_small_thumb1_377C04CA.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="minibuss_small_thumb1" border="0" alt="minibuss_small_thumb1" src="http://weblogs.asp.net/blogs/jdanforth/minibuss_small_thumb1_thumb_61E835E7.png" width="36" height="28" /&gt;&lt;/a&gt; I made a small update to &lt;a href="http://minibuss.codeplex.com/" target="_blank"&gt;MiniBuss&lt;/a&gt;, the micro service bus framework. The messages you send, Commands and Events, are &lt;strong&gt;no longer dependent on IMessage&lt;/strong&gt;. The messages sent on the bus can now be any .NET class which can be safely serialized.&lt;/p&gt;  &lt;p&gt;The MiniBuss package on NuGet has been updated (version 1.1.0.1).&lt;/p&gt;  &lt;p&gt;I’m looking for testers, reviewers and co-authors. Areas I want to look more at are multithreading/concurrency and the reply-feature (especially being able to reply to current message in multithreaded scenarios. &lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48774" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/Open+Source/default.aspx">Open Source</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Codeplex/default.aspx">Codeplex</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Service+Bus/default.aspx">Service Bus</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/msmq/default.aspx">msmq</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/MiniBuss/default.aspx">MiniBuss</category></item><item><title>MiniBuss on Codeplex</title><link>http://blog.irm.se/blogs/johan/archive/2011/08/30/MiniBuss-on-Codeplex.aspx</link><pubDate>Tue, 30 Aug 2011 11:48:17 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48772</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/minibuss_small_3A94372C.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="minibuss_small" border="0" alt="minibuss_small" src="http://weblogs.asp.net/blogs/jdanforth/minibuss_small_thumb_478E173D.png" width="36" height="28" /&gt;&lt;/a&gt; The micro service bus framework for msmq called MiniBuss is now open source on Codeplex at &lt;a href="http://minibuss.codeplex.com"&gt;http://minibuss.codeplex.com&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;There is also now a NuGet package available for easy install into projects: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/image_06EBCACE.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/jdanforth/image_thumb_25C23EAC.png" width="644" height="364" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you’re interested in co-op on this project, please contact me via Codeplex! I’m looking for devs and tester who knows their c#, msmq and concurrency.&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48772" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/c_2300_/default.aspx">c#</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Open+Source/default.aspx">Open Source</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Codeplex/default.aspx">Codeplex</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Service+Bus/default.aspx">Service Bus</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/msmq/default.aspx">msmq</category></item><item><title>ClickOnce to the Rescue</title><link>http://blog.irm.se/blogs/eric/archive/2011/08/23/ClickOnce-to-the-Rescue.aspx</link><pubDate>Tue, 23 Aug 2011 13:58:25 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48770</guid><dc:creator>ericqu</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I have two clients who are outsourcing their PCs and servers and one consequence of that is from now on it will take 3 weeks (plus additional costs) to get a MSI delivered to the clients. This way to far from our fast deliveries that we have today, so I recommended them that we should move on to ClickOnce for distributing the application. This will allow us to roll out new versions quickly and keep the cost down to a minimum. &lt;/p&gt;  &lt;p&gt;There is a switchboard integrated though and I was a little bit uncertain if we could handle the requirements of the switchboard to start the client with arguments and always with a single instance of the application. It turned out to be really simple. First of all, we did not need to make any changes in our single instance code (which uses named pipes to communicate from second instance to first). &lt;/p&gt;  &lt;p&gt;When someone calls to my client, the switchboard makes a lookup by calling a web service. In the answer it retrieves the path to the installed client, including the correct command line arguments that should be used to start the application. When switching to a ClickOnce distribution the service are not able to include a local path anymore, since the server has no idea where the application is installed. After a quick search I found that ClickOnce can also be called with parameters so that was the path I choose to go down and it worked really well. This is what I needed to do:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;In the “Manifests” settings (found under “Publish Options”) it is required to check “Allow URL parameters to be passed to application”. &lt;/li&gt;    &lt;li&gt;Next I changed the web service so it returned the URL to the ClickOnce installation (not the bootstrapper exe, but the .application file which also needs to be the installation source) followed by regular query string parameters. &lt;/li&gt;    &lt;li&gt;In my code, I just added a small function that takes command line parameters (so I continue to support local installs) as in parameters and the returns them or the parameters send through the query string.      &lt;br /&gt;      &lt;br /&gt;      &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;private static string&lt;/span&gt;[] GetCommandLineArguments(&lt;span style="color:blue;"&gt;string&lt;/span&gt;[] args)
{
    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;ApplicationDeployment&lt;/span&gt;.IsNetworkDeployed &amp;amp;&amp;amp; &lt;span style="color:#2b91af;"&gt;ApplicationDeployment&lt;/span&gt;.CurrentDeployment != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)
    {
        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;ApplicationDeployment&lt;/span&gt;.CurrentDeployment.ActivationUri != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;span style="color:blue;"&gt;
        &lt;/span&gt;{
            &lt;span style="color:blue;"&gt;string &lt;/span&gt;queryString = &lt;span style="color:#2b91af;"&gt;ApplicationDeployment&lt;/span&gt;.CurrentDeployment.ActivationUri.Query;
            &lt;span style="color:blue;"&gt;if &lt;/span&gt;(!&lt;span style="color:blue;"&gt;string&lt;/span&gt;.IsNullOrEmpty(queryString))
            {
                queryString = queryString.Replace(&lt;span style="color:#a31515;"&gt;'?'&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;'/'&lt;/span&gt;).Replace(&lt;span style="color:#a31515;"&gt;'='&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;':'&lt;/span&gt;);
                &lt;span style="color:blue;"&gt;return &lt;/span&gt;queryString.Split(&lt;span style="color:#a31515;"&gt;'&amp;amp;'&lt;/span&gt;);
            }
        }
    }

    &lt;span style="color:blue;"&gt;return &lt;/span&gt;args;
}&lt;/pre&gt;
The ActivationUri will always be null if the “Allow URL parameters to be passed to application” isn’t set. &lt;/li&gt;
&lt;/ol&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48770" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/eric/archive/tags/Windows+Forms/default.aspx">Windows Forms</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+3.5/default.aspx">.NET 3.5</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category></item><item><title>A One File .NET Micro Service Bus for MSMQ?</title><link>http://blog.irm.se/blogs/johan/archive/2011/08/19/A-One-File-.NET-Micro-Service-Bus-for-MSMQ_3F00_.aspx</link><pubDate>Fri, 19 Aug 2011 11:15:00 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48769</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;This last year our company has invested quite some time in looking at CQRS, which led to looking at great looking service-buses like &lt;a href="http://www.nservicebus.com/" target="_blank"&gt;nServiceBus&lt;/a&gt;, &lt;a href="http://hibernatingrhinos.com/open-source/rhino-service-bus" target="_blank"&gt;Rhino Service Bus&lt;/a&gt; and &lt;a href="http://masstransit-project.com/" target="_blank"&gt;Mass Transit&lt;/a&gt;, which led me to do some bus-coding on my own, mostly for fun and for learning MSMQ.&lt;/p&gt;  &lt;p&gt;Inspired by the service buses mentioned above, the result became a bare-bones-one-file “micro service bus” that I call MiniBuss which sits on top of MSMQ. The file itself is only some 400 lines of code and supports send, receive, reply, publish and subscribe/unsubscribe.&lt;/p&gt;  &lt;p&gt;Setting up a &lt;strong&gt;sender&lt;/strong&gt; may look something like this:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7c91c1dd-8041-425f-a9d5-74f4974fb427" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background-color:#ffffff;overflow:auto;padding:2px 5px;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; bus = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; MiniBuss.&lt;span style="color:#2b91af;"&gt;ServiceBus&lt;/span&gt;();&lt;br&gt; &lt;br&gt; bus.RegisterMessageEndpoint&amp;lt;&lt;span style="color:#2b91af;"&gt;HelloCommand&lt;/span&gt;&amp;gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;minibuss_receiver1@johan-dell-ssd&amp;quot;&lt;/span&gt;);&lt;br&gt; &lt;br&gt; bus.Start();&lt;br&gt; &lt;br&gt; bus.Send(&lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;HelloCommand&lt;/span&gt; { Guid = &lt;span style="color:#2b91af;"&gt;Guid&lt;/span&gt;.NewGuid(), Message = &lt;span style="color:#a31515;"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt; });&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Create the bus, register a message and tell it where messages of this type should go, start the bus and send the message.&lt;/p&gt;  &lt;p&gt;Setting up a &lt;strong&gt;receiver&lt;/strong&gt; may look something like this:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a8260128-689a-43e0-8fea-0ed31dbbd249" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background-color:#ffffff;overflow:auto;padding:2px 5px;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; bus = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ServiceBus&lt;/span&gt; { LocalEndpoint = &lt;span style="color:#a31515;"&gt;&amp;quot;minibuss_receiver1&amp;quot;&lt;/span&gt; };&lt;br&gt; &lt;br&gt; bus.RegisterMessageHandler&amp;lt;&lt;span style="color:#2b91af;"&gt;HelloCommand&lt;/span&gt;&amp;gt;(command =&amp;gt; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(command.Message + &lt;span style="color:#a31515;"&gt;&amp;quot; Guid: &amp;quot;&lt;/span&gt; + command.Guid));&lt;br&gt; &lt;br&gt; bus.Start();&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Create the bus and tell it which endpoint to listen to (which creates a local MSMQ queue if necessary) and tell it which message type to listen for and which delegate to kick off when such a message is received.&lt;/p&gt;  &lt;p&gt;Similarly, when doing a &lt;strong&gt;receive/reply&lt;/strong&gt;, you would have to create the bus on the sender side with a local endpoint and register a message-handler for replies, like this:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d63f6e83-aed9-4415-a01a-7ab8d97f3c4c" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background-color:#ffffff;overflow:auto;padding:2px 5px;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; bus = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; MiniBuss.&lt;span style="color:#2b91af;"&gt;ServiceBus&lt;/span&gt; { LocalEndpoint = &lt;span style="color:#a31515;"&gt;&amp;quot;minibuss_sender1&amp;quot;&lt;/span&gt; };&lt;br&gt; &lt;br&gt; bus.RegisterMessageEndpoint&amp;lt;&lt;span style="color:#2b91af;"&gt;HelloCommand&lt;/span&gt;&amp;gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;minibuss_receiver1@johan-dell-ssd&amp;quot;&lt;/span&gt;);&lt;br&gt; &lt;br&gt; bus.RegisterMessageHandler&amp;lt;&lt;span style="color:#2b91af;"&gt;HelloResponse&lt;/span&gt;&amp;gt;(reply =&amp;gt; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Reply from receiver: &amp;quot;&lt;/span&gt; + reply.Message));&lt;br&gt; &lt;br&gt; bus.Start();&lt;br&gt; &lt;br&gt; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Sending command...&amp;quot;&lt;/span&gt;);&lt;br&gt; bus.Send(&lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;HelloCommand&lt;/span&gt; { Guid = &lt;span style="color:#2b91af;"&gt;Guid&lt;/span&gt;.NewGuid(), Message = &lt;span style="color:#a31515;"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt; });&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The receiver would do a bus.reply() like this:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e2609164-3adf-4752-8d4f-d7aa51446180" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background-color:#ffffff;overflow:auto;padding:2px 5px;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; bus = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ServiceBus&lt;/span&gt; { LocalEndpoint = &lt;span style="color:#a31515;"&gt;&amp;quot;minibuss_receiver1&amp;quot;&lt;/span&gt; };&lt;br&gt; &lt;br&gt; bus.RegisterMessageHandler&amp;lt;&lt;span style="color:#2b91af;"&gt;HelloCommand&lt;/span&gt;&amp;gt;(command =&amp;gt;&lt;br&gt; {&lt;br&gt;     &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(command.Message + &lt;span style="color:#a31515;"&gt;&amp;quot; Guid: &amp;quot;&lt;/span&gt; + command.Guid);&lt;br&gt; &lt;br&gt;     bus.Reply(&lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;HelloResponse&lt;/span&gt; { Guid = &lt;span style="color:#2b91af;"&gt;Guid&lt;/span&gt;.NewGuid(), Message = &lt;span style="color:#a31515;"&gt;&amp;quot;Hello back!&amp;quot;&lt;/span&gt; });&lt;br&gt; });&lt;br&gt; &lt;br&gt; bus.Start();&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The MiniBus also supports &lt;strong&gt;publish&lt;/strong&gt; to multiple subscribers. A simple publisher would create a bus with a local endpoint (to receive subscribe/unsubscribe commands), tell it to handle subscriptions for a certain event, then start publishing something every 5 seconds (as an example):&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8e2c90a7-7645-4d2a-a34d-8a850245d8a5" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background-color:#ffffff;overflow:auto;padding:2px 5px;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; bus = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; MiniBuss.&lt;span style="color:#2b91af;"&gt;ServiceBus&lt;/span&gt; { LocalEndpoint = &lt;span style="color:#a31515;"&gt;&amp;quot;minibuss_publisher1&amp;quot;&lt;/span&gt; };&lt;br&gt; &lt;br&gt; bus.HandleSubscriptionsFor&amp;lt;&lt;span style="color:#2b91af;"&gt;SomethingHappenedEvent&lt;/span&gt;&amp;gt;();&lt;br&gt; &lt;br&gt; bus.Start();    &lt;br&gt; &lt;br&gt; &lt;span style="color:#2b91af;"&gt;Task&lt;/span&gt;.Factory.StartNew(() =&amp;gt; PublishingThread(bus), &lt;span style="color:#2b91af;"&gt;TaskCreationOptions&lt;/span&gt;.LongRunning);&lt;br&gt; &lt;br&gt; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Done, press ENTER to exit&amp;quot;&lt;/span&gt;);&lt;br&gt; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.ReadLine();&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;              &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:85028e28-2d61-410b-aad4-3802770c2117" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background-color:#ffffff;overflow:auto;padding:2px 5px;"&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; PublishingThread(MiniBuss.&lt;span style="color:#2b91af;"&gt;ServiceBus&lt;/span&gt; bus)&lt;br&gt; {&lt;br&gt;     &lt;span style="color:#0000ff;"&gt;while&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;)&lt;br&gt;     {&lt;br&gt;         &lt;span style="color:#2b91af;"&gt;Thread&lt;/span&gt;.Sleep(5000);&lt;br&gt;         &lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; guid = &lt;span style="color:#2b91af;"&gt;Guid&lt;/span&gt;.NewGuid();&lt;br&gt;         &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Publishing event with guid &amp;quot;&lt;/span&gt; + guid);&lt;br&gt;         bus.Publish(&lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;SomethingHappenedEvent&lt;/span&gt;() { Guid = guid, Sent = &lt;span style="color:#2b91af;"&gt;DateTime&lt;/span&gt;.Now });&lt;br&gt;     }&lt;br&gt; }&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Any clients interesting in &lt;strong&gt;subscribing&lt;/strong&gt; to events from the publisher would create a bus with a local endpoint, start the bus and then send a subscribe command to the publisher, telling it you’re interested in subscribing to a certain type of event and which delegate to handle it:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d8be7b59-5742-4b54-a002-bddbc79dc7e2" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background-color:#ffffff;overflow:auto;padding:2px 5px;"&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; bus = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; MiniBuss.&lt;span style="color:#2b91af;"&gt;ServiceBus&lt;/span&gt; {LocalEndpoint = &lt;span style="color:#a31515;"&gt;&amp;quot;minibuss_subscriber1&amp;quot;}&lt;/span&gt;;&lt;br&gt; &lt;br&gt; bus.Start();&lt;br&gt; &lt;br&gt; bus.Subscribe&amp;lt;&lt;span style="color:#2b91af;"&gt;SomethingHappenedEvent&lt;/span&gt;&amp;gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;minibuss_publisher1@localhost&amp;quot;&lt;/span&gt;, &lt;br&gt;     @event =&amp;gt; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;something happened at {&lt;/span&gt;&lt;span style="color:#3cb371;"&gt;0}&lt;/span&gt;&lt;span style="color:#a31515;"&gt;, event id {&lt;/span&gt;&lt;span style="color:#3cb371;"&gt;1}&lt;/span&gt;&lt;span style="color:#a31515;"&gt;&amp;quot;&lt;/span&gt;,&lt;br&gt;         @event.Sent, @event.Guid));&lt;br&gt; &lt;br&gt; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Waiting for events, press ENTER to exit&amp;quot;&lt;/span&gt;);&lt;br&gt; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.ReadLine();&lt;br&gt; &lt;br&gt; bus.UnSubscribe&amp;lt;&lt;span style="color:#2b91af;"&gt;SomethingHappenedEvent&lt;/span&gt;&amp;gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;minibuss_publisher1&amp;quot;&lt;/span&gt;);&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;strong&gt;Now, the question is, what do you think?&lt;/strong&gt; I &lt;em&gt;know&lt;/em&gt; there are issues with the code, like how to make message-handlers multi-threaded/concurrent without messing things up (it’s single threaded right now), and how to best handle exceptions, rollbacks and re-tries . Right now handling exceptions in send and receive works pretty well within a TransactionScope() together with ADO.NET, and if there’s an exception, the message is moved the an error-queue. No re-try or anything, only rollback and move to xxx_error. Also, the publisher doesn’t persist subscriptions, so if it is restarted subscribers wouldn’t know. You know, things like that.&lt;/p&gt;  &lt;p&gt;I’m a user of the micro-orm called &lt;a href="http://code.google.com/p/dapper-dot-net/" target="_blank"&gt;Dapper&lt;/a&gt; and like it a lot, so I’m thinking that maybe I should release this micro-bus as open source and see where people may take it, if anywhere? Maybe just down the drain because they figure out this service bus is dangerous to use and risk loosing messages or something (which would be extremely good to know :)&lt;/p&gt;  &lt;p&gt;Or maybe this code is useless because you already got nServiceBus and Rhino out there and coders don’t need another service bus?&lt;/p&gt;  &lt;p&gt;What do you say?&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48769" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/.NET/default.aspx">.NET</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Open+Source/default.aspx">Open Source</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Service+Bus/default.aspx">Service Bus</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/CQRS/default.aspx">CQRS</category></item><item><title>Pomodoro Timer for the Windows 7 TaskBar</title><link>http://blog.irm.se/blogs/johan/archive/2011/08/16/Pomodoro-Timer-for-the-Windows-7-TaskBar.aspx</link><pubDate>Tue, 16 Aug 2011 11:08:00 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48768</guid><dc:creator>johan</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;&lt;strong&gt;EDIT:&amp;nbsp; The code is now open source on codeplex, on &lt;a href="http://pomodorotaskbar.codeplex.com" target="_blank"&gt;http://pomodorotaskbar.codeplex.com &lt;/a&gt;There's a new version available&amp;nbsp;for download there too.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;If you’re into &lt;a href="http://www.pomodorotechnique.com/" target="_blank"&gt;the Pomodoro technique&lt;/a&gt; and looking for a pretty simple out-of-the-way timer which sits in the Windows 7 taskbar and is controlled from the Win7 JumpList, this one might be worth trying out. &lt;/p&gt;&lt;p&gt;&lt;strong&gt;NOTE: Icon overlays will NOT work if you're using small TaskBar icons!&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/image_69FABFDE.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/jdanforth/image_thumb_0F180A4B.png" width="334" height="43"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;That’s the timer looking like a tomato, with the remaining session minutes written out dynamically as icon overlay.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/image_34A187AC.png"&gt;&lt;img style="border-width:0px;margin:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/jdanforth/image_thumb_3E1A4622.png" width="244" height="192"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The timer has a couple of JumpList Tasks which you can use to control it. The program works well when “pinned” to the taskbar if you prefer it.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/image_63A3C383.png"&gt;&lt;img style="border-width:0px;margin:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/jdanforth/image_thumb_5420B1B4.png" width="244" height="164"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can also control the timer from the main window with one large action-button (stop, start, stop ringing and restart session).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/image_12A5FF5B.png"&gt;&lt;img style="border-width:0px;margin:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/jdanforth/image_thumb_0CEAE5B5.png" width="244" height="164"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;When the timer is stopped, you can just click on the remaining minutes-textbox and change the default session length to whatever you like. The value is stored.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/image_1D82E0A3.png"&gt;&lt;img style="border-width:0px;margin:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/jdanforth/image_thumb_7503FE8E.png" width="244" height="51"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;When the session is ended, the window flashes, the tomato shakes and a ringing sound is played a few times to get your attention. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;, this is a very simple program which I’m planning to release as open source when I’ve received some feedback. I prefer to keep it simple, but may add session logging. The name as well as the looks may change. .NET 4.0 is required.&lt;/p&gt;  &lt;div style="margin:0px;padding:0px;float:none;display:inline;" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:894107a9-6eca-4992-92a8-652e78cd280a" class="wlWriterEditableSmartContent"&gt;&lt;p&gt;Download the Pomodoro Timer: &lt;a href="http://pomodorotaskbar.codeplex.com/releases/view/71998"&gt;http://pomodorotaskbar.codeplex.com/releases/view/71998&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48768" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Open+Source/default.aspx">Open Source</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Pomodoro/default.aspx">Pomodoro</category></item><item><title>Create Tag-Cloud from RSS Feed in ASP.NET MVC</title><link>http://blog.irm.se/blogs/johan/archive/2011/08/08/Create-Tag_2D00_Cloud-from-RSS-Feed-in-ASP.NET-MVC.aspx</link><pubDate>Mon, 08 Aug 2011 11:40:12 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48763</guid><dc:creator>johan</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Say you want to generate your own tag-cloud from a list of categories or tags you pull from an RSS-feed or similar. This is one way to do it. I’m using ASP.NET MVC for this sample which creates a simple tag-cloud in a Razor-view with HTML looking something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/image_0507121F.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/jdanforth/image_thumb_3CD95642.png" width="436" height="239" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The controller-code to start out with looks like this, where you read in the RSS-feed into a &lt;strong&gt;SyndicationFeed&lt;/strong&gt; class, then pull out and flatten all the categories you have in that feed. Then group all those categories and count them to build up this simple view-model which is a Dictionary of category and percentage:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e018791a-8bdf-4fb2-8e96-7476fe3d5b1d" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background-color:#ffffff;overflow:auto;padding:2px 5px;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;HomeController&lt;/span&gt; : &lt;span style="color:#2b91af;"&gt;Controller&lt;/span&gt;&lt;br&gt; {&lt;br&gt;     &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ActionResult&lt;/span&gt; Index()&lt;br&gt;     {&lt;br&gt;         &lt;span style="color:#008000;"&gt;//get feed&lt;/span&gt;&lt;br&gt;         &lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; feed = &lt;span style="color:#2b91af;"&gt;SyndicationFeed&lt;/span&gt;.Load(&lt;span style="color:#2b91af;"&gt;XmlReader&lt;/span&gt;.Create(&lt;span style="color:#a31515;"&gt;&amp;quot;http://blog.irm.se/blogs/MainFeed.aspx&amp;quot;&lt;/span&gt;));&lt;br&gt; &lt;br&gt;         &lt;span style="color:#008000;"&gt;//get flat list of all categories/tags in the feed&lt;/span&gt;&lt;br&gt;         &lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; categoriesList = feed.Items.SelectMany(item =&amp;gt; item.Categories).Select(category =&amp;gt; category.Name);&lt;br&gt; &lt;br&gt;         &lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; categoryGroups = categoriesList.GroupBy(category =&amp;gt; category);&lt;br&gt; &lt;br&gt;         &lt;span style="color:#0000ff;"&gt;decimal&lt;/span&gt; maxNrOfACategory = categoryGroups.Max(w =&amp;gt; w.Count());&lt;br&gt; &lt;br&gt;         &lt;span style="color:#008000;"&gt;//build a dictionary with category/percentage of all categories&lt;/span&gt;&lt;br&gt;         &lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; tagCloudDictionary = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt;&amp;gt;();&lt;br&gt;         &lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; tag &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; categoryGroups)&lt;br&gt;         {&lt;br&gt;             &lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; percent = (tag.Count() / maxNrOfACategory) * 100;&lt;br&gt;             tagCloudDictionary.Add(tag.Key, (&lt;span style="color:#0000ff;"&gt;int&lt;/span&gt;)percent);&lt;br&gt;         }&lt;br&gt; &lt;br&gt;         &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; View(tagCloudDictionary);&lt;br&gt;     }&lt;br&gt; }&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt; 
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }  &lt;p&gt;So now we got this view-model which is a &lt;strong&gt;Dictionary&amp;lt;string,int&amp;gt;&lt;/strong&gt; and contains category/percentage data like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/image_62CF0698.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/jdanforth/image_thumb_21C08734.png" width="251" height="328" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So all we need to do is create some kind of cloud in HTML or similar in the view. One way of doing it is this, which creates the output shown at the top:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5be2cc55-9b3d-4844-ac07-c8de04ab8194" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background-color:#ffffff;overflow:auto;padding:2px 5px;"&gt;&lt;span style="background:#ffff00;"&gt;@model &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt;&amp;gt;&lt;br&gt; &lt;br&gt; &lt;span style="background:#ffff00;"&gt;@{&lt;/span&gt;&lt;br&gt;     ViewBag.Title = &lt;span style="color:#a31515;"&gt;&amp;quot;Index&amp;quot;&lt;/span&gt;;&lt;br&gt; }&lt;br&gt; &lt;br&gt; &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;h2&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;Tag cloud&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;h2&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt; &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;div&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;style&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;: 400px; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;font-size&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;: 25px;&amp;quot;&amp;gt;&lt;/span&gt;&lt;br&gt;     &lt;span style="background:#ffff00;"&gt;@&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; tag &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; Model)&lt;br&gt;     {&lt;br&gt;         &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;span&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;style&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;font-size: &lt;/span&gt;&lt;span style="background:#ffff00;"&gt;@(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;tag.Value / 2 + 50&lt;/span&gt;&lt;span style="background:#ffff00;"&gt;)&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;%; &amp;quot;&amp;gt;&lt;/span&gt;&lt;br&gt;         &lt;span style="background:#ffff00;"&gt;@&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (tag.Value &amp;gt; 10)&lt;br&gt;         {&lt;br&gt;             &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;span&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;style&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;font-weight&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;: bold;&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffff00;"&gt;@&lt;/span&gt;tag.Key &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;span&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;         }&lt;br&gt;         &lt;span style="color:#0000ff;"&gt;else&lt;/span&gt;&lt;br&gt;         {&lt;br&gt;             &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;span&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffff00;"&gt;@&lt;/span&gt;tag.Key &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;span&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;         }&lt;br&gt;         &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;span&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;     }&lt;br&gt; &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;div&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Obviously, to be able to click on a tag and so on you need to create a richer view-model, I just wanted to show how I grab and count the tags from the feed &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://weblogs.asp.net/blogs/jdanforth/wlEmoticon-smile_79ADD814.png" /&gt;&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48763" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/c_2300_/default.aspx">c#</category></item><item><title>Hosting Rhino Service Bus in IIS</title><link>http://blog.irm.se/blogs/eric/archive/2011/06/19/Hosting-Rhino-Service-Bus-in-IIS.aspx</link><pubDate>Sun, 19 Jun 2011 20:08:00 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48756</guid><dc:creator>ericqu</dc:creator><slash:comments>5</slash:comments><description>&lt;p&gt;This is my third post (&lt;a href="http://blog.irm.se/blogs/eric/archive/2011/06/18/Getting-Started-with-Pub_2F00_Sub-using-Rhino-Service-Bus.aspx"&gt;part 1&lt;/a&gt;, &lt;a href="http://blog.irm.se/blogs/eric/archive/2011/06/19/Consuming-Events-in-the-Same-Process-as-the-Publisher-with-Rhino-Service-Bus.aspx"&gt;part 2&lt;/a&gt;) with notes from my exploration of Rhino Service Bus and in this I will focus on how to set everything up for Pub/Sub when having IIS as a host. The first thing that must be done is to choose a strategy for where to do the initialization of the bus and other parts of the service/application. &lt;a href="http://blogs.msdn.com/b/wenlong/archive/2006/01/11/511514.aspx"&gt;Here is a good blog post&lt;/a&gt; covering the choices and for this sample I choose the AppInitialized because it supports other protocols than http and I don&amp;rsquo;t need to support any other hosts than IIS so I don&amp;rsquo;t need to cover that.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public static void &lt;/span&gt;AppInitialize()
{
    &lt;span style="color:blue;"&gt;var &lt;/span&gt;host = &lt;span style="color:blue;"&gt;new &lt;/span&gt;DefaultHost();
    host.Start&amp;lt;Bootstrapper&amp;gt;();

    &lt;span style="color:blue;"&gt;var &lt;/span&gt;consumerHost = &lt;span style="color:blue;"&gt;new &lt;/span&gt;DefaultHost();
    consumerHost.UseStandaloneCastleConfigurationFileName(&lt;span style="color:#a31515;"&gt;&amp;quot;Consumer.config&amp;quot;&lt;/span&gt;);
    consumerHost.Start&amp;lt;Bootstrapper&amp;gt;();
}&lt;/pre&gt;

&lt;p&gt;In this test I trigger the events from button clicks on a webpage, but except for that everything works as in the &lt;a href="http://blog.irm.se/blogs/eric/archive/2011/06/19/Consuming-Events-in-the-Same-Process-as-the-Publisher-with-Rhino-Service-Bus.aspx"&gt;previous post&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;When deploying it to a server with IIS installed on, I manually created the Rhino Queue folders (in my case Publisher.esent, Publisher_subscriptions.esent, Consumer.esent and Consumer_subscriptions.esent). For each folder I than gave modify permission to the account running the application pool (you will get a access denied exception if you don&amp;rsquo;t do this and giving Modify permission on the parent folder does not seem like a good idea).&lt;/p&gt;

&lt;p&gt;I haven&amp;rsquo;t been able to get a sample with RemoteAppDomainHost to work. It complains about not being able to find Rhino.ServiceBus assembly and I&amp;rsquo;m pretty sure it has to do with ASP.NET shadow copying of files. Has anyone got this working? Please leave a comment or link in that case. Thanks, Eric.&lt;/p&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48756" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+3.5/default.aspx">.NET 3.5</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/CQRS/default.aspx">CQRS</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/Rhino+Service+Bus/default.aspx">Rhino Service Bus</category></item><item><title>Consuming Events in the Same Process as the Publisher with Rhino Service Bus</title><link>http://blog.irm.se/blogs/eric/archive/2011/06/19/Consuming-Events-in-the-Same-Process-as-the-Publisher-with-Rhino-Service-Bus.aspx</link><pubDate>Sun, 19 Jun 2011 13:25:42 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48753</guid><dc:creator>ericqu</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;I recently blogged about &lt;a href="http://blog.irm.se/blogs/eric/archive/2011/06/18/Getting-Started-with-Pub_2F00_Sub-using-Rhino-Service-Bus.aspx"&gt;getting started with Rhino Service Bus for publishing and subscribing&lt;/a&gt; to events. If you did not read that post, I recommend you to do that before continuing since I will just outline my modifications in this post.&lt;/p&gt;  &lt;p&gt;My scenario is that I want to decouple things that happens when my server is getting a command. I would like to just save the parts that is core to my domain as a direct effect of the command, but other things like calling other external systems and creating a change history I would like to do later on and in its own transactions. For this I wanted to publish events from my domain and then have subscribers handling each and every scenario separately. I thought it wouldn’t be necessary to have a second process though, so in this post I will show you how both the publisher and the subscriber can exist in the same process.&lt;/p&gt;  &lt;p&gt;So based on the steps in my previous post, I copied the class that consumes my events (implementing the ConsumerOf&amp;lt;&amp;gt; interface) to the publisher project. Now I need to have a second service bus host in the Publisher project and that second host must have its own configuration file.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;I created a new configuration file, but instead of classic app.config, I called it Consumer.config and I also set the “Copy to Output Directory” to “Copy if newer”. The configuration file is a little bit different than the previous, because the host don’t want the surrounding castle element.     &lt;br /&gt;      &lt;br /&gt;      &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color:#a31515;"&gt;xml &lt;/span&gt;&lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1.0&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;encoding&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;utf-8&lt;/span&gt;&amp;quot; &lt;span style="color:blue;"&gt;?&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;configuration&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;facilities&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;facility &lt;/span&gt;&lt;span style="color:red;"&gt;id&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;rhino.esb&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bus &lt;/span&gt;&lt;span style="color:red;"&gt;threadCount&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;numberOfRetries&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;5&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;endpoint&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;rhino.queues://localhost:31317/RSB_Consumer_In_Publisher&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Consumer&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;/&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;messages&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;add
          &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;RSB.Events&lt;/span&gt;&amp;quot;
          &lt;span style="color:red;"&gt;endpoint&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;rhino.queues://localhost:31315/RSB_Publisher&lt;/span&gt;&amp;quot;
          &lt;span style="color:blue;"&gt;/&amp;gt;
      &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;messages&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;facility&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;facilities&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;configuration&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;After starting the Publisher host, I also added code to start the in-process Consumer host. The big difference here, compared to the consumer described in my last post, is that I tell the host to use another config-file, by calling UseStandaloneCastleConfigurationFileName.
    &lt;br /&gt;

    &lt;br /&gt;

    &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;static void &lt;/span&gt;Main(&lt;span style="color:blue;"&gt;string&lt;/span&gt;[] args)
{
    &lt;span style="color:blue;"&gt;var &lt;/span&gt;host = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DefaultHost&lt;/span&gt;();
    host.Start&amp;lt;&lt;span style="color:#2b91af;"&gt;Bootstrapper&lt;/span&gt;&amp;gt;();
    &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Started server publisher.&amp;quot;&lt;/span&gt;);

    &lt;span style="color:blue;"&gt;var &lt;/span&gt;consumerHost = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DefaultHost&lt;/span&gt;();
    consumerHost.UseStandaloneCastleConfigurationFileName(&lt;span style="color:#a31515;"&gt;&amp;quot;Consumer.config&amp;quot;&lt;/span&gt;);
    consumerHost.Start&amp;lt;&lt;span style="color:#2b91af;"&gt;Bootstrapper&lt;/span&gt;&amp;gt;();
    &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Started server consumer.&amp;quot;&lt;/span&gt;);

    &lt;span style="color:#2b91af;"&gt;IServiceBus &lt;/span&gt;bus = host.Container.Resolve&amp;lt;&lt;span style="color:#2b91af;"&gt;IServiceBus&lt;/span&gt;&amp;gt;();
    bus.Notify(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Event1&lt;/span&gt;());
    &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Published Event1.&amp;quot;&lt;/span&gt;);

    &lt;span style="color:#2b91af;"&gt;Thread&lt;/span&gt;.Sleep(2000);

    bus.Notify(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Event2&lt;/span&gt;());
    &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Published Event2.&amp;quot;&lt;/span&gt;);

    &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.ReadLine();
}&lt;/pre&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Another option for hosting in process is to use the RemoteAppDomainHost, which I believe will run in the same process, but in another AppDomain. This would probably add some robustness to the solution. The difference when using that hosting option is that the Consumer.config file will need to be an ordinary config-file with configSection and the facilities element must be contained in a castle element. The code for bringing the host up is similar to the one above.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;consumerHost = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;RemoteAppDomainHost&lt;/span&gt;(&lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;Bootstrapper&lt;/span&gt;));&lt;span style="color:green;"&gt;
&lt;/span&gt;consumerHost.Configuration(&lt;span style="color:#a31515;"&gt;&amp;quot;Consumer.config&amp;quot;&lt;/span&gt;);&lt;span style="color:green;"&gt;
&lt;/span&gt;consumerHost.Start();
&lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Started server consumer.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48753" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+3.5/default.aspx">.NET 3.5</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/CQRS/default.aspx">CQRS</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/Rhino+Service+Bus/default.aspx">Rhino Service Bus</category></item><item><title>Getting Started with Pub/Sub using Rhino Service Bus</title><link>http://blog.irm.se/blogs/eric/archive/2011/06/18/Getting-Started-with-Pub_2F00_Sub-using-Rhino-Service-Bus.aspx</link><pubDate>Sat, 18 Jun 2011 12:09:01 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48752</guid><dc:creator>ericqu</dc:creator><slash:comments>5</slash:comments><description>&lt;p&gt;I have a project where I want to start publishing events on the server and then have a consumer subscribing to these events and take action. First I took a quick look at &lt;a href="http://www.nservicebus.com/"&gt;nServiceBus&lt;/a&gt;, but I also thought that it would be interesting to see what else exists on the .NET platform. I found both &lt;a href="http://masstransit.pbworks.com/"&gt;Mass Transit&lt;/a&gt; and &lt;a href="http://hibernatingrhinos.com/open-source/rhino-service-bus"&gt;Rhino Service Bus&lt;/a&gt; (RSB). I decided that Rhino Service Bus might fit very well with this project since it has built-in support for Rhino Queues (of course) and it is still open source without restrictions. Rhino Queues is interesting because it is a xcopy deployment.&lt;/p&gt;  &lt;p&gt;This post is mainly about giving RSB a first run, so it will be very basic and more like a dump of my own progress.&lt;/p&gt;  &lt;p&gt;First I created a simple project for defining the events (messages) and it only contains two empty classes Event1 and Event2. It might be worth noting that there is no requirements on the classes, aka it is not necessary to implement any interfaces or mark them with any attributes.&lt;/p&gt;  &lt;p&gt;After this I created a Publisher and a Consumer project and in both projects I added a reference to the Events project and I used NuGet to add a reference to Rhino Service Bus. I began with the publisher:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Added an empty classes called BootStrapper which inherit from AbstractBootStrapper.&lt;/li&gt;    &lt;li&gt;Added an app.config     &lt;br /&gt;      &lt;br /&gt;      &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;configSections&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;section &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;castle&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;/&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;configSections&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;castle&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;facilities&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;facility &lt;/span&gt;&lt;span style="color:red;"&gt;id&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;rhino.esb&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bus &lt;/span&gt;&lt;span style="color:red;"&gt;threadCount&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;numberOfRetries&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;5&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;endpoint&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;rhino.queues://localhost:31315/RSB_Publisher&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Publisher&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;/&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;messages&lt;/span&gt;&lt;span style="color:blue;"&gt;/&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;facility&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;facilities&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;castle&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;

&lt;/span&gt;&lt;/pre&gt;
    The endpoint attribute of the bus element defines the queue this bus is listening to. The “rhino.queues” defines that Rhino Queues should be used, but RSB also supports MSMQ by using the “msmq” moniker instead.&lt;/li&gt;

  &lt;li&gt;All that is left now is to start the bus and publish the events. The code for this is straight forward and self explained.
    &lt;br /&gt;

    &lt;br /&gt;

    &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;static void &lt;/span&gt;Main(&lt;span style="color:blue;"&gt;string&lt;/span&gt;[] args)
{
    &lt;span style="color:blue;"&gt;var &lt;/span&gt;host = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DefaultHost&lt;/span&gt;();
    host.Start&amp;lt;&lt;span style="color:#2b91af;"&gt;Bootstrapper&lt;/span&gt;&amp;gt;();

    &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Starting server publisher.&amp;quot;&lt;/span&gt;);
    &lt;span style="color:#2b91af;"&gt;Thread&lt;/span&gt;.Sleep(1000);

    &lt;span style="color:#2b91af;"&gt;IServiceBus &lt;/span&gt;bus = host.Container.Resolve&amp;lt;&lt;span style="color:#2b91af;"&gt;IServiceBus&lt;/span&gt;&amp;gt;();
    bus.Notify(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Event1&lt;/span&gt;());
    &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Published Event1.&amp;quot;&lt;/span&gt;);


    &lt;span style="color:#2b91af;"&gt;Thread&lt;/span&gt;.Sleep(2000);

    bus.Notify(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Event2&lt;/span&gt;());
    &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Published Event2.&amp;quot;&lt;/span&gt;);

    &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.ReadLine();
}&lt;/pre&gt;
    The IServiceBus supports both Notify and Publish for publishing events. The difference is that the later requires at least one listener.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So with the Publisher wrapped up, lets do the same three steps, plus one additional for the Consumer.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Added an empty classes called BootStrapper which inherit from AbstractBootStrapper.&lt;/li&gt;

  &lt;li&gt;Added an app.config&lt;/li&gt;

  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;configSections&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;section &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;castle&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;/&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;configSections&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;castle&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;facilities&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;facility &lt;/span&gt;&lt;span style="color:red;"&gt;id&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;rhino.esb&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bus &lt;/span&gt;&lt;span style="color:red;"&gt;threadCount&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;numberOfRetries&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;5&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;endpoint&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;rhino.queues://localhost:31316/RSB_Consumer&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Consumer&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;/&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;messages&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;add
          &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;RSB.Events&lt;/span&gt;&amp;quot;
          &lt;span style="color:red;"&gt;endpoint&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;rhino.queues://localhost:31315/RSB_Publisher&lt;/span&gt;&amp;quot;
          &lt;span style="color:blue;"&gt;/&amp;gt;
      &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;messages&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;facility&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;facilities&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;castle&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;

&lt;/span&gt;&lt;/pre&gt;
Again the endpoint attribute of the bus element defines the queue this bus is listening to. In the consumer’s configuration I also added the messages that I want to listen for and pointing it to the endpoint that is publishing these events, aka the Publisher above.

  &lt;li&gt;Before starting the bus I also need to create a classes that can handle the events when they get published. This is done by implementing the ConsumerOf&amp;lt;&amp;gt; interface.
    &lt;br /&gt;

    &lt;br /&gt;

    &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;EventConsumer &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;ConsumerOf&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Event1&lt;/span&gt;&amp;gt;, &lt;span style="color:#2b91af;"&gt;ConsumerOf&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Event2&lt;/span&gt;&amp;gt;
{
    &lt;span style="color:blue;"&gt;public void &lt;/span&gt;Consume(&lt;span style="color:#2b91af;"&gt;Event1 &lt;/span&gt;message)
    {
        &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Received Event1&amp;quot;&lt;/span&gt;);
    }

    &lt;span style="color:blue;"&gt;public void &lt;/span&gt;Consume(&lt;span style="color:#2b91af;"&gt;Event2 &lt;/span&gt;message)
    {
        &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Received Event2&amp;quot;&lt;/span&gt;);
    }
}&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;As for the Publisher the last step is to start the bus and when this is done it will automatically tell the Publisher which events the Consumer want to receive. 
    &lt;br /&gt;

    &lt;br /&gt;

    &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;static void &lt;/span&gt;Main(&lt;span style="color:blue;"&gt;string&lt;/span&gt;[] args)
{
    &lt;span style="color:blue;"&gt;var &lt;/span&gt;host = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DefaultHost&lt;/span&gt;();
    host.Start&amp;lt;&lt;span style="color:#2b91af;"&gt;Bootstrapper&lt;/span&gt;&amp;gt;();

    &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.ReadLine();
}&lt;/pre&gt;
    

    &lt;br /&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48752" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+3.5/default.aspx">.NET 3.5</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/CQRS/default.aspx">CQRS</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/Rhino+Service+Bus/default.aspx">Rhino Service Bus</category></item><item><title>Never, never, never do Office interop on the server</title><link>http://blog.irm.se/blogs/johan/archive/2011/05/15/Never_2C00_-never_2C00_-never-do-Office-interop-on-the-server.aspx</link><pubDate>Sun, 15 May 2011 17:14:37 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48751</guid><dc:creator>johan</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;I’ve been telling people this for years and years, and still I stepped right into the mudhole a month ago. I blame stress, but still I shouldn’t have. It’s so easy to just add the interop assemblies and off you go… until you try running your stuff on the 2008 r2 server, hosted somewhere else, with just enough user rights. And even though I managed to get the !”#!¤¤”% working after a while, I got mem-leaks and follow-up probs due to the workarounds I had to do to get the interop working in the first place.&lt;/p&gt;  &lt;p&gt;Then I sat down and relaxed for a minute and realized I need to do this the right way, which is the OpenXML way.&lt;/p&gt;  &lt;p&gt;The thing is, OpenXML is – compared to Office-interop - not easy, and the Microsoft OpenXML SDK 2.0 is just lipstick on top of the XML and some things which were so easy to do with the interop assemblies gives you nightmares to do with OpenXML. Try fill in formsfields in a protected word document for example. I ditched the SDK and ended up doing it directly against the XML directly instead.&lt;/p&gt;  &lt;p&gt;I also had to fill out a few Excel spreadsheets with data, which was somewhat easier to handle than the Word-story above. But I ran into problems here too, because I wanted to do such a simple thing as setting text wrap on a few cells! I don’t know, but I’m sure Microsoft could have done something better for us poor developers that need to create docs on the server! Are we supposed to spend 40% of the coding time to just create a few simple docs, just because we go the OpenXML way? There are a quite a few pages on MSDN with samples, as well as code snippets to download, but as soon as you need to do something outside the “demo-path” you’re banging your head. Maybe I’m just stupid and doesn’t get it, or maybe I’m getting grumpy, because OpenXML is not a developer-friendly framework! There, feels much better now…&lt;/p&gt;  &lt;p&gt;Now, for Excel spreadsheets there’s good hope because you got more than a few decent packages out there to help you out, and &lt;strong&gt;the best one I’ve found so far is called &lt;/strong&gt;&lt;a href="http://closedxml.codeplex.com/" target="_blank"&gt;&lt;strong&gt;ClosedXML on Codeplex&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;.&lt;/strong&gt; It’s free and it did everything I needed to do right out of the box! It took me 5 minutes to create the 2 different spreadsheets I needed for my project, including cell formatting, text wrapping and so on. &lt;strong&gt;Cheers to MDeLeon for doing this!&lt;/strong&gt;&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48751" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/Office/default.aspx">Office</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Interop/default.aspx">Interop</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/OpenXML/default.aspx">OpenXML</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Codeplex/default.aspx">Codeplex</category></item><item><title>Refactored Dapper Extensions</title><link>http://blog.irm.se/blogs/johan/archive/2011/05/11/Refactored-Dapper-Extensions.aspx</link><pubDate>Tue, 10 May 2011 22:48:29 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48750</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;a href="http://weblogs.asp.net/jdanforth/archive/2011/05/10/simple-insert-extension-for-dapper.aspx" target="_blank"&gt;Making extensions for Dapper-dot-net&lt;/a&gt; was so fun and I needed a few more simple ones so I refactored a bit and made a few Update() and Delete() extensions as well. I’m also looking for Id-properties with the [Key] attribute on them. The class grew a bit, but it now supports the functions below. Note that this will only work for very simple objects and tables, but it might be helpful for some of you &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://weblogs.asp.net/blogs/jdanforth/wlEmoticon-smile_74B2939D.png"&gt;&lt;/p&gt; &lt;p&gt;I’m trying to follow the overall Dapper syntax as much as I can. If you done specify the table name with the input parameter, I’m using the name of the class/entity as table name, except where anonymous types are used.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;The object I’m using for testing&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Test
    {
        [Key]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Id { get; set; }
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Age { get; set; }
    }
&lt;/pre&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }


&lt;p&gt;&lt;strong&gt;Insert typed object&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;                var entity = &lt;span class="kwrd"&gt;new&lt;/span&gt; Test() { Name = &lt;span class="str"&gt;"Johan"&lt;/span&gt;, Age = 44 };
                connection.Insert(entity);
&lt;/pre&gt;
&lt;p&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Insert anonymous object&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;                connection.Insert(&lt;span class="str"&gt;"insert into test"&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; { Name = &lt;span class="str"&gt;"Johan"&lt;/span&gt;, Age = 20 });
&lt;/pre&gt;
&lt;p&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update typed object&lt;/strong&gt; (where-clause built up from Id-properties)&lt;/p&gt;&lt;pre class="csharpcode"&gt;                var entity = &lt;span class="kwrd"&gt;new&lt;/span&gt; Test() { Id = 16, Name = &lt;span class="str"&gt;"Johan"&lt;/span&gt;, Age = 50 };
                connection.Update(entity);
&lt;/pre&gt;
&lt;p&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Delete typed object&lt;/strong&gt; (where-clause built up from Id-properties)&lt;/p&gt;&lt;pre class="csharpcode"&gt;                var entity = &lt;span class="kwrd"&gt;new&lt;/span&gt; Test() { Id = 4, Name = &lt;span class="str"&gt;"Johan"&lt;/span&gt;, Age = 44 };
                var deletedCount = connection.Delete(entity);
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Delete anonymous object&lt;/strong&gt; (where-clause built up from anonymous object)&lt;/p&gt;&lt;pre class="csharpcode"&gt;                var deletedCount = connection.Delete(&lt;span class="str"&gt;"delete from test"&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; { Name = &lt;span class="str"&gt;"Johan"&lt;/span&gt; });
&lt;/pre&gt;
&lt;h4&gt;The Code:&lt;/h4&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; DapperExtensions
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Insert(&lt;span class="kwrd"&gt;this&lt;/span&gt; IDbConnection connection, &lt;span class="kwrd"&gt;object&lt;/span&gt; entityToInsert)
    {
        Insert(connection, &lt;span class="kwrd"&gt;null&lt;/span&gt;, entityToInsert);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Insert(&lt;span class="kwrd"&gt;this&lt;/span&gt; IDbConnection connection, &lt;span class="kwrd"&gt;string&lt;/span&gt; sql, &lt;span class="kwrd"&gt;object&lt;/span&gt; entityToInsert)
    {
        var name = entityToInsert.GetType().Name;
        var sb = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder(sql);
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (sql == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            sb.AppendFormat(&lt;span class="str"&gt;"insert into {0}"&lt;/span&gt;, name);
        sb.Append(&lt;span class="str"&gt;" ("&lt;/span&gt;);
        BuildInsertParameters(entityToInsert, sb);
        sb.Append(&lt;span class="str"&gt;") values ("&lt;/span&gt;);
        BuildInsertValues(entityToInsert, sb);
        sb.Append(&lt;span class="str"&gt;")"&lt;/span&gt;);
        connection.Execute(sb.ToString(), entityToInsert);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Update(&lt;span class="kwrd"&gt;this&lt;/span&gt; IDbConnection connection, &lt;span class="kwrd"&gt;object&lt;/span&gt; entityToUpdate)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; Update(connection, &lt;span class="kwrd"&gt;null&lt;/span&gt;, entityToUpdate);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Update(&lt;span class="kwrd"&gt;this&lt;/span&gt; IDbConnection connection, &lt;span class="kwrd"&gt;string&lt;/span&gt; sql, &lt;span class="kwrd"&gt;object&lt;/span&gt; entityToUpdate)
    {
        var idProps = GetIdProperties(entityToUpdate);
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (idProps.Count() == 0)
            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException(&lt;span class="str"&gt;"Entity must have at least one [Key] property"&lt;/span&gt;);

        var name = entityToUpdate.GetType().Name;

        var sb = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder(sql);
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (sql == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            sb.AppendFormat(&lt;span class="str"&gt;"update {0}"&lt;/span&gt;, name);

        sb.AppendFormat(&lt;span class="str"&gt;" set "&lt;/span&gt;);
        BuildUpdateSet(entityToUpdate, sb);
        sb.Append(&lt;span class="str"&gt;" where "&lt;/span&gt;);
        BuildWhere(sb, idProps.ToArray());

        &lt;span class="kwrd"&gt;return&lt;/span&gt; connection.Execute(sb.ToString(), entityToUpdate);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Delete&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; IDbConnection connection, T entityToDelete)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; Delete(connection, &lt;span class="kwrd"&gt;null&lt;/span&gt;, entityToDelete);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Delete&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; IDbConnection connection, &lt;span class="kwrd"&gt;string&lt;/span&gt; sql, T entityToDelete)
    {
        var idProps = &lt;span class="kwrd"&gt;typeof&lt;/span&gt; (T).IsAnonymousType() ? 
            GetAllProperties(entityToDelete) : 
            GetIdProperties(entityToDelete);

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (idProps.Count() == 0)
            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException(&lt;span class="str"&gt;"Entity must have at least one [Key] property"&lt;/span&gt;);

        var name = entityToDelete.GetType().Name;

        var sb = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder(sql);
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (sql == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            sb.AppendFormat(&lt;span class="str"&gt;"delete from {0}"&lt;/span&gt;, name);

        sb.Append(&lt;span class="str"&gt;" where "&lt;/span&gt;);
        BuildWhere(sb, idProps);

        &lt;span class="kwrd"&gt;return&lt;/span&gt; connection.Execute(sb.ToString(), entityToDelete);
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BuildUpdateSet(&lt;span class="kwrd"&gt;object&lt;/span&gt; entityToUpdate, StringBuilder sb)
    {
        var nonIdProps = GetNonIdProperties(entityToUpdate).ToArray();

        &lt;span class="kwrd"&gt;for&lt;/span&gt; (var i = 0; i &amp;lt; nonIdProps.Length; i++)
        {
            var property = nonIdProps&lt;img src="http://blog.irm.se/emoticons/emotion-55.gif" alt="Idea" /&gt;;

            sb.AppendFormat(&lt;span class="str"&gt;"{0} = @{1}"&lt;/span&gt;, property.Name, property.Name);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (i &amp;lt; nonIdProps.Length - 1)
                sb.AppendFormat(&lt;span class="str"&gt;", "&lt;/span&gt;);
        }
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BuildWhere(StringBuilder sb, IEnumerable&amp;lt;PropertyInfo&amp;gt; idProps)
    {
        &lt;span class="kwrd"&gt;for&lt;/span&gt; (var i = 0; i &amp;lt; idProps.Count(); i++)
        {
            sb.AppendFormat(&lt;span class="str"&gt;"{0} = @{1}"&lt;/span&gt;, idProps.ElementAt(i).Name, idProps.ElementAt(i).Name);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (i &amp;lt; idProps.Count() - 1)
                sb.AppendFormat(&lt;span class="str"&gt;" and "&lt;/span&gt;);
        }
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BuildInsertValues(&lt;span class="kwrd"&gt;object&lt;/span&gt; entityToInsert, StringBuilder sb)
    {
        var props = GetAllProperties(entityToInsert);

        &lt;span class="kwrd"&gt;for&lt;/span&gt; (var i = 0; i &amp;lt; props.Count(); i++)
        {
            var property = props.ElementAt(i);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (property.GetCustomAttributes(&lt;span class="kwrd"&gt;true&lt;/span&gt;).Where(a =&amp;gt; a &lt;span class="kwrd"&gt;is&lt;/span&gt; KeyAttribute).Any()) &lt;span class="kwrd"&gt;continue&lt;/span&gt;;
            sb.AppendFormat(&lt;span class="str"&gt;"@{0}"&lt;/span&gt;, property.Name);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (i &amp;lt; props.Count() - 1)
                sb.Append(&lt;span class="str"&gt;", "&lt;/span&gt;);
        }
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BuildInsertParameters(&lt;span class="kwrd"&gt;object&lt;/span&gt; entityToInsert, StringBuilder sb)
    {
        var props = GetAllProperties(entityToInsert);

        &lt;span class="kwrd"&gt;for&lt;/span&gt; (var i = 0; i &amp;lt; props.Count(); i++)
        {
            var property = props.ElementAt(i);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (property.GetCustomAttributes(&lt;span class="kwrd"&gt;true&lt;/span&gt;).Where(a =&amp;gt; a &lt;span class="kwrd"&gt;is&lt;/span&gt; KeyAttribute).Any()) &lt;span class="kwrd"&gt;continue&lt;/span&gt;;
            sb.Append(property.Name);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (i &amp;lt; props.Count() - 1)
                sb.Append(&lt;span class="str"&gt;", "&lt;/span&gt;);
        }
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; IEnumerable&amp;lt;PropertyInfo&amp;gt; GetAllProperties(&lt;span class="kwrd"&gt;object&lt;/span&gt; entity)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; entity.GetType().GetProperties();
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; IEnumerable&amp;lt;PropertyInfo&amp;gt; GetNonIdProperties(&lt;span class="kwrd"&gt;object&lt;/span&gt; entity)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; GetAllProperties(entity).Where(p =&amp;gt; p.GetCustomAttributes(&lt;span class="kwrd"&gt;true&lt;/span&gt;).Any(a =&amp;gt; a &lt;span class="kwrd"&gt;is&lt;/span&gt; KeyAttribute) == &lt;span class="kwrd"&gt;false&lt;/span&gt;);
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; IEnumerable&amp;lt;PropertyInfo&amp;gt; GetIdProperties(&lt;span class="kwrd"&gt;object&lt;/span&gt; entity)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; GetAllProperties(entity).Where( p =&amp;gt; p.GetCustomAttributes(&lt;span class="kwrd"&gt;true&lt;/span&gt;).Any(a =&amp;gt; a &lt;span class="kwrd"&gt;is&lt;/span&gt; KeyAttribute));
    }
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TypeExtension
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Boolean IsAnonymousType(&lt;span class="kwrd"&gt;this&lt;/span&gt; Type type)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (type == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;

        var hasCompilerGeneratedAttribute = type.GetCustomAttributes(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(CompilerGeneratedAttribute), &lt;span class="kwrd"&gt;false&lt;/span&gt;).Count() &amp;gt; 0;
        var nameContainsAnonymousType = type.FullName.Contains(&lt;span class="str"&gt;"AnonymousType"&lt;/span&gt;);
        var isAnonymousType = hasCompilerGeneratedAttribute &amp;amp;&amp;amp; nameContainsAnonymousType;

        &lt;span class="kwrd"&gt;return&lt;/span&gt; isAnonymousType;
    }
}
&lt;/pre&gt;&lt;pre class="csharpcode"&gt;Feel free to fork the code as much as you can, I’m too tired to stay up longer. &lt;a href="http://code.google.com/p/dapper-dot-net/" target="_blank"&gt;Dapper&lt;/a&gt; is getting really useful &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://weblogs.asp.net/blogs/jdanforth/wlEmoticon-smile_74B2939D.png"&gt;&lt;/pre&gt;&lt;pre class="csharpcode"&gt;&amp;nbsp;&lt;/pre&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48750" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/c_2300_/default.aspx">c#</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category></item><item><title>Simple Insert Extension for Dapper</title><link>http://blog.irm.se/blogs/johan/archive/2011/05/10/Simple-Insert-Extension-for-Dapper.aspx</link><pubDate>Tue, 10 May 2011 17:20:20 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48749</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Last week I started using Dapper (&lt;a href="http://code.google.com/p/dapper-dot-net/" target="_blank"&gt;dapper-dot-net on Google Code&lt;/a&gt;) for a project I’m working on. Dapper is a micro ORM, which extends IDbConnection. It’s very fast and works very well for queries where you want to return both typed and dynamic lists of objects. Have a quick look at the webpage and you’ll see what I mean.&lt;/p&gt;  &lt;p&gt;Today I needed to do some inserting, which you can do with the Execute() extension, but you’d have to type out all the “insert into xxx (col1,col2) values (@val1, @val2)” stuff. Some guys suggested to create a dapper.contrib and adding extensions of insert, update, delete and so on but it’s not there yet (at time of writing).&lt;/p&gt;  &lt;p&gt;Anyway, the extensions in dapper are already so well written I thought it should be quite easy to just add a dead simple (or stupid if you prefer) Insert() extensions on top of the existing Execute(), and I ended up with this raw unrefactored code. All it does really is building up the SQL for the insert using some property reflection, dapper itself does the heavy lifting:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; DapperExtensions
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Insert(&lt;span class="kwrd"&gt;this&lt;/span&gt; IDbConnection connection, &lt;br /&gt;                              &lt;span class="kwrd"&gt;object&lt;/span&gt; entityToInsert, &lt;span class="kwrd"&gt;string&lt;/span&gt; sql = &lt;span class="str"&gt;&amp;quot;insert into &amp;quot;&lt;/span&gt; )
    {
        var name = entityToInsert.GetType().Name;

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (sql == &lt;span class="str"&gt;&amp;quot;insert into &amp;quot;&lt;/span&gt;)
        {
            sql = &lt;span class="str"&gt;&amp;quot;insert into &amp;quot;&lt;/span&gt; + name + &lt;span class="str"&gt;&amp;quot; &amp;quot;&lt;/span&gt;;
        }
        sql += &lt;span class="str"&gt;&amp;quot; (&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;for&lt;/span&gt; (var i = 0; i &amp;lt; entityToInsert.GetType().GetProperties().Length; i++)
        {
            var propertyInfo = entityToInsert.GetType().GetProperties()&lt;img src="http://blog.irm.se/emoticons/emotion-55.gif" alt="Idea" /&gt;;
            sql += propertyInfo.Name;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (i &amp;lt; entityToInsert.GetType().GetProperties().Length - 1)
                sql += &lt;span class="str"&gt;&amp;quot;,&amp;quot;&lt;/span&gt;;
        }
        sql += &lt;span class="str"&gt;&amp;quot;) values (&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;for&lt;/span&gt; (var i = 0; i &amp;lt; entityToInsert.GetType().GetProperties().Length; i++)
        {
            var propertyInfo = entityToInsert.GetType().GetProperties()&lt;img src="http://blog.irm.se/emoticons/emotion-55.gif" alt="Idea" /&gt;;
            sql += &lt;span class="str"&gt;&amp;quot;@&amp;quot;&lt;/span&gt; + propertyInfo.Name;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (i &amp;lt; entityToInsert.GetType().GetProperties().Length - 1)
                sql += &lt;span class="str"&gt;&amp;quot;,&amp;quot;&lt;/span&gt;;
        }
        sql += &lt;span class="str"&gt;&amp;quot;)&amp;quot;&lt;/span&gt;;
        connection.Execute(sql, entityToInsert);
    }
}&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;I’m using it like this with a type:&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; (var connection = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlConnection(connectionString))
{
    connection.Open();
    var entity = &lt;span class="kwrd"&gt;new&lt;/span&gt; Test() { Name = &lt;span class="str"&gt;&amp;quot;Johan&amp;quot;&lt;/span&gt;, Age = 43 };
    connection.Insert(entity);
}&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Test
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Age { get; set; }
}&lt;/pre&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;p&gt;…or like this with an anonymous type:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; (var connection = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlConnection(connectionString))
{
    connection.Open();
    connection.Insert(&lt;span class="kwrd"&gt;new&lt;/span&gt; { Name = &lt;span class="str"&gt;&amp;quot;Johan&amp;quot;&lt;/span&gt;, Age = 43 }, &lt;span class="str"&gt;&amp;quot;insert into test&amp;quot;&lt;/span&gt;);
}&lt;/pre&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;p&gt;Works for me ™ &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://weblogs.asp.net/blogs/jdanforth/wlEmoticon-winkingsmile_63BA8282.png" /&gt;&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48749" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/c_2300_/default.aspx">c#</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category></item><item><title>Detecting Idle Time with Global Mouse and Keyboard Hooks in WPF</title><link>http://blog.irm.se/blogs/johan/archive/2011/03/19/Detecting-Idle-Time-with-Global-Mouse-and-Keyboard-Hooks-in-WPF.aspx</link><pubDate>Sat, 19 Mar 2011 11:29:47 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48736</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Years and years ago I wrote &lt;a href="http://weblogs.asp.net/jdanforth/archive/2006/06/21/454219.aspx" target="_blank"&gt;this blog post about detecting if the user was idle or active at the keyboard (and mouse)&lt;/a&gt; using a global hook. Well that code was for .NET 2.0 and Windows Forms and for some reason I wanted to try the same in WPF and noticed that a few things around the keyboard and mouse hooks didn’t work as expected in the WPF environment. So I had to change a few things and here’s the code for it, working in .NET 4.&lt;/p&gt;  &lt;p&gt;I took the liberty and refactored a few things while at it and here’s the code now. I’m sure I will need it in the far future as well.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;using &lt;/span&gt;System;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Diagnostics;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Runtime.InteropServices;

&lt;span style="color:blue;"&gt;namespace &lt;/span&gt;Irm.Tim.Snapper.Util
{
    &lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ClientIdleHandler &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;IDisposable
    &lt;/span&gt;{
        &lt;span style="color:blue;"&gt;public bool &lt;/span&gt;IsActive { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }

        &lt;span style="color:blue;"&gt;int &lt;/span&gt;_hHookKbd;
        &lt;span style="color:blue;"&gt;int &lt;/span&gt;_hHookMouse;

        &lt;span style="color:blue;"&gt;public delegate int &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;HookProc&lt;/span&gt;(&lt;span style="color:blue;"&gt;int &lt;/span&gt;nCode, &lt;span style="color:#2b91af;"&gt;IntPtr &lt;/span&gt;wParam, &lt;span style="color:#2b91af;"&gt;IntPtr &lt;/span&gt;lParam);
        &lt;span style="color:blue;"&gt;public event &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;HookProc &lt;/span&gt;MouseHookProcedure;
        &lt;span style="color:blue;"&gt;public event &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;HookProc &lt;/span&gt;KbdHookProcedure;

        &lt;span style="color:green;"&gt;//Use this function to install thread-specific hook.
        &lt;/span&gt;[&lt;span style="color:#2b91af;"&gt;DllImport&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;user32.dll&amp;quot;&lt;/span&gt;, CharSet = &lt;span style="color:#2b91af;"&gt;CharSet&lt;/span&gt;.Auto,
             CallingConvention = &lt;span style="color:#2b91af;"&gt;CallingConvention&lt;/span&gt;.StdCall)]
        &lt;span style="color:blue;"&gt;public static extern int &lt;/span&gt;SetWindowsHookEx(&lt;span style="color:blue;"&gt;int &lt;/span&gt;idHook, &lt;span style="color:#2b91af;"&gt;HookProc &lt;/span&gt;lpfn,
            &lt;span style="color:#2b91af;"&gt;IntPtr &lt;/span&gt;hInstance, &lt;span style="color:blue;"&gt;int &lt;/span&gt;threadId);

        &lt;span style="color:green;"&gt;//Call this function to uninstall the hook.
        &lt;/span&gt;[&lt;span style="color:#2b91af;"&gt;DllImport&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;user32.dll&amp;quot;&lt;/span&gt;, CharSet = &lt;span style="color:#2b91af;"&gt;CharSet&lt;/span&gt;.Auto,
             CallingConvention = &lt;span style="color:#2b91af;"&gt;CallingConvention&lt;/span&gt;.StdCall)]
        &lt;span style="color:blue;"&gt;public static extern bool &lt;/span&gt;UnhookWindowsHookEx(&lt;span style="color:blue;"&gt;int &lt;/span&gt;idHook);

        &lt;span style="color:green;"&gt;//Use this function to pass the hook information to next hook procedure in chain.
        &lt;/span&gt;[&lt;span style="color:#2b91af;"&gt;DllImport&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;user32.dll&amp;quot;&lt;/span&gt;, CharSet = &lt;span style="color:#2b91af;"&gt;CharSet&lt;/span&gt;.Auto,
             CallingConvention = &lt;span style="color:#2b91af;"&gt;CallingConvention&lt;/span&gt;.StdCall)]
        &lt;span style="color:blue;"&gt;public static extern int &lt;/span&gt;CallNextHookEx(&lt;span style="color:blue;"&gt;int &lt;/span&gt;idHook, &lt;span style="color:blue;"&gt;int &lt;/span&gt;nCode,
            &lt;span style="color:#2b91af;"&gt;IntPtr &lt;/span&gt;wParam, &lt;span style="color:#2b91af;"&gt;IntPtr &lt;/span&gt;lParam);

        &lt;span style="color:green;"&gt;//Use this hook to get the module handle, needed for WPF environment
        &lt;/span&gt;[&lt;span style="color:#2b91af;"&gt;DllImport&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;kernel32.dll&amp;quot;&lt;/span&gt;, CharSet = &lt;span style="color:#2b91af;"&gt;CharSet&lt;/span&gt;.Auto)]
        &lt;span style="color:blue;"&gt;public static extern &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IntPtr &lt;/span&gt;GetModuleHandle(&lt;span style="color:blue;"&gt;string &lt;/span&gt;lpModuleName);

        &lt;span style="color:blue;"&gt;public enum &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;HookType &lt;/span&gt;: &lt;span style="color:blue;"&gt;int
        &lt;/span&gt;{
            GlobalKeyboard = &lt;span style="color:purple;"&gt;13&lt;/span&gt;,
            GlobalMouse = &lt;span style="color:purple;"&gt;14
        &lt;/span&gt;}

        &lt;span style="color:blue;"&gt;public int &lt;/span&gt;MouseHookProc(&lt;span style="color:blue;"&gt;int &lt;/span&gt;nCode, &lt;span style="color:#2b91af;"&gt;IntPtr &lt;/span&gt;wParam, &lt;span style="color:#2b91af;"&gt;IntPtr &lt;/span&gt;lParam)
        {
            &lt;span style="color:green;"&gt;//user is active, at least with the mouse
            &lt;/span&gt;IsActive = &lt;span style="color:blue;"&gt;true&lt;/span&gt;;
            &lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.Print(&lt;span style="color:#a31515;"&gt;&amp;quot;Mouse active&amp;quot;&lt;/span&gt;);

            &lt;span style="color:green;"&gt;//just return the next hook
            &lt;/span&gt;&lt;span style="color:blue;"&gt;return &lt;/span&gt;CallNextHookEx(_hHookMouse, nCode, wParam, lParam);
        }

        &lt;span style="color:blue;"&gt;public int &lt;/span&gt;KbdHookProc(&lt;span style="color:blue;"&gt;int &lt;/span&gt;nCode, &lt;span style="color:#2b91af;"&gt;IntPtr &lt;/span&gt;wParam, &lt;span style="color:#2b91af;"&gt;IntPtr &lt;/span&gt;lParam)
        {
            &lt;span style="color:green;"&gt;//user is active, at least with the keyboard
            &lt;/span&gt;IsActive = &lt;span style="color:blue;"&gt;true&lt;/span&gt;;
            &lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.Print(&lt;span style="color:#a31515;"&gt;&amp;quot;Keyboard active&amp;quot;&lt;/span&gt;);

            &lt;span style="color:green;"&gt;//just return the next hook
            &lt;/span&gt;&lt;span style="color:blue;"&gt;return &lt;/span&gt;CallNextHookEx(_hHookKbd, nCode, wParam, lParam);
        }

        &lt;span style="color:blue;"&gt;public void &lt;/span&gt;Start()
        {
            &lt;span style="color:blue;"&gt;using &lt;/span&gt;(&lt;span style="color:blue;"&gt;var &lt;/span&gt;currentProcess = &lt;span style="color:#2b91af;"&gt;Process&lt;/span&gt;.GetCurrentProcess())
            &lt;span style="color:blue;"&gt;using &lt;/span&gt;(&lt;span style="color:blue;"&gt;var &lt;/span&gt;mainModule = currentProcess.MainModule)
            {

                &lt;span style="color:blue;"&gt;if &lt;/span&gt;(_hHookMouse == &lt;span style="color:purple;"&gt;0&lt;/span&gt;)
                {
                    &lt;span style="color:green;"&gt;// Create an instance of HookProc.
                    &lt;/span&gt;MouseHookProcedure = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;HookProc&lt;/span&gt;(MouseHookProc);
                    &lt;span style="color:green;"&gt;// Create an instance of HookProc.
                    &lt;/span&gt;KbdHookProcedure = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;HookProc&lt;/span&gt;(KbdHookProc);

                    &lt;span style="color:green;"&gt;//register a global hook
                    &lt;/span&gt;_hHookMouse = SetWindowsHookEx((&lt;span style="color:blue;"&gt;int&lt;/span&gt;)&lt;span style="color:#2b91af;"&gt;HookType&lt;/span&gt;.GlobalMouse,
                                                  MouseHookProcedure,
                                                  GetModuleHandle(mainModule.ModuleName),
                                                  &lt;span style="color:purple;"&gt;0&lt;/span&gt;);
                    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(_hHookMouse == &lt;span style="color:purple;"&gt;0&lt;/span&gt;)
                    {
                        Close();
                        &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ApplicationException&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;SetWindowsHookEx() failed for the mouse&amp;quot;&lt;/span&gt;);
                    }
                }

                &lt;span style="color:blue;"&gt;if &lt;/span&gt;(_hHookKbd == &lt;span style="color:purple;"&gt;0&lt;/span&gt;)
                {
                    &lt;span style="color:green;"&gt;//register a global hook
                    &lt;/span&gt;_hHookKbd = SetWindowsHookEx((&lt;span style="color:blue;"&gt;int&lt;/span&gt;)&lt;span style="color:#2b91af;"&gt;HookType&lt;/span&gt;.GlobalKeyboard,
                                                KbdHookProcedure,
                                                GetModuleHandle(mainModule.ModuleName),
                                                &lt;span style="color:purple;"&gt;0&lt;/span&gt;);
                    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(_hHookKbd == &lt;span style="color:purple;"&gt;0&lt;/span&gt;)
                    {
                        Close();
                        &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ApplicationException&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;SetWindowsHookEx() failed for the keyboard&amp;quot;&lt;/span&gt;);
                    }
                }
            }
        }

        &lt;span style="color:blue;"&gt;public void &lt;/span&gt;Close()
        {
            &lt;span style="color:blue;"&gt;if &lt;/span&gt;(_hHookMouse != &lt;span style="color:purple;"&gt;0&lt;/span&gt;)
            {
                &lt;span style="color:blue;"&gt;bool &lt;/span&gt;ret = UnhookWindowsHookEx(_hHookMouse);
                &lt;span style="color:blue;"&gt;if &lt;/span&gt;(ret == &lt;span style="color:blue;"&gt;false&lt;/span&gt;)
                {
                    &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ApplicationException&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;UnhookWindowsHookEx() failed for the mouse&amp;quot;&lt;/span&gt;);
                }
                _hHookMouse = &lt;span style="color:purple;"&gt;0&lt;/span&gt;;
            }

            &lt;span style="color:blue;"&gt;if &lt;/span&gt;(_hHookKbd != &lt;span style="color:purple;"&gt;0&lt;/span&gt;)
            {
                &lt;span style="color:blue;"&gt;bool &lt;/span&gt;ret = UnhookWindowsHookEx(_hHookKbd);
                &lt;span style="color:blue;"&gt;if &lt;/span&gt;(ret == &lt;span style="color:blue;"&gt;false&lt;/span&gt;)
                {
                    &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ApplicationException&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;UnhookWindowsHookEx() failed for the keyboard&amp;quot;&lt;/span&gt;);
                }
                _hHookKbd = &lt;span style="color:purple;"&gt;0&lt;/span&gt;;
            }
        }

        &lt;span style="color:blue;"&gt;#region &lt;/span&gt;IDisposable Members

        &lt;span style="color:blue;"&gt;public void &lt;/span&gt;Dispose()
        {
            &lt;span style="color:blue;"&gt;if &lt;/span&gt;(_hHookMouse != &lt;span style="color:purple;"&gt;0 &lt;/span&gt;|| _hHookKbd != &lt;span style="color:purple;"&gt;0&lt;/span&gt;)
                Close();
        }

        &lt;span style="color:blue;"&gt;#endregion
    &lt;/span&gt;}
}&lt;/pre&gt;



&lt;p&gt;The way you use it is quite simple, for example in a WPF application with a simple Window and a TextBlock:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Window &lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;WpfApplication2.MainWindow&amp;quot;
        &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
        &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;
        &lt;/span&gt;&lt;span style="color:red;"&gt;Title&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;MainWindow&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;350&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;525&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBlock &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;IdleTextBox&amp;quot;/&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Window&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;

&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And in the code behind we wire up the ClientIdleHandler and a DispatcherTimer that ticks every second:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public partial class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MainWindow &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;Window
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DispatcherTimer &lt;/span&gt;_dispatcherTimer;
    &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ClientIdleHandler &lt;/span&gt;_clientIdleHandler;

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;MainWindow()
    {
        InitializeComponent();
    }

    &lt;span style="color:blue;"&gt;private void &lt;/span&gt;Window_Loaded(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;RoutedEventArgs &lt;/span&gt;e)
    {
        &lt;span style="color:green;"&gt;//start client idle hook
        &lt;/span&gt;_clientIdleHandler = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ClientIdleHandler&lt;/span&gt;();
        _clientIdleHandler.Start();
        
        &lt;span style="color:green;"&gt;//start timer
        &lt;/span&gt;_dispatcherTimer = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DispatcherTimer&lt;/span&gt;();
        _dispatcherTimer.Tick += TimerTick;
        _dispatcherTimer.Interval = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt;(&lt;span style="color:purple;"&gt;0&lt;/span&gt;, &lt;span style="color:purple;"&gt;0&lt;/span&gt;, &lt;span style="color:purple;"&gt;0&lt;/span&gt;, &lt;span style="color:purple;"&gt;1&lt;/span&gt;);
        _dispatcherTimer.Start();
    }

    &lt;span style="color:blue;"&gt;private void &lt;/span&gt;TimerTick(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;EventArgs &lt;/span&gt;e)
    {
        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(_clientIdleHandler.IsActive)
        {
            IdleTextBox.Text = &lt;span style="color:#a31515;"&gt;&amp;quot;Active&amp;quot;&lt;/span&gt;;
            &lt;span style="color:green;"&gt;//reset IsActive flag
            &lt;/span&gt;_clientIdleHandler.IsActive = &lt;span style="color:blue;"&gt;false&lt;/span&gt;;    
        }
        &lt;span style="color:blue;"&gt;else &lt;/span&gt;IdleTextBox.Text = &lt;span style="color:#a31515;"&gt;&amp;quot;Idle&amp;quot;&lt;/span&gt;;
    }
}&lt;/pre&gt;


&lt;p&gt;Remember to reset the ClientIdleHandle IsActive flag after a check.&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48736" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category></item><item><title>Learning about CQRS and Event Sourcing</title><link>http://blog.irm.se/blogs/eric/archive/2011/03/06/Learning-about-CQRS-and-Event-Sourcing.aspx</link><pubDate>Sun, 06 Mar 2011 21:27:00 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48733</guid><dc:creator>ericqu</dc:creator><slash:comments>3</slash:comments><description>&lt;p&gt;In my struggle to use &lt;a href="http://en.wikipedia.org/wiki/Domain_driven_design"&gt;Domain-Driven Design&lt;/a&gt; (DDD) in better ways to get more value out of it and not ending up with &lt;a href="http://martinfowler.com/bliki/AnemicDomainModel.html"&gt;anemic models&lt;/a&gt;, I began reading about Command Query Responsibility Segregation (CQRS) and Event Sourcing. These are two patterns that fit very well with DDD and two of the most influent thinkers in this area is Greg Young and Udi Dahan. In this post I will simply list a couple of resources that I have found to be very useful, but first let&amp;rsquo;s start with some of the reasons why I believe this is so interesting:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;When combining CQRS and Event Sourcing you will have a built-in integration model. For me, this is huge, since when is the last time you build an application/system in isolation? The problem often is that the need for integration is not taken care of until late in the project and then we add something on top of what we created more common than not with an unsatisfied result.&lt;/li&gt;&lt;li&gt;CQRS offers great separation of concerns and removes the need for supporting reporting in the domain model.&lt;/li&gt;&lt;li&gt;The application/system is built with three relatively loose coupled parts (domain model, read model and user interface) that can be developed and evolved independently from each other.&lt;/li&gt;&lt;li&gt;We store all events generated by the system (Event Sourcing). I believe events will get more and more attention over the coming years (if not Event-Driven Architecture and BI has already put a lot of focus on it) and it opens for many interesting business scenarios.&lt;/li&gt;&lt;li&gt;It is bare bone. This can sound strange, but during the last years I have tried many new frameworks (for example different O/R mappers, WCF RIA Services and so on) without getting the &amp;ldquo;reward&amp;rdquo; I&amp;rsquo;ve been hoping for. In my lab project so far I have not used any frameworks, but I don&amp;rsquo;t believe that I &amp;lsquo;m writing more code. Rather I find my code becoming better in many ways (easier to read and maintain, better separation of concerns, faster and more).&lt;/li&gt;&lt;li&gt;It fits very well with both cloud and SOA.&lt;/li&gt;&lt;li&gt;Offers some really good way to do unit testing (or at least I have learned better ways to do it when learning about CQRS and Event Sourcing).&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;There are more reasons which is outlined in many of the following resources that I&amp;rsquo;ve found good to start with:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://skillsmatter.com/podcast/design-architecture/architectural-innovation-eventing-event-sourcing/"&gt;1 hour introductionary video by Greg Young covering both CQRS and Event Sourcing&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;&lt;a href="http://skillsmatter.com/podcast/open-source-dot-net/udi-dahan-command-query-responsibility-segregation/"&gt;1 2/3 hours video by Udi Dahan focusing on CQRS.&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.viddler.com/explore/GregYoung/videos/8/383.043/"&gt;6,5 hours video by Greg Young going into more depth.&lt;/a&gt; I recommend you to take the time to watch this even though it is long. It can also be &lt;a href="http://dl.dropbox.com/u/108121/CQRS.zip"&gt;downloaded&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;&lt;a href="http://cqrs.wordpress.com/"&gt;http://cqrs.wordpress.com/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://codebetter.com/gregyoung/"&gt;Greg Young&amp;rsquo;s blog&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://ncqrs.org/"&gt;nCQRS - .NET Open Source framework for CQRS and Event Sourcing&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://groups.google.com/group/dddcqrs/"&gt;The CQRS forum&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Of course &lt;a href="http://www.domaindrivendesign.org/books/evans_2003"&gt;Domain-Driven Design by Eric Evans&lt;/a&gt; is pre-requisite and &lt;a href="http://www.domaindrivendesign.org/books/nilsson_2006"&gt;Jimmy Nilsson&amp;rsquo;s Applying Domain-Driven Design and Patterns&lt;/a&gt; book is also a good read. &lt;/p&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48733" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/eric/archive/tags/Architecture/default.aspx">Architecture</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/Cloud+computing/default.aspx">Cloud computing</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/Event+Sourcing/default.aspx">Event Sourcing</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/DDD/default.aspx">DDD</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/CQRS/default.aspx">CQRS</category></item><item><title>The Small Things: Asynchronous WCF Calls Without Setting Up Service Reference</title><link>http://blog.irm.se/blogs/eric/archive/2011/01/29/The-Small-Things_3A00_-Asynchronous-WCF-Calls-Without-Setting-Up-Service-Reference.aspx</link><pubDate>Sat, 29 Jan 2011 12:49:01 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48727</guid><dc:creator>ericqu</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;When you are developing both the service and the client it can many times be good to not use the “Add Service Reference” in Visual Studio. Instead the service and data contracts can be defined in a shared class library. There can be many reasons for this, on popping up immediately is that such a solution removes the need to always update the service reference as the service contract evolves. A “showstopper” could be that when using the ChannelFactory to create the proxy there are no asynchronous methods there to call. Lets start with a small example.&lt;/p&gt;  &lt;pre class="code"&gt;[&lt;span style="color:#2b91af;"&gt;ServiceContract&lt;/span&gt;(Name = &lt;span style="color:#a31515;"&gt;&amp;quot;ProjectService&amp;quot;&lt;/span&gt;, Namespace = &lt;span style="color:#2b91af;"&gt;Constants&lt;/span&gt;.Namespace)]
&lt;span style="color:blue;"&gt;public interface &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IProjectService
&lt;/span&gt;{
    [&lt;span style="color:#2b91af;"&gt;OperationContract&lt;/span&gt;]
    &lt;span style="color:#2b91af;"&gt;ProjectDetails &lt;/span&gt;GetProjectById(&lt;span style="color:#2b91af;"&gt;Guid &lt;/span&gt;id);
}&lt;/pre&gt;

&lt;p&gt;This simple service interface could be used on the client with the help of ChannelFactory:&lt;/p&gt;

&lt;pre class="code"&gt;factory = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;IProjectService&lt;/span&gt;&amp;gt;(“*”); 
&lt;span style="color:#2b91af;"&gt;IProjectService &lt;/span&gt;proxy = factory.CreateChannel();&lt;/pre&gt;

&lt;p&gt;The problem now is that we most often should make the calls to services asynchronous so that the client is not blocked. What we need to do to solve this is the create a client interface that exposes the asynchronous methods. In this case it will look like this:&lt;/p&gt;

&lt;pre class="code"&gt;[&lt;span style="color:#2b91af;"&gt;ServiceContract&lt;/span&gt;(Name = &lt;span style="color:#a31515;"&gt;&amp;quot;ProjectService&amp;quot;&lt;/span&gt;, Namespace = &lt;span style="color:#2b91af;"&gt;Constants&lt;/span&gt;.Namespace)]
&lt;span style="color:blue;"&gt;public interface &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IProjectServiceClient &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;IProjectService
&lt;/span&gt;{
    [System.ServiceModel.&lt;span style="color:#2b91af;"&gt;OperationContractAttribute&lt;/span&gt;(AsyncPattern = &lt;span style="color:blue;"&gt;true&lt;/span&gt;, &lt;br /&gt;        Action = &lt;span style="color:#2b91af;"&gt;Constants&lt;/span&gt;.Namespace + &lt;span style="color:#a31515;"&gt;&amp;quot;ProjectService/GetProjectById&amp;quot;&lt;/span&gt;, &lt;br /&gt;        ReplyAction = &lt;span style="color:#2b91af;"&gt;Constants&lt;/span&gt;.Namespace + &lt;span style="color:#a31515;"&gt;&amp;quot;ProjectService/GetProjectByIdResponse&amp;quot;&lt;/span&gt;)]
    System.&lt;span style="color:#2b91af;"&gt;IAsyncResult &lt;/span&gt;BeginGetProjectById(System.&lt;span style="color:#2b91af;"&gt;Guid &lt;/span&gt;id, System.&lt;span style="color:#2b91af;"&gt;AsyncCallback &lt;/span&gt;callback, &lt;span style="color:blue;"&gt;object &lt;/span&gt;asyncState);

    &lt;span style="color:#2b91af;"&gt;ProjectDetails &lt;/span&gt;EndGetProjectById(System.&lt;span style="color:#2b91af;"&gt;IAsyncResult &lt;/span&gt;result);
}&lt;/pre&gt;

&lt;p&gt;Now all we need to do is of course switch the IProjectService to IProjectServiceClient in the ChannelFactory code and the asynchronous methods will be available. Oh … and one last thing, don’t forget to also change IProjectService to IProjectServiceClient in you client config file.&lt;/p&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48727" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/eric/archive/tags/Windows+Forms/default.aspx">Windows Forms</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/The+Small+Things/default.aspx">The Small Things</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+3.0/default.aspx">.NET 3.0</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+3.5/default.aspx">.NET 3.5</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blog.irm.se/blogs/eric/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category></item></channel></rss>
