<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" version="2.0"><channel><title>Tales from the Evil Empire</title><link>http://weblogs.asp.net/bleroy/default.aspx</link><description>Bertrand Le Roy's blog</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/TalesFromTheEvilEmpire" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="talesfromtheevilempire" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>Testing Orchard drivers</title><link>http://weblogs.asp.net/bleroy/archive/2013/04/15/testing-orchard-drivers.aspx</link><pubDate>Mon, 15 Apr 2013 19:51:31 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:10162458</guid><dc:creator>Bertrand Le Roy</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/bleroy/rsscomments.aspx?PostID=10162458</wfw:commentRss><comments>http://weblogs.asp.net/bleroy/archive/2013/04/15/testing-orchard-drivers.aspx#comments</comments><description>&lt;p&gt;If you’ve ever tried to test Orchard part drivers, you may have been blocked by the fact that the methods on drivers are protected. That, fortunately, doesn’t mean they are untestable. Those methods are still accessible through explicit interface implementations. In particular, drivers implement IContentPartDriver, which is defined as follows.&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;public interface IContentPartDriver : IDependency {
    DriverResult BuildDisplay(BuildDisplayContext context);
    DriverResult BuildEditor(BuildEditorContext context);
    DriverResult UpdateEditor(UpdateEditorContext context);
    void Importing(ImportContentContext context);
    void Imported(ImportContentContext context);
    void Exporting(ExportContentContext context);
    void Exported(ExportContentContext context);
    IEnumerable&amp;lt;ContentPartInfo&amp;gt; GetPartInfo();
    void GetContentItemMetadata(GetContentItemMetadataContext context);
}&lt;/pre&gt;

&lt;p&gt;By casting your driver to this interface, you get public access to these methods.&lt;/p&gt;

&lt;p&gt;For example, here is some code I wrote recently to test the import and export methods of a driver:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;[Test]
public void ImportGetAllDefinedProperties() {
    var doc = XElement.Parse(@&amp;quot;
&amp;lt;data&amp;gt;
&amp;lt;UspsShippingMethodPart
    Name=&amp;quot;&amp;quot;Foo&amp;quot;&amp;quot;
    Size=&amp;quot;&amp;quot;L&amp;quot;&amp;quot;
    WidthInInches=&amp;quot;&amp;quot;10&amp;quot;&amp;quot;
    LengthInInches=&amp;quot;&amp;quot;11&amp;quot;&amp;quot;
    HeightInInches=&amp;quot;&amp;quot;12&amp;quot;&amp;quot;
    MaximumWeightInOunces=&amp;quot;&amp;quot;1.3&amp;quot;&amp;quot;
    Priority=&amp;quot;&amp;quot;14&amp;quot;&amp;quot;
    International=&amp;quot;&amp;quot;true&amp;quot;&amp;quot;
    RegisteredMail=&amp;quot;&amp;quot;true&amp;quot;&amp;quot;
    Insurance=&amp;quot;&amp;quot;false&amp;quot;&amp;quot;
    ReturnReceipt=&amp;quot;&amp;quot;true&amp;quot;&amp;quot;
    CertificateOfMailing=&amp;quot;&amp;quot;true&amp;quot;&amp;quot;
    ElectronicConfirmation=&amp;quot;&amp;quot;true&amp;quot;&amp;quot;/&amp;gt;
&amp;lt;/data&amp;gt;
&amp;quot;);
    var driver = new UspsShippingMethodPartDriver(null)
        as IContentPartDriver;
    var part = new UspsShippingMethodPart();
    Helpers.PreparePart&amp;lt;UspsShippingMethodPart, UspsShippingMethodPartRecord&amp;gt;(
        part, &amp;quot;UspsShippingMethod&amp;quot;);
    var context = new ImportContentContext(
        part.ContentItem, doc, new ImportContentSession(null));
    driver.Importing(context);

    Assert.That(part.Name, Is.EqualTo(&amp;quot;Foo&amp;quot;));
    Assert.That(part.Size, Is.EqualTo(&amp;quot;L&amp;quot;));
    Assert.That(part.WidthInInches, Is.EqualTo(10));
    Assert.That(part.LengthInInches, Is.EqualTo(11));
    Assert.That(part.HeightInInches, Is.EqualTo(12));
    Assert.That(part.MaximumWeightInOunces, Is.EqualTo(1.3));
    Assert.That(part.Priority, Is.EqualTo(14));
    Assert.That(part.International, Is.True);
    Assert.That(part.RegisteredMail, Is.True);
    Assert.That(part.Insurance, Is.False);
    Assert.That(part.ReturnReceipt, Is.True);
    Assert.That(part.CertificateOfMailing, Is.True);
    Assert.That(part.ElectronicConfirmation, Is.True);
}

[Test]
public void ExportSetsAllAttributes() {
    var driver = new UspsShippingMethodPartDriver(null)
        as IContentPartDriver;
    var part = new UspsShippingMethodPart();
    Helpers.PreparePart&amp;lt;UspsShippingMethodPart, UspsShippingMethodPartRecord&amp;gt;(
        part, &amp;quot;UspsShippingMethod&amp;quot;);
    part.Name = &amp;quot;Foo&amp;quot;;
    part.Size = &amp;quot;L&amp;quot;;
    part.WidthInInches = 10;
    part.LengthInInches = 11;
    part.HeightInInches = 12;
    part.MaximumWeightInOunces = 1.3;
    part.Priority = 14;
    part.International = true;
    part.RegisteredMail = true;
    part.Insurance = false;
    part.ReturnReceipt = true;
    part.CertificateOfMailing = true;
    part.ElectronicConfirmation = true;

    var doc = new XElement(&amp;quot;data&amp;quot;);
    var context = new ExportContentContext(part.ContentItem, doc);
    driver.Exporting(context);
    var el = doc.Element(&amp;quot;UspsShippingMethodPart&amp;quot;);

    Assert.That(el, Is.Not.Null);
    Assert.That(el.Attr(&amp;quot;Name&amp;quot;), Is.EqualTo(&amp;quot;Foo&amp;quot;));
    Assert.That(el.Attr(&amp;quot;Size&amp;quot;), Is.EqualTo(&amp;quot;L&amp;quot;));
    Assert.That(el.Attr(&amp;quot;WidthInInches&amp;quot;), Is.EqualTo(&amp;quot;10&amp;quot;));
    Assert.That(el.Attr(&amp;quot;LengthInInches&amp;quot;), Is.EqualTo(&amp;quot;11&amp;quot;));
    Assert.That(el.Attr(&amp;quot;HeightInInches&amp;quot;), Is.EqualTo(&amp;quot;12&amp;quot;));
    Assert.That(el.Attr(&amp;quot;MaximumWeightInOunces&amp;quot;), Is.EqualTo(&amp;quot;1.3&amp;quot;));
    Assert.That(el.Attr(&amp;quot;Priority&amp;quot;), Is.EqualTo(&amp;quot;14&amp;quot;));
    Assert.That(el.Attr(&amp;quot;International&amp;quot;), Is.EqualTo(&amp;quot;true&amp;quot;));
    Assert.That(el.Attr(&amp;quot;RegisteredMail&amp;quot;), Is.EqualTo(&amp;quot;true&amp;quot;));
    Assert.That(el.Attr(&amp;quot;Insurance&amp;quot;), Is.EqualTo(&amp;quot;false&amp;quot;));
    Assert.That(el.Attr(&amp;quot;ReturnReceipt&amp;quot;), Is.EqualTo(&amp;quot;true&amp;quot;));
    Assert.That(el.Attr(&amp;quot;CertificateOfMailing&amp;quot;), Is.EqualTo(&amp;quot;true&amp;quot;));
    Assert.That(el.Attr(&amp;quot;ElectronicConfirmation&amp;quot;), Is.EqualTo(&amp;quot;true&amp;quot;));
}&lt;/pre&gt;

