﻿<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
  <channel>
    <title>Cranking out code</title>
    <description />
    <link>http://crankingoutcode.com/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.NET 1.6.1.0</generator>
    <language>en-US</language>
    <blogChannel:blogRoll>http://crankingoutcode.com/opml.axd</blogChannel:blogRoll>
    <blogChannel:blink>http://www.dotnetblogengine.net/syndication.axd</blogChannel:blink>
    <dc:creator>bjn</dc:creator>
    <dc:title>Cranking out code</dc:title>
    <geo:lat>0.000000</geo:lat>
    <geo:long>0.000000</geo:long>
    <item>
      <title>Google Fusion Tables</title>
      <description>&lt;p&gt;During the development of &lt;a href="http://www.miljoparkering.se"&gt;www.miljoparkering.se&lt;/a&gt; we found ourselves in the need to visualize all the streets that we currently have data for in Malmö. We had received a large csv file with all the streets in Malmö containing street name and the date when its not allowed to park there. What we needed was a way to see all these streets on a map.&lt;/p&gt;  &lt;p&gt;We googled and tried to find a method in the google maps api for adding multiple roads etc on a map. It was possible but not something easily done. All we needed was something that could produce a map quick and easy, not something we actually was going to use on &lt;a href="http://www.miljoparkering.se"&gt;www.miljoparkering.se&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Enter &lt;a href="http://www.google.com/fusiontables/Home/"&gt;Google Fusion Table&lt;/a&gt; which is an awesome addition to google docs. All you do is create a new item in Google Docs called “Table&amp;quot;. When you create a table you can chose to import existing data either from a file or from a spread sheet in google docs.&lt;/p&gt;  &lt;p&gt;We imported our csv file with all the streets. The table looks pretty much like an ordinary spread sheet but with a few key differences.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.crankingoutcode.com/image.axd?picture=table.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="table" border="0" alt="table" src="http://www.crankingoutcode.com/image.axd?picture=table_thumb.png" width="669" height="299" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;There are a few columns that special for example the Location. In our case we only had a street name but you can use a GPS position as well. All we did after the import of our file we clicked “Visualize” and then “Map” and Google maps presented us with a pretty nice map.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.crankingoutcode.com/image.axd?picture=map.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="map" border="0" alt="map" src="http://www.crankingoutcode.com/image.axd?picture=map_thumb.png" width="669" height="502" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;That took us 10 minutes to produce. It can also create heat maps based on your data and other cool stuff. Very useful stuff!&lt;/p&gt;  &lt;p&gt;Björn &amp;amp; Christer (from &lt;a href="http://www.christer.dk/"&gt;http://www.christer.dk/&lt;/a&gt;)&lt;/p&gt;</description>
      <link>http://crankingoutcode.com/post/Google-Fusion-Tables.aspx</link>
      <author>bjn</author>
      <comments>http://crankingoutcode.com/post/Google-Fusion-Tables.aspx#comment</comments>
      <guid>http://crankingoutcode.com/post.aspx?id=4e6a92d5-f5ee-4060-ac52-61661a42fa61</guid>
      <pubDate>Sat, 29 Oct 2011 14:08:44 +0200</pubDate>
      <dc:publisher>bjn</dc:publisher>
      <pingback:server>http://crankingoutcode.com/pingback.axd</pingback:server>
      <pingback:target>http://crankingoutcode.com/post.aspx?id=4e6a92d5-f5ee-4060-ac52-61661a42fa61</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://crankingoutcode.com/trackback.axd?id=4e6a92d5-f5ee-4060-ac52-61661a42fa61</trackback:ping>
      <wfw:comment>http://crankingoutcode.com/post/Google-Fusion-Tables.aspx#comment</wfw:comment>
      <wfw:commentRss>http://crankingoutcode.com/syndication.axd?post=4e6a92d5-f5ee-4060-ac52-61661a42fa61</wfw:commentRss>
    </item>
    <item>
      <title>AutoMapper initialization</title>
      <description>&lt;p&gt;AutoMapper is an excellent object-object mapper which uses a fluent configuration API and conventions to perform mapping with ease. Read more about AutoMapper &lt;a href="http://automapper.codeplex.com/" target="_blank"&gt;here&lt;/a&gt; and &lt;a href="http://www.crankingoutcode.com/post/Introducing-AutoMapper-removed-600-lines-of-code.aspx" target="_blank"&gt;my post here&lt;/a&gt;.&lt;/p&gt;  &lt;h3&gt;The Problem&lt;/h3&gt;  &lt;p&gt;When using AutoMapper you need to create a map between the objects you want to map. Of course, the maps must be created before any mapping is performed by AutoMapper. When I first started using AutoMapper I created a class (MappingConfigurer) to handle the creation of maps for AutoMapper. However, this class grew quite large over time when the system grew larger. After a while there were over 50 types getting mapped by AutoMapper. Having all of these initialized in the same class and method was a bit cumbersome after a while.&lt;/p&gt;  &lt;h3&gt;The Solution (well, one solution)&lt;/h3&gt;  &lt;p&gt;To remedy this situation I created an interface &lt;em&gt;IMappingConfiguration&lt;/em&gt;. The interface only has one method &lt;em&gt;Configure(),&lt;/em&gt; each type implementing this method &lt;a href="http://www.crankingoutcode.com/image.axd?picture=image.png"&gt;&lt;img style="margin: 0px 0px 0px 24px; display: inline; float: right" title="image" alt="image" align="right" src="http://www.crankingoutcode.com/image.axd?picture=image_thumb.png" width="211" height="113" /&gt;&lt;/a&gt;must create and configure the map its responsible for.&lt;/p&gt;  &lt;p&gt;For example, the UserMapper is responsible for mapping from User to UserViewModel. The UserMapper implements the interface &lt;em&gt;IMappingConfiguration. &lt;/em&gt;In the method &lt;em&gt;Configure()&lt;/em&gt; it creates the map needed:&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;public void Configure() {
    Mapper.CreateMap&amp;lt;User, UserViewModel&amp;gt;()
   	.ForMember(viewModel =&amp;gt; viewModel.Phone, 
		   opt =&amp;gt; opt.MapFrom(user =&amp;gt; user.Telephone.PhoneNumber)));
}&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The UserMapper class also has a method Map to do the actual mapping.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public UserViewModel Map(User user) {
    return Mapper.Map&amp;lt;User, UserViewModel&amp;gt;(user);
}&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.crankingoutcode.com/image.axd?picture=image_1.png"&gt;&lt;img style="margin: 0px 18px 12px 0px; display: inline; float: left" title="image" alt="image" align="left" src="http://www.crankingoutcode.com/image.axd?picture=image_thumb_1.png" width="211" height="149" /&gt;&lt;/a&gt;Now I have a class which is responsible for mapping User. The problem is that instead of having one giant method to create all of these maps I now have quite a lot of small classes.&lt;/p&gt;

