<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;C04MQ3c8fyp7ImA9WhBUGEk.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505</id><updated>2013-05-06T14:06:22.977+02:00</updated><category term="vs" /><category term="Vista" /><category term="Internet" /><category term="SQL" /><category term="Powershell" /><category term="silverlight" /><category term="Office" /><category term="F#" /><category term="Windows" /><category term="Security" /><category term="IIS" /><category term="ASP.NET MVC" /><category term="Programming" /><category term="Mathematica" /><category term="ASP.NET" /><category term="Testing" /><category term="visual studio" /><category term="C#" /><category term="C++" /><category term="Electronics" /><category term="Database" /><category term="WinStore" /><category term="Visual Basic" /><category term="NHibernate" /><category term="JavaScript" /><category term="WPF" /><category term="Education" /><category term="OpenGL" /><category term="Excel" /><title>Techie things</title><subtitle type="html">A blog about .NET development and software architecture.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://techiethings.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>91</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/techiethings" /><feedburner:info uri="techiethings" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-nd/3.0/" /><logo>http://creativecommons.org/images/public/somerights20.gif</logo><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Ftechiethings" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Ftechiethings" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2Ftechiethings" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/techiethings" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Ftechiethings" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Ftechiethings" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Ftechiethings" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><entry gd:etag="W/&quot;D0UHQn86eCp7ImA9WhBVEk0.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-4643388564569928247</id><published>2013-04-17T15:27:00.000+02:00</published><updated>2013-04-17T15:27:13.110+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-17T15:27:13.110+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Programming" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="Powershell" /><title>Unit testing a Powershell Commandlet</title><content type="html">I chose to write Powershell commandlets in C#. I created a class library (DLL) project and&amp;nbsp;inherited&amp;nbsp;a class from&amp;nbsp;&lt;i&gt;Cmdlet &lt;/i&gt;base class. I created a snapin class derived from&amp;nbsp;&lt;i&gt;PSSnapIn &lt;/i&gt;to be able to install my commandlets from powershell.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2&gt;
Unit testing&lt;/h2&gt;
&lt;h3&gt;
Writing a unit test&lt;/h3&gt;
&lt;pre&gt;    [TestClass]
    public class UnitTest1
    {
        private static RunspaceConfiguration config;
        private static Runspace runspace;
        private static Pipeline pipe;
        private static Command command;

        [ClassInitialize]
        public static void TestFixtureSetup(TestContext context)
        {
            config = RunspaceConfiguration.Create();

            PSSnapInException warning;
            config.AddPSSnapIn("SnapinName", out warning);

            runspace = RunspaceFactory.CreateRunspace(config);
            runspace.Open();
        }

        [ClassCleanup]
        public static void TestFixtureTeardown()
        {
            runspace.Close();
        }

        [TestInitialize]
        public void Setup()
        {
            pipe = runspace.CreatePipeline();
            command = new Command("CommandName");
            pipe.Commands.Add(command);
        }

        [TestMethod]
        public void TestMethod1()
        {
            command.Parameters.Add(new CommandParameter("ParameterName", "Value"));

            var psObject = pipe.Invoke();
        }
    }

&lt;/pre&gt;
&lt;h3&gt;
Snapin couldn't be found&lt;/h3&gt;
&lt;div&gt;
I wrote a unit test against one of my commands but it couldn't find my snapin, I got the following exception:&lt;/div&gt;
&lt;div&gt;
System.Management.Automation.PSArgumentException: System.Management.Automation.PSArgumentException: The Windows PowerShell snap-in '...' is not installed on this computer..&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I could use my snapin from Powershell&amp;nbsp;command line.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h4&gt;
Solution&lt;/h4&gt;
&lt;div&gt;
Add the following lines as post-build events:&lt;/div&gt;
&lt;div&gt;
&lt;blockquote class="tr_bq"&gt;
&lt;span style="font-family: Courier New, Courier, monospace;"&gt;c:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe $(TargetPath)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Courier New, Courier, monospace;"&gt;c:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe &amp;nbsp;$(TargetPath)&lt;/span&gt;&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Both 32-bit and 64-bit installation will happen this way.&lt;/div&gt;
&lt;h4&gt;
Cause&lt;/h4&gt;
&lt;div&gt;
Visual Studio 2012 is a 32-bit process. I registered with 64-bit install util only. Now I register both versions.&lt;/div&gt;
&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=f9lOBx7AYuE:11iypn9Lwzc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=f9lOBx7AYuE:11iypn9Lwzc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=f9lOBx7AYuE:11iypn9Lwzc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=f9lOBx7AYuE:11iypn9Lwzc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=f9lOBx7AYuE:11iypn9Lwzc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=f9lOBx7AYuE:11iypn9Lwzc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/4643388564569928247/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2013/04/unit-testing-powershell-commandlet.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/4643388564569928247?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/4643388564569928247?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/f9lOBx7AYuE/unit-testing-powershell-commandlet.html" title="Unit testing a Powershell Commandlet" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2013/04/unit-testing-powershell-commandlet.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE8HRH88fCp7ImA9WhBVEE4.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-1260568512975115722</id><published>2013-04-15T16:21:00.000+02:00</published><updated>2013-04-15T16:40:35.174+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-15T16:40:35.174+02:00</app:edited><title>XAML Resource Loading</title><content type="html">Visual Studio 2012 kept locking my .DLLs. It&amp;nbsp;happened&amp;nbsp;mostly after starting a debugger session. I could trace back the problem to a&amp;nbsp;&lt;i&gt;GetManifestResourceStream()&lt;/i&gt; call.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Solution&lt;/h2&gt;
This is my solution that seems to be working:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public Stream GetResourceStreamByType(Type type, string resourceName)
{
  var location = Assembly.GetAssembly(type).Location;
  var assemblyBytes = File.ReadAllBytes(location);

  var appDomain = AppDomain.CreateDomain("Resource domain");
  var assembly = appDomain.Load(assemblyBytes);

  return assembly.GetManifestResourceStream(resourceName);
}

public BitmapImage GetBitmapByType(Type type, string resourceName)
{
  var bmp = new BitmapImage();
  using (var source = GetResourceStreamByType(type, resourceName))
  {
    bmp.BeginInit();
    bmp.StreamSource = source;
    bmp.EndInit();
  }

  return bmp;
}
&lt;/pre&gt;
&lt;pre class="brush: csharp"&gt;&lt;/pre&gt;
&lt;h2&gt;
Reasons&lt;/h2&gt;
&lt;div&gt;
Loading the resource by calling the &lt;i&gt;GetManifestResourceStream()&lt;/i&gt; on the current assembly loads the assembly into the debugger's app domain which is Visual Studio in this case. Reading the bytes and loading them manually prevents this behavior.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I couldn't reload the form again after loading the resources this way so I had to create a separate app domain as well. Without separate app domain the assembly was already loaded and the reloading didn't happen with an error message like '&lt;b&gt;does not have a resource identified by the URI&lt;/b&gt;'.&lt;/div&gt;
&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=eeU8-5lC5FM:Iu-fZQo4Qp0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=eeU8-5lC5FM:Iu-fZQo4Qp0:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=eeU8-5lC5FM:Iu-fZQo4Qp0:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=eeU8-5lC5FM:Iu-fZQo4Qp0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=eeU8-5lC5FM:Iu-fZQo4Qp0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=eeU8-5lC5FM:Iu-fZQo4Qp0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/1260568512975115722/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2013/04/xaml-resource-loading.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/1260568512975115722?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/1260568512975115722?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/eeU8-5lC5FM/xaml-resource-loading.html" title="XAML Resource Loading" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2013/04/xaml-resource-loading.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEIHQH8-eyp7ImA9WhJVF0g.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-8966766666318811211</id><published>2012-09-04T13:02:00.001+02:00</published><updated>2012-09-04T13:02:11.153+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-09-04T13:02:11.153+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Programming" /><category scheme="http://www.blogger.com/atom/ns#" term="WinStore" /><category scheme="http://www.blogger.com/atom/ns#" term="Windows" /><title>Ember–Handlebars.helpers in Windows 8 Metro</title><content type="html">&lt;p&gt;I tried to use Ember.js Handlebars helper &lt;font face="Consolas"&gt;&lt;em&gt;{{action}}&lt;/em&gt;&lt;/font&gt; in a Windows 8 Metro (Windows Store) application. The data marker attribute appeared, but the function was never called.&lt;/p&gt; &lt;p&gt;I managed to find the &lt;strong&gt;root cause&lt;/strong&gt;: Ember.js uses &lt;font face="Consolas"&gt;&lt;em&gt;jQuery.ready()&lt;/em&gt;&lt;/font&gt; for initialization. &lt;/p&gt; &lt;h2&gt;Solution&lt;/h2&gt; &lt;p&gt;Change&lt;/p&gt;&lt;pre&gt;waitForDOMContentLoaded: function() {
    this.deferReadiness();

    var self = this;
    this.$().ready(function() {
      self.advanceReadiness();
    });
  },
&lt;/pre&gt;
&lt;p&gt;to&lt;/p&gt;&lt;pre&gt;waitForDOMContentLoaded: function() {
    this.deferReadiness();

    var self = this;
      
    WinJS.Application.addEventListener("ready", function () {
        self.advanceReadiness();
    });

  },
&lt;/pre&gt;and comment out 2 lines as shown below: &lt;pre&gt;advanceReadiness: function() {
    this._readinessDeferrals--;

    //if (this._readinessDeferrals === 0) {
      Ember.run.once(this, this.didBecomeReady);
    //}
  },
&lt;/pre&gt;
&lt;p&gt;Now you will use the Metro infrastructure for events.&lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=46YeXcdmeK0:NgmG-ldPr7g:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=46YeXcdmeK0:NgmG-ldPr7g:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=46YeXcdmeK0:NgmG-ldPr7g:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=46YeXcdmeK0:NgmG-ldPr7g:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=46YeXcdmeK0:NgmG-ldPr7g:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=46YeXcdmeK0:NgmG-ldPr7g:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/8966766666318811211/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2012/09/emberhandlebarshelpers-in-windows-8.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/8966766666318811211?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/8966766666318811211?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/46YeXcdmeK0/emberhandlebarshelpers-in-windows-8.html" title="Ember–Handlebars.helpers in Windows 8 Metro" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2012/09/emberhandlebarshelpers-in-windows-8.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0MGSHs-cSp7ImA9WhJVFk0.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-3267242684898689948</id><published>2012-09-02T20:10:00.001+02:00</published><updated>2012-09-02T20:10:29.559+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-09-02T20:10:29.559+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Programming" /><category scheme="http://www.blogger.com/atom/ns#" term="WinStore" /><category scheme="http://www.blogger.com/atom/ns#" term="Windows" /><title>Handlebars and Ember templating in Window 8 Metro</title><content type="html">&lt;p&gt;&lt;a href="http://handlebarsjs.com/" target="_blank"&gt;Handlebars&lt;/a&gt; uses script blocks for template markup. E.g.&lt;/p&gt;&lt;pre&gt;&amp;lt;script type="text/x-handlebars" data-template-name="say-hello"&amp;gt;
      Hello, &amp;lt;b&amp;gt;{{MyApp.name}}&amp;lt;/b&amp;gt;
&amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;p&gt;Unfortunately the Metro JavaScript engine removes the &lt;font face="Consolas"&gt;&lt;em&gt;data-template-name&lt;/em&gt;&lt;/font&gt; attribute from the script tag, so this method can’t be used for templating.&lt;/p&gt;
&lt;p&gt;As JS files are available locally for execution, the template files can be stored in separate HTML files and can be parsed from code. The implementation is simple:&lt;/p&gt;&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&lt;br&gt;Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync(path).done(function(folder) {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var search = folder.createFileQuery(Windows.Storage.Search.CommonFileQuery.orderByName);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; search.getFilesAsync().done(function (res) {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; res.forEach(function (file) {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var template;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Windows.Storage.FileIO.readTextAsync(file).then(function(fileContent) {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var template = Ember.Handlebars.compile(fileContent);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ember.TEMPLATES[file.displayName] = template;&lt;br&gt;[…]&lt;br&gt;&lt;/pre&gt;
&lt;p&gt;I omitted the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br211867.aspx" target="_blank"&gt;async promises&lt;/a&gt; from the code for readability, but the code won’t work without them.&lt;/p&gt;
&lt;p&gt;The code above &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;reads all the files from a folder 
&lt;li&gt;compiles the template 
&lt;li&gt;stores the compiled template as an Ember template&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Now &lt;strong&gt;Ember.js&lt;/strong&gt; and &lt;strong&gt;Handlebars.js&lt;/strong&gt; are fully functional, even &lt;font face="Consolas"&gt;&lt;em&gt;Ember.View&lt;/em&gt;&lt;/font&gt; can be used with &lt;font face="Consolas"&gt;&lt;em&gt;view.append()&lt;/em&gt;&lt;/font&gt;.&lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=ptvLpn5PgGM:A-yEF0JqEGo:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=ptvLpn5PgGM:A-yEF0JqEGo:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=ptvLpn5PgGM:A-yEF0JqEGo:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=ptvLpn5PgGM:A-yEF0JqEGo:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=ptvLpn5PgGM:A-yEF0JqEGo:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=ptvLpn5PgGM:A-yEF0JqEGo:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/3267242684898689948/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2012/09/handlebars-and-ember-templating-in.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/3267242684898689948?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/3267242684898689948?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/ptvLpn5PgGM/handlebars-and-ember-templating-in.html" title="Handlebars and Ember templating in Window 8 Metro" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2012/09/handlebars-and-ember-templating-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE4EQXsyfSp7ImA9WhJVFEQ.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-2272683021181732059</id><published>2012-09-01T12:55:00.001+02:00</published><updated>2012-09-01T12:55:00.595+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-09-01T12:55:00.595+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Electronics" /><category scheme="http://www.blogger.com/atom/ns#" term="Windows" /><category scheme="http://www.blogger.com/atom/ns#" term="Internet" /><title>Digital TV Experience</title><content type="html">&lt;p&gt;I have some experience with a Samsung &lt;a href="http://en.wikipedia.org/wiki/Smart_TV" target="_blank"&gt;smart TV&lt;/a&gt; I will summarize here.&lt;/p&gt; &lt;h2&gt;TV&lt;/h2&gt; &lt;p&gt;I have access to &lt;strong&gt;analog TV signal&lt;/strong&gt;, and I must tell you this is not what a digital TV was made for. It’s acceptable, but &lt;/p&gt; &lt;ul&gt; &lt;li&gt;the image is not sharp, thanks to the low resolution&lt;/li&gt; &lt;li&gt;the aspect ratio of the picture (aka picture size) changes among channels, or even between programs&lt;/li&gt; &lt;li&gt;the TV tries to enhance the quality of the image (e.g. sharpens the edges at still images), and sometimes that can be annoying&lt;/li&gt; &lt;li&gt;no electronic program guide (EPG)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;I tried to receive &lt;a href="http://en.wikipedia.org/wiki/DVB-T" target="_blank"&gt;DVB-T signal&lt;/a&gt; but I couldn’t. Just a few channels with long breaks in receiving. Though the image quality was wonderful and I got EPG.&lt;/p&gt; &lt;h2&gt;Teletext&lt;/h2&gt; &lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Teletext" target="_blank"&gt;Teletext&lt;/a&gt; comes with the channels supporting this technology. It is the shadow of the analog era. Digital TVs try to enhance this technology:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;store pages in memory, no need to wait for paging&lt;/li&gt; &lt;li&gt;more txt display modes&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Don’t expect too much from this.&lt;/p&gt; &lt;h2&gt;Multimedia&lt;/h2&gt; &lt;p&gt;Digital TVs support a standard protocol (&lt;a href="http://en.wikipedia.org/wiki/DLNA" target="_blank"&gt;DLNA&lt;/a&gt;) for receiving multimedia streams from other devices. Just put the two devices onto the same subnet of your LAN (use the same router with cable or Wi-Fi) and the two devices will see each other. In my case I run a Samsung AllShare DLNA server on my desktop computer and&lt;/p&gt; &lt;ul&gt; &lt;li&gt;I can select the movie I want to play from the TV’s menu&lt;/li&gt; &lt;li&gt;I can start playing the movie on my TV pressing a button on my computer using AllShare or Windows Media Player.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Smartphone" target="_blank"&gt;Smartphones&lt;/a&gt; have the same capabilities. Moreover&lt;/p&gt; &lt;ul&gt; &lt;li&gt;I can start playing a movie on the TV from my computer pressing a button on my smart phone&lt;/li&gt; &lt;li&gt;I can control the TV from the smart phone as a TV remote (needs special app on your phone)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;You can by a &lt;a href="http://en.wikipedia.org/wiki/Network-attached_storage" target="_blank"&gt;NAS&lt;/a&gt; with DLNA support and you will have an always online media server without noisy fans.&lt;/p&gt; &lt;h2&gt;HDMI&lt;/h2&gt; &lt;p&gt;Connecting a &lt;a href="http://en.wikipedia.org/wiki/HDMI" target="_blank"&gt;HDMI&lt;/a&gt; cable to the TV and the computer, means the computer’s desktop can be displayed on the TV, in excellent quality.&lt;/p&gt; &lt;p&gt;Even the sound can be redirected to the TV’s speakers or sound system. Just open the sound playback devices and set the TV as the default sound device.&lt;/p&gt; &lt;p&gt;If your TV supports &lt;a href="http://www.hdmi.org/manufacturer/hdmi_1_4/hec.aspx" target="_blank"&gt;HDMI Ethernet channel&lt;/a&gt;, you can use your TV as a(n Internet) router for multimedia device (blue-ray player etc.).&lt;/p&gt; &lt;h2&gt;Smart features&lt;/h2&gt; &lt;p&gt;I have access to a Samsung smart TV. It has an Internet browser and apps can be downloaded from a store. There are some useful apps like online radio and TV&amp;nbsp; channel guide, but the most useful app is the Internet browser. It has Flash support and loads most of the websites I tried to visit.&lt;/p&gt; &lt;p&gt;For better experience I suggest you to buy a wireless keyboard and mouse. There are multimedia keyboards combining these devices into a small device just like a game controller. &lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=G0VQOwDGsEs:CK0CQ3x3zi4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=G0VQOwDGsEs:CK0CQ3x3zi4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=G0VQOwDGsEs:CK0CQ3x3zi4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=G0VQOwDGsEs:CK0CQ3x3zi4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=G0VQOwDGsEs:CK0CQ3x3zi4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=G0VQOwDGsEs:CK0CQ3x3zi4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/2272683021181732059/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2012/09/digital-tv-experience.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/2272683021181732059?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/2272683021181732059?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/G0VQOwDGsEs/digital-tv-experience.html" title="Digital TV Experience" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2012/09/digital-tv-experience.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CE4EQH44cCp7ImA9WhJVFE8.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-1544052089894123477</id><published>2012-08-31T16:21:00.001+02:00</published><updated>2012-08-31T16:21:41.038+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-08-31T16:21:41.038+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WinStore" /><category scheme="http://www.blogger.com/atom/ns#" term="Windows" /><title>Require JS with Win 8 Metro interface</title><content type="html">&lt;p&gt;&lt;a href="http://requirejs.org" target="_blank"&gt;Require.js&lt;/a&gt; works with Windows 8 Metro-style (Windows Store) applications. &lt;/p&gt; &lt;h2&gt;Page scripts&lt;/h2&gt; &lt;p&gt;There is a JavaScript file for each HTML page files. You cannot wrap this .js file into a require function. The page events (e.g. the ready event) won’t be called. &lt;/p&gt; &lt;p&gt;You can place a require call into the event handler function and that works.&lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=dUJVjz2t4FQ:HJp7gse8Auw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=dUJVjz2t4FQ:HJp7gse8Auw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=dUJVjz2t4FQ:HJp7gse8Auw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=dUJVjz2t4FQ:HJp7gse8Auw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=dUJVjz2t4FQ:HJp7gse8Auw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=dUJVjz2t4FQ:HJp7gse8Auw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/1544052089894123477/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2012/08/require-js-with-win-8-metro-interface.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/1544052089894123477?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/1544052089894123477?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/dUJVjz2t4FQ/require-js-with-win-8-metro-interface.html" title="Require JS with Win 8 Metro interface" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2012/08/require-js-with-win-8-metro-interface.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEYFRn45fip7ImA9WhVXEk8.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-2202684627892002849</id><published>2012-04-12T11:14:00.001+02:00</published><updated>2012-04-12T11:15:17.026+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-04-12T11:15:17.026+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Programming" /><title>Git: create a tag on a (remote) branch</title><content type="html">&lt;p&gt;You can create a tag on the local branch and you must push the tag to the remote.&lt;/p&gt; &lt;h2&gt;Command line&lt;/h2&gt; &lt;p&gt;&lt;font face="Consolas"&gt;&amp;gt; git tag …&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Consolas"&gt;&amp;gt; git push --tags&lt;/font&gt;&lt;/p&gt; &lt;h2&gt;TortoiseGit&lt;/h2&gt; &lt;ol&gt; &lt;li&gt;Create tag&lt;/li&gt; &lt;ol&gt; &lt;li&gt;set tag name&lt;/li&gt; &lt;li&gt;set tag/branch/version&lt;/li&gt; &lt;li&gt;enter message&lt;/li&gt;&lt;/ol&gt; &lt;li&gt;Sync/Push&lt;/li&gt; &lt;ol&gt; &lt;li&gt;Select &lt;strong&gt;Push tags &lt;/strong&gt;instead of Push button in the dropdown&lt;/li&gt;&lt;/ol&gt;&lt;/ol&gt; &lt;h2&gt;Git Extensions&lt;/h2&gt; &lt;ol&gt; &lt;li&gt;&lt;strong&gt;Browse&lt;/strong&gt;&lt;/li&gt; &lt;li&gt;Right click on the commit log you want to tag&lt;/li&gt; &lt;li&gt;Select &lt;strong&gt;Create new tag&lt;/strong&gt;&lt;/li&gt; &lt;li&gt;Enter data&lt;/li&gt; &lt;li&gt;Push&lt;/li&gt; &lt;ol&gt; &lt;li&gt;Select &lt;strong&gt;Push tags &lt;/strong&gt;tab&lt;/li&gt;&lt;/ol&gt;&lt;/ol&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=edn0nnTtq0s:yxXTOj2HGmY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=edn0nnTtq0s:yxXTOj2HGmY:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=edn0nnTtq0s:yxXTOj2HGmY:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=edn0nnTtq0s:yxXTOj2HGmY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=edn0nnTtq0s:yxXTOj2HGmY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=edn0nnTtq0s:yxXTOj2HGmY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/2202684627892002849/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2012/04/git-create-tag-on-remote-branch.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/2202684627892002849?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/2202684627892002849?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/edn0nnTtq0s/git-create-tag-on-remote-branch.html" title="Git: create a tag on a (remote) branch" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2012/04/git-create-tag-on-remote-branch.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ck4ERX4-eyp7ImA9WhRbGEQ.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-3878868007371269090</id><published>2012-02-10T17:21:00.001+01:00</published><updated>2012-02-10T17:21:44.053+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-10T17:21:44.053+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Programming" /><title>Hate JavaScript?</title><content type="html">&lt;p&gt;Do you hate JavaScript? Well, I have bad news. There are still no alternatives in the web browsers.&lt;/p&gt; &lt;p&gt;I develop ASP.NET (MVC) –based web applications, and I must use JavaScript. What’s the big difference between the modern web applications and websites from a few years ago? Well, the server-side/client-side ratio. A few years ago I was happy coding on server-side.&lt;strong&gt; I did as much as I could do in C#, in ASP.NET&lt;/strong&gt;. I did learn JavaScript but I avoided it as much as I could (so I never knew it well enough).&lt;/p&gt; &lt;p&gt;Now you can’t avoid JavaScript anymore. More and more code is on client-side. More and more business logic and architectural challenges are on client-side, right in the browser. &lt;strong&gt;I’ve written database-like features and even messaging systems&lt;/strong&gt; in JavaScript. That challenge reminds me the early days of other languages. Missing features, missing language support, missing best practices, missing design patterns. Pure greenfield tasks.&lt;/p&gt; &lt;p&gt;How well do you speak JavaScript? A few years ago it was enough to understand how to define a function and some variables. Learn how &lt;a href="http://en.wikipedia.org/wiki/Document_Object_Model" target="_blank"&gt;DOM&lt;/a&gt; works. How different DOMs work. That’s not a small thing if you did it well. But did we &lt;strong&gt;write good, quality code with low bug ratio and good manageability&lt;/strong&gt;? I’d say no.&lt;/p&gt; &lt;p&gt;A few years later there came the &lt;strong&gt;&lt;a href="http://en.wikipedia.org/wiki/Object-oriented_programming" target="_blank"&gt;object-oriented&lt;/a&gt; world&lt;/strong&gt; to JavaScript. We, I personally, had to learn the idea behind &lt;a href="http://en.wikipedia.org/wiki/Prototype-based_programming" target="_blank"&gt;prototype-based&lt;/a&gt; languages. That’s a hard step with a ‘real’ object-oriented (Java, C#, C++) mindset. How can I implement inheritance? How can I hide data? How can I achieve polymorphism? Tough questions. Luckily along came design patterns. There are even a few books on the topic in JavaScript. Still, it’s not easy. I personally can recite 4-5 inheritance patterns. There are at least 2 data hiding patterns I can recall right now. &lt;/p&gt; &lt;p&gt;Well, many options, with their own drawbacks. It’s not easy to choose, e.g. at the beginning of a new project. &lt;strong&gt;There is no universal solution. There is no good solution&lt;/strong&gt;. You have to consider the tasks you have to do with your object model and the knowledge level of the colleagues. Usually the later is harder. &lt;strong&gt;How much knowledge people have about JavaScript&lt;/strong&gt; in e.g. Java/C# world? As much as they get along the projects. They teach each other.&amp;nbsp; To good and bed. What I saw in the last years, mostly obsolete and sometimes bad. Not easy to show them the current trends and solutions. Or may I say, contemporary engineering practices. People can, and usually are, be very proud of their coding style, quality, cleverness, etc. How can they be so neglect on these in an other language, e.g. JavaScript?&lt;/p&gt; &lt;p&gt;Now there are &lt;strong&gt;frameworks&lt;/strong&gt; for DOM manipulation (&lt;a href="http://jquery.com/" target="_blank"&gt;jQuery&lt;/a&gt;, &lt;a href="http://dojotoolkit.org/" target="_blank"&gt;dojo&lt;/a&gt;, &lt;a href="http://developer.yahoo.com/yui/" target="_blank"&gt;YUI&lt;/a&gt;), for common tasks (&lt;a href="http://documentcloud.github.com/underscore/" target="_blank"&gt;Underscore&lt;/a&gt;, &lt;a href="http://developer.yahoo.com/yui/" target="_blank"&gt;YUI&lt;/a&gt;, &lt;a href="http://code.google.com/closure/" target="_blank"&gt;Closure&lt;/a&gt;), and there are architectural frameworks (&lt;a href="http://knockoutjs.com/" target="_blank"&gt;Knockout&lt;/a&gt;, &lt;a href="http://documentcloud.github.com/backbone/" target="_blank"&gt;Backbone&lt;/a&gt;) as well. As you can see, they are fractured and you must use different frameworks for different tasks. You should choose well because it’s very very hard to change frameworks, and you have to watch out for compatibility. &lt;strong&gt;Framework version changes&lt;/strong&gt; represent huge risk in the lifetime of a project. Even a minor version change can render your web application totally useless. So test heavily.&lt;/p&gt; &lt;p&gt;No we have two ways. &lt;strong&gt;Full manual testing&lt;/strong&gt; with a lot of humans. Or follow the ‘new’ trend and use some kind of &lt;strong&gt;automated test frameworks&lt;/strong&gt; (&lt;a href="http://seleniumhq.org/" target="_blank"&gt;Selenium&lt;/a&gt;, &lt;a href="http://watir.com/" target="_blank"&gt;Watir&lt;/a&gt;). If they work the way you think. If it’s not more time to maintain your tests than execute them manually.&lt;/p&gt; &lt;p&gt;The same applies to &lt;strong&gt;unit tests&lt;/strong&gt;. There are various frameworks in different flavors (&lt;a href="http://xunit.codeplex.com/" target="_blank"&gt;xUnit&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development" target="_blank"&gt;BDD&lt;/a&gt;, etc.) with different capabilities and APIs. Some live long, some live short. Choose well. Update regularly. Follow the news, trends.&lt;/p&gt; &lt;p&gt;Well, I chose a unit testing framework. Now I should test my code. How? It produces HTML into the DOM and calculates things according to different business rules – in the same function. Well, good luck. &lt;strong&gt;Try separating your business logic from visual stuff&lt;/strong&gt;. Rings the bell? &lt;a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" target="_blank"&gt;MVC&lt;/a&gt;? &lt;a href="http://en.wikipedia.org/wiki/Model_View_ViewModel" target="_blank"&gt;MVVM&lt;/a&gt;? Well, I’d say &lt;a href="http://knockoutjs.com/" target="_blank"&gt;Knockout&lt;/a&gt; and &lt;a href="http://documentcloud.github.com/backbone/" target="_blank"&gt;Backbone&lt;/a&gt;. I’d say use (revealing) module pattern for your view model and your rendering as well. Separate them. Use a framework, e.g. &lt;a href="http://requirejs.org/" target="_blank"&gt;Require.js&lt;/a&gt;. If you do it good, you can even get rid of the inheritance and other OO problems. Now you can test your business logic separated from the UI.&lt;/p&gt; &lt;p&gt;Next problem: I have a &lt;strong&gt;dynamic &lt;a href="http://en.wikipedia.org/wiki/Ajax_(programming)" target="_blank"&gt;AJAX&lt;/a&gt; (AJAJ - Asynchronous Javascript and JSON) application calling back to the server&lt;/strong&gt;. That’s not good. Let’s &lt;a href="http://xunitpatterns.com/Test%20Spy.html" target="_blank"&gt;spy&lt;/a&gt;. Let’s &lt;a href="http://xunitpatterns.com/Test%20Stub.html" target="_blank"&gt;stub&lt;/a&gt;.&amp;nbsp; Let’s &lt;a href="http://xunitpatterns.com/Mock%20Object.html" target="_blank"&gt;mock&lt;/a&gt;. Find a framework, I chose &lt;a href="http://sinonjs.org/" target="_blank"&gt;Sinon&lt;/a&gt;. &lt;/p&gt; &lt;p&gt;So, let’s summarize. I do my job well if I know functions, variables, OO patterns, DOM frameworks, task frameworks, architectural frameworks, testing frameworks, module patterns, JavaScript mocking frameworks. Is that enough?&lt;/p&gt; &lt;p&gt;I have bed news. &lt;strong&gt;We in the web world develop applications like C++ coders develop applications for &lt;a href="http://en.wikipedia.org/wiki/Microsoft_Windows" target="_blank"&gt;Windows&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Linux" target="_blank"&gt;Linux&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Berkeley_Software_Distribution" target="_blank"&gt;BSD&lt;/a&gt;… at the same time with the same code base&lt;/strong&gt;. Instead of OSs, we have browsers and JavaScript standard versions. Now we have mobile devices as well, with different kind of browsers. So keep up, learn and write code in JavaScript. It’s better to learn and understand it than hope for surviving it. &lt;strong&gt;The next few years are about JavaScript and the Web&lt;/strong&gt;. Get used to it, accept it. &lt;strong&gt;Do it as good as you do your job on server-side.&lt;/strong&gt;&lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=tykaDqGpSHU:CoJXwESaCe8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=tykaDqGpSHU:CoJXwESaCe8:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=tykaDqGpSHU:CoJXwESaCe8:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=tykaDqGpSHU:CoJXwESaCe8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=tykaDqGpSHU:CoJXwESaCe8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=tykaDqGpSHU:CoJXwESaCe8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/3878868007371269090/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2012/02/hate-javascript.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/3878868007371269090?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/3878868007371269090?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/tykaDqGpSHU/hate-javascript.html" title="Hate JavaScript?" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2012/02/hate-javascript.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0MDRH44fip7ImA9WhRVGUs.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-2546709197945951837</id><published>2012-01-19T09:24:00.001+01:00</published><updated>2012-01-19T09:24:35.036+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-19T09:24:35.036+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Programming" /><title>jQuery div vs native doc fragment</title><content type="html">&lt;p&gt;I assumed creating a div with jQuery takes more time compared to native document fragment creation. Surprise, I was wrong. I’ve created a test page on JSPerf at &lt;a title="http://jsperf.com/jquery-vs-documentfragment" href="http://jsperf.com/jquery-vs-documentfragment"&gt;http://jsperf.com/jquery-vs-documentfragment&lt;/a&gt;. Simply put, the speed depends on the browser.&lt;/p&gt; &lt;p&gt;&lt;a title="jQuery div vs native document fragment performance" href="http://i63.photobucket.com/albums/h134/artur02/Blog/69c8d554.png" target="_blank"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" src="http://i63.photobucket.com/albums/h134/artur02/Blog/69c8d554.png" width="615" height="310"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Verdict&lt;/strong&gt;: Use document fragment in all browsers except Internet Explorer. In general, use document fragment:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;document.createDocumentFragment();&lt;/code&gt;&lt;/pre&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=iUHox2iA91k:HfdZw1AEmCI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=iUHox2iA91k:HfdZw1AEmCI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=iUHox2iA91k:HfdZw1AEmCI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=iUHox2iA91k:HfdZw1AEmCI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=iUHox2iA91k:HfdZw1AEmCI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=iUHox2iA91k:HfdZw1AEmCI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/2546709197945951837/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2012/01/jquery-div-vs-native-doc-fragment.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/2546709197945951837?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/2546709197945951837?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/iUHox2iA91k/jquery-div-vs-native-doc-fragment.html" title="jQuery div vs native doc fragment" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://i63.photobucket.com/albums/h134/artur02/Blog/th_69c8d554.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2012/01/jquery-div-vs-native-doc-fragment.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEAEQ3Y8eip7ImA9WhRSEko.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-3277649784828831891</id><published>2011-11-14T13:11:00.001+01:00</published><updated>2011-11-14T13:11:42.872+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-14T13:11:42.872+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="Internet" /><title>Less CSS and IIS 7</title><content type="html">&lt;p&gt;In case you are using &lt;a href="http://lesscss.org/"&gt;Less CSS&lt;/a&gt; to generate CSS markups, IIS won’t find your &lt;strong&gt;.less&lt;/strong&gt; files by default. You will get a &lt;strong&gt;404 Not Found&lt;/strong&gt; error. The problem is the missing MIME type.&lt;/p&gt;  &lt;p&gt;The solution is simple, just register the MIME type for .less in web.config:&lt;/p&gt;  &lt;pre&gt;&amp;lt;system.webServer&amp;gt;&lt;br /&gt;  &amp;lt;staticContent&amp;gt;&lt;br /&gt;    &amp;lt;mimeMap fileExtension=&amp;quot;.less&amp;quot; mimeType=&amp;quot;text/css&amp;quot;/&amp;gt;&lt;br /&gt;  &amp;lt;/staticContent&amp;gt;&lt;br /&gt;&amp;lt;/system.webServer&amp;gt;&lt;/pre&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=wqT8j1Gj7Hk:YXQc66A7OPw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=wqT8j1Gj7Hk:YXQc66A7OPw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=wqT8j1Gj7Hk:YXQc66A7OPw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=wqT8j1Gj7Hk:YXQc66A7OPw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=wqT8j1Gj7Hk:YXQc66A7OPw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=wqT8j1Gj7Hk:YXQc66A7OPw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/3277649784828831891/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2011/11/less-css-and-iis-7.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/3277649784828831891?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/3277649784828831891?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/wqT8j1Gj7Hk/less-css-and-iis-7.html" title="Less CSS and IIS 7" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2011/11/less-css-and-iis-7.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkMBR3w-cSp7ImA9WhdVFEg.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-5063986328175351888</id><published>2011-09-18T20:47:00.001+02:00</published><updated>2011-09-19T18:40:56.259+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-19T18:40:56.259+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET MVC" /><title>ASP.NET MVC Internals 3: Controller structure</title><content type="html">Controllers implement the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.icontroller.aspx" target="_blank"&gt;&lt;strong&gt;IController&lt;/strong&gt;&lt;/a&gt; interface:&lt;br /&gt;
&lt;pre class="brush: csharp; gutter: false; toolbar: false;"&gt;public interface IController 
{
    void Execute(RequestContext requestContext);
}&lt;/pre&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.controllerbase.aspx" target="_blank"&gt;&lt;strong&gt;ControllerBase&lt;/strong&gt;&lt;/a&gt; abstract class implements the &lt;em&gt;IController&lt;/em&gt; interface:&lt;br /&gt;
&lt;pre class="brush: csharp; gutter: false; toolbar: false; collapse: true;"&gt;public abstract class ControllerBase : MarshalByRefObject, IController 
{

    private TempDataDictionary _tempDataDictionary;
    private bool _validateRequest = true;
    private IDictionary&amp;lt;string, ValueProviderResult&amp;gt; _valueProvider;
    private ViewDataDictionary _viewDataDictionary;

    public ControllerContext ControllerContext {
        get;
        set;
    }

    public TempDataDictionary TempData {
        get {
            if (_tempDataDictionary == null) {
                _tempDataDictionary = new TempDataDictionary();
            }
            return _tempDataDictionary;
        }
        set {
            _tempDataDictionary = value;
        }
    }

    public bool ValidateRequest {
        get {
            return _validateRequest;
        }
        set {
            _validateRequest = value;
        }
    }

    public IDictionary&amp;lt;string, ValueProviderResult&amp;gt; ValueProvider {
        get {
            if (_valueProvider == null) {
                _valueProvider = new ValueProviderDictionary(ControllerContext);
            }
            return _valueProvider;
        }
        set {
            _valueProvider = value;
        }
    }

    public ViewDataDictionary ViewData {
        get {
            if (_viewDataDictionary == null) {
                _viewDataDictionary = new ViewDataDictionary();
            }
            return _viewDataDictionary;
        }
        set {
            _viewDataDictionary = value;
        }
    }

    protected virtual void Execute(RequestContext requestContext) {
        if (requestContext == null) {
            throw new ArgumentNullException("requestContext");
        }

        Initialize(requestContext);
        ExecuteCore();
    }

    protected abstract void ExecuteCore();

    protected virtual void Initialize(RequestContext requestContext) {
        ControllerContext = new ControllerContext(requestContext, this);
    }
    
    [...]
}&lt;/pre&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
The &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.aspx" target="_blank"&gt;&lt;strong&gt;Controller&lt;/strong&gt;&lt;/a&gt; class derives from &lt;em&gt;ControllerBase&lt;/em&gt; abstract class:&lt;br /&gt;
&lt;pre class="brush: csharp; gutter: false; toolbar: false; collapse: true; highlight: [121];"&gt;public abstract class Controller : ControllerBase, IActionFilter, IAuthorizationFilter, IDisposable, IExceptionFilter, IResultFilter {

    private IActionInvoker _actionInvoker;
    private ModelBinderDictionary _binders;
    private RouteCollection _routeCollection;
    private ITempDataProvider _tempDataProvider;

    public IActionInvoker ActionInvoker {
        get {
            if (_actionInvoker == null) {
                _actionInvoker = new ControllerActionInvoker();
            }
            return _actionInvoker;
        }
        set {
            _actionInvoker = value;
        }
    }

    protected internal ModelBinderDictionary Binders {
        get {
            if (_binders == null) {
                _binders = ModelBinders.Binders;
            }
            return _binders;
        }
        set {
            _binders = value;
        }
    }

    public HttpContextBase HttpContext {
        get {
            return ControllerContext == null ? null : ControllerContext.HttpContext;
        }
    }

    public ModelStateDictionary ModelState {
        get {
            return ViewData.ModelState;
        }
    }

    public HttpRequestBase Request {
        get {
            return HttpContext == null ? null : HttpContext.Request;
        }
    }

    public HttpResponseBase Response {
        get {
            return HttpContext == null ? null : HttpContext.Response;
        }
    }

    internal RouteCollection RouteCollection {
        get {
            if (_routeCollection == null) {
                _routeCollection = RouteTable.Routes;
            }
            return _routeCollection;
        }
        set {
            _routeCollection = value;
        }
    }

    public RouteData RouteData {
        get {
            return ControllerContext == null ? null : ControllerContext.RouteData;
        }
    }

    public HttpServerUtilityBase Server {
        get {
            return HttpContext == null ? null : HttpContext.Server;
        }
    }

    public HttpSessionStateBase Session {
        get {
            return HttpContext == null ? null : HttpContext.Session;
        }
    }

    public ITempDataProvider TempDataProvider {
        get {
            if (_tempDataProvider == null) {
                _tempDataProvider = new SessionStateTempDataProvider();
            }
            return _tempDataProvider;
        }
        set {
            _tempDataProvider = value;
        }
    }

    public UrlHelper Url {
        get;
        set;
    }

    public IPrincipal User {
        get {
            return HttpContext == null ? null : HttpContext.User;
        }
    }

    [...]

    protected internal virtual ContentResult Content(string content, string contentType, Encoding contentEncoding) {
        return new ContentResult {
            Content = content,
            ContentType = contentType,
            ContentEncoding = contentEncoding
        };
    }

    [...]

    protected override void ExecuteCore() {
        TempData.Load(ControllerContext, TempDataProvider);

        try {
            string actionName = RouteData.GetRequiredString("action");
            if (!ActionInvoker.InvokeAction(ControllerContext, actionName)) {
                HandleUnknownAction(actionName);
            }
        }
        finally {
            TempData.Save(ControllerContext, TempDataProvider);
        }
    }

    [...]

    protected internal virtual FilePathResult File(string fileName, string contentType, string fileDownloadName) {
        return new FilePathResult(fileName, contentType) { FileDownloadName = fileDownloadName };
    }

    protected virtual void HandleUnknownAction(string actionName) {
        throw new HttpException(404, String.Format(CultureInfo.CurrentUICulture,
            MvcResources.Controller_UnknownAction, actionName, GetType().FullName));
    }

    protected internal virtual JavaScriptResult JavaScript(string script) {
        return new JavaScriptResult { Script = script };
    }

    [...]

    protected internal virtual JsonResult Json(object data, string contentType, Encoding contentEncoding) {
        return new JsonResult {
            Data = data,
            ContentType = contentType,
            ContentEncoding = contentEncoding
        };
    }

    protected override void Initialize(RequestContext requestContext) {
        base.Initialize(requestContext);
        Url = new UrlHelper(requestContext);
    }

    protected virtual void OnActionExecuting(ActionExecutingContext filterContext) {
    }

    protected virtual void OnActionExecuted(ActionExecutedContext filterContext) {
    }

    protected virtual void OnAuthorization(AuthorizationContext filterContext) {
    }

    protected virtual void OnException(ExceptionContext filterContext) {
    }

    protected virtual void OnResultExecuted(ResultExecutedContext filterContext) {
    }

    protected virtual void OnResultExecuting(ResultExecutingContext filterContext) {
    }

    [...]

    protected internal PartialViewResult PartialView(string viewName) {
        return PartialView(viewName, null /* model */);
    }

    protected internal virtual PartialViewResult PartialView(string viewName, object model) {
        if (model != null) {
            ViewData.Model = model;
        }

        return new PartialViewResult {
            ViewName = viewName,
            ViewData = ViewData,
            TempData = TempData
        };
    }

    protected internal virtual RedirectResult Redirect(string url) {
        [...]
        return new RedirectResult(url);
    }

    protected internal RedirectToRouteResult RedirectToAction(string actionName) {
        return RedirectToAction(actionName, (RouteValueDictionary)null);
    }

    [...]

    protected internal virtual RedirectToRouteResult RedirectToAction(string actionName, string controllerName, RouteValueDictionary routeValues) {
        RouteValueDictionary mergedRouteValues;

        if (RouteData == null) {
            mergedRouteValues = RouteValuesHelpers.MergeRouteValues(actionName, controllerName, null, routeValues, true /* includeImplicitMvcValues */);
        }
        else {
            mergedRouteValues = RouteValuesHelpers.MergeRouteValues(actionName, controllerName, RouteData.Values, routeValues, true /* includeImplicitMvcValues */);
        }

        return new RedirectToRouteResult(mergedRouteValues);
    }

    [...]

    protected internal RedirectToRouteResult RedirectToRoute(string routeName) {
        return RedirectToRoute(routeName, (RouteValueDictionary)null);
    }

    [...]

    protected internal bool TryUpdateModel&amp;lt;TModel&amp;gt;(TModel model) where TModel : class {
        return TryUpdateModel(model, null, null, null, ValueProvider);
    }

    [...]

    protected internal bool TryUpdateModel&amp;lt;TModel&amp;gt;(TModel model, string prefix, string[] includeProperties, string[] excludeProperties, IDictionary&amp;lt;string, ValueProviderResult&amp;gt; valueProvider) where TModel : class {
        [...]

        Predicate&amp;lt;string&amp;gt; propertyFilter = propertyName =&amp;gt; BindAttribute.IsPropertyAllowed(propertyName, includeProperties, excludeProperties);
        IModelBinder binder = Binders.GetBinder(typeof(TModel));

        ModelBindingContext bindingContext = new ModelBindingContext() {
            Model = model,
            ModelName = prefix,
            ModelState = ModelState,
            ModelType = typeof(TModel),
            PropertyFilter = propertyFilter,
            ValueProvider = valueProvider
        };
        binder.BindModel(ControllerContext, bindingContext);
        return ModelState.IsValid;
    }

    protected internal void UpdateModel&amp;lt;TModel&amp;gt;(TModel model) where TModel : class {
        UpdateModel(model, null, null, null, ValueProvider);
    }

    [...]

    protected internal void UpdateModel&amp;lt;TModel&amp;gt;(TModel model, string prefix, string[] includeProperties, string[] excludeProperties, IDictionary&amp;lt;string, ValueProviderResult&amp;gt; valueProvider) where TModel : class {
        bool success = TryUpdateModel(model, prefix, includeProperties, excludeProperties, valueProvider);
        if (!success) {
            string message = String.Format(CultureInfo.CurrentUICulture, MvcResources.Controller_UpdateModel_UpdateUnsuccessful,
                typeof(TModel).FullName);
            throw new InvalidOperationException(message);
        }
    }

    protected internal ViewResult View() {
        return View(null /* viewName */, null /* masterName */, null /* model */);
    }

    protected internal ViewResult View(object model) {
        return View(null /* viewName */, null /* masterName */, model);
    }

    protected internal ViewResult View(string viewName) {
        return View(viewName, null /* masterName */, null /* model */);
    }

    protected internal ViewResult View(string viewName, string masterName) {
        return View(viewName, masterName, null /* model */);
    }

    protected internal ViewResult View(string viewName, object model) {
        return View(viewName, null /* masterName */, model);
    }

    protected internal virtual ViewResult View(string viewName, string masterName, object model) {
        if (model != null) {
            ViewData.Model = model;
        }

        return new ViewResult {
            ViewName = viewName,
            MasterName = masterName,
            ViewData = ViewData,
            TempData = TempData
        };
    }

    protected internal ViewResult View(IView view) {
        return View(view, null /* model */);
    }

    protected internal virtual ViewResult View(IView view, object model) {
        if (model != null) {
            ViewData.Model = model;
        }

        return new ViewResult {
            View = view,
            ViewData = ViewData,
            TempData = TempData
        };
    }

    #region IActionFilter Members
    void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext) {
        OnActionExecuting(filterContext);
    }

    void IActionFilter.OnActionExecuted(ActionExecutedContext filterContext) {
        OnActionExecuted(filterContext);
    }
    #endregion

    #region IAuthorizationFilter Members
    void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext) {
        OnAuthorization(filterContext);
    }
    #endregion

    #region IExceptionFilter Members
    void IExceptionFilter.OnException(ExceptionContext filterContext) {
        OnException(filterContext);
    }
    #endregion

    #region IResultFilter Members
    void IResultFilter.OnResultExecuting(ResultExecutingContext filterContext) {
        OnResultExecuting(filterContext);
    }

    void IResultFilter.OnResultExecuted(ResultExecutedContext filterContext) {
        OnResultExecuted(filterContext);
    }
    #endregion
}&lt;/pre&gt;The Controller class implements the &lt;em&gt;ExecuteCore()&lt;/em&gt; function. It sets the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.tempdatadictionary.aspx" target="_blank"&gt;&lt;em&gt;TempData&lt;/em&gt;&lt;/a&gt; to make it available during the action method execution. The method reads the action name from the &lt;em&gt;RouteData&lt;/em&gt; and calls the action method, identified by the recently read name, using the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.iactioninvoker.aspx" target="_blank"&gt;&lt;em&gt;ActionInvoker.InvokeAction()&lt;/em&gt;&lt;/a&gt; method. &lt;br /&gt;
All the usually used helper methods such as &lt;a href="http://msdn.microsoft.com/en-us/library/dd460331.aspx" target="_blank"&gt;&lt;em&gt;View()&lt;/em&gt;&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/dd470933.aspx" target="_blank"&gt;&lt;em&gt;UpdateModel()&lt;/em&gt;&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/dd492492.aspx" target="_blank"&gt;&lt;em&gt;File()&lt;/em&gt;&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/dd504936.aspx" target="_blank"&gt;&lt;em&gt;Json()&lt;/em&gt;&lt;/a&gt; are defined by the Controller class. &lt;br /&gt;
&lt;a href="http://s63.photobucket.com/albums/h134/artur02/Blog/?action=view&amp;amp;current=d37cdc78.png" target="_blank"&gt;&lt;img alt="ASP.NET MCV: Controller inheritance" border="0" src="http://i63.photobucket.com/albums/h134/artur02/Blog/th_d37cdc78.png" /&gt;&lt;/a&gt;&lt;br /&gt;
Link: &lt;a href="http://artur02.googlecode.com/svn/trunk/AspNetMvc/RequestPipeline/Controller.png" target="_blank"&gt;ASP.NET MVC – Controller inheritance&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=MYRI6CZ3DmE:_8GgVbdMrpE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=MYRI6CZ3DmE:_8GgVbdMrpE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=MYRI6CZ3DmE:_8GgVbdMrpE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=MYRI6CZ3DmE:_8GgVbdMrpE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=MYRI6CZ3DmE:_8GgVbdMrpE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=MYRI6CZ3DmE:_8GgVbdMrpE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/5063986328175351888/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2011/09/aspnet-mvc-internals-3-controller.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/5063986328175351888?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/5063986328175351888?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/MYRI6CZ3DmE/aspnet-mvc-internals-3-controller.html" title="ASP.NET MVC Internals 3: Controller structure" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://i63.photobucket.com/albums/h134/artur02/Blog/th_d37cdc78.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2011/09/aspnet-mvc-internals-3-controller.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ck8ARXs-cCp7ImA9WhdVFEg.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-4539859615961424893</id><published>2011-09-17T18:42:00.001+02:00</published><updated>2011-09-19T18:47:24.558+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-19T18:47:24.558+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET MVC" /><title>ASP.NET MVC Internals 2: Controller</title><content type="html">The &lt;em&gt;&lt;strong&gt;MvcHandler&lt;/strong&gt;&lt;/em&gt; class processes an HTTP request. The routing framework calls its &lt;em&gt;ProcessRequest()&lt;/em&gt; function in case of an incoming request matching an MVC route.&lt;br /&gt;
&lt;pre class="brush: csharp; toolbar: false;"&gt;public class MvcHandler : IHttpHandler, IRequiresSessionState 
{
    [...]
    protected internal virtual void ProcessRequest(HttpContextBase httpContext) 
    {
        AddVersionHeader(httpContext);

        // Get the controller type
        string controllerName = RequestContext.RouteData.GetRequiredString(&amp;amp;quot;controller&amp;amp;quot;);

        // Instantiate the controller and call Execute
        IControllerFactory factory = ControllerBuilder.GetControllerFactory();
        IController controller = factory.CreateController(RequestContext, controllerName);
        if (controller == null) {
            throw new InvalidOperationException(
                String.Format(
                    CultureInfo.CurrentUICulture,
                    MvcResources.ControllerBuilder_FactoryReturnedNull,
                    factory.GetType(),
                    controllerName));
        }
        try {
            controller.Execute(RequestContext);
        }
        finally {
            factory.ReleaseController(controller);
        }
    }
    [...]
}&lt;/pre&gt;&lt;p&gt;Firstly it reads the controller name from the routing data and after that it creates a controller by the name read before. Finally it calls the &lt;em&gt;Execute&lt;/em&gt; method of the controller to run the controller’s code.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
The &lt;em&gt;&lt;strong&gt;ControllerBuilder&lt;/strong&gt;&lt;/em&gt; is a factory for creating the controller instance. &lt;/p&gt;&lt;pre class="brush: csharp; toolbar: false; highlight: [8];"&gt;public class ControllerBuilder 
{
    [...]
    private Func&amp;lt;IControllerFactory&amp;gt; _factoryThunk;

    public ControllerBuilder() 
    {
        SetControllerFactory(new DefaultControllerFactory() {
            ControllerBuilder = this
        });
    }

    [...]
    public IControllerFactory GetControllerFactory() {
        IControllerFactory controllerFactoryInstance = _factoryThunk();
        return controllerFactoryInstance;
    }

    public void SetControllerFactory(IControllerFactory controllerFactory) 
    {
        if (controllerFactory == null) {
            throw new ArgumentNullException("controllerFactory");
        }

        _factoryThunk = () =&amp;gt; controllerFactory;
    }
    [...]
}&lt;/pre&gt;The constructor of the class at line 8 calls the &lt;em&gt;SetControllerFactory&lt;/em&gt; method with a &lt;em&gt;DefaultControllerFactory&lt;/em&gt; instance. Thus the &lt;em&gt;&lt;strong&gt;DefaultControllerFactory&lt;/strong&gt;&lt;/em&gt; class will look up and call the controller with the name provided by the &lt;em&gt;RouteData&lt;/em&gt;.&lt;br /&gt;
&lt;pre class="brush: csharp; gutter: false; toolbar: false;"&gt;public class DefaultControllerFactory : IControllerFactory 
{
    private IBuildManager _buildManager;
    private ControllerBuilder _controllerBuilder;
    private ControllerTypeCache _instanceControllerTypeCache;
    private static ControllerTypeCache _staticControllerTypeCache = new ControllerTypeCache();

    [...]

    public virtual IController CreateController(RequestContext requestContext, string controllerName) 
    {
        [...]
        RequestContext = requestContext;
        Type controllerType = GetControllerType(controllerName);
        IController controller = GetControllerInstance(controllerType);
        return controller;
    }

    protected internal virtual IController GetControllerInstance(Type controllerType) 
    {
        [...]
        try {
            return (IController)Activator.CreateInstance(controllerType);
        }
        catch (Exception ex) {
            throw new InvalidOperationException(
                String.Format(
                    CultureInfo.CurrentUICulture,
                    MvcResources.DefaultControllerFactory_ErrorCreatingController,
                    controllerType),
                ex);
        }
    }

    protected internal virtual Type GetControllerType(string controllerName) 
    {
        [...]

        // first search in the current route's namespace collection
        object routeNamespacesObj;
        Type match;
        [...]

        // then search in the application's default namespace collection
        [...]

        // if all else fails, search every namespace
        return GetControllerTypeWithinNamespaces(controllerName, null /* namespaces */);
    }

    private Type GetControllerTypeWithinNamespaces(string controllerName, HashSet&amp;lt;string&amp;gt; namespaces) 
    {
        // Once the master list of controllers has been created we can quickly index into it
        ControllerTypeCache.EnsureInitialized(BuildManager);

        IList&amp;lt;Type&amp;gt; matchingTypes = ControllerTypeCache.GetControllerTypes(controllerName, namespaces);
        switch (matchingTypes.Count) {
            case 0:
                // no matching types
                return null;

            case 1:
                // single matching type
                return matchingTypes[0];

            default:
                // multiple matching types
                // we need to generate an exception containing all the controller types
                StringBuilder sb = new StringBuilder();
                foreach (Type matchedType in matchingTypes) {
                    sb.AppendLine();
                    sb.Append(matchedType.FullName);
                }
                throw new InvalidOperationException([...]);
        }
    }

}&lt;/pre&gt;As soon as the &lt;em&gt;DefaultControllerFactory.CreateController&lt;/em&gt; function, it finds the type of the controller by its name and creates an instance after that. The framework uses the &lt;em&gt;&lt;strong&gt;ControllerTypeCache&lt;/strong&gt;&lt;/em&gt; class to find the controller types. &lt;br /&gt;
&lt;pre class="brush: csharp; gutter: false; toolbar: false;"&gt;internal sealed class ControllerTypeCache 
{
    [...]

    public void EnsureInitialized(IBuildManager buildManager) 
    {
        if (_cache == null) {
            lock (_lockObj) {
                if (_cache == null) {
                    List&amp;lt;Type&amp;gt; controllerTypes = GetAllControllerTypes(buildManager);
                    [...]
                }
            }
        }
    }

    private static List&amp;lt;Type&amp;gt; GetAllControllerTypes(IBuildManager buildManager) 
    {
        // Go through all assemblies referenced by the application and search for
        // controllers and controller factories.
        List&amp;lt;Type&amp;gt; controllerTypes = new List&amp;lt;Type&amp;gt;();
        ICollection assemblies = buildManager.GetReferencedAssemblies();
        foreach (Assembly assembly in assemblies) {
            Type[] typesInAsm;
            try {
                typesInAsm = assembly.GetTypes();
            }
            catch (ReflectionTypeLoadException ex) {
                typesInAsm = ex.Types;
            }
            controllerTypes.AddRange(typesInAsm.Where(IsControllerType));
        }
        return controllerTypes;
    }

    [...]

    internal static bool IsControllerType(Type t) {
        return
            t != null &amp;amp;&amp;amp;
            t.IsPublic &amp;amp;&amp;amp;
            t.Name.EndsWith("Controller", StringComparison.OrdinalIgnoreCase) &amp;amp;&amp;amp;
            !t.IsAbstract &amp;amp;&amp;amp;
            typeof(IController).IsAssignableFrom(t);
    }
}&lt;/pre&gt;The &lt;em&gt;ControllerTypeCache.EnsureInitialized&lt;/em&gt; (called by &lt;em&gt;DefaultControllerFactory.GetControllerTypeWithinNamespaces&lt;/em&gt;) uses the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.compilation.buildmanager.aspx" target="_blank"&gt;BuildManager&lt;/a&gt; class (in MVC, wrapped by &lt;em&gt;BuildManagerWrapper&lt;/em&gt; that implements the internal &lt;em&gt;IBuildManager&lt;/em&gt; interface) to find the available assemblies. The &lt;em&gt;ControllerTypeCache.GetAllControllerTypes&lt;/em&gt; returns the controller types referenced by the project. A class is a controller type if the class is&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;public &lt;/li&gt;
&lt;li&gt;its name ends with “Controller”, casing is ignored &lt;/li&gt;
&lt;li&gt;the type is not abstract &lt;/li&gt;
&lt;li&gt;the type “implements” (can be assigned to) the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.icontroller.aspx" target="_blank"&gt;IController&lt;/a&gt; interface. &lt;/li&gt;
&lt;/ul&gt;Finally the &lt;em&gt;DefaultControllerFactory.GetControllerInstance&lt;/em&gt; creates the instance for the Type using &lt;a href="http://msdn.microsoft.com/en-us/library/wccyzw83.aspx" target="_blank"&gt;&lt;em&gt;Activator.CreateInstance()&lt;/em&gt;&lt;/a&gt; method. Now we have the controller instance to work with.&lt;br /&gt;
The &lt;em&gt;MvcHandler.ProcessRequest()&lt;/em&gt; calls the &lt;em&gt;controller.Execute()&lt;/em&gt; to run the controller code.&lt;br /&gt;
&lt;a href="http://s63.photobucket.com/albums/h134/artur02/Blog/?action=view&amp;amp;current=80d84305.png" target="_blank"&gt;&lt;img alt="ASP.NET MVC Finding Controller" border="0" src="http://i63.photobucket.com/albums/h134/artur02/Blog/th_80d84305.png" /&gt;&lt;/a&gt; &lt;br /&gt;
Link: &lt;a href="http://i63.photobucket.com/albums/h134/artur02/Blog/80d84305.png" target="_blank"&gt;ASP.NET MVC – Finding the controller&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=9x1jJzZr_1s:ltNRlCNqI9Q:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=9x1jJzZr_1s:ltNRlCNqI9Q:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=9x1jJzZr_1s:ltNRlCNqI9Q:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=9x1jJzZr_1s:ltNRlCNqI9Q:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=9x1jJzZr_1s:ltNRlCNqI9Q:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=9x1jJzZr_1s:ltNRlCNqI9Q:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/4539859615961424893/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2011/09/aspnet-mvc-internals-2-controller.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/4539859615961424893?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/4539859615961424893?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/9x1jJzZr_1s/aspnet-mvc-internals-2-controller.html" title="ASP.NET MVC Internals 2: Controller" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://i63.photobucket.com/albums/h134/artur02/Blog/th_80d84305.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2011/09/aspnet-mvc-internals-2-controller.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUUMQnsyfyp7ImA9WhdVEkU.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-2715534065769580403</id><published>2011-09-15T10:11:00.001+02:00</published><updated>2011-09-17T20:14:43.597+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-17T20:14:43.597+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET MVC" /><title>ASP.NET MVC Internals 1: Bootstrapping</title><content type="html">&lt;p&gt;The topic of this article is the ASP.NET MVC bootstrapping process.&lt;/p&gt;&lt;p&gt;Everything starts in &lt;strong&gt;Global.asax&lt;/strong&gt;:&lt;/p&gt;&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:795f1de5-a86c-43dd-b1b2-1ff40b358afe" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: c#;gutter:false;toolbar:false;"&gt;public class MvcApplication : System.Web.HttpApplication
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

    }

    protected void Application_Start()
    {
        RegisterRoutes(RouteTable.Routes);
    }
}&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This code initializes the ASP.NET Routing framework. The MapRoute() function is an extension method, defined in &lt;strong&gt;RouteCollectionExtensions.cs&lt;/strong&gt;. It’s code is simple:&lt;/p&gt;&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:984baf9e-d0f4-4ab5-8eec-0df8ecacf521" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: c#;toolbar:false;"&gt;public static Route MapRoute(this RouteCollection routes, string name, string url, object defaults, object constraints, string[] namespaces) {
	if (routes == null) {
		throw new ArgumentNullException("routes");
	}
	if (url == null) {
		throw new ArgumentNullException("url");
	}

	Route route = new Route(url, new MvcRouteHandler()) {
		Defaults = new RouteValueDictionary(defaults),
		Constraints = new RouteValueDictionary(constraints)
	};

	if ((namespaces != null) &amp;amp;&amp;amp; (namespaces.Length &amp;gt; 0)) {
		route.DataTokens = new RouteValueDictionary();
		route.DataTokens["Namespaces"] = namespaces;
	}

	routes.Add(name, route);

	return route;
}&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Simply creates a route with an MvcRouteHandler at line 9. ASP.NET MVC registers this routing handler to catch the routing requests (&lt;strong&gt;MvcRouteHandler.cs&lt;/strong&gt;):&lt;/p&gt;&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:dc078b00-3c45-4e1d-944a-151f58006284" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: c#;gutter:false;toolbar:false;"&gt;namespace System.Web.Mvc {
    using System.Web.Routing;

    public class MvcRouteHandler : IRouteHandler {
        protected virtual IHttpHandler GetHttpHandler(RequestContext requestContext) {
            return new MvcHandler(requestContext);
        }

        #region IRouteHandler Members
        IHttpHandler IRouteHandler.GetHttpHandler(RequestContext requestContext) {
            return GetHttpHandler(requestContext);
        }
        #endregion
    }
}&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This code registers the MvcHandler class (&lt;strong&gt;MvcHandler.cs&lt;/strong&gt;) for handling MVC routing requests:&lt;/p&gt;&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:e22c9dd9-8d14-48ee-ac83-7183e35a997f" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: c#;gutter:false;toolbar:false;"&gt;public class MvcHandler : IHttpHandler, IRequiresSessionState 
{ [...] }&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The class implements the &lt;a href="http://msdn.microsoft.com/en-us/library/7ezc17x8.aspx" target="_blank"&gt;IHttpHandler&lt;/a&gt; interface from System.Web.dll to be able to ‘synchronously process HTTP Web requests using custom HTTP handlers’. This interface has only one method: &lt;/p&gt;&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:b7435f46-307c-478a-848b-0268d0674fb1" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: c#;gutter:false;toolbar:false;"&gt;void ProcessRequest(httpContext context)&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The implementation of this method will handle the HTTP request. It builds up the MVC infrastructure and calls the appropriate classes (in transitive way) to select the controller, find the action method and do all the related functionality.&lt;/p&gt;&lt;p&gt;&lt;a href="http://s63.photobucket.com/albums/h134/artur02/Blog/?action=view&amp;amp;current=f63d836e.png" target="_blank"&gt;&lt;img src="http://i63.photobucket.com/albums/h134/artur02/Blog/th_f63d836e.png" border="0" alt="Photobucket" &gt;&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;Link: &lt;a href="http://i63.photobucket.com/albums/h134/artur02/Blog/f63d836e.png" target="_blank"&gt;ASP.MET MVC Bootstrapping process&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=cd9pN8HUS5A:QnOBsbIXbwo:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=cd9pN8HUS5A:QnOBsbIXbwo:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=cd9pN8HUS5A:QnOBsbIXbwo:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=cd9pN8HUS5A:QnOBsbIXbwo:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=cd9pN8HUS5A:QnOBsbIXbwo:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=cd9pN8HUS5A:QnOBsbIXbwo:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/2715534065769580403/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2011/09/aspnet-mvc-internals-1.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/2715534065769580403?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/2715534065769580403?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/cd9pN8HUS5A/aspnet-mvc-internals-1.html" title="ASP.NET MVC Internals 1: Bootstrapping" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://i63.photobucket.com/albums/h134/artur02/Blog/th_f63d836e.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2011/09/aspnet-mvc-internals-1.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0UDRnY6eyp7ImA9Wx9REUo.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-9138791909410880456</id><published>2010-12-12T18:34:00.001+01:00</published><updated>2010-12-12T18:34:37.813+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-12T18:34:37.813+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Programming" /><category scheme="http://www.blogger.com/atom/ns#" term="Internet" /><title>jQuery and DOM dimension measurement</title><content type="html">&lt;p&gt;I had to rewrite a code that used standard DOM functions (like offsetWidth) to jQuery functions (like outerWidth).    &lt;br /&gt;This is a simple document visually summarizing the differences.&lt;/p&gt;  &lt;p&gt;Link: &lt;a href="http://code.google.com/p/artur02/source/browse/trunk/docs/jQueryHtmlHeight/jQueryHtmlHeight.docx?r=10" target="_blank"&gt;jQuery HMTL with height cheat sheet (DOCX)&lt;/a&gt;     &lt;br /&gt;Link: &lt;a href="http://code.google.com/p/artur02/source/browse/trunk/docs/jQueryHtmlHeight/jQueryHtmlHeight.pdf?r=10" target="_blank"&gt;jQuery HMTL with height cheat sheet (PDF)&lt;/a&gt;&lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=LIN1WaZ3X7E:cHBSiQCoAz4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=LIN1WaZ3X7E:cHBSiQCoAz4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=LIN1WaZ3X7E:cHBSiQCoAz4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=LIN1WaZ3X7E:cHBSiQCoAz4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=LIN1WaZ3X7E:cHBSiQCoAz4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=LIN1WaZ3X7E:cHBSiQCoAz4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/9138791909410880456/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2010/12/jquery-and-dom-dimension-measurement.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/9138791909410880456?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/9138791909410880456?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/LIN1WaZ3X7E/jquery-and-dom-dimension-measurement.html" title="jQuery and DOM dimension measurement" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2010/12/jquery-and-dom-dimension-measurement.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0UBQXk9fCp7ImA9Wx9TFEg.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-4157840089121160363</id><published>2010-11-22T21:54:00.001+01:00</published><updated>2010-11-22T21:54:10.764+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-22T21:54:10.764+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Programming" /><category scheme="http://www.blogger.com/atom/ns#" term="C++" /><title>WaitableTimer in C++</title><content type="html">&lt;p&gt;This is an example code for calling a &lt;strong&gt;waitable timer&lt;/strong&gt;. This is a good way to wait for a timer event without using CPU (thread blocks). There is a small &lt;strong&gt;trick in the code&lt;/strong&gt;. It’s hard to create a FILETIME properly so I create a SYSTEMTIME (and set it according to my needs), convert it to FILETIME, finally I cast that to LARGE_INTEGER* (to fulfill the needs of SetWaitableTimer).&lt;/p&gt;  &lt;p&gt;I set the timer to &lt;strong&gt;autoreset&lt;/strong&gt;, so it will restart counting after firing the event (counts again and again). The first event (“CALLED”) occurs after 3 secs, the subsequent events occur after 2 secs.&lt;/p&gt;  &lt;p&gt;The &lt;strong&gt;WaitForSingleObject&lt;/strong&gt; blocks until a timer event is fired. I break the loop after 5 events, stop the timer and delete the timer handle.&lt;/p&gt;    &lt;h3&gt;stdafx.h&lt;/h3&gt;  &lt;div id="codeSnippetWrapper"&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" id="codeSnippet"&gt;&lt;span style="color: #cc6633"&gt;#pragma&lt;/span&gt; &lt;span style="color: #cc6633"&gt;once&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &lt;span style="color: #006080"&gt;&amp;quot;targetver.h&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &amp;lt;stdio.h&amp;gt;&lt;br /&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &amp;lt;tchar.h&amp;gt;&lt;br /&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &amp;lt;Windows.h&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; std;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;h3&gt;WaitableTimer.cpp&lt;/h3&gt;

&lt;div id="codeSnippetWrapper"&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" id="codeSnippet"&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &lt;span style="color: #006080"&gt;&amp;quot;stdafx.h&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; _tmain(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; argc, _TCHAR* argv[])&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; count = 0;    &lt;span style="color: #008000"&gt;// Iteration counter&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    HANDLE hTimer = NULL;    &lt;span style="color: #008000"&gt;// WaitableTimer handle&lt;/span&gt;&lt;br /&gt;    hTimer = CreateWaitableTimer(    &lt;span style="color: #008000"&gt;// Create waitable timer&lt;/span&gt;&lt;br /&gt;        NULL,&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;FALSE&lt;/span&gt;,    &lt;span style="color: #008000"&gt;// Autoreset --&amp;gt; timer restarts counting after event fired&lt;/span&gt;&lt;br /&gt;        NULL);&lt;br /&gt;&lt;br /&gt;    SYSTEMTIME time;        &lt;span style="color: #008000"&gt;// System time structure&lt;/span&gt;&lt;br /&gt;    GetSystemTime(&amp;amp;time);    &lt;span style="color: #008000"&gt;// Curren time&lt;/span&gt;&lt;br /&gt;    time.wSecond += 3;        &lt;span style="color: #008000"&gt;// Wait 3 sec&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    FILETIME ftime;    &lt;span style="color: #008000"&gt;// File time (expected by SetWaitableTimer)&lt;/span&gt;&lt;br /&gt;    SystemTimeToFileTime(&amp;amp;time, &amp;amp;ftime);    &lt;span style="color: #008000"&gt;// Convert system to file time&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(!SetWaitableTimer(    &lt;span style="color: #008000"&gt;// Set waitable timer&lt;/span&gt;&lt;br /&gt;        hTimer,    &lt;span style="color: #008000"&gt;// Timer handle&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;reinterpret_cast&lt;/span&gt;&amp;lt;LARGE_INTEGER*&amp;gt;(&amp;amp;ftime),    &lt;span style="color: #008000"&gt;// Convert file time to large integer&lt;/span&gt;&lt;br /&gt;        2000,    &lt;span style="color: #008000"&gt;// Period time, fire again after 2 sec&lt;/span&gt;&lt;br /&gt;        NULL,&lt;br /&gt;        NULL,&lt;br /&gt;        0))&lt;br /&gt;    {&lt;br /&gt;            cout &amp;lt;&amp;lt; &lt;span style="color: #006080"&gt;&amp;quot;SetWaitableTimer failed&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt;  GetLastError() &amp;lt;&amp;lt; endl;&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;while&lt;/span&gt;(WaitForSingleObject(hTimer, 5000) == WAIT_OBJECT_0){    &lt;span style="color: #008000"&gt;// Wait for timer event&lt;/span&gt;&lt;br /&gt;        cout &amp;lt;&amp;lt; &lt;span style="color: #006080"&gt;&amp;quot;CALLED &amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; ++count &amp;lt;&amp;lt; endl;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(count+1 &amp;gt; 5){    &lt;span style="color: #008000"&gt;// Exit after 5 events&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;        &lt;br /&gt;    CancelWaitableTimer(hTimer);    &lt;span style="color: #008000"&gt;// Stop timer&lt;/span&gt;&lt;br /&gt;    CloseHandle(hTimer);            &lt;span style="color: #008000"&gt;// Delete handle&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;See source code&lt;/strong&gt;: &lt;a href="http://code.google.com/p/artur02/source/browse/trunk/CPP/WaitableTimer/WaitableTimer.cpp"&gt;http://code.google.com/p/artur02/source/browse/trunk/CPP/WaitableTimer/WaitableTimer.cpp&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Waitable timer objects: &lt;a href="http://msdn.microsoft.com/en-us/library/ms687012(VS.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/ms687012(VS.85).aspx&lt;/a&gt;

  &lt;br /&gt;CreateWaitableTimer function: &lt;a href="http://msdn.microsoft.com/en-us/library/ms682492(v=VS.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/ms682492(v=VS.85).aspx&lt;/a&gt;

  &lt;br /&gt;SetWaitableTimer function: &lt;a href="http://msdn.microsoft.com/en-us/library/ms686289(v=VS.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/ms686289(v=VS.85).aspx&lt;/a&gt;

  &lt;br /&gt;Systemtime structure: &lt;a href="http://msdn.microsoft.com/en-us/library/ms687008(v=VS.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/ms687008(v=VS.85).aspx&lt;/a&gt;

  &lt;br /&gt;Usage example: &lt;a href="http://msdn.microsoft.com/en-us/library/ms687008(v=VS.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/ms687008(v=VS.85).aspx&lt;/a&gt;&lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=fALS4d03NDg:HUjjOaMouo0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=fALS4d03NDg:HUjjOaMouo0:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=fALS4d03NDg:HUjjOaMouo0:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=fALS4d03NDg:HUjjOaMouo0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=fALS4d03NDg:HUjjOaMouo0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=fALS4d03NDg:HUjjOaMouo0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/4157840089121160363/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2010/11/waitabletimer-in-c.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/4157840089121160363?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/4157840089121160363?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/fALS4d03NDg/waitabletimer-in-c.html" title="WaitableTimer in C++" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2010/11/waitabletimer-in-c.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0MHQHszfSp7ImA9Wx5aEEk.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-2336633939422852102</id><published>2010-11-06T12:03:00.001+01:00</published><updated>2010-11-06T12:03:51.585+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-06T12:03:51.585+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Programming" /><title>Perforce file exclusion</title><content type="html">&lt;p&gt;There are file types and folders I don’t want to see in a source control repository. These are user-specific settings, temporary folders and binaries. There is a simple client-side way to exclude these files and folders. Just add the following lines to your workspace definition:&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="598"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="363"&gt;&lt;strong&gt;Pattern&lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="233"&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="363"&gt;         &lt;pre&gt;-//depot/.../*.suo //WORKSPACE/.../*.suo&lt;/pre&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="233"&gt;Solution user options file.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="363"&gt;
        &lt;pre&gt;-//depot/.../bin/... //WORKSPACE/.../bin/...&lt;/pre&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="233"&gt;Generated binaries.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="363"&gt;
        &lt;pre&gt;-//depot/.../obj/... //WORKSPACE/.../obj/...&lt;/pre&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="233"&gt;Object files.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="363"&gt;
        &lt;pre&gt;-//depot/.../*.user //WORKSPACE/.../*.user&lt;/pre&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="233"&gt;User settings. Can contain useful information, e.g. startup parameters.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=dAmx8sSPlEM:a9TynD0R5yA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=dAmx8sSPlEM:a9TynD0R5yA:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=dAmx8sSPlEM:a9TynD0R5yA:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=dAmx8sSPlEM:a9TynD0R5yA:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=dAmx8sSPlEM:a9TynD0R5yA:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=dAmx8sSPlEM:a9TynD0R5yA:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/2336633939422852102/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2010/11/perforce-file-exclusion.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/2336633939422852102?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/2336633939422852102?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/dAmx8sSPlEM/perforce-file-exclusion.html" title="Perforce file exclusion" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2010/11/perforce-file-exclusion.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkAASX87eCp7ImA9Wx5aEEk.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-5084535758128752632</id><published>2010-11-06T11:51:00.001+01:00</published><updated>2010-11-06T11:52:28.100+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-06T11:52:28.100+01:00</app:edited><title>CV Tag Cloud</title><content type="html">&lt;p&gt;&lt;a href="http://www.wordle.net/show/wrdl/2686570/CV" target="_blank"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; border-top: 0px; border-right: 0px; padding-top: 0px" border="0" src="http://i63.photobucket.com/albums/h134/artur02/Blog/6466b550.png" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The tag cloud of my CV. Can be viewed in full size: &lt;a href="http://www.wordle.net/show/wrdl/2686570/CV"&gt;http://www.wordle.net/show/wrdl/2686570/CV&lt;/a&gt;&lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=ew1y8yDAPvQ:KsmNXDspDhM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=ew1y8yDAPvQ:KsmNXDspDhM:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=ew1y8yDAPvQ:KsmNXDspDhM:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=ew1y8yDAPvQ:KsmNXDspDhM:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=ew1y8yDAPvQ:KsmNXDspDhM:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=ew1y8yDAPvQ:KsmNXDspDhM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/5084535758128752632/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2010/11/cv-tag-cloud.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/5084535758128752632?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/5084535758128752632?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/ew1y8yDAPvQ/cv-tag-cloud.html" title="CV Tag Cloud" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://i63.photobucket.com/albums/h134/artur02/Blog/th_6466b550.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2010/11/cv-tag-cloud.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0UARHw6fip7ImA9Wx5bFU4.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-2515990663665082279</id><published>2010-10-31T15:19:00.001+01:00</published><updated>2010-10-31T15:27:25.216+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-31T15:27:25.216+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Programming" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>Simple Map Reduce Example in C#</title><content type="html">&lt;p&gt;This is an example of map-reduce implementation for IEnumerable. This code is not optimized. I think we shouldn’t create separate Task for each enumerated item. Probably partitioning the enumeration and dealing with bigger chunks of data would be much more efficient.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Browse source code&lt;/strong&gt;: &lt;a href="http://code.google.com/p/artur02/source/browse/#svn/trunk/MapReduce" target="_blank"&gt;Google Code&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;MapReduce function for IEnumerable:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Collections;

namespace MapReduceCode
{
    public static class MapReduce
    {
        public static Task&amp;lt;TResult&amp;gt; ForEachParallel&amp;lt;TItem, TSubResult, TResult, TParam&amp;gt;(this IEnumerable items, Func&amp;lt;TItem, TParam, TSubResult&amp;gt; map, Func&amp;lt;TSubResult[], TResult&amp;gt; reduce, TParam &lt;span class="kwrd"&gt;param&lt;/span&gt;)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (items == null) { &lt;span class="kwrd"&gt;throw&lt;/span&gt; new ArgumentNullException(&lt;span class="str"&gt;&amp;quot;items&amp;quot;&lt;/span&gt;); }
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (map == null) { &lt;span class="kwrd"&gt;throw&lt;/span&gt; new ArgumentNullException(&lt;span class="str"&gt;&amp;quot;map&amp;quot;&lt;/span&gt;); }
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (reduce == null) { &lt;span class="kwrd"&gt;throw&lt;/span&gt; new ArgumentNullException(&lt;span class="str"&gt;&amp;quot;reduce&amp;quot;&lt;/span&gt;); }

            &lt;span class="kwrd"&gt;return&lt;/span&gt; Task&amp;lt;TResult&amp;gt;.Factory.StartNew(() =&amp;gt;
            {
                List&amp;lt;Task&amp;lt;TSubResult&amp;gt;&amp;gt; tasks = new List&amp;lt;Task&amp;lt;TSubResult&amp;gt;&amp;gt;();

                &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (TItem item &lt;span class="kwrd"&gt;in&lt;/span&gt; items)
                {
                    Task&amp;lt;TSubResult&amp;gt; t = Task&amp;lt;TSubResult&amp;gt;.Factory.StartNew(item2 =&amp;gt;
                        {
                            var mparam = (Tuple&amp;lt;TItem, TParam&amp;gt;)item2;
                            &lt;span class="kwrd"&gt;return&lt;/span&gt; map(mparam.Item1, mparam.Item2);
                        },
                        new Tuple&amp;lt;TItem, TParam&amp;gt;(item, &lt;span class="kwrd"&gt;param&lt;/span&gt;),
                        TaskCreationOptions.None | TaskCreationOptions.AttachedToParent);
                    tasks.Add(t);
                }

                List&amp;lt;TSubResult&amp;gt; results = new List&amp;lt;TSubResult&amp;gt;();
                &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Task&amp;lt;TSubResult&amp;gt; task &lt;span class="kwrd"&gt;in&lt;/span&gt; tasks)
                {
                    results.Add(task.Result);
                }

                &lt;span class="kwrd"&gt;return&lt;/span&gt; reduce(results.ToArray());
            });
        }
    }
}&lt;/pre&gt;

&lt;p&gt;Usage example: &lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections;
&lt;span class="kwrd"&gt;using&lt;/span&gt; MapReduceCode;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Threading;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Threading.Tasks;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MapReduce
{
    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program
    {
        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)
        {
            var a = Generate().ForEachParallel&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;(
                (element, param)=&amp;gt; 
                {
                    var result = element * param;
                    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Map: {0}, {1}&amp;quot;&lt;/span&gt;, result, Task.CurrentId);
                    Thread.Sleep(&lt;span class="kwrd"&gt;new&lt;/span&gt; Random(DateTime.Now.Millisecond).Next(500));
                    &lt;span class="kwrd"&gt;return&lt;/span&gt; result;
                }, 
                (subresult)=&amp;gt;
                {
                    var sum = 0;
                    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var item &lt;span class="kwrd"&gt;in&lt;/span&gt; subresult)
                    {
                        sum += item;
                    }
                    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Reduce: {0}&amp;quot;&lt;/span&gt;, sum);
                    &lt;span class="kwrd"&gt;return&lt;/span&gt; sum;
                }, 
                5);

            Console.WriteLine(a.Result);
            
        }

        &lt;span class="kwrd"&gt;static&lt;/span&gt; IEnumerable Generate()
        {
            &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 100; i++)
            {
                &lt;span class="kwrd"&gt;yield&lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; i;
            }
        }
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Result:&lt;/p&gt;