&lt;p&gt;The Attr method, in case you're wondering, is &lt;a href="http://weblogs.asp.net/bleroy/archive/2013/04/14/a-c-helper-to-read-and-write-xml-from-and-to-objects.aspx"&gt;an extension method I blogged about yesterday&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The Helper class that I’m using here massages a fake part to behave like a real part. It gives the part a fake record, and adds a fake content item around it. It might not be enough in all situations, but it does make the fake convincing enough in this case.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public static ContentItem PreparePart&amp;lt;TPart, TRecord&amp;gt;(
    TPart part, string contentType, int id = -1)
    where TPart: ContentPart&amp;lt;TRecord&amp;gt;
    where TRecord: ContentPartRecord, new() {

    part.Record = new TRecord();
    var contentItem = part.ContentItem = new ContentItem
    {
        VersionRecord = new ContentItemVersionRecord
        {
            ContentItemRecord = new ContentItemRecord()
        },
        ContentType = contentType
    };
    contentItem.Record.Id = id;
    contentItem.Weld(part);
    return contentItem;
}&lt;/pre&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=10162458" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/TalesFromTheEvilEmpire/~4/P5m_doyHS0g" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/bleroy/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/Orchard/default.aspx">Orchard</category></item><item><title>A C# helper to read and write XML from and to objects</title><link>http://weblogs.asp.net/bleroy/archive/2013/04/14/a-c-helper-to-read-and-write-xml-from-and-to-objects.aspx</link><pubDate>Mon, 15 Apr 2013 00:04:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:10157543</guid><dc:creator>Bertrand Le Roy</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://weblogs.asp.net/bleroy/rsscomments.aspx?PostID=10157543</wfw:commentRss><comments>http://weblogs.asp.net/bleroy/archive/2013/04/14/a-c-helper-to-read-and-write-xml-from-and-to-objects.aspx#comments</comments><description>&lt;p&gt;I really like jQuery’s pattern of attribute getters and setters. They are fluent and work really well with HTML and XML DOMs. If you specify a value in addition to the name, it’s setting, otherwise it’s getting. In C#, we have an OK API for XML, XElement, but it’s not as easy to use as jQuery’s attr methods. It is also missing the flexibility of Javascript with regards to parameter types. To recreate the simplicity of attr in C#, I built a set of extension methods for the most common simple types: &lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;var el = new XElement(&amp;quot;node&amp;quot;);
el.Attr(&amp;quot;foo&amp;quot;, &amp;quot;bar&amp;quot;)
  .Attr(&amp;quot;baz&amp;quot;, 42)
  .Attr(&amp;quot;really&amp;quot;, true);
var answer = el.Attr(&amp;quot;baz&amp;quot;);&lt;/pre&gt;



&lt;p&gt;The element built by this code looks like this: &lt;/p&gt;

&lt;pre class="brush: xml;"&gt;&amp;lt;node foo=&amp;quot;bar&amp;quot; baz=&amp;quot;42&amp;quot; really=&amp;quot;true&amp;quot;/&amp;gt;&lt;/pre&gt;



&lt;p&gt;And the answer variable will contain “42”.&lt;/p&gt;

&lt;p&gt;Even with this API, there is still a fair amount of repetition in code that reads and writes XML from and to objects. You could rely on serialization in those cases, of course, but when you need a little more control, and the types are not necessarily serializable, or if you just want to do it manually, you need something more. This is why I also built ToAttr and FromAttr. Both are extension methods that take an object and an expression for what property of the object to get or set from XML attributes. The methods will infer the type and name from the property.&lt;/p&gt;

&lt;p&gt;This is especially useful when writing the import and export methods in an Orchard part driver: &lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;protected override void Importing(&lt;br /&gt;    UspsShippingMethodPart part,&lt;br /&gt;    ImportContentContext context) {&lt;br /&gt;
    var el = context.Data.Element(typeof(UspsShippingMethodPart).Name);
    if (el == null) return;
    el.FromAttr(part, p =&amp;gt; p.Name)
      .FromAttr(part, p =&amp;gt; p.Size)
      .FromAttr(part, p =&amp;gt; p.WidthInInches)
      .FromAttr(part, p =&amp;gt; p.LengthInInches)
      .FromAttr(part, p =&amp;gt; p.HeightInInches)
      .FromAttr(part, p =&amp;gt; p.MaximumWeightInOunces)
      .FromAttr(part, p =&amp;gt; p.Priority)
      .FromAttr(part, p =&amp;gt; p.International)
      .FromAttr(part, p =&amp;gt; p.RegisteredMail)
      .FromAttr(part, p =&amp;gt; p.Insurance)
      .FromAttr(part, p =&amp;gt; p.ReturnReceipt)
      .FromAttr(part, p =&amp;gt; p.CertificateOfMailing)
      .FromAttr(part, p =&amp;gt; p.ElectronicConfirmation);
}

protected override void Exporting(&lt;br /&gt;    UspsShippingMethodPart part, ExportContentContext context) {&lt;br /&gt;
    context.Element(typeof (UspsShippingMethodPart).Name)
           .ToAttr(part, p =&amp;gt; p.Name)
           .ToAttr(part, p =&amp;gt; p.Size)
           .ToAttr(part, p =&amp;gt; p.WidthInInches)
           .ToAttr(part, p =&amp;gt; p.LengthInInches)
           .ToAttr(part, p =&amp;gt; p.HeightInInches)
           .ToAttr(part, p =&amp;gt; p.MaximumWeightInOunces)
           .ToAttr(part, p =&amp;gt; p.Priority)
           .ToAttr(part, p =&amp;gt; p.International)
           .ToAttr(part, p =&amp;gt; p.RegisteredMail)
           .ToAttr(part, p =&amp;gt; p.Insurance)
           .ToAttr(part, p =&amp;gt; p.ReturnReceipt)
           .ToAttr(part, p =&amp;gt; p.CertificateOfMailing)
           .ToAttr(part, p =&amp;gt; p.ElectronicConfirmation);
}&lt;/pre&gt;



&lt;p&gt;There is no need to specify attribute names or types here, everything is inferred from the expression. Both methods manipulate XML looking like this: &lt;/p&gt;

&lt;pre class="brush: xml;"&gt;&amp;lt;UspsShippingMethodPart
        Name=&amp;quot;Foo&amp;quot;
        Size=&amp;quot;L&amp;quot;
        WidthInInches=&amp;quot;10&amp;quot;
        LengthInInches=&amp;quot;11&amp;quot;
        HeightInInches=&amp;quot;12&amp;quot;
        MaximumWeightInOunces=&amp;quot;1.3&amp;quot;
        Priority=&amp;quot;14&amp;quot;
        International=&amp;quot;true&amp;quot;
        RegisteredMail=&amp;quot;true&amp;quot;
        Insurance=&amp;quot;false&amp;quot;
        ReturnReceipt=&amp;quot;true&amp;quot;
        CertificateOfMailing=&amp;quot;true&amp;quot;
        ElectronicConfirmation=&amp;quot;true&amp;quot;/&amp;gt;&lt;/pre&gt;



&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; You may notice that there is still quite some repetition of the part parameter in the import/export code above. In order to remove this repetition, I’ve added a small class that aggregates the XML element with a context and has simpler ToAttr and From Attr methods. With this new helper class, we can rewrite the driver’s import/export code to be even more concise:

  &lt;pre class="brush: csharp;"&gt;protected override void Importing(&lt;br /&gt;    UspsShippingMethodPart part, ImportContentContext context) {&lt;br /&gt;
    var el = context.Data.Element(typeof (UspsShippingMethodPart).Name);
    if (el == null) return;
    el.With(part)
      .FromAttr(p =&amp;gt; p.Name)
      .FromAttr(p =&amp;gt; p.Size)
      .FromAttr(p =&amp;gt; p.WidthInInches)
      .FromAttr(p =&amp;gt; p.LengthInInches)
      .FromAttr(p =&amp;gt; p.HeightInInches)
      .FromAttr(p =&amp;gt; p.MaximumWeightInOunces)
      .FromAttr(p =&amp;gt; p.Priority)
      .FromAttr(p =&amp;gt; p.International)
      .FromAttr(p =&amp;gt; p.RegisteredMail)
      .FromAttr(p =&amp;gt; p.Insurance)
      .FromAttr(p =&amp;gt; p.ReturnReceipt)
      .FromAttr(p =&amp;gt; p.CertificateOfMailing)
      .FromAttr(p =&amp;gt; p.ElectronicConfirmation);
}