&lt;p&gt;To execute the &lt;em&gt;Configure()&lt;/em&gt; method of all these mapping classes I use reflection to find all the types implementing the interface and executing the method. The first version was just plain type navigation using LINQ and reflection. But after a while I realized I needed this kind of functionality in other projects as well and in other scenarios. What I really wanted was an easy way to find all types implementing an interface and executing a method on the interface. Different ways of doing it. I could have used Castle Windsor for resolving all types implementing the &lt;em&gt;IMappingConfiguration&lt;/em&gt; interface but I’m not using Castle Windsor in all of my projects and I don’t want to integrate Windsor just for this reason.&lt;/p&gt;

&lt;p&gt;I started by writing down the way I wanted to be expressed:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;FindTypes
    .InAssembly(typeof(UserMapper).Assembly)
    .Implementing&amp;lt;IMappingConfiguration&amp;gt;()
    .Execute(mappingConfigurer =&amp;gt; mappingConfigurer.Configure());&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Higher level of abstraction and could potentially be used in other scenarios. For example, instead of executing a method it could return a list of types implementing the interface. Could even extend it to use Windsor. Instead of InAssembly, it could be InContainer(container), and it would use Windsor to resolve all types implementing the interface and still executing the method.&lt;/p&gt;

&lt;h3&gt;Code&lt;/h3&gt;

&lt;p&gt;This was the code I came up with (while watching an episode of Red Dwarf), so its at best a proof-of-concept &lt;img style="border-bottom-style: none; border-right-style: none; border-top-style: none; border-left-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://www.crankingoutcode.com/image.axd?picture=wlEmoticon-winkingsmile.png" /&gt;&lt;/p&gt;

&lt;p&gt;The first part, which all it does it indicates where to look for types.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;FindTypes.InAssembly(typeof(UserMapper).Assembly)&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The code is quite simple, static method which returns an AssemblyNavigator with the supplied assembly as a parameter to the constructor.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public class FindTypes
    {
        public static AssemblyNavigator InAssembly(Assembly assembly)
        {
            return new AssemblyNavigator(assembly);
        }
    }&lt;/pre&gt;

&lt;p&gt;The next part of the expression, is just filtering out the types implementing the interface.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;    .Implementing&amp;lt;IMappingConfiguration&amp;gt;()&lt;/pre&gt;

&lt;p&gt;
  &lt;br /&gt;The code uses LINQ to select the types in the assembly that is implementing the interface. The most difficult part of this code was figuring out the way to invoke &lt;em&gt;IsAssignableFrom()&lt;/em&gt;, very easy to do it the other way around.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public class AssemblyNavigator
    {
        private readonly Assembly _assembly;

        public AssemblyNavigator(Assembly assembly)
        {
            _assembly = assembly;
        }

        public TypeList&amp;lt;T&amp;gt; Implementing&amp;lt;T&amp;gt;() where T : class
        {
            var listOfTypesImplementingInterface = from type in _assembly.GetTypes()
                                      where typeof(T).IsAssignableFrom(type) &amp;amp;&amp;amp; type.IsClass
                                      select type;
            
            return new TypeList&amp;lt;T&amp;gt;(listOfTypesImplementingInterface);
        }
    }&lt;/pre&gt;

&lt;p&gt;Also, note the type.IsClass in the where-clause. You’ll need this or otherwise you might end up with the interface it self. This method returns a &lt;em&gt;TypeList&amp;lt;T&amp;gt;&lt;/em&gt; which is used in the last part of the expression.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;.Execute(mapping =&amp;gt; mapping.Configure());&lt;/pre&gt;