&lt;p&gt;&lt;font face="Consolas"&gt;Map: 0, 1
    &lt;br /&gt;Map: 5, 2

    &lt;br /&gt;Map: 10, 3

    &lt;br /&gt;Map: 20, 4

    &lt;br /&gt;Map: 15, 5

    &lt;br /&gt;Map: 25, 6

    &lt;br /&gt;Map: 30, 7

    &lt;br /&gt;Map: 35, 8

    &lt;br /&gt;Map: 40, 9

    &lt;br /&gt;Map: 45, 10

    &lt;br /&gt;Map: 50, 11

    &lt;br /&gt;Map: 55, 12

    &lt;br /&gt;Map: 60, 13

    &lt;br /&gt;Map: 65, 14

    &lt;br /&gt;Map: 70, 15

    &lt;br /&gt;Map: 75, 16

    &lt;br /&gt;Map: 80, 17

    &lt;br /&gt;Map: 85, 18

    &lt;br /&gt;Map: 90, 19

    &lt;br /&gt;Map: 95, 20

    &lt;br /&gt;Map: 100, 21

    &lt;br /&gt;Map: 105, 22

    &lt;br /&gt;Map: 110, 23

    &lt;br /&gt;Map: 115, 24

    &lt;br /&gt;Map: 120, 25

    &lt;br /&gt;Map: 125, 26

    &lt;br /&gt;Map: 130, 27

    &lt;br /&gt;Map: 135, 28

    &lt;br /&gt;Map: 140, 29

    &lt;br /&gt;Map: 145, 30

    &lt;br /&gt;Map: 150, 31

    &lt;br /&gt;Map: 155, 32

    &lt;br /&gt;Map: 160, 33

    &lt;br /&gt;Map: 165, 34

    &lt;br /&gt;Map: 170, 35

    &lt;br /&gt;Map: 175, 36

    &lt;br /&gt;Map: 180, 37

    &lt;br /&gt;Map: 185, 38

    &lt;br /&gt;Map: 190, 39

    &lt;br /&gt;Map: 195, 40

    &lt;br /&gt;Map: 200, 41

    &lt;br /&gt;Map: 205, 42

    &lt;br /&gt;Map: 210, 43

    &lt;br /&gt;Map: 215, 44

    &lt;br /&gt;Map: 225, 45

    &lt;br /&gt;&lt;em&gt;&lt;strong&gt;Map: 230, 47&lt;/strong&gt;

      &lt;br /&gt;&lt;/em&gt;Map: 220, 46

    &lt;br /&gt;Map: 235, 48

    &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Map: 245, 50&lt;/em&gt;&lt;/strong&gt;

    &lt;br /&gt;Map: 240, 49

    &lt;br /&gt;Map: 250, 51

    &lt;br /&gt;Map: 255, 52

    &lt;br /&gt;Map: 260, 53

    &lt;br /&gt;Map: 265, 54

    &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Map: 275, 56
        &lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;Map: 270, 55

    &lt;br /&gt;Map: 285, 57

    &lt;br /&gt;Map: 280, 58

    &lt;br /&gt;Map: 290, 59

    &lt;br /&gt;Map: 295, 60

    &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Map: 300, 62&lt;/em&gt;&lt;/strong&gt;

    &lt;br /&gt;Map: 305, 61

    &lt;br /&gt;Map: 310, 63

    &lt;br /&gt;Map: 315, 64

    &lt;br /&gt;Map: 320, 65

    &lt;br /&gt;Map: 325, 66

    &lt;br /&gt;Map: 330, 67

    &lt;br /&gt;Map: 335, 68

    &lt;br /&gt;Map: 340, 69

    &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Map: 355, 72&lt;/em&gt;&lt;/strong&gt;

    &lt;br /&gt;Map: 350, 71

    &lt;br /&gt;Map: 360, 73

    &lt;br /&gt;Map: 365, 74

    &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Map: 345, 70&lt;/em&gt;&lt;/strong&gt;

    &lt;br /&gt;Map: 370, 75

    &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Map: 380, 77&lt;/em&gt;&lt;/strong&gt;

    &lt;br /&gt;Map: 375, 76

    &lt;br /&gt;Map: 390, 79

    &lt;br /&gt;Map: 395, 80

    &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Map: 385, 78&lt;/em&gt;&lt;/strong&gt;

    &lt;br /&gt;Map: 400, 81

    &lt;br /&gt;Map: 405, 82

    &lt;br /&gt;Map: 415, 84

    &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Map: 425, 86
        &lt;br /&gt;Map: 410, 83&lt;/em&gt;&lt;/strong&gt;

    &lt;br /&gt;Map: 420, 85

    &lt;br /&gt;Map: 430, 87

    &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Map: 440, 89&lt;/em&gt;&lt;/strong&gt;

    &lt;br /&gt;Map: 435, 88

    &lt;br /&gt;Map: 450, 90

    &lt;br /&gt;Map: 445, 91

    &lt;br /&gt;Map: 455, 92

    &lt;br /&gt;Map: 460, 93

    &lt;br /&gt;Map: 470, 95

    &lt;br /&gt;Map: 480, 97

    &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Map: 475, 96&lt;/em&gt;&lt;/strong&gt;

    &lt;br /&gt;Map: 485, 98

    &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Map: 465, 94&lt;/em&gt;&lt;/strong&gt;

    &lt;br /&gt;Map: 490, 99

    &lt;br /&gt;Map: 495, 100

    &lt;br /&gt;Reduce: 24750

    &lt;br /&gt;24750&lt;/font&gt;&lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=AMqkNRmXQfM:bccnqg2P-OU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=AMqkNRmXQfM:bccnqg2P-OU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=AMqkNRmXQfM:bccnqg2P-OU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=AMqkNRmXQfM:bccnqg2P-OU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=AMqkNRmXQfM:bccnqg2P-OU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=AMqkNRmXQfM:bccnqg2P-OU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/2515990663665082279/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2010/10/simple-map-reduce-example-in-c.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/2515990663665082279?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/2515990663665082279?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/AMqkNRmXQfM/simple-map-reduce-example-in-c.html" title="Simple Map Reduce Example in C#" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>2</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2010/10/simple-map-reduce-example-in-c.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEIHQHcycSp7ImA9WxFXEkU.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-8407657171768765254</id><published>2010-05-19T18:28:00.001+02:00</published><updated>2010-05-19T18:28:51.999+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-05-19T18:28:51.999+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="Programming" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>CAL and AutoMapper</title><content type="html">&lt;p&gt;I’m using &lt;strong&gt;Composite Application Library&lt;/strong&gt; (CAL) in a project. I decided to use &lt;strong&gt;AutoMapper&lt;/strong&gt; as well. I put AutoMapper’s &lt;em&gt;Mapper.CreateMap&amp;lt;source, dest&amp;gt;()&lt;/em&gt; calls into one of the &lt;em&gt;Bootstrapper.cs&lt;/em&gt; methods. I got an &lt;strong&gt;InvalidOperationException in the ModuleCatalog’s InnerLoad()&lt;/strong&gt; function.&lt;/p&gt;  &lt;h3&gt;Reason&lt;/h3&gt;  &lt;p&gt;AutoMapper creates an in-memory assembly and CAL tries to read all the assemblies’ &lt;em&gt;Location&lt;/em&gt; property. This property raises an InvalidOperationException in case of in-memory assemblies.&lt;/p&gt;  &lt;h3&gt;Solution&lt;/h3&gt;  &lt;p&gt;Insert AutoMapper mappings right after the &lt;em&gt;Bootstrapper.Run()&lt;/em&gt; call. In my case I call this in &lt;em&gt;App.xaml.cs&lt;/em&gt;, so you can write the following:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnStartup(StartupEventArgs e)
{
    &lt;span class="kwrd"&gt;base&lt;/span&gt;.OnStartup(e);

    &lt;span class="rem"&gt;// Run bootstrapper&lt;/span&gt;
    Bootstrapper bootstrapper = &lt;span class="kwrd"&gt;new&lt;/span&gt; Bootstrapper();
    bootstrapper.Run();

    &lt;span class="rem"&gt;// AutoMapper mappings&lt;/span&gt;
    Parallel.Invoke(CreateAutoMapperMappings);
}

&lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// Creates the AutoMapper mappings.&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateAutoMapperMappings()
{
    Mapper.CreateMap&amp;lt;Source, Dest&amp;gt;();
}&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=zoPTknMAaB8:3oiggCUjQ8o:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=zoPTknMAaB8:3oiggCUjQ8o:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=zoPTknMAaB8:3oiggCUjQ8o:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=zoPTknMAaB8:3oiggCUjQ8o:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=zoPTknMAaB8:3oiggCUjQ8o:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=zoPTknMAaB8:3oiggCUjQ8o:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/8407657171768765254/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2010/05/cal-and-automapper.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/8407657171768765254?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/8407657171768765254?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/zoPTknMAaB8/cal-and-automapper.html" title="CAL and AutoMapper" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2010/05/cal-and-automapper.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEENRH48fyp7ImA9WxFQGEo.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-4421392213878580628</id><published>2010-05-14T23:31:00.001+02:00</published><updated>2010-05-14T23:31:35.077+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-05-14T23:31:35.077+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Programming" /><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><title>F#: Piping and Composition</title><content type="html">&lt;p&gt;Piping and compositions are very expressive tools in F#. It significantly improves code readability. &lt;/p&gt;  &lt;p&gt;Let’s have the following functions:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;gt; let square x = x*x;;      &lt;br /&gt;val square : int -&amp;gt; int &lt;/p&gt;    &lt;p&gt;&amp;gt; let negate x = -x;;      &lt;br /&gt;val negate : int –&amp;gt; int&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Function &lt;em&gt;square&lt;/em&gt; returns the square of x, while &lt;em&gt;negate&lt;/em&gt; returns the negated value of x. &lt;/p&gt;  &lt;p&gt;We can calculate square(negate(10)) as follows:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;gt; let x = negate 10;;      &lt;br /&gt;val x : int = –10&lt;/p&gt;    &lt;p&gt;&amp;gt; let x = square x;;      &lt;br /&gt;val x : int = 100&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Or a simpler way:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;gt; let x = square (negate 10);;      &lt;br /&gt;val x : int = 100&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;/p&gt;  &lt;h3&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/h3&gt;  &lt;h3&gt;&lt;strong&gt;Piping&lt;/strong&gt;&lt;/h3&gt;  &lt;p&gt;We can define piping as symbol-named function definition that simply applies two functions in reverse order:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;let (|&amp;gt;) f x =      &lt;br /&gt;&amp;#160; x f&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The example with piping:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;gt; 10 |&amp;gt; negate |&amp;gt; square;;      &lt;br /&gt;val it : int = 100&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;That means ((10 negate) square) –&amp;gt; (square (negate 10)). I used an integer (10) as &lt;em&gt;f&lt;/em&gt;. &lt;/p&gt;  &lt;h3&gt;Composition&lt;/h3&gt;  &lt;p&gt;Composition is a reverse-order function composition:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;let (&amp;gt;&amp;gt;) f g x =      &lt;br /&gt;&amp;#160; g(f x)&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The example with composition:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;gt; (negate &amp;gt;&amp;gt; square) 10;;      &lt;br /&gt;val it : int = 100&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;That means ((negate square) 10) –&amp;gt; (square (negate 10)).&lt;/p&gt;  &lt;h3&gt;Usage&lt;/h3&gt;  &lt;p&gt;The examples above are very simple ones. The real benefits of piping and composition reveal in case of function definitions and usage.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Pipes&lt;/strong&gt; can reverse parameter definition orders (like in 10 |&amp;gt; negate) and can help type inferring. When F# infers types, it evaluates from upper left corner to lover right corner of the text file, so sometimes it doesn't know the type of a function parameter. Pipe brings parameters forward.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Composition&lt;/strong&gt; can help omitting function parameter declaration. If the first function expects a parameter, the composed function expects it’s parameter.&amp;#160; &lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=c84C8YY3c14:tU90JYuqI-s:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=c84C8YY3c14:tU90JYuqI-s:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=c84C8YY3c14:tU90JYuqI-s:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=c84C8YY3c14:tU90JYuqI-s:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=c84C8YY3c14:tU90JYuqI-s:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=c84C8YY3c14:tU90JYuqI-s:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/4421392213878580628/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2010/05/f-piping-and-composition.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/4421392213878580628?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/4421392213878580628?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/c84C8YY3c14/f-piping-and-composition.html" title="F#: Piping and Composition" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2010/05/f-piping-and-composition.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkYBSH84fSp7ImA9WxFQEE0.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-5569859929436754087</id><published>2010-05-04T21:09:00.001+02:00</published><updated>2010-05-04T21:09:19.135+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-05-04T21:09:19.135+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Database" /><title>Database Comparison</title><content type="html">&lt;p&gt;I' am very interested in open source database comparisons. I found two interesting blog posts:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.ss.javaworld.in/sukhvindersingh" target="_blank"&gt;Sukhvinder Singh&lt;/a&gt; wrote about the &lt;a href="http://www.ss.javaworld.in/articles/design-concepts/database-comparison-table-h2-hsqldb-derby-postgresql-mysql" target="_blank"&gt;comparison of H2, HSQLDB, DERBY, PostgreSQL, MySQL&lt;/a&gt;.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://3rdstage.blogspot.com/" target="_blank"&gt;Thirdstage&lt;/a&gt; wrote about the comparison of about &lt;a href="http://3rdstage.blogspot.com/2009/03/comparion-of-hsqldb-h2-sqlite.html" target="_blank"&gt;HSQLDB, H2, SQLite&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Link: &lt;a href="http://www.ss.javaworld.in/articles/design-concepts/database-comparison-table-h2-hsqldb-derby-postgresql-mysql" target="_blank"&gt;H2, HSQLDB, DERBY, PostgreSQL, MySQL&lt;/a&gt;    &lt;br /&gt;Link: &lt;a href="http://3rdstage.blogspot.com/2009/03/comparion-of-hsqldb-h2-sqlite.html" target="_blank"&gt;HSQLDB, H2, SQLite&lt;/a&gt;&lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=jnezJ8x-JqA:qb5PPoNxwVw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=jnezJ8x-JqA:qb5PPoNxwVw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=jnezJ8x-JqA:qb5PPoNxwVw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=jnezJ8x-JqA:qb5PPoNxwVw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=jnezJ8x-JqA:qb5PPoNxwVw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=jnezJ8x-JqA:qb5PPoNxwVw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/5569859929436754087/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2010/05/database-comparison.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/5569859929436754087?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/5569859929436754087?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/jnezJ8x-JqA/database-comparison.html" title="Database Comparison" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2010/05/database-comparison.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkcAQ305cCp7ImA9WxFRF0Q.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-4501151035766918632</id><published>2010-05-02T11:54:00.001+02:00</published><updated>2010-05-02T11:54:02.328+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-05-02T11:54:02.328+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="Programming" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>Get WPF DataGrid row and cell</title><content type="html">&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;  &lt;p&gt;There are no simple built-in methods for accessing individual rows or columns in WPF DataGrid. The following code samples will provide simple methods for accessing these items. &lt;/p&gt;  &lt;p&gt;First of all we need a helper function for &lt;strong&gt;selecting a visual child&lt;/strong&gt;:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; T GetVisualChild&amp;lt;T&amp;gt;(Visual parent) &lt;span class="kwrd"&gt;where&lt;/span&gt; T : Visual
{
    T child = &lt;span class="kwrd"&gt;default&lt;/span&gt;(T);
    &lt;span class="kwrd"&gt;int&lt;/span&gt; numVisuals = VisualTreeHelper.GetChildrenCount(parent);
    &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; numVisuals; i++)
    {
        Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
        child = v &lt;span class="kwrd"&gt;as&lt;/span&gt; T;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (child == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
            child = GetVisualChild&amp;lt;T&amp;gt;(v);
        }
       &lt;span class="kwrd"&gt;if&lt;/span&gt; (child != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
       {
           &lt;span class="kwrd"&gt;break&lt;/span&gt;;
       }
   }
       &lt;span class="kwrd"&gt;return&lt;/span&gt; child;
}&lt;/pre&gt;