protected override void Exporting(&lt;br /&gt;    UspsShippingMethodPart part, ExportContentContext context) {&lt;br /&gt;
    context.Element(typeof (UspsShippingMethodPart).Name)
           .With(part)
           .ToAttr(p =&amp;gt; p.Name)
           .ToAttr(p =&amp;gt; p.Size)
           .ToAttr(p =&amp;gt; p.WidthInInches)
           .ToAttr(p =&amp;gt; p.LengthInInches)
           .ToAttr(p =&amp;gt; p.HeightInInches)
           .ToAttr(p =&amp;gt; p.MaximumWeightInOunces)
           .ToAttr(p =&amp;gt; p.Priority)
           .ToAttr(p =&amp;gt; p.International)
           .ToAttr(p =&amp;gt; p.RegisteredMail)
           .ToAttr(p =&amp;gt; p.Insurance)
           .ToAttr(p =&amp;gt; p.ReturnReceipt)
           .ToAttr(p =&amp;gt; p.CertificateOfMailing)
           .ToAttr(p =&amp;gt; p.ElectronicConfirmation);
}&lt;/pre&gt;
&lt;/p&gt;

&lt;p&gt;You can find the code for this helper class here: 
  &lt;br /&gt;&lt;a title="https://gist.github.com/bleroy/5384405" href="https://gist.github.com/bleroy/5384405"&gt;https://gist.github.com/bleroy/5384405&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And I have a small test suite for the whole thing here: 
  &lt;br /&gt;&lt;a href="https://gist.github.com/bleroy/5385284"&gt;https://gist.github.com/bleroy/5385284&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=10157543" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/TalesFromTheEvilEmpire/~4/1VMKbvOgPz0" height="1" width="1"/&gt;</description></item><item><title>Getting your Raspberry Pi to output the right resolution</title><link>http://weblogs.asp.net/bleroy/archive/2013/04/10/getting-your-raspberry-pi-to-output-the-right-resolution.aspx</link><pubDate>Thu, 11 Apr 2013 05:14:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:10129716</guid><dc:creator>Bertrand Le Roy</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/bleroy/rsscomments.aspx?PostID=10129716</wfw:commentRss><comments>http://weblogs.asp.net/bleroy/archive/2013/04/10/getting-your-raspberry-pi-to-output-the-right-resolution.aspx#comments</comments><description>&lt;p&gt;I was setting up a new Raspberry Pi under Raspbian on a Samsung monitor the other day. If you don’t do anything, Raspbian and the Pi will attempt to detect the modes supported by your monitor and will make a choice of what seems best to it. And sometimes it gets that very wrong. In those cases, you’ll need to find what the right mode is and to set it up.&lt;/p&gt;  &lt;p&gt;It took me quite a few attempts before I succeeded, mostly misled by misinformed forum and blog posts. The right post, the one that has all the correct info does exist however: &lt;a href="http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&amp;amp;t=5851"&gt;http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&amp;amp;t=5851&lt;/a&gt;. Let me distil this to a short set of instructions, in case you don’t want to dive in and assimilate all that information. Here is what worked for me…&lt;/p&gt;  &lt;p&gt;From the command-line, logged-in as root…&lt;/p&gt;  &lt;p&gt;1. Get the list of what’s supported by your monitor:   &lt;pre class="brush: bash;"&gt;tvservice -d edid
edidparser edid&lt;/pre&gt;
&lt;/p&gt;

&lt;p&gt;2. Find the mode that you want in the resulting list (for me it was “HDMI:EDID DMT mode (82) 1920x1080p @ 60 Hz with pixel clock 148 MHz” with a score of 124,416, which wasn’t the highest, explaining why I had a lower resolution by default). The mode number is the one between parentheses: 82.&lt;/p&gt;

&lt;p&gt;3. Edit the config file:
  &lt;pre class="brush: bash;"&gt;nano /boot/config.txt&lt;/pre&gt;
&lt;/p&gt;

&lt;p&gt;Find the section about HDMI, uncomment it and set the right group and mode from step 2. If your mode description contains “DMT”, the group should be 2, and if it contains “CEA”, it should be 1, so for me that was:
  &lt;pre class="brush: bash;"&gt;hdmi_group=2
hdmi_mode=82&lt;/pre&gt;
&lt;/p&gt;

&lt;p&gt;Exit the editor with CTRL+X, followed by Y.&lt;/p&gt;

&lt;p&gt;4. Reboot:
  &lt;pre class="brush: bash;"&gt;shutdown -r now&lt;/pre&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=10129716" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/TalesFromTheEvilEmpire/~4/pIdqvxFq9ZE" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/bleroy/archive/tags/Nwazet/default.aspx">Nwazet</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/Raspberry+Pi/default.aspx">Raspberry Pi</category></item><item><title>Logging SQL queries in Orchard</title><link>http://weblogs.asp.net/bleroy/archive/2013/04/03/logging-sql-queries-in-orchard.aspx</link><pubDate>Thu, 04 Apr 2013 02:02:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:10091735</guid><dc:creator>Bertrand Le Roy</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://weblogs.asp.net/bleroy/rsscomments.aspx?PostID=10091735</wfw:commentRss><comments>http://weblogs.asp.net/bleroy/archive/2013/04/03/logging-sql-queries-in-orchard.aspx#comments</comments><description>&lt;p&gt;It is often useful to see what database queries were made during a specific request in Orchard. There are quite a few ways to do this (you can &lt;a href="http://msdn.microsoft.com/en-us/library/ms191006(v=sql.105).aspx"&gt;trace right from SQL Server&lt;/a&gt;, or you can use &lt;a href="http://gallery.orchardproject.net/List/Modules/Orchard.Module.Four2n.MiniProfiler"&gt;Mini-Profiler&lt;/a&gt; for instance), but this morning &lt;a href="http://sebastienros.com/"&gt;Sébastien&lt;/a&gt; showed me a really easy one that I thought I’d share.&lt;/p&gt;  &lt;p&gt;Find the log4net.config file in /src/Orchard.Web/Config and edit it to add the following tag:   &lt;pre class="brush: xml;"&gt;&amp;lt;logger name=&amp;quot;NHibernate.SQL&amp;quot;&amp;gt;
  &amp;lt;priority value=&amp;quot;DEBUG&amp;quot; /&amp;gt;
&amp;lt;/logger&amp;gt;&lt;/pre&gt;
&lt;/p&gt;

&lt;p&gt;Restart the application, then hit the URL you want to test, and look at your logs in App_data/logs. You should see new entries looking like this:
  &lt;pre class="brush: plain;"&gt;2013-04-03 18:57:30,367 [17] NHibernate.SQL -
  SELECT warmupsett0_.Id as Id575_0_,
         warmupsett0_.Urls as Urls575_0_,
         warmupsett0_.Scheduled as Scheduled575_0_,
         warmupsett0_.Delay as Delay575_0_,
         warmupsett0_.OnPublish as OnPublish575_0_
  FROM VuLu_Orchard_Warmup_WarmupSettingsPartRecord warmupsett0_
  WHERE warmupsett0_.Id=@p0;

  @p0 = 1 [Type: Int32 (0)]&lt;/pre&gt;
&lt;/p&gt;

&lt;p&gt;(only not as nicely formatted)&lt;/p&gt;