&lt;p&gt;
  &lt;br /&gt;The &lt;em&gt;Execute() &lt;/em&gt;method creates an instance of the type and invokes the method supplied as an Action&amp;lt;T&amp;gt; on the instance.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt; public class TypeList&amp;lt;T&amp;gt; where T : class
    {
        private readonly IEnumerable&amp;lt;Type&amp;gt; _listOfTypes;

        public TypeList(IEnumerable&amp;lt;Type&amp;gt; listOfTypes)
        {
            _listOfTypes = listOfTypes;
        }

        public void Execute(Action&amp;lt;T&amp;gt; action)
        {
            foreach (var type in _listOfTypes)
            {
                var instanceOfType = Activator.CreateInstance(type) as T;
                action(instanceOfType);
            }
        }
    }&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;That’s all the code that was needed to get it working. If it’s usable, maybe, it hides the details of the implementation.
  &lt;br /&gt;At least it was fun writing it.&lt;/p&gt;</description>
      <link>http://crankingoutcode.com/post/AutoMapper-initialization.aspx</link>
      <author>bjn</author>
      <comments>http://crankingoutcode.com/post/AutoMapper-initialization.aspx#comment</comments>
      <guid>http://crankingoutcode.com/post.aspx?id=fe7b69a7-09c8-46d2-9320-15b6233907e4</guid>
      <pubDate>Tue, 14 Dec 2010 22:08:55 +0200</pubDate>
      <category>C#</category>
      <category>automapper</category>
      <category>fluent</category>
      <dc:publisher>bjn</dc:publisher>
      <pingback:server>http://crankingoutcode.com/pingback.axd</pingback:server>
      <pingback:target>http://crankingoutcode.com/post.aspx?id=fe7b69a7-09c8-46d2-9320-15b6233907e4</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://crankingoutcode.com/trackback.axd?id=fe7b69a7-09c8-46d2-9320-15b6233907e4</trackback:ping>
      <wfw:comment>http://crankingoutcode.com/post/AutoMapper-initialization.aspx#comment</wfw:comment>
      <wfw:commentRss>http://crankingoutcode.com/syndication.axd?post=fe7b69a7-09c8-46d2-9320-15b6233907e4</wfw:commentRss>
    </item>
    <item>
      <title>Presentation Zen by Garr Reynolds</title>
      <description>&lt;p&gt;This book was recommended to me by a friend when I said I was interested in presentation technique and design. The author (Garr Reynolds) explains simple ideas on presentation and design in a very easy to read manner. The book contains a lot of examples with slides “before” and “after”. Makes it very visual and easy to understand what Reynolds means with his ideas. Thanks to all the examples in the book it’s very easy to get ideas and be inspired to do better.&lt;/p&gt;  &lt;p&gt;&lt;img style="margin: 0px 0px 0px 10px; display: inline; float: right" align="right" src="http://ecx.images-amazon.com/images/I/41hMmcWQdwL._SL160_.jpg" width="191" height="231" /&gt;&lt;/p&gt;  &lt;p&gt;The book starts with the situation today, how PowerPoint is misused and mainly used for displaying bullet after bullet with text. &lt;/p&gt;  &lt;p&gt;The next chapter gives ideas on how to prepare. Don’t start with PowerPoint and create &lt;/p&gt;  &lt;p&gt;slides. Instead think through what you want your presentation to convey. Reynolds mentions two questions you should ask yourself whenever you do a presentation: “What’s Your Point? Why Does It Matter?” If you can’t answer those two questions, your audience probably wont be able to grasp the core message of your presentation either.&lt;/p&gt;  &lt;p&gt;After you’ve worked out your core message and the flow of the presentation Reynolds continues to talk about design. Reynolds is a strong believer in simplicity, amplification through simplification. Keep it clean and simple.&lt;/p&gt;  &lt;p&gt;The last part of the book is where most of the example slides are. With both a before and after image, visualizing the difference between the two.&lt;/p&gt;  &lt;p&gt;Since the book is only about 200 pages and filled with pictures it’s very easy to read through it. I must say I felt very motivated to start on a new presentation and being able to use these tips n tricks I’ve picked up from the book.&lt;/p&gt;  &lt;p&gt;I highly recommend this book!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.amazon.com/Presentation-Zen-Simple-Design-Delivery/dp/0321525655%3FSubscriptionId%3D0JTCV5ZMHMF7ZYTXGFR2%26tag%3Dbrdicr-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0321525655" target="_blank"&gt;Link to Amazon&lt;/a&gt;&lt;/p&gt;</description>
      <link>http://crankingoutcode.com/post/Presentation-Zen-by-Garr-Reynolds.aspx</link>
      <author>bjn</author>
      <comments>http://crankingoutcode.com/post/Presentation-Zen-by-Garr-Reynolds.aspx#comment</comments>
      <guid>http://crankingoutcode.com/post.aspx?id=6f013db1-c257-47dc-bdf2-9768463b87ea</guid>
      <pubDate>Sun, 05 Dec 2010 16:27:34 +0200</pubDate>
      <category>book</category>
      <dc:publisher>bjn</dc:publisher>
      <pingback:server>http://crankingoutcode.com/pingback.axd</pingback:server>
      <pingback:target>http://crankingoutcode.com/post.aspx?id=6f013db1-c257-47dc-bdf2-9768463b87ea</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://crankingoutcode.com/trackback.axd?id=6f013db1-c257-47dc-bdf2-9768463b87ea</trackback:ping>
      <wfw:comment>http://crankingoutcode.com/post/Presentation-Zen-by-Garr-Reynolds.aspx#comment</wfw:comment>
      <wfw:commentRss>http://crankingoutcode.com/syndication.axd?post=6f013db1-c257-47dc-bdf2-9768463b87ea</wfw:commentRss>
    </item>
    <item>
      <title>Code Contracts</title>
      <description>&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx" target="_blank"&gt;Code Contracts&lt;/a&gt; is shipped with .NET Framework 4.0 in the namespace &lt;em&gt;&lt;strong&gt;System.Diagnostics.Contracts&lt;/strong&gt;&lt;/em&gt;. Code Contracts is a way to do runtime and static checking of pre and post conditions in the code. Like Debug.Assert on steroids. The biggest thumbs up is the static analysis which would generate compile errors if the condition is false. Sounded like an awesome thing so after creating a new project in VS2010 with target 4.0 I wrote the following method.&lt;/p&gt;  &lt;pre class="brush: csharp; highlight: 10;"&gt;class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Divide(10,0));
        }

        public static double Divide(int numerator, int denominator)
        { 
            Contract.Requires(denominator != 0);
            return numerator / denominator;
        }
    }&lt;/pre&gt;

&lt;p&gt;Compiled the program with &lt;strong&gt;&lt;em&gt;no compile errors&lt;/em&gt;&lt;/strong&gt;. Weird. Executed the program and thought I’d at least would get a runtime exception of some sort that the condition failed. Wrong again, &lt;strong&gt;&lt;em&gt;no runtime exception&lt;/em&gt;&lt;/strong&gt;. Well, only an ordinary DivideByZeroException was thrown. After inspecting the code with Reflector I could see that the Contract.Requires line had been removed by the compiler.&lt;/p&gt;

