<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>valeriu.caraulean</title>
    <description>Valeriu Caraulean: personal site &amp; blog</description>
    <link>http://caraulean.com/</link>
    <atom:link href="http://caraulean.com/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Sun, 31 Mar 2019 21:04:00 +0000</pubDate>
    <lastBuildDate>Sun, 31 Mar 2019 21:04:00 +0000</lastBuildDate>
    <generator>Jekyll v3.7.4</generator>
    
      <item>
        <title>Migrating to new csproj format</title>
        <description>&lt;p&gt;We’ve got a bunch of projects at work that are using the &lt;em&gt;old style&lt;/em&gt; project file format. And since we’re already on Visual Studio 2017 and Rider, we were looking to new csproj format were the most interesting benefit would be it’s simplicity.&lt;/p&gt;

&lt;p&gt;This is a &lt;em&gt;how to&lt;/em&gt; guide on how to approach a such migration and description of few tricky moments and issues encountered.&lt;/p&gt;

&lt;h2 id=&quot;read-the-docs&quot;&gt;Read the docs…&lt;/h2&gt;

&lt;p&gt;… or at least keep them at hand:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/dotnet/core/tools/csproj&quot;&gt;The &lt;em&gt;new&lt;/em&gt; csproj format&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h2&gt;

&lt;p&gt;Using the Visual Studio Installer check that you have next components:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;.NET Core cross-platform development workload&lt;/li&gt;
  &lt;li&gt;Targeting packs and SDKs for the version of the framework that you’re targeting&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;upgrading-the-project&quot;&gt;Upgrading the project&lt;/h2&gt;

&lt;p&gt;Simplest part. Replace the context of csproj with these lines:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot; ToolsVersion=&quot;15.0&quot;&amp;gt;
  &amp;lt;PropertyGroup&amp;gt;
    &amp;lt;OutputType&amp;gt;Exe&amp;lt;/OutputType&amp;gt;
    &amp;lt;TargetFramework&amp;gt;net462&amp;lt;/TargetFramework&amp;gt;
  &amp;lt;/PropertyGroup&amp;gt;
&amp;lt;/Project&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;upgrading-package-references&quot;&gt;Upgrading package references&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Preparetive step, not strictly necessary.&lt;/em&gt; Go to Nuget settings of your IDE of choice and set “Default package management format” to “PackageReference”.&lt;/p&gt;

&lt;p&gt;There’s an important difference while using new &lt;code class=&quot;highlighter-rouge&quot;&gt;PackageReference&lt;/code&gt; compared to previous &lt;code class=&quot;highlighter-rouge&quot;&gt;packages.config&lt;/code&gt;. New format includes only “top level” packages - ones that you reference directly in your code. As such don’t blindly add every package found in &lt;code class=&quot;highlighter-rouge&quot;&gt;packages.config&lt;/code&gt; as a &lt;code class=&quot;highlighter-rouge&quot;&gt;PackageReference&lt;/code&gt;. Instead:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Compile the project without any references&lt;/li&gt;
  &lt;li&gt;Follow compilation errors and edge them out one-by-one by adding missing packages&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;cleanup--miscellaneous&quot;&gt;Cleanup &amp;amp; miscellaneous&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Remove AssemblyInfo.cs. Check if it contains any useful attributes &amp;amp; set them in project properties or csproj directly&lt;/li&gt;
  &lt;li&gt;Remove packages.config&lt;/li&gt;
  &lt;li&gt;Remove &lt;code class=&quot;highlighter-rouge&quot;&gt;packages&lt;/code&gt; folder in solution root&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;dealing-with-embedded-resources&quot;&gt;Dealing with embedded resources&lt;/h3&gt;

&lt;p&gt;If project contains any content/resource files, Include them explicitly in csproj:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &amp;lt;ItemGroup&amp;gt;
    &amp;lt;Content Include=&quot;Mappings.csv&quot;&amp;gt;
      &amp;lt;CopyToOutputDirectory&amp;gt;PreserveNewest&amp;lt;/CopyToOutputDirectory&amp;gt;
    &amp;lt;/Content&amp;gt;
  &amp;lt;/ItemGroup&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Or, as embedded resources using wildcards:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &amp;lt;ItemGroup&amp;gt;
    &amp;lt;EmbeddedResource Include=&quot;.\**\*.json&quot; Exclude=&quot;.\bin\**\*.json;.\obj\**\*.json&quot; /&amp;gt;
  &amp;lt;/ItemGroup&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;nuget-integration&quot;&gt;Nuget integration&lt;/h2&gt;

&lt;p&gt;The new msbuild took over for some manipulations related to nuget packages. So this area will need to be reviewed. Some particular items:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;nuspec&lt;/code&gt; files, if used, have to be referenced from csproj files explicitly&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;nuspec&lt;/code&gt; files can be avoided completely and properties defined &lt;a href=&quot;https://docs.microsoft.com/en-us/dotnet/core/tools/csproj#nuget-metadata-properties&quot;&gt;directly in csproj&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;nuget pack&lt;/code&gt; will not work anymore. &lt;code class=&quot;highlighter-rouge&quot;&gt;dotnet pack&lt;/code&gt; or the equivalent &lt;code class=&quot;highlighter-rouge&quot;&gt;msbuild /t:pack&lt;/code&gt; have to be used to generate nuget packages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Actually, the common package related pattern will be: &lt;code class=&quot;highlighter-rouge&quot;&gt;msbuild /t:restore;build;pack&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;pitfalls--possible-issues&quot;&gt;Pitfalls &amp;amp; possible issues&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;New project will pick up &lt;em&gt;all&lt;/em&gt; .cs files in the project file directories and sub-directories. Some leftovers might get in the project. Fix: review &amp;amp; remove unnecessary.&lt;/li&gt;
  &lt;li&gt;Warnings about binding redirects. Fix: open &lt;code class=&quot;highlighter-rouge&quot;&gt;app.config&lt;/code&gt; and remove mentioned assemblies.&lt;/li&gt;
  &lt;li&gt;Compilation errors in &lt;code class=&quot;highlighter-rouge&quot;&gt;AssemblyInfo.cs&lt;/code&gt; about duplicated definitions. Fix: remove AssemblyInfo.cs&lt;/li&gt;
  &lt;li&gt;Output folder now includes target framework moniker. Example: &lt;code class=&quot;highlighter-rouge&quot;&gt;bin\Debug\net462&lt;/code&gt;. If any build or deployment scripts are relying on old path, then it has to be fixed.&lt;/li&gt;
  &lt;li&gt;Additional files that have to exist in output folder aren’t automatically included. Fix: any additional resource files have to be included explicitly in new csproj.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;Directory.GetCurrentDirectory()&lt;/code&gt; returns a different thing than before. Affects &lt;code class=&quot;highlighter-rouge&quot;&gt;Directory.Exists&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;Directory.CreateDirectory&lt;/code&gt; and probably any other API that are accepting relative paths. Apparently, new CLI tooling is setting default &lt;em&gt;Working Directory&lt;/em&gt; (in both VS2017 and Rider) to location of the project file, contrary to output folder.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;nuget pack&lt;/code&gt; will not work anymore. &lt;code class=&quot;highlighter-rouge&quot;&gt;dotnet pack&lt;/code&gt; or the equivalent &lt;code class=&quot;highlighter-rouge&quot;&gt;msbuild /t:pack&lt;/code&gt; have to be used to generate nuget packages.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;build-server-woes-teamcity&quot;&gt;Build server woes (TeamCity)&lt;/h2&gt;