&lt;p&gt;To disable the SQL trace, just edit log4net.config and set the value to ERROR instead of DEBUG.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=10091735" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/TalesFromTheEvilEmpire/~4/MatqtedoDBs" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/bleroy/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/SQL/default.aspx">SQL</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/NHibernate/default.aspx">NHibernate</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/Orchard/default.aspx">Orchard</category></item><item><title>This is how we should read hexadecimal…</title><link>http://weblogs.asp.net/bleroy/archive/2013/03/21/this-is-how-we-should-read-hexadecimal.aspx</link><pubDate>Fri, 22 Mar 2013 05:04:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:10030075</guid><dc:creator>Bertrand Le Roy</dc:creator><slash:comments>22</slash:comments><wfw:commentRss>http://weblogs.asp.net/bleroy/rsscomments.aspx?PostID=10030075</wfw:commentRss><comments>http://weblogs.asp.net/bleroy/archive/2013/03/21/this-is-how-we-should-read-hexadecimal.aspx#comments</comments><description>&lt;p&gt;Today my five-year-old told me that when she was four, she thought that what came after ninety-nine was… tenty. You know, because seventy, eighty, ninety, tenty.&lt;/p&gt;  &lt;p&gt;At first I thought it was just funny and charming, but then I realized it was actually a really good idea. Tenty is only nonsensical if you’re counting in base ten (or lower), but it makes total sense for higher bases.&lt;/p&gt;  &lt;p&gt;How do people usually read 0xA0? “A-zero”? How unimaginative! Let’s read that “tenty” from now on!&lt;/p&gt;  &lt;p&gt;Here are some more examples of how to read hexadecimal in a non-boring way:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;0xB3 is eleventy-three&lt;/li&gt;    &lt;li&gt;0xCA is twelvety-ten&lt;/li&gt;    &lt;li&gt;0xD9 is thirteenty-nine&lt;/li&gt;    &lt;li&gt;0xEC is fourteenty-twelve&lt;/li&gt;    &lt;li&gt;0xFF is fifteenty-fifteen&lt;/li&gt;    &lt;li&gt;0xF04A is fifteen hexathousand forty-ten&lt;/li&gt;    &lt;li&gt;0x4B2AC0AA is forty-eleven hexamillion, two hexahundred tenty-twelve hexathousand tenty-ten&lt;/li&gt;    &lt;li&gt;and of course, seven-eleven will have to change their logo to 0x7B.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Is this the greatest thing or what?&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=10030075" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/TalesFromTheEvilEmpire/~4/5RH2MqDdch8" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/bleroy/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/Geek/default.aspx">Geek</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/Math/default.aspx">Math</category></item><item><title>Taking an Orchard site offline while you update it</title><link>http://weblogs.asp.net/bleroy/archive/2013/03/12/taking-an-orchard-site-offline-while-you-update-it.aspx</link><pubDate>Tue, 12 Mar 2013 18:52:28 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:9979633</guid><dc:creator>Bertrand Le Roy</dc:creator><slash:comments>6</slash:comments><wfw:commentRss>http://weblogs.asp.net/bleroy/rsscomments.aspx?PostID=9979633</wfw:commentRss><comments>http://weblogs.asp.net/bleroy/archive/2013/03/12/taking-an-orchard-site-offline-while-you-update-it.aspx#comments</comments><description>&lt;p&gt;&lt;img title="(c) Bertrand Le Roy 2012" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: left; padding-top: 0px; padding-left: 0px; margin: 2px 10px 5px 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="(c) Bertrand Le Roy 2012" align="left" src="http://weblogs.asp.net/blogs/bleroy/image_181E3DF7.png" width="164" height="244" /&gt;If your hosted environment does not give you a staging site and the means to swap it easily with the production environment like Azure Cloud Services do, or if you don’t have a staging database, or if you just need to take your site offline for the public while you perform data updates in the admin, you may be wondering what solutions you have, if any.&lt;/p&gt;  &lt;p&gt;IIS has an &lt;font face="Courier New"&gt;app_offline.htm&lt;/font&gt; feature that you can use, that will serve a static page for all requests but that’s rather brutal as it does not just take the site offline for your users, it also does so for you. While that file exists, you can do absolutely nothing with your site. You cannot access the admin, you cannot preview your changes, nothing. So when you flip the switch back, it’s anyone’s guess whether the changes you blindly made actually work, even if they did on your machine…&lt;/p&gt;  &lt;p&gt;We need a better solution. Well, I happen to have one...&lt;/p&gt;  &lt;p&gt;All you have to do is create a new theme named “Offline” with just one /Views/Layout.cshtml file containing a message along the lines of “We are updating the site. We apologize for the inconvenience. Please come back in a few minutes.” You can add stylesheets to make it pretty if you want to. It’s a full theme, you can go crazy.&lt;/p&gt;  &lt;p&gt;The important thing is that this theme has one layout, and that this layout does nothing but display its message. It has no zones, so no dynamic content is going to be served to the public from the site no matter what URL is hit.&lt;/p&gt;  &lt;p&gt;Once you have made this theme current, all your visitors are seeing it, but you can still access the admin of the site and do whatever you want.&lt;/p&gt;  &lt;p&gt;Better, you can use the “Theme Preview” feature of Orchard to check what your changes look like while your users continue to see the “offline” page. Just go to Themes, and click Preview on your regular theme…&lt;/p&gt;  &lt;p&gt;Once you are satisfied with your changes and judge the site to be ready to be taken back online, just restore your theme as the current. The “Offline” theme can sit there and do nothing until the next time you need it.&lt;/p&gt;  &lt;p&gt;I’ve used this technique successfully last time I updated an Orchard site. It worked great. I hope it helps others…&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=9979633" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/TalesFromTheEvilEmpire/~4/0rLnRhbrBW4" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/bleroy/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/Orchard/default.aspx">Orchard</category></item><item><title>Dead simple stubbing for JavaScript</title><link>http://weblogs.asp.net/bleroy/archive/2013/03/08/dead-simple-stubbing-for-javascript.aspx</link><pubDate>Fri, 08 Mar 2013 18:29:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:9961668</guid><dc:creator>Bertrand Le Roy</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/bleroy/rsscomments.aspx?PostID=9961668</wfw:commentRss><comments>http://weblogs.asp.net/bleroy/archive/2013/03/08/dead-simple-stubbing-for-javascript.aspx#comments</comments><description>&lt;p&gt;I’m writing a lot of JavaScript these days, and for testing I mostly use QUnit. When I need to quickly stub a piece of the code that I’m testing, I like to use the following micro-library. What it does is enable you to replace a bunch of methods on an object with stub versions, in a easily reversible way.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;I use RequireJS, but if you don’t, just remove the define and outer function.&lt;/p&gt; &lt;/blockquote&gt;  &lt;pre class="brush: js;"&gt;define(function() {
    var stub = function(obj, stubs) {
        obj._stubbed = obj._stubbed || {};
        for (var name in stubs) {
            obj._stubbed[name] = obj[name];
            obj[name] = stubs[name];
        }
    };
    stub.restore = function(obj) {
        if (!obj || !obj._stubbed) return;
        for (var name in obj._stubbed) {
            obj[name] = obj._stubbed[name];
        }
        delete obj._stubbed;
    };
    return stub;
});&lt;/pre&gt;

&lt;p&gt;Here is how you would replace two methods bar and baz on an object foo:&lt;/p&gt;

&lt;pre class="brush: js;"&gt;stub(foo, {
    bar: function() {
        return &amp;quot;stubbed bar&amp;quot;;
    },
    baz: function(glop) {
        return &amp;quot;stubbed baz &amp;quot; + glop;
    }
});&lt;/pre&gt;

&lt;p&gt;And here is how you can put everything back in place once you’re done:&lt;/p&gt;

&lt;pre class="brush: js;"&gt;stub.restore(foo);&lt;/pre&gt;