&lt;p align="left"&gt;Googling a bit and I came to &lt;a href="http://blogs.msdn.com/b/bclteam/archive/2010/01/26/i-just-installed-visual-studio-2010-now-how-do-i-get-code-contracts-melitta-andersen.aspx" target="_blank"&gt;this page&lt;/a&gt;. OK, so even if Code Contracts are shipped with .NET Framewor&lt;a href="http://www.crankingoutcode.com/image.axd?picture=shame.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 14px 0px 0px 21px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Photo by Céline Mackowiak" border="0" alt="Photo by Céline Mackowiak" align="right" src="http://www.crankingoutcode.com/image.axd?picture=shame_thumb.jpg" width="184" height="244" /&gt;&lt;/a&gt;k 4.0 the tools are not included and the code (Contract.Requires) will be removed by the compiler by default. The page told me to download the tools from &lt;a href="(http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx" target="_blank"&gt;devlabs&lt;/a&gt;. &lt;/p&gt;

&lt;p align="left"&gt;While at that page I realized that the static checking of contracts is only available to &lt;strong&gt;PREMIUM&lt;/strong&gt; and &lt;strong&gt;ULTIMATE&lt;/strong&gt; versions of VS2010. That’s really bad. I totally agree with &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/481327/make-data-contract-static-checking-available-in-professional-edition?wa=wsignin1.0"&gt;https://connect.microsoft.com/VisualStudio/feedback/details/481327/make-data-contract-static-checking-available-in-professional-edition?wa=wsignin1.0&lt;/a&gt; and &lt;a href="http://connect.microsoft.com/VisualStudio/feedback/details/106484/code-quality-tools-should-not-be-limited-to-team-system" target="_blank"&gt;http://connect.microsoft.com/VisualStudio/feedback/details/106484/code-quality-tools-should-not-be-limited-to-team-system&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Anyways, to at least get runtime validation running with VS2010 Pro I had to:&lt;/p&gt;

&lt;p&gt;1. Download the &lt;strong&gt;STANDARD&lt;/strong&gt; edition of Code Contract tools from &lt;a href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx" target="_blank"&gt;this page&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;2. Go to to project properties and check the checkbox &lt;em&gt;Perform runtime checking&lt;/em&gt;, which is found on the tab Code Contracts.&lt;/p&gt;

