<?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"?><!-- generator="wordpress/2.3.1" --><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">

<channel>
	<title>.Net Smoothie</title>
	<link>http://www.richardbushnell.net</link>
	<description>A perfect blend of all things Dot Net</description>
	<pubDate>Thu, 12 Mar 2009 13:54:33 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
	<language>en</language>
			<image><link>http://richardbushnell.net</link><url>http://farm1.static.flickr.com/211/509088131_d8563bd805_t.jpg</url><title>Richard Bushnell</title></image><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/dotnetSmoothie" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Connecting to Azure Table Storage</title>
		<link>http://www.richardbushnell.net/index.php/2009/03/12/connecting-to-azure-table-storage/</link>
		<comments>http://www.richardbushnell.net/index.php/2009/03/12/connecting-to-azure-table-storage/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 13:52:22 +0000</pubDate>
		<dc:creator>Richard Bushnell</dc:creator>
		
		<category><![CDATA[Azure]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Azure table-storage]]></category>

		<guid isPermaLink="false">http://www.richardbushnell.net/index.php/2009/03/12/connecting-to-azure-table-storage/</guid>
		<description><![CDATA[After you finally manage to get Table Storage working (see nice tutorial here) you&#8217;ll try to deploy it to your staging environment. That means you need to change the configuration.
There are three settings to use: AccountName, AccountSharedKey and TableStorageEndpoint. 
Unfortunately, the values you need for them aren&#8217;t what you would naturally expect.
AccountName: This isn&#8217;t your [...]]]></description>
			<content:encoded><![CDATA[<p>After you finally manage to get Table Storage working (see nice tutorial here) you&#8217;ll try to deploy it to your staging environment. That means you need to change the configuration.</p>
<p>There are three settings to use: <strong>AccountName</strong>, <strong>AccountSharedKey</strong> and <strong>TableStorageEndpoint</strong>. </p>
<p>Unfortunately, the values you need for them aren&#8217;t what you would naturally expect.</p>
<p><strong>AccountName</strong>: This isn&#8217;t <em>your</em> account name, but the name of your storage account. (I guess that&#8217;s why it has to be a unique name at the time you create it.) On the summary page of your storage project you will only see the value you need in the list of endpoints. It&#8217;s the first part of each of the three domain names.</p>
<p><strong>AccountSharedKey</strong>: This is the Primary Access Key as found in the summary page of your storage project in the developer portal.</p>
<p><strong>TableStorageEndpoint</strong>: This isn&#8217;t the endpoint as described in the summary page, but rather a shortened version. Just lop off the AccountName part of the endpoint you use as described in the summary page. That should give you something like <strong>http://table.core.windows.net</strong>.</p>
<p>For more information see <a href="http://msdn.microsoft.com/en-us/library/dd203057.aspx" onclick="javascript:pageTracker._trackVisit('/outbound/article/msdn.microsoft.com');">this article</a> on MSDN.</p>
<p>It is so time-consuming to get right, that it really makes sense to follow the advice in the documentation. First, test locally. Then test your local hosted app using the live Storage account. Finally, load your app and test that in the staging environment.</p>
<p>Saying that, I haven&#8217;t yet managed to get the second scenario to work. It just crashes on start-up. (Help!)</p>

<img src="http://feeds.feedburner.com/~r/dotnetSmoothie/~4/Pf4dic6838s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/index.php/2009/03/12/connecting-to-azure-table-storage/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Learning Windows Azure</title>
		<link>http://www.richardbushnell.net/index.php/2009/03/12/learning-windows-azure/</link>
		<comments>http://www.richardbushnell.net/index.php/2009/03/12/learning-windows-azure/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 10:01:40 +0000</pubDate>
		<dc:creator>Richard Bushnell</dc:creator>
		
		<category><![CDATA[ASP.Net]]></category>

		<category><![CDATA[Azure]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Software]]></category>

		<category><![CDATA[Azure cloud getting-started]]></category>

		<guid isPermaLink="false">http://www.richardbushnell.net/index.php/2009/03/12/learning-windows-azure/</guid>
		<description><![CDATA[I started to learn how to use the Azure Cloud Service from Microsoft this week. Currently it&#8217;s still in Tech Preview stage. Unfortunately you can tell that from the SDK documentation.
Here&#8217;s some useful links to get you going:

Screencasts: http://msdn.microsoft.com/en-us/azure/dd439432.aspx       These are quite basic, but trust me, you need them [...]]]></description>
			<content:encoded><![CDATA[<p>I started to learn how to use the Azure Cloud Service from Microsoft this week. Currently it&#8217;s still in Tech Preview stage. Unfortunately you can tell that from the SDK documentation.</p>
<p>Here&#8217;s some useful links to get you going:</p>
<ol>
<li><strong>Screencasts</strong>: <a href="http://msdn.microsoft.com/en-us/azure/dd439432.aspx"title="http://msdn.microsoft.com/en-us/azure/dd439432.aspx"  onclick="javascript:pageTracker._trackVisit('/outbound/article/msdn.microsoft.com');">http://msdn.microsoft.com/en-us/azure/dd439432.aspx</a>       <br />These are quite basic, but trust me, you need them to be basic to get you started. </li>
<li><strong>SDK</strong>: <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=80e3eabf-0507-4560-aeb6-d31e9a70a0a6&amp;displaylang=en"title="http://www.microsoft.com/downloads/details.aspx?FamilyID=80e3eabf-0507-4560-aeb6-d31e9a70a0a6&amp;displaylang=en"  onclick="javascript:pageTracker._trackVisit('/outbound/article/www.microsoft.com');">http://www.microsoft.com/downloads/details.aspx?FamilyID=80e3eabf-0507-4560-aeb6-d31e9a70a0a6&amp;displaylang=en</a>       <br />Contains CHTM-style documentation, tools and samples. Don&#8217;t expect too much from the docs; they explain enough to get you confused, and then have an API reference. You need to unzip the samples and get into them to start understanding how everything fits together. </li>
<li><strong>Visual Studio Templates</strong>: <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=8e90b639-1ef0-4e21-bb73-fc22662911bc&amp;displaylang=en"title="http://www.microsoft.com/downloads/details.aspx?FamilyID=8e90b639-1ef0-4e21-bb73-fc22662911bc&amp;displaylang=en"  onclick="javascript:pageTracker._trackVisit('/outbound/article/www.microsoft.com');">http://www.microsoft.com/downloads/details.aspx?FamilyID=8e90b639-1ef0-4e21-bb73-fc22662911bc&amp;displaylang=en</a>       <br />This gives you a set of project and item templates which you can use to create and publish Azure applications. Don&#8217;t worry about the extra projects it adds to a solution, or the config files. You will learn more about them later. </li>
<li>The <strong>Azure developer center</strong> on MSDN: <a href="http://msdn.microsoft.com/en-us/azure/default.aspx"title="http://msdn.microsoft.com/en-us/azure/default.aspx"  onclick="javascript:pageTracker._trackVisit('/outbound/article/msdn.microsoft.com');">http://msdn.microsoft.com/en-us/azure/default.aspx</a> </li>
</ol>
<p>Assuming you already <a href="http://go.microsoft.com/fwlink/?LinkID=129453" target="_blank" onclick="javascript:pageTracker._trackVisit('/outbound/article/go.microsoft.com');">registered for Azure</a>, that&#8217;s all you really need to get started.</p>
<p>The biggest problem I found at first was deploying an app. Once you have generated an Azure project in Visual Studio, you expect to be able to publish it from Visual Studio too. Unfortunately you can&#8217;t, and it takes a little more effort. I&#8217;ll write more about that in another post.</p>
<p>I also needed help trying to understand what to focus on to get started. So here&#8217;s a big tip: Ignore .Net Services, Live Services, and SQL Data Services. They aren&#8217;t part of Azure per se. You can come back to them later. First you just need a hosted project and some storage - either blob storage or table storage. (There&#8217;s also queue storage, but I bet no one will want to use that straight away - it&#8217;s for tying two apps together, which no one will want to do at first.)</p>
<p>I recommend you <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=80e3eabf-0507-4560-aeb6-d31e9a70a0a6&amp;displaylang=en" onclick="javascript:pageTracker._trackVisit('/outbound/article/www.microsoft.com');">download the SDK</a> and the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=8e90b639-1ef0-4e21-bb73-fc22662911bc&amp;displaylang=en" onclick="javascript:pageTracker._trackVisit('/outbound/article/www.microsoft.com');">Visual Studio templates</a>, create yourself a &#8220;Web Role&#8221; project (which is really the equivalent of an ASP.Net project), and work on that. Then move onto table and blob storage. You can use the <a href="http://msdn.microsoft.com/en-us/azure/dd439432.aspx" target="_blank" onclick="javascript:pageTracker._trackVisit('/outbound/article/msdn.microsoft.com');">screencasts</a> to help you.</p>
<p>Good luck getting started!</p>

<img src="http://feeds.feedburner.com/~r/dotnetSmoothie/~4/IVHWeOFUf7E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/index.php/2009/03/12/learning-windows-azure/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C# Acrobatics : Lambdas and Expression Methods as a replacement for NVelocity</title>
		<link>http://www.richardbushnell.net/index.php/2008/06/02/c-acrobatics-lambdas-and-expression-methods-as-a-replacement-for-nvelocity/</link>
		<comments>http://www.richardbushnell.net/index.php/2008/06/02/c-acrobatics-lambdas-and-expression-methods-as-a-replacement-for-nvelocity/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 10:09:06 +0000</pubDate>
		<dc:creator>Richard Bushnell</dc:creator>
		
		<category><![CDATA[.Net]]></category>

		<category><![CDATA[ASP.Net]]></category>

		<category><![CDATA[C# 3.0]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[Extension Methods]]></category>

		<category><![CDATA[Lambda Expressions]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[ListView]]></category>

		<category><![CDATA[NVelocity]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/06/02/c-acrobatics-lambdas-and-expression-methods-as-a-replacement-for-nvelocity/</guid>
		<description><![CDATA[I&#8217;ve been very quiet recently. (I&#8217;m trying to not be so loud, Scott.  ) You see, I&#8217;ve been writing a lot of ASP.Net code for a site I&#8217;m working on. And, to be honest, I&#8217;ve been having a lot of trouble. The source code for .Net has been very helpful, and I&#8217;ve learnt a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been very quiet recently. (I&#8217;m trying to not be so <a href="http://www.hanselman.com/blog/ProfessionalismProgrammingAndPunditryAndSuccessAsAMetric.aspx" target="_blank" onclick="javascript:pageTracker._trackVisit('/outbound/article/www.hanselman.com');">loud</a>, Scott. <img src='http://www.richardbushnell.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) You see, I&#8217;ve been writing a lot of ASP.Net code for a site I&#8217;m working on. And, to be honest, I&#8217;ve been having a <em>lot</em> of trouble. The <a href="http://richardbushnell.net/index.php/2008/04/18/the-value-of-being-free-to-see-the-source/" target="_blank" >source code for .Net</a> has been very helpful, and I&#8217;ve learnt a lot about what&#8217;s going on under the covers of ASP.Net because of it. </p>
<p>(Note: I won&#8217;t comment here on the quality of the code I&#8217;ve found - I&#8217;ll leave that up to you to judge. But in any case, I&#8217;ve been trying to build on top of it.)</p>
<p>One thing I&#8217;ve found to be important is the reliance on Web Controls. (It&#8217;s got something to do with javascript libraries, but that&#8217;s another story.) Getting away from the &quot;standard&quot; way to do ASP.Net isn&#8217;t easy though. Even the ninjas on the <a href="http://www.haacked.com/archive/2008/05/31/the-design-is-never-right-the-first-time.aspx" target="_blank" onclick="javascript:pageTracker._trackVisit('/outbound/article/www.haacked.com');">ASP.Net MVC</a> team <a href="http://www.haacked.com/archive/2008/05/03/code-based-repeater-for-asp.net-mvc.aspx" target="_blank" onclick="javascript:pageTracker._trackVisit('/outbound/article/www.haacked.com');">seem to be having trouble</a>. However, with the magic of lambdas and extension methods in C#, I think I might have just about managed to get something usable. I thought I&#8217;d publish my work here, and see what comments I got.</p>
<p>I think it&#8217;s best to start with what my ASP.Net code looks like once I&#8217;ve got everything working. (Notice I still have some Web Controls in there, but that&#8217;s because I&#8217;ve not worked out how to do sorting of data without web controls yet.)</p>
<p>The inspiration for this was taken from the <a href="r" target="_blank">improvements made to NVelocity</a> by the gurus on the Castle Project. I thought it looked great, and I&#8217;d like something similar, but I didn&#8217;t really want to learn a whole new scripting language and integrate it into my working environment just for rendering a bit of HTML. So I built some C# classes to do a similar thing for me instead. It&#8217;s not as nice as NVelocity, but it&#8217;s okay for now.</p>
<p><strong>Warning</strong>: The following code may contain statements of a disturbing nature to more sensitive readers. We cannot be held responsible for any confusion, delusion or mental illness caused by this code.</p>
<p>It starts by taking a collection of Task objects, and calling the extension method &quot;ForEach&quot; on them:</p>
<pre class="code"><span style="background: #ffee62">&lt;%</span> Tasks.ForEach(sections =&gt; {
   sections.NoData = tasks =&gt; {
<span style="background: #ffee62">%&gt;
</span><span style="color: blue">   &lt;</span><span style="color: #a31515">p</span><span style="color: blue">&gt;
</span>   Hey, you&#8217;ve got nothing to do.<span style="color: blue">&lt;/</span><span style="color: #a31515">p</span><span style="color: blue">&gt;
   &lt;</span><span style="color: #a31515">p</span><span style="color: blue">&gt;
</span><span style="background: #ffee62">&lt;%
</span>   };
   sections.BeforeAll = tasks =&gt; {
   <span style="background: #ffee62">%&gt;
</span>  <span style="color: blue">&lt;</span><span style="color: #a31515">table </span><span style="color: red">class</span><span style="color: blue">=&quot;task-list&quot;&gt;
    &lt;</span><span style="color: #a31515">tr </span><span style="color: red">class</span><span style="color: blue">=&quot;task-list-header&quot;&gt;
      &lt;</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">LinkButton </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">CommandName</span><span style="color: blue">=&quot;Sort&quot; </span><span style="color: red">CommandArgument</span><span style="color: blue">=&quot;StartDate&quot;
          </span><span style="color: red">Text</span><span style="color: blue">=&quot;Started&quot; /&gt;
      &lt;/</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">LinkButton </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">CommandName</span><span style="color: blue">=&quot;Sort&quot; </span><span style="color: red">CommandArgument</span><span style="color: blue">=&quot;DueOn&quot;
          </span><span style="color: red">Text</span><span style="color: blue">=&quot;Due&quot; /&gt;
      &lt;/</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">LinkButton </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">CommandName</span><span style="color: blue">=&quot;Sort&quot; </span><span style="color: red">CommandArgument</span><span style="color: blue">=&quot;Priority&quot;
          </span><span style="color: red">Text</span><span style="color: blue">=&quot;Priority&quot; /&gt;
      &lt;/</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">LinkButton </span><span style="color: red">CssClass</span><span style="color: blue">=&quot;task-description&quot; </span><span style="color: red">CommandName</span><span style="color: blue">=&quot;Sort&quot; </span><span style="color: red">CommandArgument</span><span style="color: blue">=&quot;Title&quot;
          </span><span style="color: red">Text</span><span style="color: blue">=&quot;Description&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; /&gt;
      &lt;/</span><span style="color: #a31515">th</span><span style="color: blue">&gt;</span><span style="color: blue">      &lt;</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
      &lt;/</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">tr</span><span style="color: blue">&gt;
   </span><span style="background: #ffee62">&lt;%
</span>   };
     sections.Before = task =&gt; {
    <span style="background: #ffee62">%&gt;
</span>    <span style="color: blue">&lt;</span><span style="color: #a31515">tr </span><span style="color: red">class</span><span style="color: blue">=&quot;</span><span style="background: #ffee62">&lt;%</span>= this.tableCssClasses.Next() <span style="background: #ffee62">%&gt;</span><span style="color: blue">&quot;&gt;
    </span><span style="background: #ffee62">&lt;%
</span>   };
   sections.Each = task =&gt; {
    <span style="background: #ffee62">%&gt;</span>
    <span style="color: blue">&lt;</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">div </span><span style="color: red">class</span><span style="color: blue">=&#8217;calendar calendar-icon-</span><span style="background: #ffee62">&lt;%</span>= task.StartMonth <span style="background: #ffee62">%&gt;</span><span style="color: blue">&#8216;&gt;
        &lt;</span><span style="color: #a31515">div </span><span style="color: red">class</span><span style="color: blue">=&quot;calendar-day&quot;&gt;
          </span><span style="background: #ffee62">&lt;%</span><span style="color: blue">= </span>task.StartDayOfMonth <span style="background: #ffee62">%&gt;</span><span style="color: blue">&lt;/</span><span style="color: #a31515">div</span><span style="color: blue">&gt;
      &lt;/</span><span style="color: #a31515">div</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">div </span><span style="color: red">class</span><span style="color: blue">=&#8217;calendar calendar-icon-</span><span style="background: #ffee62">&lt;%</span>= task.DueMonth <span style="background: #ffee62">%&gt;</span><span style="color: blue">&#8216;&gt;
        &lt;</span><span style="color: #a31515">div </span><span style="color: red">class</span><span style="color: blue">=&quot;calendar-day&quot;&gt;
          </span><span style="background: #ffee62">&lt;%</span><span style="color: blue">= </span>task.DueDayOfMonth <span style="background: #ffee62">%&gt;</span><span style="color: blue">&lt;/</span><span style="color: #a31515">div</span><span style="color: blue">&gt;
      &lt;/</span><span style="color: #a31515">div</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
      </span><span style="background: #ffee62">&lt;%</span><span style="color: blue">= </span>task.Priority <span style="background: #ffee62">%&gt;
</span>    <span style="color: blue">&lt;/</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">td </span><span style="color: red">class</span><span style="color: blue">=&quot;task-title&quot;&gt;
      &lt;</span><span style="color: #a31515">a </span><span style="color: red">href</span><span style="color: blue">=&#8217;</span><span style="background: #ffee62">&lt;%</span>= Href.For(&quot;~/Tasks/{0}/Show.aspx&quot;, task.ID) <span style="background: #ffee62">%&gt;</span><span style="color: blue">&#8216;&gt;</span><span style="background: #ffee62">&lt;%</span><span style="color: blue">= </span>task.Title <span style="background: #ffee62">%&gt;</span><span style="color: blue">&lt;/</span><span style="color: #a31515">a</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
</span><span style="color: blue">    &lt;</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Button </span><span style="color: red">ID</span><span style="color: blue">=&quot;Button1&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">CssClass</span><span style="color: blue">=&quot;button&quot; </span><span style="color: red">CommandName</span><span style="color: blue">=&quot;Delete&quot; </span><span style="color: red">Text</span><span style="color: blue">=&quot;Mark Done&quot; /&gt;
    &lt;/</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
    </span><span style="background: #ffee62">&lt;%
</span>   };

   sections.After = task =&gt; {
    <span style="background: #ffee62">%&gt;
</span>    <span style="color: blue">&lt;/</span><span style="color: #a31515">tr</span><span style="color: blue">&gt;
    </span><span style="background: #ffee62">&lt;%
</span>   };

   sections.AfterAll = task =&gt; {
    <span style="background: #ffee62">%&gt;
</span>    <span style="color: blue">&lt;/</span><span style="color: #a31515">table</span><span style="color: blue">&gt;
    </span><span style="background: #ffee62">&lt;%
</span>   };
 });
<span style="background: #ffee62">%&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste" onclick="javascript:pageTracker._trackVisit('/outbound/article/11011.net');"></a></p>
<p>It might take a while to grasp what&#8217;s going on here. The code actually starts using an Extension method to IEnumerable that looks like this:</p>
<pre class="code"><span style="color: gray">public static void </span>ForEach&lt;T&gt;(<span style="color: gray">this </span><span style="color: #2b91af">IEnumerable</span>&lt;T&gt; enumerable, <span style="color: #2b91af">ForeachSectionSetter</span>&lt;T&gt; sectionSetter) {
  <span style="color: gray">if </span>(enumerable != <span style="color: gray">null</span>) {

    <span style="color: gray">if </span>(sectionSetter != <span style="color: gray">null</span>) {
      <span style="color: #2b91af">ForeachSections</span>&lt;T&gt; sections = <span style="color: gray">new </span><span style="color: #2b91af">ForeachSections</span>&lt;T&gt;();
      sectionSetter(sections);

      <span style="color: gray">if </span>(enumerable.Count() == 0) {
        <span style="color: gray">if </span>(sections.NoData != <span style="color: gray">null</span>)
          sections.NoData(enumerable);
        <span style="color: gray">return</span>;
      }

      <span style="color: gray">if </span>(sections.BeforeAll != <span style="color: gray">null</span>)
        sections.BeforeAll(enumerable);

      <span style="color: gray">int </span>itemIndex = 0;
      T previousItem = <span style="color: gray">default</span>(T);

      <span style="color: gray">foreach </span>(T item <span style="color: gray">in </span>enumerable) {
        <span style="color: gray">if </span>(sections.Before != <span style="color: gray">null</span>)
          sections.Before(item);
        <span style="color: gray">if </span>(itemIndex % 2 == 1 &amp;&amp; sections.Odd != <span style="color: gray">null</span>)
          sections.Odd(item);
        <span style="color: gray">if </span>(itemIndex % 2 == 0 &amp;&amp; sections.Even != <span style="color: gray">null</span>)
          sections.Even(item);
        <span style="color: gray">if </span>(itemIndex &gt; 0 &amp;&amp; sections.Between != <span style="color: gray">null</span>)
          sections.Between(previousItem, item);
        <span style="color: gray">if </span>(sections.Each != <span style="color: gray">null</span>)
          sections.Each(item);
        <span style="color: gray">if </span>(sections.After != <span style="color: gray">null</span>)
          sections.After(item);
        itemIndex++;
        previousItem = item;
      }
      <span style="color: gray">if </span>(sections.AfterAll != <span style="color: gray">null</span>)
        sections.AfterAll(enumerable);
    }
  }
}</pre>
<p><a href="http://11011.net/software/vspaste" onclick="javascript:pageTracker._trackVisit('/outbound/article/11011.net');"></a></p>
<p>The delegate ForEachSectionSetter is used by the calling method with a lambda expression. As a parameter it receives an ForeachSections object, which looks like this:</p>
<pre class="code"><span style="color: gray">public class </span><span style="color: #2b91af">ForeachSections</span>&lt;T&gt; {
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;T&gt; Each { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;<span style="color: #2b91af">IEnumerable</span>&lt;T&gt;&gt; BeforeAll { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;T&gt; Before { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;T,T&gt; Between { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;T&gt; Odd { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;T&gt; Even { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;T&gt; After { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;<span style="color: #2b91af">IEnumerable</span>&lt;T&gt;&gt; AfterAll { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;<span style="color: #2b91af">IEnumerable</span>&lt;T&gt;&gt; NoData { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
}</pre>
<p><a href="http://11011.net/software/vspaste" onclick="javascript:pageTracker._trackVisit('/outbound/article/11011.net');"></a></p>
<p>The calling method gets the chance to set the properties of this class before it is returned to the constructor of the ForEach method for processing. And because each property is already preset to a default value (Null in this case), the constructor can use the ForeachSections object just like a set of default or optional parameters. The caller can simply set values to the properties it needs, and ignore the rest.</p>
<p>If I had tried this another way, using overloadable constructors, it would have led to multiple constructors with indistinguishable signatures. If I&#8217;d have used property initializers, I wouldn&#8217;t have been able to run the whole routine without requiring a second call to the object, which actually wasn&#8217;t possible. </p>
<p>Basically, I couldn&#8217;t think of another way to do it. </p>
<p>The properties of the ForeachSections object are all delegates too. That means that we can use them with lambdas, which gives us lambdas inside of a lambda. (Hmm, very confusing!)</p>
<p>So what do you think? Could <em>you</em> use something like this? Can you make it simpler? Leave me a comment if you can.</p>

<img src="http://feeds.feedburner.com/~r/dotnetSmoothie/~4/Y55MLq3Q4xc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/index.php/2008/06/02/c-acrobatics-lambdas-and-expression-methods-as-a-replacement-for-nvelocity/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Value of Being Free to See the Source</title>
		<link>http://www.richardbushnell.net/index.php/2008/04/18/the-value-of-being-free-to-see-the-source/</link>
		<comments>http://www.richardbushnell.net/index.php/2008/04/18/the-value-of-being-free-to-see-the-source/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 14:09:54 +0000</pubDate>
		<dc:creator>Richard Bushnell</dc:creator>
		
		<category><![CDATA[ASP.Net]]></category>

		<category><![CDATA[Visual Studio]]></category>

		<category><![CDATA[exceptions]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/04/18/the-value-of-being-free-to-see-the-source/</guid>
		<description><![CDATA[Since the source code to ASP.Net was made available, I&#8217;ve been using it extensively. Here&#8217;s a great example of why it&#8217;s so valuable.
I&#8217;ve been trying to integrate the Enterprise Library 3.1 Exception Handling Block into my application. My application is split into a core and web UI specific components, so I&#8217;ve defined errors in my [...]]]></description>
			<content:encoded><![CDATA[<p>Since the <a href="http://richardbushnell.net/index.php/2008/01/17/net-source-code-now-available/" >source code to ASP.Net was made available</a>, I&#8217;ve been using it extensively. Here&#8217;s a great example of why it&#8217;s so valuable.</p>
<p>I&#8217;ve been trying to integrate the Enterprise Library 3.1 Exception Handling Block into my application. My application is split into a core and web UI specific components, so I&#8217;ve defined errors in my code to be thrown when a resource is not available. The web application configuration file specifies that if a specific exception, e.g. a ResourceNotFoundException, is thrown, the Exception Handling Block should replace that exception with a 404 Resource Not Found error using Http. That should in turn use the CustomErrors feature to redirect to a 404 not found page.</p>
<p>Makes sense, and sounds simple, don&#8217;t you think? </p>
<p>Nothing in the docs says that it shouldn&#8217;t work.</p>
<p><em>But it doesn&#8217;t</em>. It simply <em>won&#8217;t work</em>. Why? Well, there&#8217;s nothing on the web. But after spending some serious hours digging through the source code, I can finally see why.</p>
<p>Here&#8217;s a lovely little hidden-to-the-world snippet of the code I got inside of Visual Studio:</p>
<pre class="code">code = HttpException.GetHttpCodeForException(e);

<span style="color: green">// Don&#8217;t raise event for 404.  See VSWhidbey 124147.
</span><span style="color: blue">if </span>(code != 404) {
  WebBaseEvent.RaiseRuntimeError(e, <span style="color: blue">this</span>);
}</pre>
<p><a href="http://11011.net/software/vspaste" onclick="javascript:pageTracker._trackVisit('/outbound/article/11011.net');"></a>So it would never work! </p>
<p>Nice of them to let me know.</p>

<img src="http://feeds.feedburner.com/~r/dotnetSmoothie/~4/B1rHwNKLxE0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/index.php/2008/04/18/the-value-of-being-free-to-see-the-source/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Easy Data-loading with LINQ-to-SQL and LINQ-to-XML</title>
		<link>http://www.richardbushnell.net/index.php/2008/03/20/easy-data-loading-with-linq-to-sql-and-linq-to-xml-4/</link>
		<comments>http://www.richardbushnell.net/index.php/2008/03/20/easy-data-loading-with-linq-to-sql-and-linq-to-xml-4/#comments</comments>
		<pubDate>Thu, 20 Mar 2008 07:53:48 +0000</pubDate>
		<dc:creator>Richard Bushnell</dc:creator>
		
		<category><![CDATA[.Net]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[LINQ]]></category>

		<category><![CDATA[LINQ to SQL]]></category>

		<category><![CDATA[LINQ-to-XML]]></category>

		<category><![CDATA[Software]]></category>

		<category><![CDATA[VB.Net]]></category>

		<category><![CDATA[Visual Studio]]></category>

		<category><![CDATA[data]]></category>

		<category><![CDATA[loading]]></category>

		<category><![CDATA[VB]]></category>

		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/03/20/easy-data-loading-with-linq-to-sql-and-linq-to-xml-4/</guid>
		<description><![CDATA[.Net 3.5 had some nice tricks in it. LINQ-to-XML was one of them. With the new &#34;X&#34;-types, you can make working with XML really easy. 
VB.Net 9 takes it one step further, and lets you write XML in your code without strings.
&#34;Hey Rich, that&#8217;s old news,&#34; I hear you say. &#34;And who&#8217;s interested in VB [...]]]></description>
			<content:encoded><![CDATA[<p>.Net 3.5 had some nice tricks in it. LINQ-to-XML was one of them. With the new &quot;X&quot;-types, you can make working with XML really easy. </p>
<p>VB.Net 9 takes it one step further, and lets you write XML in your code without strings.</p>
<p>&quot;Hey Rich, that&#8217;s old news,&quot; I hear you say. &quot;And who&#8217;s interested in VB today anyway?&quot;</p>
<p>Well, apparently there are a lot of VB-er&#8217;s still out there. I am mainly a C# developer myself, but I found that VB was perfect for a problem I had recently -&#160; loading of XML data into a SQL Server table.</p>
<p> <a href="http://www.richardbushnell.net/index.php/2008/03/20/easy-data-loading-with-linq-to-sql-and-linq-to-xml-4/#more-98" class="more-link" >(more&#8230;)</a></p>

<img src="http://feeds.feedburner.com/~r/dotnetSmoothie/~4/nSUB_YRwLos" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/index.php/2008/03/20/easy-data-loading-with-linq-to-sql-and-linq-to-xml-4/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Silverlight 2 Poster Available</title>
		<link>http://www.richardbushnell.net/index.php/2008/03/17/silverlight-2-poster-available/</link>
		<comments>http://www.richardbushnell.net/index.php/2008/03/17/silverlight-2-poster-available/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 07:52:43 +0000</pubDate>
		<dc:creator>Richard Bushnell</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/03/17/silverlight-2-poster-available/</guid>
		<description><![CDATA[You&#8217;re not a real Silverlight developer until you have the poster stuck up on your wall.
Apparently these were hot at Mix.
Thanks to Brad Abrams for posting it.

]]></description>
			<content:encoded><![CDATA[<p><a href="http://brad_abrams.members.winisp.net/Projects/Mix08SL2Poster/Silverlight2PosterMIX08.jpg" target="_blank" onclick="javascript:pageTracker._trackVisit('/outbound/article/brad_abrams.members.winisp.net');"><img style="border-right: 0px; border-top: 0px; margin: 0px 20px 20px 0px; border-left: 0px; border-bottom: 0px" height="150" alt="image" src="http://richardbushnell.net/wp-content/uploads/2008/03/image11.png" width="240" align="left" border="0" /></a>You&#8217;re not a <em>real</em> Silverlight developer until you have <a href="http://brad_abrams.members.winisp.net/Projects/Mix08SL2Poster/Silverlight2PosterMIX08.jpg" target="_blank" onclick="javascript:pageTracker._trackVisit('/outbound/article/brad_abrams.members.winisp.net');">the poster</a> stuck up on your wall.</p>
<p>Apparently these were hot at Mix.</p>
<p>Thanks to <a href="http://blogs.msdn.com/brada/archive/2008/03/16/silverlight-2-developer-poster.aspx" target="_blank" onclick="javascript:pageTracker._trackVisit('/outbound/article/blogs.msdn.com');">Brad Abrams</a> for posting it.</p>

<img src="http://feeds.feedburner.com/~r/dotnetSmoothie/~4/I4xH02T_rMA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/index.php/2008/03/17/silverlight-2-poster-available/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Design Guidelines for LINQ</title>
		<link>http://www.richardbushnell.net/index.php/2008/03/13/design-guidelines-for-linq/</link>
		<comments>http://www.richardbushnell.net/index.php/2008/03/13/design-guidelines-for-linq/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 18:40:24 +0000</pubDate>
		<dc:creator>Richard Bushnell</dc:creator>
		
		<category><![CDATA[.Net]]></category>

		<category><![CDATA[C# 3.0]]></category>

		<category><![CDATA[Design]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[Extension Methods]]></category>

		<category><![CDATA[LINQ]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Software]]></category>

		<category><![CDATA[Guidelines]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/03/13/design-guidelines-for-linq/</guid>
		<description><![CDATA[Have you wondered if and when you should use the new LINQ features in .Net 3.5?
Like, where should I put a new extension method? Should I use Func&#60;T&#62; or a custom delegate? How do I best implement a mix-in (extension methods on an interface)?
Well, Mircea Trofin has just published a new draft of some LINQ [...]]]></description>
			<content:encoded><![CDATA[<p>Have you wondered if and when you should use the new LINQ features in .Net 3.5?</p>
<p>Like, where should I put a new extension method? Should I use Func&lt;T&gt; or a custom delegate? How do I best implement a mix-in (extension methods on an interface)?</p>
<p>Well, Mircea Trofin has just published a new draft of some <a href="http://blogs.msdn.com/mirceat/archive/2008/03/13/linq-framework-design-guidelines.aspx" target="_blank" onclick="javascript:pageTracker._trackVisit('/outbound/article/blogs.msdn.com');">LINQ design guidelines</a>. You might just find your answers there.</p>

<img src="http://feeds.feedburner.com/~r/dotnetSmoothie/~4/bP8dN2JlrHA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/index.php/2008/03/13/design-guidelines-for-linq/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Read Word Documents in a Web Browser</title>
		<link>http://www.richardbushnell.net/index.php/2008/03/07/read-word-documents-in-a-web-browser/</link>
		<comments>http://www.richardbushnell.net/index.php/2008/03/07/read-word-documents-in-a-web-browser/#comments</comments>
		<pubDate>Fri, 07 Mar 2008 07:33:09 +0000</pubDate>
		<dc:creator>Richard Bushnell</dc:creator>
		
		<category><![CDATA[.Net]]></category>

		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/03/07/read-word-documents-in-a-web-browser/</guid>
		<description><![CDATA[ I love this! Not because of the features, but because of the way it works.
Tim Sneath just blogged about TextGlow - an online Word docx file reader. The docx format is XML, and Silverlight 2 apps can use LINQ-to-XML to parse it and format it for display inside the browser.
Amazing!
You can read more about [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.textglow.net/" onclick="javascript:pageTracker._trackVisit('/outbound/article/www.textglow.net');"><img style="border-right: 0px; border-top: 0px; margin: 0px 20px 20px 0px; border-left: 0px; border-bottom: 0px" height="232" alt="image" src="http://richardbushnell.net/wp-content/uploads/2008/03/image10.png" width="240" align="left" border="0" /></a> I love <a href="http://www.textglow.net/" onclick="javascript:pageTracker._trackVisit('/outbound/article/www.textglow.net');">this!</a> Not because of the features, but because of the way it works.</p>
<p><a href="http://blogs.msdn.com/tims/archive/2008/03/06/a-great-early-silverlight-2-showcase-textglow.aspx" onclick="javascript:pageTracker._trackVisit('/outbound/article/blogs.msdn.com');">Tim Sneath</a> just blogged about <a href="http://www.textglow.net/" onclick="javascript:pageTracker._trackVisit('/outbound/article/www.textglow.net');">TextGlow</a> - an online Word docx file reader. The docx format is XML, and Silverlight 2 apps can use LINQ-to-XML to parse it and format it for display inside the browser.</p>
<p>Amazing!</p>
<p>You can read more about it on <a href="http://blogs.msdn.com/tims/archive/2008/03/06/a-great-early-silverlight-2-showcase-textglow.aspx" onclick="javascript:pageTracker._trackVisit('/outbound/article/blogs.msdn.com');">Tim&#8217;s blog</a>.</p>

<img src="http://feeds.feedburner.com/~r/dotnetSmoothie/~4/w3KF8fd3zWw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/index.php/2008/03/07/read-word-documents-in-a-web-browser/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Mix 08 WPF Scheduling Application</title>
		<link>http://www.richardbushnell.net/index.php/2008/03/05/mix-08-wpf-scheduling-application/</link>
		<comments>http://www.richardbushnell.net/index.php/2008/03/05/mix-08-wpf-scheduling-application/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 08:41:59 +0000</pubDate>
		<dc:creator>Richard Bushnell</dc:creator>
		
		<category><![CDATA[.Net]]></category>

		<category><![CDATA[Design]]></category>

		<category><![CDATA[WPF]]></category>

		<category><![CDATA[Apps]]></category>

		<category><![CDATA[Mix08]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/03/05/mix-08-wpf-scheduling-application/</guid>
		<description><![CDATA[Mix 08 seems to be much more mature than ever before. In previous years there were a lot of ideas being spoken about; this year there are much more implementations of those ideas available to look at. It seems like a lot of people have been working on the new technologies over the past year [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://richardbushnell.net/wp-content/uploads/2008/03/image5.png" ><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 20px 20px 0px; border-right-width: 0px" height="186" alt="image" src="http://richardbushnell.net/wp-content/uploads/2008/03/image-thumb3.png" width="136" align="left" border="0" /></a>Mix 08 seems to be much more mature than ever before. In previous years there were a lot of ideas being spoken about; this year there are much more implementations of those ideas available to look at. It seems like a lot of people have been working on the new technologies over the past year or so. Hopefully that will lead to the ripening of many technologies (especially WPF) to a point where we can actually use them.</p>
<p>As an example, there is a <a href="http://thirteen23.com/experiences/desktop/mix08/" onclick="javascript:pageTracker._trackVisit('/outbound/article/thirteen23.com');">scheduling application</a> available for Mix. Unfortunately it only runs on Vista, but I captured a video and made a few screenshots for you.</p>
<p>This is the opening screen, with an agenda for the 4 days of the event:</p>
<p><a href="http://richardbushnell.net/wp-content/uploads/2008/03/image8.png" ><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 40px 0px 0px; width: 420px; border-right-width: 0px" height="334" alt="image" src="http://richardbushnell.net/wp-content/uploads/2008/03/image-thumb6.png" width="420" border="0" /></a></p>
<p>(Click the image to make it larger.)</p>
<p> <a href="http://www.richardbushnell.net/index.php/2008/03/05/mix-08-wpf-scheduling-application/#more-78" class="more-link" >(more&#8230;)</a></p>

<img src="http://feeds.feedburner.com/~r/dotnetSmoothie/~4/ZAhWHGCjA-M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/index.php/2008/03/05/mix-08-wpf-scheduling-application/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Silverlight for Nokia Phones</title>
		<link>http://www.richardbushnell.net/index.php/2008/03/05/silverlight-for-nokia-phones/</link>
		<comments>http://www.richardbushnell.net/index.php/2008/03/05/silverlight-for-nokia-phones/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 06:45:45 +0000</pubDate>
		<dc:creator>Richard Bushnell</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/03/05/silverlight-for-nokia-phones/</guid>
		<description><![CDATA[ BBC News has just released an article referring to a deal made between Microsoft and Nokia to put Silverlight on mobile phones.
Yet another reason to get polishing those WPF skills.

]]></description>
			<content:encoded><![CDATA[<p><a href="http://richardbushnell.net/wp-content/uploads/2008/03/image4.png" ><img style="border-right: 0px; border-top: 0px; margin: 0px 20px 20px 0px; border-left: 0px; border-bottom: 0px" height="152" alt="image" src="http://richardbushnell.net/wp-content/uploads/2008/03/image-thumb2.png" width="203" align="left" border="0"></a> BBC News has just released an article referring to a <a href="http://news.bbc.co.uk/2/hi/science/nature/7276907.stm" target="_blank" onclick="javascript:pageTracker._trackVisit('/outbound/article/news.bbc.co.uk');">deal made between Microsoft and Nokia to put Silverlight on mobile phones</a>.</p>
<p>Yet another reason to get polishing those WPF skills.</p>

<img src="http://feeds.feedburner.com/~r/dotnetSmoothie/~4/4xSeRjhRyuc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/index.php/2008/03/05/silverlight-for-nokia-phones/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