&lt;p&gt;I hope this helps...&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=9961668" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/TalesFromTheEvilEmpire/~4/R8SW0KBil9s" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/bleroy/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/JavaScript/default.aspx">JavaScript</category></item><item><title>Always have a host or URL prefix on the default Orchard tenant</title><link>http://weblogs.asp.net/bleroy/archive/2013/02/24/always-have-a-host-or-url-prefix-on-the-default-orchard-tenant.aspx</link><pubDate>Mon, 25 Feb 2013 01:54:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:9909716</guid><dc:creator>Bertrand Le Roy</dc:creator><slash:comments>4</slash:comments><wfw:commentRss>http://weblogs.asp.net/bleroy/rsscomments.aspx?PostID=9909716</wfw:commentRss><comments>http://weblogs.asp.net/bleroy/archive/2013/02/24/always-have-a-host-or-url-prefix-on-the-default-orchard-tenant.aspx#comments</comments><description>&lt;p&gt;The multi-tenancy feature in Orchard enables you to host multiple sites within the same Orchard instance. It’s not a a security feature, just a way to improve site density, and to enable you to save on hosting costs. Nevertheless, a request to a specific existing tenant should never be answered with a page from another tenant. Ever.&lt;/p&gt;  &lt;p&gt;There is however a fallback mechanism that enables one tenant to handle all requests that weren’t identified by another tenant. While this could be considered useful in some scenarios, I’m hereby declaring it bad practice.&lt;/p&gt;  &lt;p&gt;If for any reason a tenant fails to start, for example, requests to that tenant are going to fall back. Even if you were in a scenario where you considered fallback to be useful, this is an unexpected and positively undesirable result. It’s much better to fail with an error message or a 404 than to fail with a fallback to a different site than the one the client asked for.&lt;/p&gt;  &lt;p&gt;So here is my recommendation:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font style="background-color: #ffff00"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font style="style"&gt;&lt;strong&gt;Always have a host or URL prefix configured on &lt;em&gt;all&lt;/em&gt; tenants, in particular the default tenant.&lt;/strong&gt;&lt;/font&gt;&lt;font style="background-color: #ffff00"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt; &lt;p&gt;This way, no fallback will ever happen, and requests will only be handled by a tenant that recognizes its own host name.&lt;/p&gt; &lt;p&gt;Here is, for example, the new configuration of the default tenant on my hosted web sites:&lt;/p&gt;  &lt;p&gt;&lt;img title="Always specify the host name on your Orchard tenants" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 8px 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="Always specify the host name on your Orchard tenants" src="http://weblogs.asp.net/blogs/bleroy/DefaultTenantConfig_35234678.png" width="522" height="192" /&gt;&lt;/p&gt;  &lt;p&gt;Note that I have multiple hosts configured here, including the host that I use on my dev machine for local development, but the point here is to specify something on all tenants.&lt;/p&gt;  &lt;p&gt;This is important.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=9909716" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/TalesFromTheEvilEmpire/~4/YvOirolA13Y" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/bleroy/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/Orchard/default.aspx">Orchard</category></item><item><title>Easy content templates for Orchard, take 2</title><link>http://weblogs.asp.net/bleroy/archive/2013/02/13/easy-content-templates-for-orchard-take-2.aspx</link><pubDate>Thu, 14 Feb 2013 00:21:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:9869783</guid><dc:creator>Bertrand Le Roy</dc:creator><slash:comments>5</slash:comments><wfw:commentRss>http://weblogs.asp.net/bleroy/rsscomments.aspx?PostID=9869783</wfw:commentRss><comments>http://weblogs.asp.net/bleroy/archive/2013/02/13/easy-content-templates-for-orchard-take-2.aspx#comments</comments><description>&lt;p&gt;Placement.info is an XML file that orchestrates the different parts of a content item and sends each of the shapes they create into specific local content zones. If the previous sentence sounded confusing to you, fear not, this post is for you.&lt;/p&gt;  &lt;p&gt;When writing an Orchard theme, more often than not, you know exactly what parts exist in your content type, and you know where you want them to render. Placement can be extremely powerful, but it’s rather abstract and it reverses the usual logic of placing contents on a page. What most people really want to do is write a template with simple markup and placeholders inside that markup for the rendering of specific parts such as title, summary, tags, etc. Placement forces you to dispatch those part shapes from a completely separate file.&lt;/p&gt;  &lt;p&gt;In the Summer of 2011, I wrote a little article to explain how to write custom templates for specific content types in Orchard, without using &lt;a href="http://orchardproject.net/docs/Understanding-placement-info.ashx"&gt;placement.info&lt;/a&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/bleroy/archive/2011/07/31/so-you-don-t-want-to-use-placement-info.aspx"&gt;So you don’t want to use placement.info?&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The solution worked, but relied on a hack that will break with the next version of Orchard (1.7).&lt;/p&gt;  &lt;p&gt;Sébastien Ros gave me a little trick the other day that enables the same thing, in a simpler, less hacky form. It still uses placement somewhat, but in a very simple way.&lt;/p&gt;  &lt;p&gt;The idea is to create one local zone per part instead of the usual header, content and footer zones. Here we are going to send the relevant shapes to those zones through placement:   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Match&lt;/span&gt; &lt;span class="attr"&gt;ContentType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;BlogPost&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Match&lt;/span&gt; &lt;span class="attr"&gt;DisplayType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Summary&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Place&lt;/span&gt; &lt;span class="attr"&gt;Parts_Common_Body_Summary&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Summary:0&amp;quot;&lt;/span&gt;
           &lt;span class="attr"&gt;Parts_Tags_ShowTags&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Tags:0&amp;quot;&lt;/span&gt;
           &lt;span class="attr"&gt;Parts_Common_Metadata_Summary&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;MetadataSummary:0&amp;quot;&lt;/span&gt;
           &lt;span class="attr"&gt;Parts_Comments_Count&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;CommentsCount:0&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Match&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Match&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&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;/p&gt;