&lt;p&gt;After that I got the runtime exception ContractException: precondition failed.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;font color="#ff0000"&gt;Lesson learned, there’s a price for code quality, it just happens to be the same price as for VS2010 Premium or Ultimate…&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;</description>
      <link>http://crankingoutcode.com/post/Code-Contracts.aspx</link>
      <author>bjn</author>
      <comments>http://crankingoutcode.com/post/Code-Contracts.aspx#comment</comments>
      <guid>http://crankingoutcode.com/post.aspx?id=b6cdf537-fea0-4793-8ef9-8a36409199d4</guid>
      <pubDate>Fri, 03 Dec 2010 22:34:08 +0200</pubDate>
      <category>net4</category>
      <category>VisualStudio</category>
      <dc:publisher>bjn</dc:publisher>
      <pingback:server>http://crankingoutcode.com/pingback.axd</pingback:server>
      <pingback:target>http://crankingoutcode.com/post.aspx?id=b6cdf537-fea0-4793-8ef9-8a36409199d4</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://crankingoutcode.com/trackback.axd?id=b6cdf537-fea0-4793-8ef9-8a36409199d4</trackback:ping>
      <wfw:comment>http://crankingoutcode.com/post/Code-Contracts.aspx#comment</wfw:comment>
      <wfw:commentRss>http://crankingoutcode.com/syndication.axd?post=b6cdf537-fea0-4793-8ef9-8a36409199d4</wfw:commentRss>
    </item>
    <item>
      <title>Just ordered some books</title>
      <description>&amp;#160; &lt;table border="0" cellspacing="5" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="150"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/41hMmcWQdwL._SL160_.jpg" /&gt; &lt;/td&gt;        &lt;td valign="top"&gt;&lt;a href="http://www.amazon.com/Presentation-Zen-Simple-Design-Delivery/dp/0321525655%3FSubscriptionId%3D0JTCV5ZMHMF7ZYTXGFR2%26tag%3Dbrdicr-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0321525655"&gt;Presentation Zen: Simple Ideas on Presentation Design and Delivery&lt;/a&gt;           &lt;br /&gt;          &lt;br /&gt;Presentation designer and internationally acclaimed communications expert Garr Reynolds, creator of the most popular Web site on presentation design and delivery on the net — presentationzen.com — shares his experience in a provocative mix of illumination, inspiration, education, and guidance that will change the way you think about making presentations with PowerPoint or Keynote. Presentation Zen challenges the conventional wisdom of making &amp;quot;slide presentations&amp;quot; in today’s world and encourages you to think differently and more creatively about the preparation, design, and delivery of your presentations. Combining solid principles of design with the tenets of Zen simplicity, this book will help you along the path to simpler, more effective presentations.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;br /&gt;  &lt;table border="0" cellspacing="5" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="150"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/41HXiIojloL._SL160_.jpg" /&gt; &lt;/td&gt;        &lt;td valign="top"&gt;&lt;a href="http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X%3FSubscriptionId%3D0JTCV5ZMHMF7ZYTXGFR2%26tag%3Dbrdicr-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D020161622X"&gt;The Pragmatic Programmer: From Journeyman to Master&lt;/a&gt;           &lt;br /&gt;          &lt;br /&gt;Straight from the programming trenches, The Pragmatic Programmer cuts through the increasing specialization and technicalities of modern software development to examine the core process--taking a requirement and producing working, maintainable code that delights its users. It covers topics ranging from personal responsibility and career development to architectural techniques for keeping your code flexible and easy to adapt and reuse.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;br /&gt;  &lt;table border="0" cellspacing="5" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="150"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/51S%2BJSdifGL._SL160_.jpg" /&gt; &lt;/td&gt;        &lt;td valign="top"&gt;&lt;a href="http://www.amazon.com/Kanban-David-J-Anderson/dp/0984521402%3FSubscriptionId%3D0JTCV5ZMHMF7ZYTXGFR2%26tag%3Dbrdicr-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0984521402"&gt;Kanban&lt;/a&gt;           &lt;br /&gt;          &lt;br /&gt;          &lt;p&gt;The Kanban Method will improve your existing development process. This book explains why and shows you how to get started using it right now. Case studies and illustrations make it easy to adopt the improvements you need for your unique situation.            &lt;br /&gt;Limiting work in progress and visualizing your work are just the beginning. Optimize your processes to achieve better prioritization, higher quality work and a sustainable pace.&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;br /&gt;  &lt;table border="0" cellspacing="5" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="150"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/51KASPAA4PL._SL160_.jpg" /&gt; &lt;/td&gt;        &lt;td valign="top"&gt;&lt;a href="http://www.amazon.com/Why-Software-Sucks-What-About/dp/0321466756%3FSubscriptionId%3D0JTCV5ZMHMF7ZYTXGFR2%26tag%3Dbrdicr-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0321466756"&gt;Why Software Sucks...and What You Can Do About It&lt;/a&gt;           &lt;br /&gt;          &lt;br /&gt;It’s no secret that software sucks. You know that from personal experience, whether you use computers for work or personal tasks. In this book, programming insider David Platt explains why that’s the case and, more importantly, why it doesn’t have to be that way. And he explains it in plain, jargon-free English that’s a joy to read, using real-world examples with which you’re already familiar. In the end, he suggests what you, as a typical user, without a technical background, can do about this sad state of our software—how you, as an informed consumer, don’t have to take the abuse that bad software dishes out.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;br /&gt;  &lt;table border="0" cellspacing="5" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="150"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/41BwJuu4s-L._SL160_.jpg" /&gt; &lt;/td&gt;        &lt;td valign="top"&gt;&lt;a href="http://www.amazon.com/Asshole-Rule-Civilized-Workplace-Surviving/dp/0446698202%3FSubscriptionId%3D0JTCV5ZMHMF7ZYTXGFR2%26tag%3Dbrdicr-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0446698202"&gt;The No Asshole Rule: Building a Civilized Workplace and Surviving One That Isn't&lt;/a&gt;           &lt;br /&gt;          &lt;br /&gt;We all know them or know of them--the jerks and bullies at work who demean, criticize, and sap the energy of others, usually their underlings. It could be the notorious bad boss or the jealous coworker, but everyone agrees that they make life miserable for their victims and create a hostile and emotionally stifling environment. Fed up with how these creeps treat others and poison the workplace, Sutton declares war and comes out calling them exactly what they are--&amp;quot;certified assholes.&amp;quot; Caricatured in sitcoms such as &lt;i&gt;The Office&lt;/i&gt;, these brutes are too often tolerated until irreparable damage is done to individuals and the organization as a whole.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;br /&gt;  &lt;table border="0" cellspacing="5" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="150"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/41rgYq2PIGL._SL160_.jpg" /&gt; &lt;/td&gt;        &lt;td valign="top"&gt;&lt;a href="http://www.amazon.com/Thinkertoys-Handbook-Creative-Thinking-Techniques-2nd/dp/1580087736%3FSubscriptionId%3D0JTCV5ZMHMF7ZYTXGFR2%26tag%3Dbrdicr-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D1580087736"&gt;Thinkertoys: A Handbook of Creative-Thinking Techniques (2nd Edition)&lt;/a&gt;           &lt;br /&gt;          &lt;br /&gt;THINKERTOYS will teach you how to generate new ideas for businesses, markets, sales techniques, and products and product extensions. Packed with fun and practical tools and exercises, it outlines 30 practical linear and intuitive techniques that can be used by individuals or groups to tackle and solve business problems in fresh, creative ways.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;br /&gt;  &lt;table border="0" cellspacing="5" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="150"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/41QlZNOl2vL._SL160_.jpg" /&gt; &lt;/td&gt;        &lt;td valign="top"&gt;&lt;a href="http://www.amazon.com/Rework-Jason-Fried/dp/0307463745%3FSubscriptionId%3D0JTCV5ZMHMF7ZYTXGFR2%26tag%3Dbrdicr-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0307463745"&gt;Rework&lt;/a&gt;           &lt;br /&gt;          &lt;br /&gt;Explores a different reality of business. This book is suitable for hardcore entrepreneurs, small-business owners, people stuck in day jobs who want to get out, and artists who don't want to starve.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;</description>
      <link>http://crankingoutcode.com/post/Just-ordered-some-books.aspx</link>
      <author>bjn</author>
      <comments>http://crankingoutcode.com/post/Just-ordered-some-books.aspx#comment</comments>
      <guid>http://crankingoutcode.com/post.aspx?id=564642e9-effd-480c-a9af-6bcf3a810fc2</guid>
      <pubDate>Sun, 31 Oct 2010 21:19:17 +0200</pubDate>
      <category>book</category>
      <dc:publisher>bjn</dc:publisher>
      <pingback:server>http://crankingoutcode.com/pingback.axd</pingback:server>
      <pingback:target>http://crankingoutcode.com/post.aspx?id=564642e9-effd-480c-a9af-6bcf3a810fc2</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://crankingoutcode.com/trackback.axd?id=564642e9-effd-480c-a9af-6bcf3a810fc2</trackback:ping>
      <wfw:comment>http://crankingoutcode.com/post/Just-ordered-some-books.aspx#comment</wfw:comment>
      <wfw:commentRss>http://crankingoutcode.com/syndication.axd?post=564642e9-effd-480c-a9af-6bcf3a810fc2</wfw:commentRss>
    </item>
    <item>
      <title>Task Parallel Library – from foreach to Parallel.ForEach</title>
      <description>&lt;p&gt;With the release of .NET framework 4 the Task Parallel Library (TPL) is now a part of the core framework without the need to install any extensions. The TPL exposes a higher level of abstraction for creating threads. It includes a new way of constructoring For and ForEach loops, and make these run in parallel without manually creating and managing threads.&lt;/p&gt;  &lt;p&gt;Under the hood the TPL will create a number of threads. The number of threads will vary depending on the number of cores in the system running the application. Microsoft has completely redone the threadpool for .NET 4 CLR for it to be optimized for computers with a larger number of cores. Check out &lt;a href="http://aviadezra.blogspot.com/2009/04/task-parallel-library-parallel.html"&gt;this&lt;/a&gt; excellent explanation of how it works in detail.&lt;/p&gt;  &lt;p&gt;The TPL will reduce the complexity of your application code vastly and enables the developers to utilize all cores in the system more efficiently. Instead of having to manually creating threads its now as easy as calling Parallel.ForEach() for executing some operations in parallel. &lt;/p&gt;  &lt;p&gt;Lets show an example. This snippets creates a list of 10 dates and then loops over each date and executes the method SimulateLongRunningMethod, which sleeps for one second and then just prints out the argument.&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;            