&lt;p&gt;There is a simple method for getting the &lt;strong&gt;current (selected) row&lt;/strong&gt; of the DataGrid:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; DataGridRow GetSelectedRow(&lt;span class="kwrd"&gt;this&lt;/span&gt; DataGrid grid)
{
    &lt;span class="kwrd"&gt;return&lt;/span&gt; (DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem);
}&lt;/pre&gt;

&lt;p&gt;We can also get a &lt;strong&gt;row by its indices&lt;/strong&gt;:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; DataGridRow GetRow(&lt;span class="kwrd"&gt;this&lt;/span&gt; DataGrid grid, &lt;span class="kwrd"&gt;int&lt;/span&gt; index)
{
    DataGridRow row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromIndex(index);
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (row == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
    {
        &lt;span class="rem"&gt;// May be virtualized, bring into view and try again.&lt;/span&gt;
        grid.UpdateLayout();
        grid.ScrollIntoView(grid.Items[index]);
        row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromIndex(index);
    }
    &lt;span class="kwrd"&gt;return&lt;/span&gt; row;
}&lt;/pre&gt;

&lt;p&gt;Now we can &lt;strong&gt;get a cell&lt;/strong&gt; of a DataGrid by an existing row:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; DataGridCell GetCell(&lt;span class="kwrd"&gt;this&lt;/span&gt; DataGrid grid, DataGridRow row, &lt;span class="kwrd"&gt;int&lt;/span&gt; column)
{
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (row != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
    {
        DataGridCellsPresenter presenter = GetVisualChild&amp;lt;DataGridCellsPresenter&amp;gt;(row);

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (presenter == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
            grid.ScrollIntoView(row, grid.Columns[column]);
            presenter = GetVisualChild&amp;lt;DataGridCellsPresenter&amp;gt;(row);
        }

        DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
        &lt;span class="kwrd"&gt;return&lt;/span&gt; cell;
    }
    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;Or we can simply select a &lt;strong&gt;row by its indices&lt;/strong&gt;:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; DataGridCell GetCell(&lt;span class="kwrd"&gt;this&lt;/span&gt; DataGrid grid, &lt;span class="kwrd"&gt;int&lt;/span&gt; row, &lt;span class="kwrd"&gt;int&lt;/span&gt; column)
{
    DataGridRow rowContainer = grid.GetRow(row);
    &lt;span class="kwrd"&gt;return&lt;/span&gt; grid.GetCell(rowContainer, column);
}&lt;/pre&gt;

&lt;p&gt;The functions above are extension methods. &lt;strong&gt;Their use is simple&lt;/strong&gt;:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;var selectedRow = grid.GetSelectedRow();
var columnCell = grid.GetCell(selectedRow, 0);&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://code.google.com/p/artur02/source/browse/trunk/DataGridExtensions/DataGridHelper.cs" target="_blank"&gt;View source on Google Code (unformatted selection possible)&lt;/a&gt;&lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=qmDEadAQD2I:pzCTi6100yA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=qmDEadAQD2I:pzCTi6100yA:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=qmDEadAQD2I:pzCTi6100yA:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=qmDEadAQD2I:pzCTi6100yA:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=qmDEadAQD2I:pzCTi6100yA:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=qmDEadAQD2I:pzCTi6100yA:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/4501151035766918632/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2010/05/get-wpf-datagrid-row-and-cell.html#comment-form" title="24 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/4501151035766918632?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/4501151035766918632?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/qmDEadAQD2I/get-wpf-datagrid-row-and-cell.html" title="Get WPF DataGrid row and cell" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>24</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2010/05/get-wpf-datagrid-row-and-cell.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkEDRnk5fyp7ImA9WxFSFUw.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-5126978408898582528</id><published>2010-04-17T16:31:00.001+02:00</published><updated>2010-04-17T16:31:17.727+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-04-17T16:31:17.727+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="Programming" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>Mixed mode assemblies on .NET 4.0</title><content type="html">&lt;blockquote&gt;   &lt;p&gt;&lt;strong&gt;Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.&lt;/strong&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I got this message when I tried to start a project migrated from .NET 3.5 to .NET 4.0. I case of migration, migration wizard inserts a &lt;font face="Courier New"&gt;&amp;lt;startup&amp;gt;&amp;lt;/startup&amp;gt;&lt;/font&gt; tag into the app.config file. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;: insert the &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;&lt;strong&gt;useLegacyV2RuntimeActivationPolicy=&amp;quot;true&amp;quot;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;attribute into the &lt;font face="Courier New"&gt;startup&lt;/font&gt; tag. Application should work now.&lt;/p&gt;  &lt;p&gt;Reason: .NET 4.0 changed mixed mode assembly loading mechanisms. &lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=_jpTYzlBzmA:8AEZHd8ebr8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=_jpTYzlBzmA:8AEZHd8ebr8:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=_jpTYzlBzmA:8AEZHd8ebr8:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=_jpTYzlBzmA:8AEZHd8ebr8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=_jpTYzlBzmA:8AEZHd8ebr8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=_jpTYzlBzmA:8AEZHd8ebr8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/5126978408898582528/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2010/04/mixed-mode-assemblies-on-net-40.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/5126978408898582528?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/5126978408898582528?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/_jpTYzlBzmA/mixed-mode-assemblies-on-net-40.html" title="Mixed mode assemblies on .NET 4.0" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2010/04/mixed-mode-assemblies-on-net-40.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkUERnw_cSp7ImA9WxFSFU0.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-6498687240108291726</id><published>2010-04-17T14:36:00.001+02:00</published><updated>2010-04-17T14:43:27.249+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-04-17T14:43:27.249+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="Programming" /><category scheme="http://www.blogger.com/atom/ns#" term="NHibernate" /><title>NHibernate session management</title><content type="html">&lt;p&gt;When you start working with NHibernate, you will see code examples like this one:&lt;/p&gt;  &lt;div 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: #0000ff"&gt;int&lt;/span&gt; userID = 1234;&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: #0000ff"&gt;using&lt;/span&gt;( ISession session = sessionFactory.OpenSession() )&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: #0000ff"&gt;using&lt;/span&gt;( session.BeginTransaction() ) {&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;    User user = session.Get&amp;lt;User&amp;gt;(userID); &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;    session.Transaction.Commit();&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;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;You get a session object, start a transaction and finally commit that. This is fine when you work in a simple one-layer application or you are OK with tight coupling. When you have multiple layers, or working with binding like in WPF, things get complicated.&lt;/p&gt;

&lt;h3&gt;Session management strategies&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Session per application&lt;/strong&gt; 

    &lt;br /&gt;Simplest approach. Just one session for the whole application, typically returned by a singleton. 

    &lt;br /&gt;&lt;em&gt;Problem&lt;/em&gt;: Async calls can interfere with each other, cache size grows, unrecoverable exceptions, stale data &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Session per screen&lt;/strong&gt; 

    &lt;br /&gt;New session for every form/view/… There are multiple concurrent sessions. 

    &lt;br /&gt;&lt;em&gt;Problem&lt;/em&gt;: You can keep a screen opened for a long time, so stale data is expectable. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Session per data access&lt;/strong&gt; 

    &lt;br /&gt;Every single data access uses a new session object. 

    &lt;br /&gt;&lt;em&gt;Problem&lt;/em&gt;: Lazy loading won’t work, problem with 1st level cache… &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Session per use-case&lt;/strong&gt; 

    &lt;br /&gt;You create a new session for every use-case. There will be concurrent sessions. &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;Firs try: Following examples – Session per data access&lt;/h3&gt;

&lt;p&gt;I’ve created an application with the simplest solution possible. I followed the examples and whenever I tried to access data, I created a session and a transaction. Everything was fine, until I tried to employ lazy loading. It simply did not work. There was no open sessions the lazy loader proxy could have used.&lt;/p&gt;

&lt;h3&gt;Second try: Session per application&lt;/h3&gt;

&lt;p&gt;I modified the application. I created a singleton that returned a session object. Every single data access used this session. The application worked fine – for a while. I used SQLite as DBMS, and SQLite has not the best threading support. So I got exceptions randomly. Sometimes a control was empty, sometimes it was filled with data. Exceptions happened about 1 out of 15 tries. I suspected a threading issue and it seems it was.&lt;/p&gt;

&lt;h3&gt;Third try: Session per use-case&lt;/h3&gt;

&lt;p&gt;I had to implement a session per use-case (business transaction) solution to solve the problems above. A business transaction is a user-initiated action involving multiple complicated operations (steps). All operations (and the transaction itself) are either successful or unsuccessful. The state of the involved members are well-defined and consistent at the end of the transaction.&lt;/p&gt;

&lt;p&gt;We have to be able to keep alive the NHiberanate &lt;font face="Courier New"&gt;ISession&lt;/font&gt; object over multiple operations. The solution is the &lt;a href="http://www.martinfowler.com/eaaCatalog/unitOfWork.html" target="_blank"&gt;unit of work&lt;/a&gt; pattern. It encapsulates the &lt;font face="Courier New"&gt;ISession&lt;/font&gt; object, so we can pass it around and implement the &lt;font face="Courier New"&gt;IDisposable&lt;/font&gt; pattern. The class implementing the unit of work pattern can expose &lt;font face="Courier New"&gt;ISession&lt;/font&gt; functionality. See the example UML class diagram below.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://i63.photobucket.com/albums/h134/artur02/Blog/3508c3ca.png" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Illustration: Unit of Work" border="0" alt="Illustration: Unit of Work" src="http://i63.photobucket.com/albums/h134/artur02/Blog/3508c3ca.png" width="244" height="204" /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;

&lt;p&gt;This is an example of calling the UnitOfWork object instance:&lt;/p&gt;

&lt;div 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: #0000ff"&gt;using&lt;/span&gt; (UnitOfWork unitOfWork = database.CreateUnitOfWork())&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;/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;    PropertiesRepository propertiesRepository = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertiesRepository(unitOfWork);&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;    properties = propertiesRepository.Current;&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;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;You can use a simple factory (it is the &lt;font face="Courier New"&gt;database&lt;/font&gt; object here) to create a new &lt;font face="Courier New"&gt;UnitOfWork&lt;/font&gt; instance. This instance should be passed to all the classes accessing NHibernate functionality. This is important, so design your data access and manipulating classes according to this constraint!&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="http://blog.schuager.com/2009/03/rich-client-nhibernate-session.html" target="_blank"&gt;Rich-client NHibernate session management&lt;/a&gt; 

  &lt;br /&gt;Link: &lt;a href="http://www.martinfowler.com/eaaCatalog/unitOfWork.html" target="_blank"&gt;Unit of Work&lt;/a&gt;&lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=sNC56IWvTbc:bRWY1jKZmI0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=sNC56IWvTbc:bRWY1jKZmI0:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=sNC56IWvTbc:bRWY1jKZmI0:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=sNC56IWvTbc:bRWY1jKZmI0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=sNC56IWvTbc:bRWY1jKZmI0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=sNC56IWvTbc:bRWY1jKZmI0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/6498687240108291726/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2010/04/nhibernate-session-management.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/6498687240108291726?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/6498687240108291726?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/sNC56IWvTbc/nhibernate-session-management.html" title="NHibernate session management" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://i63.photobucket.com/albums/h134/artur02/Blog/th_3508c3ca.png" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2010/04/nhibernate-session-management.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEUGRXo9fSp7ImA9WxFSFU0.&quot;"><id>tag:blogger.com,1999:blog-581522584150589505.post-9130391049981985289</id><published>2010-04-17T13:03:00.001+02:00</published><updated>2010-04-17T13:03:44.465+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-04-17T13:03:44.465+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Visual Basic" /><title>CodePlex TFS from VS2010</title><content type="html">&lt;p&gt;Visual Studio 2010 Professional has a built-in Team Foundation Server (TFS) client. There are some user interface changes on the Add Team Foundation Server screen. When you are connecting to the CodePlex TFS, you need to specify the following information:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Name or URL of TFS: &lt;strong&gt;tfs&amp;lt;number&amp;gt;.codeplex.com&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;Connection details&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Path: &lt;strong&gt;tfs&lt;/strong&gt;&lt;/li&gt;      &lt;li&gt;Port number: &lt;strong&gt;443&lt;/strong&gt;&lt;/li&gt;      &lt;li&gt;Protocol: &lt;strong&gt;HTTPS&lt;/strong&gt;&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;There is no need to specify &lt;strong&gt;Project name&lt;/strong&gt; anywhere on this screen.&lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=FrArP2QN1OQ:Cc-1YM3w3NU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=FrArP2QN1OQ:Cc-1YM3w3NU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=FrArP2QN1OQ:Cc-1YM3w3NU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=FrArP2QN1OQ:Cc-1YM3w3NU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?i=FrArP2QN1OQ:Cc-1YM3w3NU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/techiethings?a=FrArP2QN1OQ:Cc-1YM3w3NU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/techiethings?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://techiethings.blogspot.com/feeds/9130391049981985289/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techiethings.blogspot.com/2010/04/codeplex-tfs-from-vs2010.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/9130391049981985289?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/581522584150589505/posts/default/9130391049981985289?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/techiethings/~3/FrArP2QN1OQ/codeplex-tfs-from-vs2010.html" title="CodePlex TFS from VS2010" /><author><name>Artúr Herczeg</name><uri>https://plus.google.com/115779309732788804055</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-J3z4ROeheR0/AAAAAAAAAAI/AAAAAAAAAAA/ImFylxynh-w/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://techiethings.blogspot.com/2010/04/codeplex-tfs-from-vs2010.html</feedburner:origLink></entry></feed>