&lt;p&gt;This sends shapes into Summary, Tags, MetadataSummary and CommentsCount zones. Those do not yet exist. &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Caveat:&lt;/strong&gt; when naming your custom zones, be careful not to collide with existing properties or zones on the Model, lest you end up with unexpected and confusing results. Using longish and very explicit names usually works well for that.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The template can now simply create and render those zones. Here is my Content-BlogPost.Summary.cshtml template:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;@using Orchard.ContentManagement
@{
    var blogPost = Model.ContentItem;
}
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;article&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;content-item blog-post&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;header&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;h1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;@Url.ItemDisplayUrl((IContent)blogPost)&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;br /&gt;      &lt;/span&gt;@blogPost.TitlePart.Title&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;h1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;header&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    @Display(Model.Summary)
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;footer&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    @Display(Model.Tags)
    @Display(Model.MetadataSummary)
    @Display(Model.CommentsCount)
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;footer&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;article&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Notice how in the case of the title, I’m not even using the shape given by the part, but I’m accessing the properties directly on the TitlePart. The other parts are rendered through the special zone that we created using the Display function. And that is all. You can now focus on building your template, and it will be pretty obvious what will render where…&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=9869783" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/TalesFromTheEvilEmpire/~4/GTFKvGRErGw" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/bleroy/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/Orchard/default.aspx">Orchard</category></item><item><title>Creating simple custom Orchard widgets</title><link>http://weblogs.asp.net/bleroy/archive/2013/02/05/creating-simple-custom-orchard-widgets.aspx</link><pubDate>Wed, 06 Feb 2013 06:21:27 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:9844342</guid><dc:creator>Bertrand Le Roy</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://weblogs.asp.net/bleroy/rsscomments.aspx?PostID=9844342</wfw:commentRss><comments>http://weblogs.asp.net/bleroy/archive/2013/02/05/creating-simple-custom-orchard-widgets.aspx#comments</comments><description>&lt;p&gt;If you want to create a simple widget in Orchard, such as a box of social links, you have three possibilities:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Find &lt;a href="http://gallery.orchardproject.net/List/Modules/Orchard.Module.Szmyd.Orchard.Modules.Sharing"&gt;a module on the gallery&lt;/a&gt; or write one yourself, but there is overhead associated with modules, which may make this overkill.&lt;/li&gt;    &lt;li&gt;Use an HTML widget and paste a bunch of HTML and Javascript, hoping administrators of the site don’t break it accidentally. I don’t like this, it feels like a hack.&lt;/li&gt;    &lt;li&gt;Create a simple widget, following the instructions in this post.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;First, let’s create a content type (in the admin, go to Content / Content Types and click “Create new type”) and call it “Social Links”.&lt;/p&gt;  &lt;p&gt;Add the widget and identity parts. Those are the only ones you really need:&lt;/p&gt;  &lt;p&gt;&lt;img title="Pick the identity and widget parts" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="Pick the identity and widget parts" src="http://weblogs.asp.net/blogs/bleroy/image_678C700B.png" width="106" height="302" /&gt;&lt;/p&gt;  &lt;p&gt;Uncheck creatable and draftable, add the “Widget” stereotype (with an upper-case ‘W’: I made the mistake, as you can see, of using a lower-case ‘w’ on my first try, and it did prevent the widget from being seen as such):&lt;/p&gt;  &lt;p&gt;&lt;img title="configuring the new type" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="configuring the new type" src="http://weblogs.asp.net/blogs/bleroy/image_04951ED4.png" width="272" height="302" /&gt;&lt;/p&gt;  &lt;p&gt;Now when you add a widget, the social links widget appears in the list:&lt;/p&gt;  &lt;p align="center"&gt;&lt;img title="The new widget can now be added to a zone" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="The new widget can now be added to a zone" src="http://weblogs.asp.net/blogs/bleroy/image_4FF75349.png" width="144" height="302" /&gt;&lt;/p&gt;  &lt;p&gt;It’s a simple, apparently featureless widget, which minimizes the chances of accidentally messing it up.&lt;/p&gt;  &lt;p&gt;All that’s left to do now is to add a template to the theme that will render what we want. We’ll take advantage of shape alternates. Using shape tracing, we quickly discover that we can name our template Widget-SocialLinks.cshtml to target it narrowly enough:&lt;/p&gt;  &lt;p&gt;&lt;img title="Shape tracing can show us how to override the rendering" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="Shape tracing can show us how to override the rendering" src="http://weblogs.asp.net/blogs/bleroy/image_6AC37955.png" width="402" height="220" /&gt;&lt;/p&gt;  &lt;p&gt;Once the file has been added to the Views folder of my theme, I can paste in &lt;a href="https://developers.facebook.com/docs/reference/plugins/like/"&gt;the code from Facebook&lt;/a&gt;, Twitter, or whatever else I want in there.&lt;/p&gt;  &lt;p&gt;&lt;img title="All done" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="All done" src="http://weblogs.asp.net/blogs/bleroy/image_7EDF268F.png" width="269" height="122" /&gt;&lt;/p&gt;  &lt;p&gt;Done. Fastest and simplest way to create a new widget.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=9844342" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/TalesFromTheEvilEmpire/~4/hK7LPpR0n5g" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/bleroy/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/Orchard/default.aspx">Orchard</category></item><item><title>Writing an unthemed view while still using Orchard shapes and helpers</title><link>http://weblogs.asp.net/bleroy/archive/2012/10/20/writing-an-unthemed-view-while-still-using-orchard-shapes-and-helpers.aspx</link><pubDate>Sat, 20 Oct 2012 21:16:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:9160341</guid><dc:creator>Bertrand Le Roy</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://weblogs.asp.net/bleroy/rsscomments.aspx?PostID=9160341</wfw:commentRss><comments>http://weblogs.asp.net/bleroy/archive/2012/10/20/writing-an-unthemed-view-while-still-using-orchard-shapes-and-helpers.aspx#comments</comments><description>&lt;p&gt;This quick tip will show how you can write a custom view for a custom controller action in Orchard that does not use the current theme, but that still retains the ability to use shapes, as well as zones, Script and Style helpers.&lt;/p&gt;  &lt;p&gt;The controller action, first, needs to opt out of theming:   &lt;pre class="csharpcode"&gt;[Themed(&lt;span class="kwrd"&gt;false&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Index() {}&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;/p&gt;

&lt;p&gt;Then, we still want to use a shape as the view model, because Clay is so awesome:
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; dynamic _shapeFactory;

&lt;span class="kwrd"&gt;public&lt;/span&gt; MyController(IShapeFactory shapeFactory) {
    _shapeFactory = shapeFactory;
}