&lt;p&gt;We’ve got TeamCity on the build duty. Few things were needed there to support building of new project format:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Update Nuget Tools to a version that supports the new msbuild tooling (4.x will do)&lt;/li&gt;
  &lt;li&gt;To get the new msbuild tools on agents most reasonable option will be to use &lt;a href=&quot;https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017&quot;&gt;Build Tools for Visual Studio 2017&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;If you’re getting this error: &lt;code class=&quot;highlighter-rouge&quot;&gt;error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.&lt;/code&gt; then install &lt;code class=&quot;highlighter-rouge&quot;&gt;.NET Core Build Tools&lt;/code&gt; payload. Event if the app isn’t targeting .NET Core, this payload is still needed to correctly handle &lt;code class=&quot;highlighter-rouge&quot;&gt;PackageReference&lt;/code&gt; in csproj.&lt;/li&gt;
  &lt;li&gt;Build configuration was probably stamping the assembly with version. Previously common approach was to update &lt;code class=&quot;highlighter-rouge&quot;&gt;AssemblyInfo.cs&lt;/code&gt; before passing it to &lt;code class=&quot;highlighter-rouge&quot;&gt;msbuild&lt;/code&gt;. As we got rid of this file, we can achieve same results by passing &lt;code class=&quot;highlighter-rouge&quot;&gt;Version&lt;/code&gt; parameter to &lt;code class=&quot;highlighter-rouge&quot;&gt;msbuild&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Sun, 18 Feb 2018 22:00:00 +0000</pubDate>
        <link>http://caraulean.com/2018/migrating-to-new-csproj-format/</link>
        <guid isPermaLink="true">http://caraulean.com/2018/migrating-to-new-csproj-format/</guid>
        
        
        <category>.net,</category>
        
        <category>csproj</category>
        
      </item>
    
      <item>
        <title>Timestamp accuracy and resolution in NLog</title>
        <description>&lt;p&gt;In one of internal projects we got a situation where our log management system was displaying entries from NLog in wrong “logical” order, despite being explicitly ordered by timestamp.&lt;/p&gt;

&lt;p&gt;Here are few insights I got after investigating the case.&lt;/p&gt;