List&amp;lt;DateTime&amp;gt; dates = new List&amp;lt;DateTime&amp;gt;();
for (int i = 0; i &amp;lt; 10; i++)
	dates.Add(DateTime.Now.AddDays(i));
Stopwatch watch = new Stopwatch();
watch.Start();
foreach (var date in dates)
{
	SimulateLongRunningMethod(date);
}
watch.Stop();
Console.WriteLine(&amp;quot;Took: &amp;quot; + watch.Elapsed);
private void SimulateLongRunningMethod(DateTime date)
{
	Thread.Sleep(1 * 1000);
        Console.WriteLine(date);
}&lt;/pre&gt;

&lt;p&gt;The output of the above would be (depending on when you run it of course):&lt;/p&gt;

&lt;p&gt;2010-10-03 20:08:58 
  &lt;br /&gt;2010-10-04 20:08:58 

  &lt;br /&gt;2010-10-05 20:08:58 

  &lt;br /&gt;2010-10-06 20:08:58 

  &lt;br /&gt;2010-10-07 20:08:58 

  &lt;br /&gt;2010-10-08 20:08:58 

  &lt;br /&gt;2010-10-09 20:08:58 

  &lt;br /&gt;2010-10-10 20:08:58 

  &lt;br /&gt;2010-10-11 20:08:58 

  &lt;br /&gt;2010-10-12 20:08:58 

  &lt;br /&gt;Took: 00:00:10.0730300&lt;/p&gt;

&lt;p&gt;All of the dates are in order and it took 10 seconds to do the execution.&lt;/p&gt;

&lt;p&gt;Changing the foreach loop to Parallel.ForEach is easy.&lt;/p&gt;

&lt;p&gt;Instead of the foreach we saw in the previous example it is now:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;Parallel.ForEach(dates, date =&amp;gt; SimulateLongRunningMethod(date));&lt;/pre&gt;
The output is:

&lt;br /&gt;

&lt;p&gt;2010-10-04 20:13:51
  &lt;br /&gt;2010-10-08 20:13:51

  &lt;br /&gt;2010-10-03 20:13:51

  &lt;br /&gt;2010-10-09 20:13:51

  &lt;br /&gt;2010-10-05 20:13:51

  &lt;br /&gt;2010-10-10 20:13:51

  &lt;br /&gt;2010-10-07 20:13:51

  &lt;br /&gt;2010-10-12 20:13:51

  &lt;br /&gt;2010-10-06 20:13:51

  &lt;br /&gt;2010-10-11 20:13:51

  &lt;br /&gt;Took: 00:00:03.0930603 &lt;/p&gt;

&lt;p&gt;This is running on my dual core computer, your result may vary. The result is not in order anymore as each thread is pulling data from the list. The execution time was decreased with approximately 7 seconds. &lt;/p&gt;