[Themed(&lt;span class="kwrd"&gt;false&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Index() {
    &lt;span class="kwrd"&gt;return&lt;/span&gt; View(_shapeFactory.MyShapeName(
        Foo: 42,
        Bar: &lt;span class="str"&gt;&amp;quot;baz&amp;quot;&lt;/span&gt;
        ));
}&lt;/pre&gt;
&lt;/p&gt;

&lt;p&gt;As you can see, we injected a shape factory, and that enables us to build our shape from our action and inject that into the view as the model.&lt;/p&gt;

&lt;p&gt;Finally, in the view (that would in Views/MyController/Index.cshtml here), just use helpers as usual. The only gotcha is that you need to use “Layout” in order to declare zones, and that two of those zones, Head and Tail, are mandatory for the top and bottom scripts and stylesheets to be injected properly. Names are important here.
  &lt;pre class="csharpcode"&gt;@{
    Style.Include(&amp;quot;somestylesheet.css&amp;quot;);
    Script.Require(&amp;quot;jQuery&amp;quot;);
    Script.Include(&amp;quot;somescript.js&amp;quot;);
    using(Script.Foot()) {
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            $(&lt;span class="kwrd"&gt;function&lt;/span&gt; () {
                &lt;span class="rem"&gt;// Do stuff&lt;/span&gt;
            })
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    }
}
&lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="html"&gt;DOCTYPE&lt;/span&gt; &lt;span class="attr"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;My unthemed page&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        @Display(Layout.Head)
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;h1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;My unthemed page&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;h1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;@Model.Foo is the answer.&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    @Display(Layout.Tail)
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/p&gt;

&lt;p&gt;Note that if you define your own zones using &lt;font face="Courier New"&gt;@Display(Layout.SomeZone)&lt;/font&gt; in your view, you can perfectly well send additional shapes to them from your controller action, if you injected an instance of IWorkContextAccessor:

  &lt;pre class="csharpcode"&gt;_workContextAccessor.GetContext().Layout
    .SomeZone.Add(_shapeFactory.SomeOtherShape());&lt;/pre&gt;
&lt;/p&gt;

&lt;p&gt;Of course, you’ll need to write a SomeOtherShape.cshtml template for that shape but I think this is pretty neat.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=9160341" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/TalesFromTheEvilEmpire/~4/bVHrnPLb7Ss" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/bleroy/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/Orchard/default.aspx">Orchard</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/Clay/default.aspx">Clay</category></item><item><title>TypeScript first impressions</title><link>http://weblogs.asp.net/bleroy/archive/2012/10/01/typescript-first-impressions.aspx</link><pubDate>Mon, 01 Oct 2012 20:51:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:9031444</guid><dc:creator>Bertrand Le Roy</dc:creator><slash:comments>17</slash:comments><wfw:commentRss>http://weblogs.asp.net/bleroy/rsscomments.aspx?PostID=9031444</wfw:commentRss><comments>http://weblogs.asp.net/bleroy/archive/2012/10/01/typescript-first-impressions.aspx#comments</comments><description>&lt;p&gt;Anders published &lt;a href="http://channel9.msdn.com/posts/Anders-Hejlsberg-Introducing-TypeScript"&gt;a video of his new project today&lt;/a&gt;, which aims at creating a superset of JavaScript, that compiles down to regular current JavaScript. Anders is a tremendously clever guy, and it always shows in his work. There is much to like in the enterprise (good code completion, refactoring and adoption of &lt;a href="http://weblogs.asp.net/bleroy/archive/2012/09/03/namespaces-are-obsolete.aspx"&gt;the module pattern instead of namespaces&lt;/a&gt; to name three), but a few things made me rise an eyebrow.&lt;/p&gt;  &lt;p&gt;First, there is no mention of &lt;a href="http://coffeescript.org/"&gt;CoffeeScript&lt;/a&gt; or &lt;a href="http://en.wikipedia.org/wiki/Google_Dart"&gt;Dart&lt;/a&gt;, but he does talk briefly about &lt;a href="http://www.nikhilk.net/ScriptSharp"&gt;Script#&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Google_Web_Toolkit"&gt;GWT&lt;/a&gt;. This is probably because the target audience seems to be the same as the audience for the latter two, i.e. developers who are more comfortable with statically-typed languages such as C# and Java than dynamic languages such as JavaScript. I don’t think he’s aiming at JavaScript developers. Classes and interfaces, although well executed, are not especially appealing.&lt;/p&gt;  &lt;p&gt;Second, as any code generation tool (and this is true of CoffeeScript as well), you’d better like the generated code. I didn’t, unfortunately. The code that I saw is not the code I would have written. What’s more, I didn’t always find the TypeScript code especially more expressive than what it gets compiled to.&lt;/p&gt;  &lt;p&gt;I also have a few questions.&lt;/p&gt;  &lt;p&gt;Is it possible to duck-type interfaces? For example, if I have an IPoint2D interface with x and y coordinates, can I pass any object that has x and y into a function that expects IPoint2D or do I need to necessarily create a class that implements that interface, and new up an instance that explicitly declares its contract? The appeal of dynamic languages is the ability to make objects as you go. This needs to be kept intact.&lt;/p&gt;&lt;p&gt;&lt;b&gt;UPDATE&lt;/b&gt;: this works.&lt;/p&gt;  &lt;p&gt;More technical: why are generated variables and functions prefixed with _ rather than the $ that the &lt;a href="http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf"&gt;EcmaScript&lt;/a&gt; spec recommends for machine-generated variables?&lt;/p&gt;  &lt;p&gt;In conclusion, while this is a good contribution to the set of ideas around JavaScript evolution, I don’t expect a lot of adoption outside of the devoted Microsoft developers, but maybe some influence on the language itself. But I’m often wrong. I would certainly not use it because &lt;strong&gt;I disagree with the central motivation&lt;/strong&gt; for doing this: Anders explicitly says he built this because “writing application-scale JavaScript is hard”. I would restate that “writing application-scale JavaScript is hard for people who are used to statically-typed languages”. The community has built a set of good practices over the last few years that do scale quite well, and many people are successfully developing and maintaining impressive applications directly in JavaScript.&lt;/p&gt;  &lt;p&gt;You can play with TypeScript here: &lt;a href="http://www.typescriptlang.org"&gt;http://www.typescriptlang.org&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=9031444" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/TalesFromTheEvilEmpire/~4/V5lGiKngrHY" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/bleroy/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/Microsoft/default.aspx">Microsoft</category></item><item><title>Final laptop, ultimate laptop or neither?</title><link>http://weblogs.asp.net/bleroy/archive/2012/09/23/final-laptop-ultimate-laptop-or-neither.aspx</link><pubDate>Mon, 24 Sep 2012 00:50:38 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:8978481</guid><dc:creator>Bertrand Le Roy</dc:creator><slash:comments>4</slash:comments><wfw:commentRss>http://weblogs.asp.net/bleroy/rsscomments.aspx?PostID=8978481</wfw:commentRss><comments>http://weblogs.asp.net/bleroy/archive/2012/09/23/final-laptop-ultimate-laptop-or-neither.aspx#comments</comments><description>&lt;p&gt;&lt;img title="Samsung Series 9" style="float: left; margin: 0px 10px 10px 0px; display: inline" alt="Samsung Series 9" align="left" src="http://www.beritateknologi.com/wp-content/uploads/2011/01/samsung-9-series.jpg" width="240" height="173" /&gt;Jeff Atwood has &lt;a href="http://www.codinghorror.com/blog/2012/09/the-last-pc-laptop.html"&gt;an interesting post&lt;/a&gt; today where he says his current laptop may be the last one he buys. The argument is that &lt;a href="http://yieldthought.com/post/12239282034/swapped-my-macbook-for-an-ipad"&gt;tablets are a better option&lt;/a&gt; now, with longer battery life, less lap overheating, and a nicer form factor. But well, tablets are not for me. I always need a keyboard, a full version of Windows, I rarely need to run on the battery for very long, and the tablet form factor just doesn’t work for me. I like my screen to stand on its own, even on my lap, and having a separated keyboard is just clumsy. The surface looks like an interesting compromise, but the lack of a robust hinge makes it a no-go for me. Also, I want a single machine that works for everything I do.&lt;/p&gt;  &lt;p&gt;I usually buy my desktop machines with a very different approach from the Atwoods and Hanselmans of the world: they seem to always go for the best and change them often, whereas I go for older, cheaper parts that I swap out to make the computers last as long as possible. Buying lots of new devices all the time feels icky to the environmentalist in me.&lt;/p&gt;  &lt;p&gt;The last machine I retired was twenty years old and the only reason I changed it was that I got a case for free with the replacement parts I needed. Granted, the case &lt;em&gt;was&lt;/em&gt; the only remaining original part. But still, I’ve made it last by swapping old parts with new ones as needed, and it’s been a very economical solution. I never go for the top-of-the-line, makes-your-eyes-bleed-with-ecstasy graphics cards, processors and memory. Instead, I buy year-old-ish parts, in that sweet spot where they have gotten extremely inexpensive but are still the equivalent of last year’s best. Last year was awesome last year, remember? And before you ask, I do most of my gaming on Xbox, so I really don’t need a gaming type of PC.&lt;/p&gt;  &lt;p&gt;Laptops are different however: you can’t swap parts so easily. A couple of years ago, I started using my laptop as my main machine. This has the advantage that I can work anywhere with the same tools and data, even if I’m not connected. In my home office, in &lt;a href="http://www.besthf.com/best/Furniture/Chairs/Video-Rockers"&gt;my rocker&lt;/a&gt; in front of the TV, in a coffee house or on the plane. Nothing to copy onto it before I leave, it’s all already there, always, like a little cloud that follows me everywhere I go. Laptops are awesomely light and small nowadays, and they can still pack all the power that I need. When I started working freelance last year, I shopped around and after considering a MacBook Air, I settled on a &lt;a href="http://www.samsung.com/us/computer/laptops/NP900X3A-A03US"&gt;Samsung Series 9&lt;/a&gt; with 6GB of RAM and 256GB of SSD. I did not want to have to change anything on the machine, and the Samsung was the only machine that reached out of the box all my requirements, one of which was to be very small, and another that I could hook it to a large external screen.&lt;/p&gt;  &lt;p&gt;A year after, I still love that machine. I’ve had an issue with the quality of the plastics, and had to replace the piece that surrounds the keyboard after it cracked (covered under the awesome 3-year warranty), and I do resent the lack of anything else than HDMI when I talk at conferences, but overall it’s a fantastic piece of technology and a near-perfect fit for me.&lt;/p&gt;  &lt;p&gt;Would I surrender the advantages of having everything I need in a form factor that I like for a hipper tablet? Of course not. As I said, tablets are not for me. They may be fantastic devices, but I need my Visual Studio, my keyboard and my hinge.&lt;/p&gt;  &lt;p&gt;Is it the ultimate laptop? Of course not. I wouldn’t mind a retina-like screen, double the SSD, and a little more battery juice.&lt;/p&gt;  &lt;p&gt;So why am I telling you all that? In today’s hardware market, we have more variety and form factors than we ever had before: phones, tablets, hybrids, laptops, &lt;a href="http://www.raspberrypi.org/"&gt;ridiculously small and cheap microcontrollers that can output HD video&lt;/a&gt;, and of course desktops. That’s choice, people, and if you can handle it, it’s a wonderful thing to have. Pick what fits your life and work styles (and make it last).&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8978481" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/TalesFromTheEvilEmpire/~4/ynNfOxo_DbM" height="1" width="1"/&gt;</description></item><item><title>Namespaces are obsolete</title><link>http://weblogs.asp.net/bleroy/archive/2012/09/03/namespaces-are-obsolete.aspx</link><pubDate>Mon, 03 Sep 2012 21:42:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:8888702</guid><dc:creator>Bertrand Le Roy</dc:creator><slash:comments>59</slash:comments><wfw:commentRss>http://weblogs.asp.net/bleroy/rsscomments.aspx?PostID=8888702</wfw:commentRss><comments>http://weblogs.asp.net/bleroy/archive/2012/09/03/namespaces-are-obsolete.aspx#comments</comments><description>&lt;p&gt;&lt;img title="Microsoft.SqlServer.Management.Smo.Agent" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: left; padding-top: 0px; padding-left: 0px; margin: 0px 10px 10px 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="Microsoft.SqlServer.Management.Smo.Agent" align="left" src="http://weblogs.asp.net/blogs/bleroy/image_64CD2233.png" width="244" height="232" /&gt;To those of us who have been around for a while, namespaces have been part of the landscape. One could even say that they have been defining the large-scale features of the landscape in question.&lt;/p&gt;  &lt;p&gt;However, something happened fairly recently that I think makes this venerable structure obsolete. Before I explain this development and why it’s a superior concept to namespaces, let me recapitulate what namespaces are and why they’ve been so good to us over the years…&lt;/p&gt;  &lt;p&gt;Namespaces are used for a few different things:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;Scope&lt;/strong&gt;: a namespace delimits the portion of code where a name (for a class, sub-namespace, etc.) has the specified meaning. Namespaces are usually the highest-level scoping structures in a software package.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Collision prevention&lt;/strong&gt;: name collisions are a universal problem. Some systems, such as jQuery, wave it away, but the problem remains. Namespaces provide a reasonable approach to global uniqueness (and in some implementations such as XML, enforce it). In .NET, there are &lt;a href="http://msdn.microsoft.com/en-us/library/c3ay4x3d(VS.80).aspx"&gt;ways to relocate a namespace&lt;/a&gt; to avoid those rare collision cases.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Hierarchy&lt;/strong&gt;: programmers like neat little boxes, and especially boxes within boxes within boxes. For some reason. Regular human beings on the other hand, tend to think linearly, which is why the Windows explorer for example has tried in a few different ways to flatten the file system hierarchy for the user.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;1 is clearly useful because we need to protect our code from bleeding effects from the rest of the application (and vice versa). A language with only global constructs may be what some of us started programming on, but it’s not desirable in any way today.&lt;/p&gt;  &lt;p&gt;2 may not be always reasonably worth the trouble (jQuery is doing fine with its global plug-in namespace), but we still need it in many cases. One should note however that globally unique names are not the only possible implementation. In fact, they are a rather extreme solution. What we really care about is collision prevention &lt;em&gt;within our application&lt;/em&gt;. What happens outside is irrelevant.&lt;/p&gt;  &lt;p&gt;3 is, more than anything, an aesthetical choice. A common convention has been to encode the whole pedigree of the code into the namespace. Come to think about it, we never think we need to import “Microsoft.SqlServer.Management.Smo.Agent” and that would be very hard to remember. What we want to do is bring nHibernate into our app.&lt;/p&gt;  &lt;p&gt;And this is precisely what you’ll do with modern package managers and module loaders. I want to take the specific example of &lt;a href="http://requirejs.org"&gt;RequireJS&lt;/a&gt;, which is commonly used with &lt;a href="http://nodejs.org/"&gt;Node&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Here is how you import a module with RequireJS:   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;var&lt;/span&gt; http = require(&lt;span class="str"&gt;&amp;quot;http&amp;quot;&lt;/span&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;/p&gt;

&lt;p&gt;This is of course importing a HTTP stack module into the code. There is no noise here. Let’s break this down.&lt;/p&gt;

&lt;p&gt;Scope (1) is provided by the one scoping mechanism in JavaScript: the closure surrounding the module’s code. Whatever scoping mechanism is provided by the language would be fine here.&lt;/p&gt;

&lt;p&gt;Collision prevention (2) is very elegantly handled. Whereas relocating is an afterthought, and an exceptional measure with namespaces, it is here on the frontline. You &lt;em&gt;always&lt;/em&gt; relocate, using an extremely familiar pattern: variable assignment. We are very much used to managing our local variable names and any possible collision will get solved very easily by picking a different name.&lt;/p&gt;

&lt;p&gt;Wait a minute, I hear some of you say. This is only taking care of collisions on the client-side, on the left of that assignment. What if I have two libraries with the name “http”? Well, You can better qualify the path to the module, which is what the require parameter really is.&lt;/p&gt;

&lt;p&gt;As for hierarchical organization, you don’t really want that, do you?&lt;/p&gt;

&lt;p&gt;RequireJS’ module pattern does elegantly cover the bases that namespaces used to cover, but it also promotes additional good practices.&lt;/p&gt;

&lt;p&gt;First, it promotes usage of self-contained, single responsibility units of code through the closure-based, stricter scoping mechanism. Namespaces are somewhat more porous, as using/import statements can be used bi-directionally, which leads us to my second point…&lt;/p&gt;

&lt;p&gt;Sane dependency graphs are easier to achieve and sustain with such a structure. With namespaces, it is easy to construct dependency cycles (&lt;a href="http://www.infoq.com/articles/NDepend"&gt;that’s bad&lt;/a&gt;, mmkay?). With this pattern, the equivalent would be to build mega-components, which are an easier problem to spot than a decay into inter-dependent namespaces, for which you need &lt;a href="http://www.ndepend.com/"&gt;specialized tools&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I really like this pattern very much, and I would like to see more environments implement it. One could argue that dependency injection has some commonalities with this for example. What do you think? This is the half-baked result of some morning shower reflections, and I’d love to read your thoughts about it. What am I missing?&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8888702" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/TalesFromTheEvilEmpire/~4/rAXwXLKUjEA" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/bleroy/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/Dynamic+languages/default.aspx">Dynamic languages</category></item><item><title>A quick guide to the built-in Orchard modules</title><link>http://weblogs.asp.net/bleroy/archive/2012/07/16/a-quick-guide-to-the-built-in-orchard-modules.aspx</link><pubDate>Mon, 16 Jul 2012 11:35:05 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:8745810</guid><dc:creator>Bertrand Le Roy</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://weblogs.asp.net/bleroy/rsscomments.aspx?PostID=8745810</wfw:commentRss><comments>http://weblogs.asp.net/bleroy/archive/2012/07/16/a-quick-guide-to-the-built-in-orchard-modules.aspx#comments</comments><description>&lt;p&gt;With the imminent release of Orchard 1.5, the number of built-in modules in the default distribution is getting quite impressive, if not intimidating. Now may be a good time to give new and old users a tour of what comes out of the box. Who knows, we may discover a hidden nugget or two along the way…&lt;/p&gt;  &lt;p&gt;I just finished writing a massive documentation topic that describes all Orchard features that come with the source code and WebPI distributions:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://docs.orchardproject.net/Documentation/Builtin-features"&gt;All built-in Orchard modules described&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I added the guide to the official Orchard documentation site. It details what modules come in the default package, which are only available from the source code package or from the gallery, and also mentions which are enabled by default.&lt;/p&gt;  &lt;p&gt;Documentation, like everything in Orchard, is open source, so you can contribute to this topic and others: &lt;a href="https://github.com/OrchardCMS/OrchardDoc/blob/131e204d65293549c8dd838c2a08a0aaf88f97ab/Documentation/Builtin-Features.markdown"&gt;Edit this topic&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I hope this helps.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8745810" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/TalesFromTheEvilEmpire/~4/2BJV7TW5UYM" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/bleroy/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/bleroy/archive/tags/Orchard/default.aspx">Orchard</category></item></channel></rss>