&lt;p&gt;Let’s create a basic example to show the problem.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;for (var i = 0; i &amp;lt; 100; i++ )
{
    _log.Info($&quot;Iteration {i}: {DateTime.Now.ToString(&quot;HH:mm:ss.fffffff&quot;)}&quot;);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If we run this code with default NLog configuration, we will get output like this:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;2016-07-11 16:14:23.8486343 Iteration 0: 16:14:23.8486343
2016-07-11 16:14:23.8486343 Iteration 1: 16:14:23.8496384
2016-07-11 16:14:23.8486343 Iteration 2: 16:14:23.8506392
2016-07-11 16:14:23.8486343 Iteration 3: 16:14:23.8526399
2016-07-11 16:14:23.8486343 Iteration 4: 16:14:23.8536741
2016-07-11 16:14:23.8486343 Iteration 5: 16:14:23.8546388
2016-07-11 16:14:23.8566766 Iteration 6: 16:14:23.8566766
2016-07-11 16:14:23.8566766 Iteration 7: 16:14:23.8576574
2016-07-11 16:14:23.8566766 Iteration 8: 16:14:23.8596377
2016-07-11 16:14:23.8566766 Iteration 9: 16:14:23.8596377
2016-07-11 16:14:23.8566766 Iteration 10: 16:14:23.8606376
2016-07-11 16:14:23.8566766 Iteration 11: 16:14:23.8606376
2016-07-11 16:14:23.8566766 Iteration 12: 16:14:23.8616403
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As you see, multiple log entries are recorder with same timestamp (but check the timestamps in the message - they are much more varied). This looks fine if you’re looking in a console or in a single log file. But it will get quite annoying if you’re querying your log storage system and ordering results by time - sort order will be not what you would expect.&lt;/p&gt;

&lt;p&gt;If we dig deeper in this problem, we will discover that NLog, has a mechanism called &lt;a href=&quot;https://github.com/NLog/NLog/wiki/Time-Source&quot;&gt;TimeSource&lt;/a&gt;. This provider is used to get the current time for each instance of LogEventInfo class created for every log entry in your application. There are a total of 4 different time source implementations, and, of course, you can create your own, if you please.&lt;/p&gt;

&lt;p&gt;The default implementation of NLog’s time source is optimized for performance and caches the values that are being returned. Caching logic uses &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/system.environment.tickcount(v=vs.110).aspx&quot;&gt;Environment.TickCount&lt;/a&gt; intervals to return time stamps for new log entries. And the resolution of TickCount property is limited to resolution of system timer which is not a fixed value but typically varies in the 10-16 ms range.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;As a result, with default configuration, you get a timestamp resolution of ~15 milliseconds for your log entries.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Luckily, NLog provides other implementations of TimeSource. They are documented to an extend &lt;a href=&quot;https://github.com/NLog/NLog/wiki/Time-Source&quot;&gt;here&lt;/a&gt;. The default is the &lt;code class=&quot;highlighter-rouge&quot;&gt;FastLocal&lt;/code&gt; and is has the caching behaviour I described above. &lt;code class=&quot;highlighter-rouge&quot;&gt;FastUTC&lt;/code&gt; is using a similar caching approach but returning UTC timestamps. &lt;code class=&quot;highlighter-rouge&quot;&gt;AccurateLocal&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;AccurateUTC&lt;/code&gt;, theoretically, should be better bets if you want a more precise timestamps in your log entries.&lt;/p&gt;

&lt;p&gt;If we change our NLog configuration to use a more accurate time source:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;nlog&amp;gt;
  &amp;lt;time type=&quot;AccurateUTC&quot; /&amp;gt;
&amp;lt;/nlog&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;… then we will get a quite different picture in the output:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;2016-07-11 21:20:32.5920090 Iteration 0: 23:20:32.5889709
2016-07-11 21:20:32.5939717 Iteration 1: 23:20:32.5929728
2016-07-11 21:20:32.5949707 Iteration 2: 23:20:32.5949707
2016-07-11 21:20:32.5959701 Iteration 3: 23:20:32.5959701
2016-07-11 21:20:32.6310051 Iteration 4: 23:20:32.6310051
2016-07-11 21:20:32.6330058 Iteration 5: 23:20:32.6330058
2016-07-11 21:20:32.6340033 Iteration 6: 23:20:32.6340033
2016-07-11 21:20:32.6370016 Iteration 7: 23:20:32.6370016
2016-07-11 21:20:32.6400059 Iteration 8: 23:20:32.6400059
2016-07-11 21:20:32.6766186 Iteration 9: 23:20:32.6766186
2016-07-11 21:20:32.6795909 Iteration 10: 23:20:32.6795909
2016-07-11 21:20:32.6826277 Iteration 11: 23:20:32.6826277
2016-07-11 21:20:32.6835886 Iteration 12: 23:20:32.6835886
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now we got a much better results: our logging timestamps are matching quite nicely timestamps from our message generated by DateTime.Now!&lt;/p&gt;

&lt;p&gt;Both of the &lt;code class=&quot;highlighter-rouge&quot;&gt;accurate&lt;/code&gt; time sources are using respectively current values of DateTime: &lt;code class=&quot;highlighter-rouge&quot;&gt;DateTime.Now&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;DateTime.UtcNow&lt;/code&gt;. And this is giving us a better result, with timestamp resolution closer to 1 ms.&lt;/p&gt;

&lt;p&gt;I actually wondered, how much is the difference in performance will be between &lt;code class=&quot;highlighter-rouge&quot;&gt;fast&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;accurate&lt;/code&gt; TimeSource implementations? &lt;a href=&quot;https://github.com/PerfDotNet/BenchmarkDotNet&quot;&gt;BenchmarkDotNet&lt;/a&gt; to the rescue! &lt;a href=&quot;https://gist.github.com/vcaraulean/6a0e3201ea7889e06bd35391bba0d521&quot;&gt;I quickly put together a benchmark&lt;/a&gt; that measured the difference between using different time sources. Results are quite interesting:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Method&lt;/th&gt;
      &lt;th&gt;Median&lt;/th&gt;
      &lt;th&gt;StdDev&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;FastLocal&lt;/td&gt;
      &lt;td&gt;5.7752 ns&lt;/td&gt;
      &lt;td&gt;0.3450 ns&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FastUtc&lt;/td&gt;
      &lt;td&gt;5.8330 ns&lt;/td&gt;
      &lt;td&gt;0.4939 ns&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;AccurateLocal&lt;/td&gt;
      &lt;td&gt;784.4354 ns&lt;/td&gt;
      &lt;td&gt;61.6136 ns&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;AccurateUtc&lt;/td&gt;
      &lt;td&gt;7.0547 ns&lt;/td&gt;
      &lt;td&gt;0.3934 ns&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Quite telling: &lt;code class=&quot;highlighter-rouge&quot;&gt;fast&lt;/code&gt; implementations are the fastest but, as we’ve seen before, timestamps are cached and not that precise. &lt;code class=&quot;highlighter-rouge&quot;&gt;AccurateUTC&lt;/code&gt; is a very close runner. If you’re asking, why is this not the default time source, the response probably will be the dreaded &lt;code class=&quot;highlighter-rouge&quot;&gt;backward compatibility&lt;/code&gt;, as time sources were added around NLog 2.x.&lt;/p&gt;

&lt;h3 id=&quot;summing-up&quot;&gt;Summing up&lt;/h3&gt;
&lt;p&gt;If you care about timestamps in your logs, change the default TimeSource to &lt;code class=&quot;highlighter-rouge&quot;&gt;AccurateUTC&lt;/code&gt;. There’s a very small performance overhead, but you will get a much better accuracy and all your timestamps will be in UTC. Actually, the second gain (UTC timestamps), is extremely valuable when you have to deal with logging in complex or geographically distributed applications. So, please, consider it.&lt;/p&gt;
</description>
        <pubDate>Tue, 12 Jul 2016 21:02:00 +0000</pubDate>
        <link>http://caraulean.com/2016/timestamp-accuracy-and-resolution-in-nlog/</link>
        <guid isPermaLink="true">http://caraulean.com/2016/timestamp-accuracy-and-resolution-in-nlog/</guid>
        
        
        <category>nlog,</category>
        
        <category>.net</category>
        
      </item>
    
      <item>
        <title>Handling custom URI Schemes with ClickOnce</title>
        <description>&lt;p&gt;&lt;em&gt;This article will show how to handle URI schemes containing parameters in a ClickOnce applications. For example, a link like &lt;code class=&quot;highlighter-rouge&quot;&gt;theapp://notificatons?eventId=124&lt;/code&gt; can be handled by a ClickOnce application, where query parameters are passed in and can be handled by application itself. It’s also sometimes called &lt;code class=&quot;highlighter-rouge&quot;&gt;deep link&lt;/code&gt; activation in a ClickOnce context.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;URI scheme is a useful concept. It allows you to register an &lt;a href=&quot;https://en.wikipedia.org/wiki/Uniform_Resource_Identifier&quot;&gt;URI&lt;/a&gt; with your OS and then whenever an URL that corresponds to that URI schema will be clicked, you application will be launched. It’s very handy in some cases. Handling URI Schemes is &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/aa767914.aspx&quot;&gt;well documented&lt;/a&gt; and, actually, quite simple. But it gets more though if you want to do it in a ClickOnce application in the case if you want to react to whatever is coming after URI scheme.&lt;/p&gt;

&lt;p&gt;In our cases we wanted to send out emails with some specially formatted links (something like &lt;code class=&quot;highlighter-rouge&quot;&gt;theapp://notificatons?eventId=124&lt;/code&gt;). When clicked, these links should open our application and then navigate to a “notifications” view and load details of a specific event. All this from a &lt;strong&gt;ClickOnce&lt;/strong&gt; application. The hard part here is handling the URI arguments, thus the parts &lt;code class=&quot;highlighter-rouge&quot;&gt;navigation&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;eventId=124&lt;/code&gt; have to be available to the application.&lt;/p&gt;

&lt;p&gt;We came with a way to do it and here’s a description how it can be done. And there are two ways to do it:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;doing it properly: get rid of ClickOnce. If you can ditch ClickOnce - DO IT. Seriously.&lt;/li&gt;
  &lt;li&gt;the hard way: read on…&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;implementation-constraints-details--challenges&quot;&gt;Implementation constraints, details &amp;amp; challenges:&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;ClickOnce application&lt;/li&gt;
  &lt;li&gt;Custom URI scheme&lt;/li&gt;
  &lt;li&gt;Application should be able to handle parameters encoded in URI like this: &lt;code class=&quot;highlighter-rouge&quot;&gt;theapp://notificatons?eventId=124&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Clicking on a such link should launch the application and allow the app to handle launch parameters&lt;/li&gt;
  &lt;li&gt;(constraint) The process should work even if Chrome is set as default browser&lt;/li&gt;
  &lt;li&gt;(limitation) Activation URI is a web address (approach is not handling apps installed from local or network paths)&lt;/li&gt;
  &lt;li&gt;(limitation) You have to launch application at least once manually to make it work&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;show-me-the-code&quot;&gt;Show me the code!&lt;/h2&gt;

&lt;p&gt;You can jump straight into the code. I have a WPF project that I used to work on this feature and test activation. &lt;a href=&quot;https://github.com/vcaraulean/ClickOnceCustomUriScheme&quot;&gt;Code is on GitHub&lt;/a&gt;. Most interesting classes are &lt;a href=&quot;https://github.com/vcaraulean/ClickOnceCustomUriScheme/blob/master/ClickOnceCustomUriScheme/ApplicationUri/ApplicationUriSchema.cs&quot;&gt;ApplicationUriSchema.cs&lt;/a&gt; where all interesting things are happening and you might check also &lt;a href=&quot;https://github.com/vcaraulean/ClickOnceCustomUriScheme/blob/master/ClickOnceCustomUriScheme/MainWindowViewModel.cs&quot;&gt;MainWindowViewModel.cs&lt;/a&gt; to see how to get the lauch URI and query string parameters. Application is logging all useful info and decisions, so watch the logs to understand what’s going on.&lt;/p&gt;

&lt;h2 id=&quot;so-how-this-works&quot;&gt;So, how this works?&lt;/h2&gt;

&lt;p&gt;The trick is to register as a command handler for our URI scheme the location of ClickOnce application. Then, when application is launched from via URI scheme, detect that and start new instance of ClickOnce application with parameters from the initial activation URL and shut down the current application instance. Parameters then are accessible in ClickOnce context via ActivationUri. We got 3 steps here.&lt;/p&gt;

&lt;h4 id=&quot;1-register-application-uri-scheme&quot;&gt;1. Register application URI scheme&lt;/h4&gt;

&lt;p&gt;When application is launched for the first time it will update the Windows Registry to register URI with the application. The shell command that will handle the URI is set to the location of where ClickOnce executable is installed. That’s an unique location that changes every time a new version is installed. So every time a new application version is run for the first time, the registry settings that point URI protocol to command location are updated with new .exe file location&lt;/p&gt;

&lt;h4 id=&quot;2-restart-application-launched-from-uri-handler-with-clickonce-context&quot;&gt;2. Restart application launched from URI handler with ClickOnce context&lt;/h4&gt;
&lt;p&gt;When application is launched from a link with corresponding URI schema two things are happening:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;starting &lt;code class=&quot;highlighter-rouge&quot;&gt;iexplore.exe&lt;/code&gt; with parameters list containing the URL to the application’s ActivationUrl and a query string containing parameters encoded in where a new process is started having as a launch parameters&lt;/li&gt;
  &lt;li&gt;shutting down current instance&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-handling-startup-parameters-from-clickonce-context&quot;&gt;3. Handling startup parameters from ClickOnce context&lt;/h4&gt;
&lt;p&gt;Now we’re running in ClickOnce context with ActivationUrl containing the ClickOnce location and a query string containing URL parameters from original link.&lt;/p&gt;

&lt;h2 id=&quot;to-sum-up&quot;&gt;To sum up&lt;/h2&gt;

&lt;p&gt;Have a look at the code. But. It’s a hack and work-around. It’s not 100% bullet-proof and not pretty for users to see (ClickOnce launch dialog is shown then closed to leave place to new instance of application). But it worked for us, in our environment and user base.&lt;/p&gt;

&lt;p&gt;But again, if possible, don’t tackle such things with ClickOnce. Step up and use a proper install/update/uninstall framework. &lt;a href=&quot;http://wixtoolset.org/&quot;&gt;WiX&lt;/a&gt; or &lt;a href=&quot;https://github.com/Squirrel/Squirrel.Windows&quot;&gt;Squirrel&lt;/a&gt; are just few alternatives…&lt;/p&gt;
</description>
        <pubDate>Sun, 24 Apr 2016 15:00:00 +0000</pubDate>
        <link>http://caraulean.com/2016/handling-custom-uri-scheme-with-clickonce/</link>
        <guid isPermaLink="true">http://caraulean.com/2016/handling-custom-uri-scheme-with-clickonce/</guid>
        
        
        <category>clickonce,</category>
        
        <category>.net</category>
        
      </item>
    
      <item>
        <title>Install and configure Elasticsearch in Windows</title>
        <description>&lt;p&gt;&lt;em&gt;Recently I had to install &amp;amp; configure Elasticsearch and took some notes about it for further reference. Everything down here is actual at the moment of writing, March 2016 and Elasticsearch version 2.2.0.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.elastic.co/&quot;&gt;Elasticsearch official site&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h2&gt;

&lt;h3 id=&quot;java-runtime&quot;&gt;Java Runtime&lt;/h3&gt;

&lt;p&gt;Verify installed version of Java Runtime Environment or &lt;a href=&quot;http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html&quot;&gt;install it&lt;/a&gt;. Latest JDK 8 is strongly recommended.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Check available JDK using command line: &lt;code class=&quot;highlighter-rouge&quot;&gt;java -version&lt;/code&gt;. Expected output: &lt;code class=&quot;highlighter-rouge&quot;&gt;java version 1.8.0_73&lt;/code&gt;. Last numbers might be different, but &lt;code class=&quot;highlighter-rouge&quot;&gt;1.8&lt;/code&gt; is expected.&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Check system variables. Required environment variable: JAVA_HOME pointing to install location of JDK. Example:&lt;/p&gt;

    &lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;JAVA_HOME: C:\Program Files\Java\jre1.8.0_73&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;installation&quot;&gt;Installation&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Download zip file from https://www.elastic.co/downloads/elasticsearch.&lt;/li&gt;
  &lt;li&gt;Unzip downloaded file to location where your application will run from. &lt;code class=&quot;highlighter-rouge&quot;&gt;C:\Program Files\Elasticsearch-2.2.0&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;configuration&quot;&gt;Configuration&lt;/h2&gt;
&lt;p&gt;Location of configuration file: &lt;code class=&quot;highlighter-rouge&quot;&gt;{install-path}\config\elasticsearch.yml&lt;/code&gt;. This is a text file using YAML format and that can be edited in any text editor.&lt;/p&gt;

&lt;h3 id=&quot;data-folders&quot;&gt;Data folders&lt;/h3&gt;
&lt;p&gt;Uncomment lines containing &lt;code class=&quot;highlighter-rouge&quot;&gt;path.data&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;path.logs&lt;/code&gt; keys. Set values to the location where elasticsearch should store indexes, documents and log files. Example:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;path.data: D:\Elasticsearch\Data
path.logs: D:\Elasticsearch\Logs
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;exposing-elasticsearch-endpoint-over-the-local-network&quot;&gt;Exposing elasticsearch endpoint over the local network&lt;/h3&gt;

&lt;p&gt;Uncomment &lt;code class=&quot;highlighter-rouge&quot;&gt;network.host&lt;/code&gt; and set value to &lt;code class=&quot;highlighter-rouge&quot;&gt;_site&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;network.host: _site_
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This will make elasticserch available under machine’s site name. Example: &lt;code class=&quot;highlighter-rouge&quot;&gt;http://servername:9200&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;set-the-heap-size&quot;&gt;Set the heap size&lt;/h3&gt;
&lt;p&gt;By default Elasticsearch will reserve 1 GB for it’s heap. For most installations it’s not enough. Set it appropriatelly to RAM available on your servers and server load. To set the heap size you have to create a system environment variable (more details &lt;a href=&quot;https://www.elastic.co/guide/en/elasticsearch/guide/current/heap-sizing.html&quot;&gt;here&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ES_HEAP_SIZE: 4g
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;set-field-data-cache-size&quot;&gt;Set field data cache size&lt;/h3&gt;
&lt;p&gt;If you have data that often changes or becomes obsolete (like log messages) it’s useful to &lt;a href=&quot;https://www.elastic.co/guide/en/elasticsearch/guide/current/_limiting_memory_usage.html&quot;&gt;set the field data cache size&lt;/a&gt;  in your config file:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;indices.fielddata.cache.size: 40%
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;optional-install-web-interface-for-monitoring&quot;&gt;(optional) Install web interface for monitoring&lt;/h3&gt;

&lt;p&gt;Recomended tool: &lt;a href=&quot;https://github.com/lmenezes/elasticsearch-kopf&quot;&gt;kopf&lt;/a&gt;. To install, from &lt;code class=&quot;highlighter-rouge&quot;&gt;{install-path}&lt;/code&gt; run next command:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;{install-path}\bin\plugin.bat install menezes/elasticsearch-kopf/2.0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If install is failing to download or install check plugin’s homepage. If nothing works, download  plugin to a temporary location and install it from a file:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bin\plugin install d:\temp\{path downloaded plugin zip file}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If even that is not working, unzip content of downloaded file to &lt;code class=&quot;highlighter-rouge&quot;&gt;{install-path}\plugins\kopf&lt;/code&gt; and restart the service.&lt;/p&gt;

&lt;p&gt;Plugin should be accessible at: &lt;code class=&quot;highlighter-rouge&quot;&gt;http://servername:9200/_plugin/kopf&lt;/code&gt;&lt;/p&gt;

&lt;h3 id=&quot;configure-to-run-as-a-service&quot;&gt;Configure to run as a service&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Install elasticsearch service. Open command line and navigate to installation folder. Execute &lt;code class=&quot;highlighter-rouge&quot;&gt;bin\service.bat install&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Open Services management console (services.msc) and find &lt;code class=&quot;highlighter-rouge&quot;&gt;Elasticsearch 2.2.0&lt;/code&gt; service. Change &lt;code class=&quot;highlighter-rouge&quot;&gt;Startup Type&lt;/code&gt; to &lt;code class=&quot;highlighter-rouge&quot;&gt;Automatic&lt;/code&gt;. If you need to run the service under a specific user account that’s the place to set that up.&lt;/li&gt;
  &lt;li&gt;Start the service&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;checks-post-configure--post-install&quot;&gt;Checks (post-configure &amp;amp; post-install)&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;After starting the service check logs for any errors.&lt;/li&gt;
  &lt;li&gt;Open &lt;code class=&quot;highlighter-rouge&quot;&gt;http://machinename:9200/&lt;/code&gt; in browser. No web page is opened but request should succeed by returning a JSON response or a file (depending on the browser).&lt;/li&gt;
  &lt;li&gt;If any of monitoring plugins is installed check there the state of your cluster and nodes (for example on &lt;code class=&quot;highlighter-rouge&quot;&gt;http://machinename:9200/_plugin/kopf&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;setting-up-a-basic-cluster&quot;&gt;Setting up a basic cluster&lt;/h2&gt;

&lt;p&gt;If you want the simplest configuration but you want a your cluster to have some redundancy and good performance - then Elastic’s default settings will work well for you. Say, for redundancy and query distribution you want to run an ES cluster on 2 (or &lt;code class=&quot;highlighter-rouge&quot;&gt;n&lt;/code&gt; nodes). Then your starting point will be a very basic &lt;code class=&quot;highlighter-rouge&quot;&gt;elasticsearch.yml&lt;/code&gt; (example for 2 nodes):&lt;/p&gt;

&lt;p&gt;First node:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cluster.name: my-es-cluster
node.name: my-es-node-one
network.host: _site_            # this will make ES available via host/mashine name
http.port: 9200                 # listening endpoint
discovery.zen.ping.unicast.hosts: [&quot;es-host-1&quot;, &quot;es-host-2&quot;]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Second node:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cluster.name: my-es-cluster
node.name: my-es-node-two
network.host: _site_
http.port: 9200
discovery.zen.ping.unicast.hosts: [&quot;es-host-1&quot;, &quot;es-host-2&quot;]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Notice that the only difference is the node name.&lt;/p&gt;

&lt;p&gt;Pretty self-explanatory. This should be enough to get you a working cluster of 2 boxes where both nodes will be master-eligible and data nodes and only one node will be playing the role of master node. But you can still query getting them processed on any of nodes. More about network settings&lt;/p&gt;
</description>
        <pubDate>Mon, 07 Mar 2016 20:20:00 +0000</pubDate>
        <link>http://caraulean.com/2016/install-and-configure-elasticsearch-in-windows/</link>
        <guid isPermaLink="true">http://caraulean.com/2016/install-and-configure-elasticsearch-in-windows/</guid>
        
        
        <category>elasticsearch</category>
        
      </item>
    
      <item>
        <title>Using Caliburn.Micro with async/await</title>
        <description>&lt;p&gt;This post will give an overview of how you can use async/await features from C# 5.0 with &lt;a href=&quot;http://caliburnmicro.codeplex.com/&quot;&gt;Caliburn.Micro (CM)&lt;/a&gt;. If you’ve found an error or want to complete the content please let me know in the comments. A sample application demonstrating async/await interactions in CM &lt;a href=&quot;https://github.com/vcaraulean/CaliburnMicro.AsyncDemo&quot;&gt;is available on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;setting-it-up&quot;&gt;Setting it up&lt;/h2&gt;
&lt;p&gt;To use Tasks and async/await features you need the latest version of Caliburn.Micro. Support for Tasks was introduced in version 1.5, so you’ll need a version higher than that. And, of course, you need .NET Framework 4.5 or higher. All examples in this post were tested in a WPF application targeting .NET 4.5 framework. However, same code will be probably valid for Silverlight, WP8 and Windows8 apps.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;h4 id=&quot;create-and-configure-new-project-to-test-the-concepts&quot;&gt;Create and configure new project to test the concepts&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Create new WPF 4.5 application&lt;/li&gt;
  &lt;li&gt;Install Caliburn.Micro from nuget. You’d better choose the &lt;code class=&quot;highlighter-rouge&quot;&gt;Caliburn.Micro.Start&lt;/code&gt; package as it has everything required to run a Caliburn application (boostrapper, container, main screen)&lt;/li&gt;
  &lt;li&gt;Change App.cs to correctly bootstrap with Caliburn, &lt;a href=&quot;http://caliburnmicro.codeplex.com/wikipage?title=Nuget&quot;&gt;here is how to do it&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;async-actions&quot;&gt;Async Actions&lt;/h2&gt;
&lt;p&gt;The syntax for attaching actions in XAML will remain unchanged:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;Button x:Name=&quot;RunTask1Async&quot;&amp;gt;
&amp;lt;Button cal:Message.Attach=&quot;RunTask1Async&quot;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When declaring action’s method we can specify that we want to handle it asynchronously:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    public async void RunTask1Async()
    {
        Log(&quot;RunTask1Async - starting a 4 second task&quot;);
        await Task.Delay(4000);
        Log(&quot;RunTask1Async completed&quot;);
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And that’s all you need to execute an action asynchronously (if you have to execute a Task).&lt;/p&gt;

&lt;h2 id=&quot;async-handlers-for-screen-events-and-overrides&quot;&gt;Async handlers for Screen events and overrides&lt;/h2&gt;

&lt;p&gt;CM offers few handy methods that allow to connect to Screen’s lifetime events. Some method overrides with async signatures:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;	protected override async void OnInitialize()
	{
		Log(&quot;OnInitialize - starting a 7 seconds task&quot;);
		await Task.Delay(7000);
		Log(&quot;OnInitialize completed&quot;);
	}
    protected override async void OnActivate() { }
    protected override async void OnViewLoaded(object view) { }
    protected override async void OnViewAttached(object view, object context) { }
	...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To note here that even if the method in base class is not marked &lt;code class=&quot;highlighter-rouge&quot;&gt;async&lt;/code&gt;, our overrides declare them with &lt;code class=&quot;highlighter-rouge&quot;&gt;async&lt;/code&gt; modifiers and it runs fine.&lt;/p&gt;

&lt;p&gt;Similarly, you can handle Screen’s events the same way how you’re handling any .NET event in asynchronous way:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;	{
		// ...
		ViewAttached += OnViewAttachedEventHandler;
	}
	private async void OnViewAttachedEventHandler(object sender, ViewAttachedEventArgs args)
	{
		Log(&quot;OnViewAttachedEventHandler- starting a 1 second task&quot;);
		await Task.Delay(1000);
		Log(&quot;OnViewAttachedEventHandler completed&quot;);
	}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;ihandlewithtask-interface&quot;&gt;IHandleWithTask interface&lt;/h2&gt;
&lt;p&gt;This is a new addition to CM, declared as:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    public interface IHandleWithTask&amp;lt;TMessage&amp;gt; : IHandle
    {
        Task Handle(TMessage message);
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It’s extremely useful when you want to handle a particular message using a Task and off-load application’s main thread.&lt;/p&gt;

&lt;p&gt;An example:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;	public class Message { }

	public class MessageHandler : IHandleWithTask&amp;lt;Message&amp;gt;
	{
		public MessageHandler(IEventAggregator eventAggregator)
		{
			eventAggregator.Subscribe(this);
		}

		public async Task Handle(Message message)
		{
			await Task.Delay(3000);
		}
	}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;convert-coroutines-to-tasks&quot;&gt;Convert coroutines to Tasks&lt;/h2&gt;
&lt;p&gt;This can be done easily by using an extension method:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;	public async void WrapIResultInTaskAsync()
	{
		await new SimpleCoroutine().ExecuteAsync();
	}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;async-void-or-async-task&quot;&gt;“async void” or “async Task”&lt;/h2&gt;
&lt;p&gt;A great question will be: should I use &lt;code class=&quot;highlighter-rouge&quot;&gt;async void&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;async Task&lt;/code&gt; as a return value of action methods, screen’s events and overrides? Since you can do both and the code will compile and run mostly fine, let’s see what &lt;a href=&quot;http://blog.stephencleary.com/&quot;&gt;Stephen Cleary&lt;/a&gt; writes about it in &lt;a href=&quot;http://msdn.microsoft.com/en-us/magazine/jj991977.aspx&quot;&gt;Best Practices in Asynchronous Programming&lt;/a&gt; article:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;You should prefer async Task to async void. Async Task methods enable easier error-handling, composability and testability. The exception to this guideline is asynchronous event handlers, which must return void. This exception includes methods that are logically event handlers even if they’re not literally event handlers (for example, ICommand.Execute implementations).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I will join this recommendation. Actions are event handlers at their core, normally they are executed as “start and forget”. If something happens (an exception), it will be handled at application level. For the case when you want to handle any exceptions locally, you may want to create an override which returns an &lt;code class=&quot;highlighter-rouge&quot;&gt;async Task&lt;/code&gt;. Also, this will allow calling same method action from another part of the program or write a unit test to verify an asynchronous process.&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://devlicio.us/blogs/rob_eisenberg/archive/2013/03/18/durandal-1-2-0-and-caliburn-micro-1-5-0-released.aspx&quot;&gt;Caliburn.Micro. 1.5.0 release notes&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/magazine/jj991977.aspx&quot;&gt;“Best Practices in Asynchronous Programming” by Stephen Cleary (MSDN Mag)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://marcoamendola.wordpress.com/2012/10/16/coroutines-are-dead-long-live-coroutines/&quot;&gt;“Coroutines are dead. Long live Coroutines.” by Marco Amendola&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blogs.msdn.com/b/pfxteam/archive/2012/04/12/async-await-faq.aspx&quot;&gt;Async/Await FAQ&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is pretty much it. If you’ve found an error or may complete this post with additional info, let me know in the comments.&lt;/p&gt;
</description>
        <pubDate>Mon, 15 Jul 2013 11:21:00 +0000</pubDate>
        <link>http://caraulean.com/2013/using-caliburn-micro-with-async-await/</link>
        <guid isPermaLink="true">http://caraulean.com/2013/using-caliburn-micro-with-async-await/</guid>
        
        
      </item>
    
      <item>
        <title>Book review - NoSQL Distilled</title>
        <description>&lt;p&gt;&lt;a href=&quot;http://www.amazon.com/NoSQL-Distilled-Emerging-Persistence-ebook/dp/B0090J3SYW&quot;&gt;NoSQL Distilled: A Brief Guide to the Emerging World of Polyglot Persistence&lt;/a&gt; by Martin Fowler and Pramod J. Sadalage.&lt;/p&gt;

&lt;p&gt;For some time already I’ve been keeping an eye on rising popularity of NoSQL. From reading articles and blog posts about various aspects and flavors, I adventured myself and dived more deeply into RavenDb, a NoSQL Document Database. Still, the picture I had in my mind was somewhat blurry and had few areas where I wasn’t sure that I understand some basic things.
&lt;!-- more --&gt;
This book is a very good starting point into NoSQL world. It starts with explaining the rise of popularity of NoSQL solutions for multiple domains and modern data storage requirements. Then it explains important concepts around NoSQL data stores like aggregation and distribution models, consistency, versioning and Map-Reduce. The second part of the book takes a look at each family of NoSQL flavors and analyzes their features, data modeling challenges and applicability of concrete database in various domains. Key-Value databases are presented by &lt;a href=&quot;http://basho.com/products/riak-overview/&quot;&gt;Riak&lt;/a&gt;, Document Databases by &lt;a href=&quot;http://www.mongodb.org/&quot;&gt;MongoDB&lt;/a&gt; with few mentions of &lt;a href=&quot;http://ravendb.net/&quot;&gt;RavenDb&lt;/a&gt;, &lt;a href=&quot;http://cassandra.apache.org/&quot;&gt;Cassandra&lt;/a&gt; represents the Column-Family store type, and, final group, the Graph databases are explained using &lt;a href=&quot;http://www.neo4j.org/&quot;&gt;Neo4J&lt;/a&gt;. Last chapters of the book talk about schema migrations, data storage options outside of NoSQL area and what you should consider when choosing a database.&lt;/p&gt;

&lt;p&gt;One of the ideas frequently discussed trough the whole book is why people are choosing NoSQL solutions:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;There are two primary reasons for considering NoSQL. One is to handle data access with sizes and performance that demand a cluster; the other is to improve the productivity of application development by using a more convenient data interaction style.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Most often when you speak about NoSQL with somebody the reaction looks like “ah, that thing that Google and Amazon runs on thousands of servers”. And nobody who only have heard of NoSQL is sensing the second great advantage of these systems: improving productivity and flexibility of your development team and make the life of application developer easier.&lt;/p&gt;

&lt;p&gt;NoSQL doesn’t means a complete schema-less data storage. Instead of having rigid definitions of schema and relationships as in the world of Relational Database, the shape of data is defined by application itself. That is, application is defining how it wants to store and access the data. No more you have to fight the impedance mismatch between relational model and in-memory data structures. Forget the performance penalization of an ORM, limitations of relational model in querying, aggregating and shaping data. Instead, your application defines the aggregate model and naturally persist it. Then it has reach options to slice and dice stored data, perform flexible Map-Reduce transformations and offers reach analytical capabilities. This allows development teams to be more flexible and productive when building complex systems. When your data storage is a simple commodity, easy to access and manipulate, you will have much more time to work on your domain, business logic or User Interface.&lt;/p&gt;

&lt;p&gt;Each kind of NoSQL implementation offers it’s own advantages and has it’s weak points. For me the most interesting are the Document Databases like MongoDB and RavenDb. They will suit a very broad range of applications because of the notion of a Document - something with properties and values aggregated in one entity stored as a simple JSON document. This will give you ability to index documents, write rich document based queries and much more.&lt;/p&gt;

&lt;h3 id=&quot;summary&quot;&gt;Summary&lt;/h3&gt;

&lt;p&gt;A great overview of existent NoSQL technologies, their characteristics and applicability of each of them in various domains. The book is short as it was really meant as an overview, not a deep dive in these technologies.&lt;/p&gt;

&lt;p&gt;At the moment when I write this review Amazon places this book as #1 in Databases category and #2 in Databases/SQL, it has 15 reviews with an overall score of 4.5.&lt;/p&gt;

&lt;p&gt;Highly recommended.&lt;/p&gt;
</description>
        <pubDate>Fri, 14 Dec 2012 09:38:00 +0000</pubDate>
        <link>http://caraulean.com/2012/book-review-nosql-distilled/</link>
        <guid isPermaLink="true">http://caraulean.com/2012/book-review-nosql-distilled/</guid>
        
        
        <category>books</category>
        
        <category>nosql</category>
        
      </item>
    
      <item>
        <title>Do less and achieve more with RavenDb</title>
        <description>&lt;p&gt;If you’re after a document database for a .NET application it’s hard to miss the buzz around &lt;a href=&quot;http://ravendb.net&quot;&gt;RavenDb&lt;/a&gt;. Although there are many other NoSQL databases that are getting much more attention and popularity, RavenDb distinguishes itself by being a native in .NET ecosystem while still offering great value as a generic, technology agnostic data store.&lt;/p&gt;

&lt;p&gt;Dealing with Relational Databases, SQL and Object-Relational Mapping are probably the most omnipresent skills in any developer’s career. But take a .NET dev with a good background in modern database technologies and let him play few hours with RavenDb and I guarantee that he’ll come back impressed.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;p&gt;And there is a good reason for that. One of the most impressive things is how easy it to define a class, fill it with data then just throw it in the store. Then load it back an put it on the screen or send over the wires. All this without any object-to-database mappings, no transformations, no base classes; with only few lines of configuration and initialization code. It’s fascinating when you’re an ORM veteran and experience it for the first time…&lt;/p&gt;

&lt;p&gt;I won’t go over all of the features of RavenDb. I will just touch few points that, in my opinion, can drastically reduce the amount of infrastructure code of almost any application, be it a client-server “enterprise-grade” system, web site / service or even a rich desktop application.&lt;/p&gt;

&lt;p&gt;Disclaimer: YMMV. I’m writing about things I’ve seen or experienced myself.&lt;/p&gt;

&lt;h2 id=&quot;reduce-your-mapping-layers&quot;&gt;Reduce your mapping layers&lt;/h2&gt;

&lt;p&gt;Things you probably (or certainly) will not need with RavenDb:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Maintain a mapping layer to fit your domain model in a relational database with it’s rules and constraints&lt;/li&gt;
  &lt;li&gt;Keep on the eternal fight with lazy relations&lt;/li&gt;
  &lt;li&gt;Map your domain to DTOs and backwards when you’re talking over the wires (especially using WCF)&lt;/li&gt;
  &lt;li&gt;Map the DTOs to client side models and view models&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All this stuff is code. Code to be written, tested and maintained. Take this code and throw it away. Feel better now? I’m glad for you…&lt;/p&gt;

&lt;p&gt;Of course you’ll have some mapping code. As example you’ll probably have to shape your documents to display them on the screen or create static indexes. But I’d consider it as a business/domain concern and not just plumbing code to please your communication layer or mapping framework.&lt;/p&gt;

&lt;h2 id=&quot;cut-through-your-infrastructure&quot;&gt;Cut through your infrastructure&lt;/h2&gt;

&lt;p&gt;What I love in RavenDb is that it’s not a mere data store. It comes with a bunch of features and bundles that aren’t directly related to persist and query data, but are much more like functional or business components for your application covering real feature requirements. Examples?&lt;/p&gt;

&lt;h4 id=&quot;search&quot;&gt;Search&lt;/h4&gt;

&lt;p&gt;Any reasonably sized and feature rich application that is manipulating data records is incomplete without an embedded search feature. In .NET world the choice is extremely limited. You’ll probably choose the Lucene.NET, write code to sync your search indexes with database/domain changes, then, run scary with the hope to never have to touch that code again. If you’ve worked with Lucene.NET, you know what I’m talking about…&lt;/p&gt;

&lt;p&gt;Much of the RavenDb powers are based on Lucene.NET. But you’ll barely observe it hidden behind a friendly API and the “usual suspect”, LINQ.&lt;/p&gt;

&lt;h4 id=&quot;security&quot;&gt;Security&lt;/h4&gt;

&lt;p&gt;You never meet a stakeholder or client obsessed about security? Move on to the next point…&lt;/p&gt;

&lt;p&gt;Authorization is hard: Users, Roles, Operations, Permissions. Then add row level security. Oh my, it’s really hard. And it’s even harder to get it working properly and with minimal penalization on performance. I think because it’s a tough challenge there aren’t many generic solutions for this problem.&lt;/p&gt;

&lt;p&gt;RavenDb comes with &lt;a href=&quot;http://ravendb.net/docs/server/bundles/authorization&quot;&gt;Authorization Bundle&lt;/a&gt;. The only thing you have to do is to define your rules and (when required) add additional checks for constraints in your business or domain logic.&lt;/p&gt;

&lt;h4 id=&quot;client-notifications&quot;&gt;Client notifications&lt;/h4&gt;

&lt;p&gt;It’s called &lt;a href=&quot;http://ayende.com/blog/157121/awesome-feature-of-the-day-ravendb-changes-api&quot;&gt;Changes API&lt;/a&gt;, it let’s your client know when a document changes on the server. I’ve been there, done that:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Whenever NHibernate detects a change, send a message about it to a queue.&lt;/li&gt;
  &lt;li&gt;Have a service listening to that queue.&lt;/li&gt;
  &lt;li&gt;When there’s a message, notify all interested subscribers about it.&lt;/li&gt;
  &lt;li&gt;Over WCF. Duplex channel. Silverlight…&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And I still have known bugs in that subsystem.&lt;/p&gt;

&lt;p&gt;Now take all this stuff and throw it away. Using RavenDb’s client API you can subscribe to change events of a single document, a document type or index. An the awesome part - it implements IObservable from &lt;a href=&quot;http://www.introtorx.com/&quot;&gt;Reactive Extensions&lt;/a&gt;. Ditto.&lt;/p&gt;

&lt;h4 id=&quot;versioningaudit&quot;&gt;Versioning/Audit&lt;/h4&gt;

&lt;p&gt;With &lt;a href=&quot;http://ravendb.net/docs/server/bundles/versioning&quot;&gt;Versioning Bundle&lt;/a&gt; RavenDb will keep the history of changes made to a document. With the audit trail you’ll be able to find who changed what and when. Depending on your architecture it may be very simple to implement basic audit infrastructure. But it’s a much more challenging task to keep around modifications and with relational model is very hard to revert changes when your records were stored in database. With Versioning Bundle it’s easy to plug in and know everything.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;To refrain: all this stuff is code. Code to be written, tested, maintained.&lt;/p&gt;

&lt;p&gt;And one more thing. All this components are written by the authors of RavenDb. While I’m confident in my skills, I know my limits. I wouldn’t be able to do a better job integrating with a third-party system than the people who wrote it from scratch.&lt;/p&gt;

&lt;p&gt;I’ve highlighted only some of typical parts of a reasonably complex software system but there are more, of course. With RavenDb you already have functional blocks ready for integration and use. This is a point to consider when time-to-marked is critical or you care about your product. And less of a concern when you’re only after your monthly paycheck.&lt;/p&gt;

&lt;p&gt;Even if you have already some of these subsystems in place and are using “typical” architecture with a service layer, ORM and relational database, you should seriously consider RavenDb while you’re at early stages of your product.&lt;/p&gt;

&lt;p&gt;Because with RavenDb you can do less but achieve more by focusing on things that really matter: your domain model, business knowledge and that bizarre wrapper around it, called User Interface.&lt;/p&gt;
</description>
        <pubDate>Thu, 15 Nov 2012 09:40:00 +0000</pubDate>
        <link>http://caraulean.com/2012/do-less-and-achieve-more-with-ravendb/</link>
        <guid isPermaLink="true">http://caraulean.com/2012/do-less-and-achieve-more-with-ravendb/</guid>
        
        
        <category>ravendb</category>
        
      </item>
    
      <item>
        <title>Diving deeper in Reactive Extensions, concurrency</title>
        <description>&lt;p&gt;I’ve started using &lt;a href=&quot;http://msdn.microsoft.com/en-us/data/gg577609.aspx&quot;&gt;Reactive Extensions, Rx&lt;/a&gt; library without digging too much in it’s internals. Had a case where I wanted to filter a stream of events and decided I’d try something new for me, Rx. But as it always happens with powerful and flexible tools, starting with few superficial articles and examples from the Web without diving deeper in the concepts is a pretty bad idea.&lt;/p&gt;

&lt;p&gt;This time I’ve been bitten by &lt;em&gt;concurrency&lt;/em&gt; issues.
&lt;!-- more --&gt;
And the best resource I’ve found so far is the &lt;a href=&quot;http://www.introtorx.com/&quot;&gt;Introduction to Rx&lt;/a&gt; ebook by &lt;a href=&quot;http://leecampbell.blogspot.co.uk/&quot;&gt;Lee Campbell&lt;/a&gt;. It costs only around a buck on Amazon and it’s available for free from the site.&lt;/p&gt;

&lt;p&gt;I’ve jumped straight to the &lt;a href=&quot;http://www.introtorx.com/Content/v1.0.10621.0/15_SchedulingAndThreading.html&quot;&gt;Chapter 4, Concurrency&lt;/a&gt; and for surely will pass without a hurry over the rest of the book. This chapter has an nice check list about best threading options for some scenarios:&lt;/p&gt;

&lt;h3 id=&quot;ui-applications&quot;&gt;UI Applications&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;The final subscriber is normally the presentation layer and should control the scheduling.&lt;/li&gt;
  &lt;li&gt;Observe on the DispatcherScheduler to allow updating of ViewModels&lt;/li&gt;
  &lt;li&gt;Subscribe on a background thread to prevent the UI from becoming unresponsive
    &lt;ul&gt;
      &lt;li&gt;If the subscription will not block for more than 50ms then
        &lt;ul&gt;
          &lt;li&gt;Use the TaskPoolScheduler if available, or&lt;/li&gt;
          &lt;li&gt;Use the ThreadPoolScheduler&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;If any part of the subscription could block for longer than 50ms, then you should use the NewThreadScheduler.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;service-layer&quot;&gt;Service layer&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;If your service is reading data from a queue of some sort, consider using a dedicated EventLoopScheduler. This way, you can preserve order of events&lt;/li&gt;
  &lt;li&gt;If processing an item is expensive (&amp;gt;50ms or requires I/O), then consider using a NewThreadScheduler&lt;/li&gt;
  &lt;li&gt;If you just need the scheduler for a timer, e.g. for Observable.Interval or Observable.Timer, then favor the TaskPool. Use the ThreadPool if the TaskPool is not available for your platform.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;And by the way, on author’s blog I’ve found another interesting series of articles: &lt;a href=&quot;http://leecampbell.blogspot.co.uk/2009/01/responsive-uis-in-wpf-dispatchers-to.html&quot;&gt;Responsive UIs in WPF - Dispatchers to Concurrency to testability&lt;/a&gt;. That’s something I’d be reading after sorting out concurrency issues from my code.&lt;/p&gt;
</description>
        <pubDate>Tue, 09 Oct 2012 22:04:00 +0000</pubDate>
        <link>http://caraulean.com/2012/diving-deeper-in-reactive-extensions/</link>
        <guid isPermaLink="true">http://caraulean.com/2012/diving-deeper-in-reactive-extensions/</guid>
        
        
        <category>rx</category>
        
        <category>wpf</category>
        
      </item>
    
      <item>
        <title>Visual Studio 2012 dark theme tip - light up your UserControl in XAML designer</title>
        <description>&lt;p&gt;I really like the new Visual Studio 2012. And the dark theme looks cool and is so much easier for the eyes.&lt;/p&gt;

&lt;p&gt;But there is a real problem when you’re working with User Controls in designer. And we have lots of them. What is the problem then? Look at the picture:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;../images/2012/vs-dark-1.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Yup, that is a UserControl with few elements on it. With a default transparent background it’s is hardly visible on design surface. In runtime, when put on a parent (usually a Window) it will take background of the parent and all elements will be visible.&lt;/p&gt;

&lt;p&gt;Looking trough the VS2012 settings I’ve seen options to customize Windows Form Designer, Workflow and HTML Designers but nothing about customizing the XAML designer. Pretty bad, Microsoft.&lt;/p&gt;

&lt;p&gt;In this case Styling comes to the rescue! With some styling and by using a trigger to enable the style only for Design Time, we’ll get this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;../images/2012/vs-dark-2.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Much better now! To achieve it you have to put a small XAML fragment in your Generic.xaml or App.xaml and you should be done:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;Style TargetType=&quot;{x:Type UserControl}&quot;&amp;gt;
    &amp;lt;Style.Triggers&amp;gt;
        &amp;lt;Trigger Property=&quot;ComponentModel:DesignerProperties.IsInDesignMode&quot;
                 Value=&quot;true&quot;&amp;gt;
            &amp;lt;Setter Property=&quot;Background&quot;
                    Value=&quot;White&quot; /&amp;gt;
        &amp;lt;/Trigger&amp;gt;
    &amp;lt;/Style.Triggers&amp;gt;
&amp;lt;/Style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That’s how you’ll have your views well visible (and actually, design-able) in dark theme.&lt;/p&gt;

&lt;h3 id=&quot;update&quot;&gt;Update:&lt;/h3&gt;

&lt;p&gt;I’ve looked again if there are any options in Visual Studio 2012 to lighten a bit the dark background in designer. And found an &lt;a href=&quot;http://connect.microsoft.com/VisualStudio/feedback/details/758745/wpf-designer-unusable-in-dark-theme&quot;&gt;issue reported on Microsoft Connect&lt;/a&gt; about this very problem. Unfortunately, this is “by design” and cannot be customized, at least yet:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Yes, this is an unfortunately limitation in Visual Studio 2012 RTM. We would have loved to have the ability to change the default background color of the design surface, but could not get around to it (we have it on our backlog).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And a user has even posted a workaround that is mostly the same as above…&lt;/p&gt;
</description>
        <pubDate>Thu, 30 Aug 2012 23:35:00 +0000</pubDate>
        <link>http://caraulean.com/2012/visual-studio-2012-dark-theme-tip/</link>
        <guid isPermaLink="true">http://caraulean.com/2012/visual-studio-2012-dark-theme-tip/</guid>
        
        
        <category>wpf</category>
        
      </item>
    
      <item>
        <title>Evening time, time for fun</title>
        <description>&lt;p&gt;Or for whatever keeps you entertained…&lt;/p&gt;

&lt;p&gt;This evening it started when I looked how to make Windows Live Writer store drafts in my SkyDrive. As usual, started with googling it. Found a &lt;a href=&quot;http://lehsys.blogspot.ch/2011/04/how-to-change-drafts-and-recent-posts.html&quot;&gt;trick with a registry key&lt;/a&gt; that should point WLW to any folder I want. Nice trick, except it was not working on my PC.&lt;/p&gt;

&lt;p&gt;Why a trick that works for other people isn’t working in my machine?! This hooked me up and it ended badly. In about 2 hours I’ve:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Poked around WLW’s registry settings&lt;/li&gt;
  &lt;li&gt;Run &lt;a href=&quot;http://technet.microsoft.com/en-US/sysinternals&quot;&gt;procmon &amp;amp; procexp&lt;/a&gt; on WindowsLiveWriter.exe&lt;/li&gt;
  &lt;li&gt;Decompiled Windows Live Writer using &lt;a href=&quot;http://www.jetbrains.com/decompiler/&quot;&gt;dotPeek&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Got a rough picture of WLW’s code structure and some knowledge of it’s initialization procedure&lt;/li&gt;
  &lt;li&gt;Found the code that handles custom folder and seen that it should work as the trick described&lt;/li&gt;
  &lt;li&gt;Learned from code that WLW can run in portable code and &lt;a href=&quot;http://www.christophdebaene.com/blog/2011/08/20/windows-live-writer-2011-tips/&quot;&gt;how to do it&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Learned how to use Just-In-Time Debugger to &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/a329t4ed.aspx&quot;&gt;launch an .exe file and attach the Visual Studio’s debugger&lt;/a&gt; from application’s start&lt;/li&gt;
  &lt;li&gt;Failed to make WLW crash so I can break in debugger&lt;/li&gt;
  &lt;li&gt;Learned about &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/15d1wtaf.aspx&quot;&gt;setting a function breakpoint&lt;/a&gt;, and that’s useless without symbols&lt;/li&gt;
  &lt;li&gt;Gave up…&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then I had a glass of Talisker and before giving up completely tried again the trick with registry key…&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It. Worked.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Moral of the story – stupid, evident errors happen all the time. And, sadly, it takes time to recover. You’re lucky if you’re not under pressure, running to deadline or doing a demo. And you’re really lucky if you can learn new things on the way and keep yourself entertained :)&lt;/p&gt;
</description>
        <pubDate>Tue, 28 Aug 2012 21:07:18 +0000</pubDate>
        <link>http://caraulean.com/2012/evening-time-time-for-fun/</link>
        <guid isPermaLink="true">http://caraulean.com/2012/evening-time-time-for-fun/</guid>
        
        
        <category>general</category>
        
      </item>
    
  </channel>
</rss>