&lt;p&gt;That’s how easy it is to change your single threaded application into an application that will utilize all the available cores in your machine. Be careful though, concurrency issues might be exposed in your application if it hasn’t been designed for multi-thread execution in the beginning.&lt;/p&gt;</description>
      <link>http://crankingoutcode.com/post/Task-Parallel-Library-e28093-from-foreach-to-ParallelForEach.aspx</link>
      <author>bjn</author>
      <comments>http://crankingoutcode.com/post/Task-Parallel-Library-e28093-from-foreach-to-ParallelForEach.aspx#comment</comments>
      <guid>http://crankingoutcode.com/post.aspx?id=1bb95ba3-a375-44bc-9b67-6d0d7fe27fd8</guid>
      <pubDate>Sun, 03 Oct 2010 20:20:01 +0200</pubDate>
      <category>tpl</category>
      <category>C#</category>
      <category>net</category>
      <category>net4</category>
      <dc:publisher>bjn</dc:publisher>
      <pingback:server>http://crankingoutcode.com/pingback.axd</pingback:server>
      <pingback:target>http://crankingoutcode.com/post.aspx?id=1bb95ba3-a375-44bc-9b67-6d0d7fe27fd8</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://crankingoutcode.com/trackback.axd?id=1bb95ba3-a375-44bc-9b67-6d0d7fe27fd8</trackback:ping>
      <wfw:comment>http://crankingoutcode.com/post/Task-Parallel-Library-e28093-from-foreach-to-ParallelForEach.aspx#comment</wfw:comment>
      <wfw:commentRss>http://crankingoutcode.com/syndication.axd?post=1bb95ba3-a375-44bc-9b67-6d0d7fe27fd8</wfw:commentRss>
    </item>
    <item>
      <title>Issues building Sharp Architecture through hornget</title>
      <description>&lt;p&gt;Just tried to build Sharp Architecture through &lt;a href="http://code.google.com/p/hornget/"&gt;hornget&lt;/a&gt;:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;horn.exe –install:sharp.architecture&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;It failed with the message “&lt;font color="#ff0000"&gt;The type or namespace name 'AutoMap' does not exist in the namespace 'FluentNHibernate' (are you missing an assembly reference?)&lt;/font&gt;” and 16 errors with the same message. All I needed to do was to open the SharpArch.sln in c:\users\&amp;lt;my username&amp;gt;\.horn\frameworks\sharp.architecture\working\src\sharparch and Resharper immediately told me to add a using statement to FluentNHibernate.Automapping. Seems like they’ve changed namespace in fluent nhibernate from FluentNHibernate.AutoMap to FluentNHibernate.Automapping. After changing this and made sure that I could compile the solution I just ran the horn command line tool again and it built everything successfully. Just remember to revert the changes or wipe the folder clean so there wont be any conflicts the next time…&lt;/p&gt;</description>
      <link>http://crankingoutcode.com/post/Issues-building-Sharp-Architecture-through-hornget.aspx</link>
      <author>bjn</author>
      <comments>http://crankingoutcode.com/post/Issues-building-Sharp-Architecture-through-hornget.aspx#comment</comments>
      <guid>http://crankingoutcode.com/post.aspx?id=53a4ba3a-129b-45db-b285-f59ad5f30246</guid>
      <pubDate>Wed, 07 Oct 2009 21:08:28 +0200</pubDate>
      <category>nhibernate</category>
      <category>fluent</category>
      <category>automapper</category>
      <dc:publisher>bjn</dc:publisher>
      <pingback:server>http://crankingoutcode.com/pingback.axd</pingback:server>
      <pingback:target>http://crankingoutcode.com/post.aspx?id=53a4ba3a-129b-45db-b285-f59ad5f30246</pingback:target>
      <slash:comments>9</slash:comments>
      <trackback:ping>http://crankingoutcode.com/trackback.axd?id=53a4ba3a-129b-45db-b285-f59ad5f30246</trackback:ping>
      <wfw:comment>http://crankingoutcode.com/post/Issues-building-Sharp-Architecture-through-hornget.aspx#comment</wfw:comment>
      <wfw:commentRss>http://crankingoutcode.com/syndication.axd?post=53a4ba3a-129b-45db-b285-f59ad5f30246</wfw:commentRss>
    </item>
    <item>
      <title>Introducing AutoMapper removed 600 lines of code</title>
      <description>&lt;p&gt;AutoMapper is a convention-based object-object mapper as described by the AutoMapper project homepage (&lt;a href="http://www.codeplex.com/AutoMapper"&gt;http://www.codeplex.com/AutoMapper&lt;/a&gt;).&lt;/p&gt;  &lt;p&gt;Basically it will map properties between two different objects (different types). If the name of the properties are the same it just works. It works with lists and nested types. All you need to do is initiate the mapping and then do the actual mapping. Here’s an example when mapping from an instance of type User to a UserViewModel instance.&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; Mapper.CreateMap&amp;lt;User, UserViewModel&amp;gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; User user = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UserRepository().Get(1);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; UserViewModel userViewModel = Mapper.Map&amp;lt;User, UserViewModel&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;If the structure/name isn’t something that AutoMapper can figure out how to map then it’s possible to add manual mappings with lambda expressions. For example if the User has a Telephone type with a property called PhoneNumber and the UserViewModel has a basic string property called Phone:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; Mapper.CreateMap&amp;lt;User, UserViewModel&amp;gt;()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;     .ForMember(viewModel =&amp;gt; viewModel.Phone, opt =&amp;gt; opt.MapFrom(user =&amp;gt; user.Telephone.PhoneNumber)));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Very cool stuff indeed. I introduced AutoMapper in one of the projects I’m currently working on and since it was mostly 1-1 mapping that was done, I reduced over 600 lines of code in two hours in the project. Since I just replaced the body of my mapper methods with the call to AutoMapper that meant that all the unit tests I had written could verify that everything worked as before.&lt;/p&gt;</description>
      <link>http://crankingoutcode.com/post/Introducing-AutoMapper-removed-600-lines-of-code.aspx</link>
      <author>bjn</author>
      <comments>http://crankingoutcode.com/post/Introducing-AutoMapper-removed-600-lines-of-code.aspx#comment</comments>
      <guid>http://crankingoutcode.com/post.aspx?id=d8880f82-295b-4455-bf70-f312bbb9bbb9</guid>
      <pubDate>Sun, 04 Oct 2009 20:02:20 +0200</pubDate>
      <category>C#</category>
      <category>automapper</category>
      <dc:publisher>bjn</dc:publisher>
      <pingback:server>http://crankingoutcode.com/pingback.axd</pingback:server>
      <pingback:target>http://crankingoutcode.com/post.aspx?id=d8880f82-295b-4455-bf70-f312bbb9bbb9</pingback:target>
      <slash:comments>11</slash:comments>
      <trackback:ping>http://crankingoutcode.com/trackback.axd?id=d8880f82-295b-4455-bf70-f312bbb9bbb9</trackback:ping>
      <wfw:comment>http://crankingoutcode.com/post/Introducing-AutoMapper-removed-600-lines-of-code.aspx#comment</wfw:comment>
      <wfw:commentRss>http://crankingoutcode.com/syndication.axd?post=d8880f82-295b-4455-bf70-f312bbb9bbb9</wfw:commentRss>
    </item>
    <item>
      <title>Confusing error message with ASP.NET MVC when returning File()</title>
      <description>&lt;p&gt;Currently I’m building a image gallery component for a website where the user is able to upload images and they are displayed in a gallery using &lt;a title="http://pikachoose.com" href="http://pikachoose.com"&gt;http://pikachoose.com&lt;/a&gt;. I have one action on my controller called Download which takes the id of the image that should be downloaded as an argument. It worked fine using this code (in the beginning):&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ActionResult Download(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; id)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     var image = Repository.GetById(id);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; File(image.Data, image.ContentType, image.Filename);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The problem with this code only showed up with some images. The problem is the last parameter to File(), image.Filename. Which is the filename of the original image the user has uploaded. If the filename contains “invalid characters” ASP.NET MVC throws this exception:&lt;/p&gt;

&lt;pre&gt;[FormatException: An invalid character was found in the mail header.]
   System.Net.Mime.MailBnfHelper.GetTokenOrQuotedString(String data, StringBuilder builder) &lt;/pre&gt;

&lt;pre&gt;   System.Net.Mime.ContentDisposition.ToString() +270
   System.Web.Mvc.FileResult.ExecuteResult(ControllerContext context) +164&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The part that confused me was “in the mail header”. Suppose they’re reusing some mail component for mime parsing. To fix it I only had to make sure that the filename didn’t had any invalid characters, I did it by setting it to the filename I use on the server instead of the filename submitted by the user.&lt;/p&gt;</description>
      <link>http://crankingoutcode.com/post/Confusing-error-message-with-ASPNET-MVC-when-returning-File().aspx</link>
      <author>bjn</author>
      <comments>http://crankingoutcode.com/post/Confusing-error-message-with-ASPNET-MVC-when-returning-File().aspx#comment</comments>
      <guid>http://crankingoutcode.com/post.aspx?id=d5ff528b-e642-4f9b-a407-389b0b896c38</guid>
      <pubDate>Wed, 08 Jul 2009 21:51:00 +0200</pubDate>
      <category>mvc</category>
      <dc:publisher>bjn</dc:publisher>
      <pingback:server>http://crankingoutcode.com/pingback.axd</pingback:server>
      <pingback:target>http://crankingoutcode.com/post.aspx?id=d5ff528b-e642-4f9b-a407-389b0b896c38</pingback:target>
      <slash:comments>32</slash:comments>
      <trackback:ping>http://crankingoutcode.com/trackback.axd?id=d5ff528b-e642-4f9b-a407-389b0b896c38</trackback:ping>
      <wfw:comment>http://crankingoutcode.com/post/Confusing-error-message-with-ASPNET-MVC-when-returning-File().aspx#comment</wfw:comment>
      <wfw:commentRss>http://crankingoutcode.com/syndication.axd?post=d5ff528b-e642-4f9b-a407-389b0b896c38</wfw:commentRss>
    </item>
    <item>
      <title>Storing large strings with Fluent NHibernate (automapping)</title>
      <description>&lt;p&gt;When using the automapping feature of Fluent NHibernate you may encounter some problems when storing large text data in the database. Below is a class which gets mapped by the automapper in Fluent NHibernate. Both Title and TextContent are strings. The difference between them is that the TextContent property might store a large chunk of text.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.crankingoutcode.com/content/binary/WindowsLiveWriter/StoringlargestringswithFluentNHibernatea_1165A/image_4.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="144" alt="image" src="http://www.crankingoutcode.com/content/binary/WindowsLiveWriter/StoringlargestringswithFluentNHibernatea_1165A/image_thumb_1.png" width="187" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;The default automapper in Fluent NHibernate will create a table with a nvarchar(255) column for both the Title and TextContent. This is fine for most cases but in this case the TextContent property may contain much more than 255 characters. Trying to save the entity with more than 255 characters stored in TextContent will give throw an exception saying:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;font color="#ff0000"&gt;System.Data.SqlClient.SqlException: String or binary data would be truncated.          &lt;br /&gt;The statement has been terminated.&lt;/font&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;This is the same problem you might run into when using Castle ActiveRecord which also will do a default nvarchar(255) for a string property. It's quite simple to override the default automapper in Fluent NHibernate to change the column in the database into a text type for example. All you need to do is create a class which implements the interface IAutoMappingOverride&amp;lt;T&amp;gt; and add it to the configuration.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span id="lnum1" style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; HeadlineOverride : IAutoMappingOverride&amp;lt;Headline&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span id="lnum2" style="color: #606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span id="lnum3" style="color: #606060"&gt;   3:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Override(AutoMap&amp;lt;Headline&amp;gt; mapping)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span id="lnum4" style="color: #606060"&gt;   4:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span id="lnum5" style="color: #606060"&gt;   5:&lt;/span&gt;             mapping.Map(t =&amp;gt; t.TextContent).CustomTypeIs(&lt;span style="color: #006080"&gt;&amp;quot;StringClob&amp;quot;&lt;/span&gt;).CustomSqlTypeIs(&lt;span style="color: #006080"&gt;&amp;quot;text&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span id="lnum6" style="color: #606060"&gt;   6:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span id="lnum7" style="color: #606060"&gt;   7:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;All you need to do a manual mapping of the field and set the custom type to StringClob and SqlType to text. All the other properties will still be mapped by the automapper in Fluent NHibernate. To make sure that Fluent NHibernate will load the override into the configuration you need to set it up.&lt;/p&gt;

&lt;div&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; AutoPersistenceModel&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;        .MapEntitiesFromAssemblyOf&amp;lt;Headline&amp;gt;()&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;        .Where(t =&amp;gt; t.Namespace == &lt;span style="color: #006080"&gt;&amp;quot;Incendi.Models&amp;quot;&lt;/span&gt;)&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;        .UseOverridesFromAssemblyOf&amp;lt;HeadlineOverride&amp;gt;();&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;
On line #4 it tells the automapper to use the overrides from the assembly where HeadlineOverride is declared. If you drop/create the schema with this updated configuration you'll end up with a text type on the TextContent column instead of a varchar(255). 

</description>
      <link>http://crankingoutcode.com/post/Storing-large-strings-with-Fluent-NHibernate-(automapping).aspx</link>
      <author>bjn</author>
      <comments>http://crankingoutcode.com/post/Storing-large-strings-with-Fluent-NHibernate-(automapping).aspx#comment</comments>
      <guid>http://crankingoutcode.com/post.aspx?id=fee67e05-08bb-486b-9430-251f3c9b9c04</guid>
      <pubDate>Sat, 14 Mar 2009 18:47:53 +0200</pubDate>
      <category>nhibernate</category>
      <dc:publisher>bjn</dc:publisher>
      <pingback:server>http://crankingoutcode.com/pingback.axd</pingback:server>
      <pingback:target>http://crankingoutcode.com/post.aspx?id=fee67e05-08bb-486b-9430-251f3c9b9c04</pingback:target>
      <slash:comments>19</slash:comments>
      <trackback:ping>http://crankingoutcode.com/trackback.axd?id=fee67e05-08bb-486b-9430-251f3c9b9c04</trackback:ping>
      <wfw:comment>http://crankingoutcode.com/post/Storing-large-strings-with-Fluent-NHibernate-(automapping).aspx#comment</wfw:comment>
      <wfw:commentRss>http://crankingoutcode.com/syndication.axd?post=fee67e05-08bb-486b-9430-251f3c9b9c04</wfw:commentRss>
    </item>
  </channel>
</rss>