<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" 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/"><channel><title>ASP.NET Weblogs</title><link>http://weblogs.asp.net/default.aspx?GroupID=4</link><description>ASP.NET Community Bloggers</description><dc:language>en-US</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Daily tech links for .net and related technologies - November 21-23, 2009</title><link>http://weblogs.asp.net/sanjeevagarwal/archive/2009/11/22/daily-tech-links-for-net-and-related-technologies-november-21-23-2009.aspx</link><pubDate>Sun, 22 Nov 2009 06:52:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7262877</guid><dc:creator>SanjeevAgarwal</dc:creator><author>SanjeevAgarwal</author><slash:comments>2</slash:comments><description>Daily tech links for .net and related technologies - November 21-23, 2009 Web Development ASP.NET MVC: Creating reports using Chart control T4MVC 2.5.01: added support for Html.RenderAction and Html.Action Web Application Configuration Analyzer (WACA) The Search Developer Story in SharePoint 2010 – Query Interfaces Using the Microsoft Ajax Library 3.5 with the CDN Microsoft AJAX Library Preview 6 &amp;amp; Data Binding Web Design User Interface Design Is Not About Lorem Ipsum And Pretty Boxes The Ultimate...(&lt;a href="http://weblogs.asp.net/sanjeevagarwal/archive/2009/11/22/daily-tech-links-for-net-and-related-technologies-november-21-23-2009.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7262877" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/JQuery/default.aspx">JQuery</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/CSS/default.aspx">CSS</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/WPF/default.aspx">WPF</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/WCF/default.aspx">WCF</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/MVC/default.aspx">MVC</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/XML/default.aspx">XML</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/Ajax/default.aspx">Ajax</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/Database/default.aspx">Database</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/ORM/default.aspx">ORM</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/Entity+Framework/default.aspx">Entity Framework</category></item><item><title>ASP.NET MVC: Creating reports using Chart control</title><link>http://weblogs.asp.net/gunnarpeipman/archive/2009/11/21/asp-net-mvc-creating-reports-using-chart-control.aspx</link><pubDate>Sat, 21 Nov 2009 13:36:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7262585</guid><dc:creator>DigiMortal</dc:creator><author>DigiMortal</author><slash:comments>9</slash:comments><description>&lt;p&gt;&lt;a href="http://weblogs.asp.net/gunnarpeipman/archive/2008/11/29/lt-asp-chart-gt.aspx"&gt;ASP.NET Chart control&lt;/a&gt; is powerful control you can use to add charting support to your web applications. Although chart controls are mainly used with ASP.NET forms it is not very hard to use them also in &lt;a href="http://weblogs.asp.net/gunnarpeipman/archive/tags/MVC/default.aspx"&gt;ASP.NET MVC applications&lt;/a&gt;. In this posting I will show you how to use ASP.NET Chart control in ASP.NET MVC application and I will illustrate how to do it easily so you don’t mess up your views.&lt;/p&gt;  &lt;p&gt;Before we start coding I want to make some notes about my solution:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;this solution is pretty new and it is sure that one can improve the code provided here, &lt;/li&gt;    &lt;li&gt;using this solution I’m trying to generalize in-place reporting for MVC applications, &lt;/li&gt;    &lt;li&gt;also I’m trying to keep my views as clean as possible – chart definitions are not small if you have more complex charts or if you want very nice looking charts. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If you are not familiar with ASP.NET Chart control then please read my blog posting &lt;a href="http://weblogs.asp.net/gunnarpeipman/archive/2008/11/29/lt-asp-chart-gt.aspx"&gt;&amp;lt;asp:Chart&amp;gt;&lt;/a&gt;. You find there simple introduction to this free control and also all necessary links.&lt;/p&gt;  &lt;h3&gt;Solution overview&lt;/h3&gt;  &lt;p&gt;What we are trying to build here is shown on the following diagram. Our main goal is to avoid using ASP.NET forms elements in our MVC line user interface. Also we want to generalize reporting support so we have one interface for all reports. &lt;/p&gt;  &lt;p align="center"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Solution overview" border="0" alt="Solution overview" src="http://weblogs.asp.net/blogs/gunnarpeipman/aspnetmvcchartcontroldiagram_69A13A0D.png" width="532" height="245" /&gt; &lt;/p&gt;  &lt;p&gt;I introduce here pretty simple report. If you have more complex reports then you can extend reporting interface shown below later. You may also find useful to reorganize outputing system. I am using here simple works-for-me or works-for-prototyping solution. I want to focus on point and let’s try not to lose it.&lt;/p&gt;  &lt;h3&gt;Reporting interface&lt;/h3&gt;  &lt;p&gt;Before we create our first report let’s define interface for it. This interface must define all basic actions we need to do with reports:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;set source with report data, &lt;/li&gt;    &lt;li&gt;bind data to report, &lt;/li&gt;    &lt;li&gt;write report image to some (output) stream. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;This is my reporting interface. Note that DataSource has only setter – it is because I don’t have currently need to ask data from chart. I only provide data to it.&lt;/p&gt;  &lt;hr size="1" /&gt;  &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;interface&lt;/span&gt; &lt;span style="color: #2b91af"&gt;IReportControl &lt;font color="#000000"&gt;:&lt;/font&gt; IDisposable&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;void&lt;/span&gt; DataBind();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;object&lt;/span&gt; DataSource { &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;void&lt;/span&gt; SaveChartImage(&lt;span style="color: #2b91af"&gt;Stream&lt;/span&gt; stream);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;hr size="1" /&gt;  &lt;p&gt;As you can see this interface is pretty thin. I am sure that it will grow in the future when need for more complex reports appears.&lt;/p&gt;  &lt;h3&gt;Sample report&lt;/h3&gt;  &lt;p&gt;Let’s define one report for testing purposes. Add web user control called MyReport.ascx to Reports folder of your web application and drag ASP.NET Chart control on it. Here is definition of my control.&lt;/p&gt;  &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;   &lt;hr size="1" /&gt;     &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;%&lt;span style="color: #a31515"&gt;@&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Control&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Language&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;C#&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;AutoEventWireup&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;true&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;        &lt;br /&gt;&lt;/span&gt;&lt;span style="color: red"&gt;&amp;#160;&amp;#160;&amp;#160; CodeBehind&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;LastEnquiriesChart.ascx.cs&lt;/span&gt;&amp;quot;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;Inherits&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ReportingApp.Web.Reports.LastEnquiriesChart&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;        &lt;br /&gt;&lt;/span&gt;%&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;%&lt;span style="color: #a31515"&gt;@&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Register&lt;/span&gt;&lt;span style="color: blue"&gt;        &lt;br /&gt;&lt;/span&gt;&lt;span style="color: red"&gt;&amp;#160;&amp;#160;&amp;#160; assembly&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;&amp;quot;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;namespace&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;System.Web.UI.DataVisualization.Charting&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;tagprefix&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;asp&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;        &lt;br /&gt;&lt;/span&gt;%&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp:Chart&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;ID&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Chart1&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;server&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Palette&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Excel&lt;/span&gt;&amp;quot;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;200px&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;200px&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;series&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp:Series&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Series2&lt;/span&gt;&amp;quot;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;CustomProperties&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;DrawingStyle=Emboss&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;XValueMember&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Date&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;YValueMembers&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Count&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;IsValueShownAsLabel&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;True&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;Font&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft Sans Serif, 8pt&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;        &lt;br /&gt;&lt;/span&gt;&lt;span style="color: red"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; LabelBackColor&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;255, 255, 192&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;LabelBorderColor&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;192, 192, 0&lt;/span&gt;&amp;quot;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;LabelForeColor&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Red&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp:Series&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;series&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;chartareas&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp:ChartArea&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ChartArea1&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;BorderDashStyle&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Solid&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;AxisX&lt;/span&gt;&lt;span style="color: blue"&gt;        &lt;br /&gt;&lt;/span&gt;&lt;span style="color: red"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; IntervalAutoMode&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;VariableCount&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; IntervalOffsetType&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Days&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;IntervalType&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Days&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;IsLabelAutoFit&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;False&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;IsStartedFromZero&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;False&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;MajorGrid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;Interval&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Auto&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;IntervalOffsetType&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Days&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; IntervalType&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Days&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;AxisX&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp:ChartArea&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;chartareas&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Titles&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp:Title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;#160; &lt;br /&gt;&lt;/span&gt;&lt;span style="color: red"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Font&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft Sans Serif, 8pt, style=Bold&lt;/span&gt;&amp;quot;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Title1&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Last week enquiries&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp:Title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Titles&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp:Chart&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;hr size="1" /&gt; &lt;/div&gt;  &lt;p&gt;If you look at the definition and consider it as simple one you understand why I don’t want this mark-up to be there in my views. This is just one simple report. But consider for a moment three complex reports. 90% of my view will be one huge report definition then and I will miss all the good things that views have.&lt;/p&gt;  &lt;p&gt;As I want this report to be interfaced with my reporting mechanism I make it implement IReportControl interface. Code-behind of my control is as follows.&lt;/p&gt;  &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;   &lt;hr size="1" /&gt;     &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;partial&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;LastEnquiriesChart&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;UserControl&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;IReportControl&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;object&lt;/span&gt; DataSource&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;set&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Chart1.DataSource = &lt;span style="color: blue"&gt;value&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; DataBind()&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;base&lt;/span&gt;.DataBind();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Chart1.DataBind();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; SaveChartImage(&lt;span style="color: #2b91af"&gt;Stream&lt;/span&gt; stream)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Chart1.SaveImage(stream);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt;    &lt;hr size="1" /&gt; &lt;/div&gt;  &lt;p&gt;All other user controls we are using for reporting must also implement IReportControl interface. This leads us to one interesting finding – we don’t have to host only chart control in our user controls, we have to host there whatever ASP.NET forms control we need for reporting. We can also create wrapper controls that get report image from some other external source (let’s say we have some COM component that is able to return reports as images).&lt;/p&gt;  &lt;h3&gt;Creating loader&lt;/h3&gt;  &lt;p&gt;Now we have sample report control and interface we can use to provide data and catch output of report. It is time to create meeting place for two worlds: ASP.NET forms and ASP.NET MVC framework. I created class called ReportLoader. The name of this class is good enough for me because it tells me that this is the integration point between two worlds. Let’s look at loader implementation now.&lt;/p&gt;  &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;   &lt;hr size="1" /&gt;     &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ChartLoader&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; SaveChartImage(&lt;span style="color: blue"&gt;string&lt;/span&gt; controlLocation,      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt; data, &lt;span style="color: #2b91af"&gt;Stream&lt;/span&gt; stream)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;using&lt;/span&gt; (&lt;span style="color: blue"&gt;var&lt;/span&gt; page = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Page&lt;/span&gt;())&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;using&lt;/span&gt; (&lt;span style="color: blue"&gt;var&lt;/span&gt; control = (&lt;span style="color: #2b91af"&gt;IReportControl&lt;/span&gt;)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; page.LoadControl(&lt;span style="color: #a31515"&gt;&amp;quot;~/Reports/&amp;quot;&lt;/span&gt; + controlLocation))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; control.DataSource = data;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; control.DataBind();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; control.SaveChartImage(stream);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt;    &lt;hr size="1" /&gt; &lt;/div&gt;  &lt;p&gt;Loader does one trick: it doesn’t render the control. It only runs as long as report is written to stream and then it disposes user control and temporary page instance to avoid all other actions they may take. I made ChartLoader and SaveChartImage methods as static because I don’t need hell load of classes and super-cool architecture right now.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;h3&gt;Creating controller action&lt;/h3&gt;  &lt;p&gt;We are almost there… Let’s create now controller action that returns chart image. As I am prototyping my application I use very robust controller action. You may be more polite coders and I strongly suggest you to read &lt;a href="http://biasecurities.com/"&gt;Bia Securities&lt;/a&gt; blog posting &lt;a href="http://biasecurities.com/blog/2008/binaryresult-for-asp-net-mvc/"&gt;BinaryResult for Asp.Net MVC&lt;/a&gt;. You can find BinaryResult implementation also from &lt;a href="http://www.codeplex.com/MVCContrib"&gt;MVC Contrib project&lt;/a&gt;.&lt;/p&gt;  &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;   &lt;hr size="1" /&gt;     &lt;p style="margin: 0px"&gt;[&lt;span style="color: #2b91af"&gt;HttpGet&lt;/span&gt;]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ActionResult&lt;/span&gt; GetChart()&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; repository = &lt;span style="color: #2b91af"&gt;Resolver&lt;/span&gt;.Resolve&amp;lt;&lt;span style="color: #2b91af"&gt;IPriceEnquiryRepository&lt;/span&gt;&amp;gt;();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; enquiries = repository.ListPriceEnquiries();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; data = &lt;span style="color: blue"&gt;from&lt;/span&gt; p &lt;span style="color: blue"&gt;in&lt;/span&gt; enquiries&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;group&lt;/span&gt; p &lt;span style="color: blue"&gt;by&lt;/span&gt; p.Date.Date &lt;span style="color: blue"&gt;into&lt;/span&gt; g&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;select&lt;/span&gt; &lt;span style="color: blue"&gt;new&lt;/span&gt; { Date = g.Key, Count = g.Count() };&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; Response.Clear();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; Response.ContentType = &lt;span style="color: #a31515"&gt;&amp;quot;image/png&amp;quot;&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;ChartLoader&lt;/span&gt;.SaveChartImage(&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #a31515"&gt;&amp;quot;LastEnquiriesChart.ascx&amp;quot;&lt;/span&gt;,&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; data, &lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Response.OutputStream);&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; Response.End();&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: blue"&gt;null&lt;/span&gt;; &lt;span style="color: green"&gt;// have to return something&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt;    &lt;hr size="1" /&gt; &lt;/div&gt;  &lt;p&gt;Now we have controller action that asks data from somewhere, prepares it for report and asks report as image from ChartLoader. Before outputing the report Response is cleared and content type is set to PNG. After writing image to response output stream the response is ended immediately to avoid any mark-up that may be written there otherwise. &lt;/p&gt;  &lt;p&gt;As you can see I created special automatic objects for reporting. If you look at my report definition you can see that x-axis is bound to Date and y-axis to Count. You can also prepare reporting data in some near-DAL class methods and then slide this data through controller to report. The choice is yours.&lt;/p&gt;  &lt;h3&gt;Adding report to view&lt;/h3&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 0px 0px 15px; display: inline; border-top: 0px; border-right: 0px" title="ASP.NET Chart control output" border="0" alt="ASP.NET Chart control output" align="right" src="http://weblogs.asp.net/blogs/gunnarpeipman/aspnetmvcchartimage_61C9219E.png" width="200" height="200" /&gt; Now let’s link report to view. We just have to add one simple img tag to our view and make it src to call out GetChart() method defined above.&lt;/p&gt;  &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;   &lt;hr size="1" /&gt;     &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;img&lt;/span&gt;&lt;span style="color: blue"&gt;        &lt;br /&gt;&lt;/span&gt;&lt;span style="color: red"&gt;&amp;#160;&amp;#160;&amp;#160; src&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;%&lt;span style="color: blue"&gt;= &lt;/span&gt;&lt;span style="color: red"&gt;Url.Action&lt;/span&gt;(&amp;quot;&lt;span style="color: blue"&gt;GetChart&lt;/span&gt;&amp;quot;)%&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&amp;quot;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;alt&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Last week enquiries&lt;/span&gt;&amp;quot;&amp;#160; &lt;br /&gt;&lt;span style="color: red"&gt;&amp;#160;&amp;#160;&amp;#160; title&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Last week enquiries&lt;/span&gt;&amp;quot;      &lt;br /&gt;&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;hr size="1" /&gt; &lt;/div&gt;  &lt;p&gt;Output of report is shown on right. I don’t have much data here and my report is not very nice but it works. Now, if you are not too tired or bored, it is time to make your chart very nice and show it to your boss or customer.&lt;/p&gt;  &lt;h3&gt;Conclusion&lt;/h3&gt;  &lt;p&gt;Mixing forms and MVC worlds of ASP.NET doesn’t always have to end up with hard mess. In this posting I showed you how to add simple but pretty generic reports support to your ASP.NET MVC application. Due to good interfacing we achieved separation between forms and MVC templates and linking reports to views is very-very simple. &lt;/p&gt;  &lt;p&gt;Of course, code and interfaces represented here are not production-ready examples. But they give you right direction and you can always improve design of my solution. My point was to illustrate how to mix MVC and forms world in reporting context and I feel like I succeeded this time. What do you think? :)&lt;/p&gt;

&lt;hr size="1" /&gt;

&lt;table border="0" cellpadding="0" cellspacing="2" width="100%"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fgunnarpeipman%2farchive%2f2009%2f11%2f21%2fasp-net-mvc-creating-reports-using-chart-control.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fgunnarpeipman%2farchive%2f2009%2f11%2f21%2fasp-net-mvc-creating-reports-using-chart-control.aspx" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td align="center"&gt;
&lt;a rev="vote-for" href="http://pimpthisblog.com/ASPNET-MVC-Creating-reports-using-Chart-control"&gt;&lt;img alt="pimp it" src="http://pimpthisblog.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fgunnarpeipman%2Farchive%2F2009%2F11%2F21%2Fasp-net-mvc-creating-reports-using-chart-control.aspx" style="border:0px"/&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td align="center"&gt;
&lt;a rev="vote-for" href="http://www.9efish.com/ASPNET-MVC-Creating-reports-using-Chart-control"&gt;&lt;img alt="顶" src="http://www.9efish.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fgunnarpeipman%2Farchive%2F2009%2F11%2F21%2Fasp-net-mvc-creating-reports-using-chart-control.aspx" style="border:0px"/&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td align="center"&gt;
&lt;a rev="vote-for" href="http://progg.ru/ASPNET-MVC-Creating-reports-using-Chart-control"&gt;&lt;img alt="Progg it" src="http://progg.ru/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fgunnarpeipman%2Farchive%2F2009%2F11%2F21%2Fasp-net-mvc-creating-reports-using-chart-control.aspx" style="border:0px"/&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td align="right"&gt;
&lt;a rev="vote-for" href="http://dotnetshoutout.com/ASPNET-MVC-Creating-reports-using-Chart-control"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fgunnarpeipman%2Farchive%2F2009%2F11%2F21%2Fasp-net-mvc-creating-reports-using-chart-control.aspx" style="border:0px"/&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="4"&gt;&lt;/td&gt;
&lt;td align="right"&gt;
&lt;a rev="vote-for" href="http://servefault.com/ASPNET-MVC-Creating-reports-using-Chart-control"&gt;&lt;img alt="Shout it!" src="http://servefault.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fgunnarpeipman%2Farchive%2F2009%2F11%2F21%2Fasp-net-mvc-creating-reports-using-chart-control.aspx&amp;countBackColor=00cc00" style="border:0px"/&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7262585" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/gunnarpeipman/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/gunnarpeipman/archive/tags/Graphics/default.aspx">Graphics</category><category domain="http://weblogs.asp.net/gunnarpeipman/archive/tags/Web+development/default.aspx">Web development</category><category domain="http://weblogs.asp.net/gunnarpeipman/archive/tags/MVC/default.aspx">MVC</category></item><item><title>Unit Testing and Integration Testing in real projects</title><link>http://weblogs.asp.net/omarzabir/archive/2009/11/21/unit-testing-and-integration-testing-in-real-projects.aspx</link><pubDate>Sat, 21 Nov 2009 10:52:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7262490</guid><dc:creator>oazabir</dc:creator><author>oazabir</author><slash:comments>1</slash:comments><description>&lt;p&gt;I am yet to find a proper sample on how to do realistic Test Driven
Development (TDD) and how to write proper unit tests for complex
business applications, that gives you enough confidence to stop doing
manual tests anymore. Generally &lt;a href="http://www.c-sharpcorner.com/UploadFile/rmcochran/test_driven_development10072006125103PM/test_driven_development.aspx" mce_href="http://www.c-sharpcorner.com/UploadFile/rmcochran/test_driven_development10072006125103PM/test_driven_development.aspx"&gt;the samples&lt;/a&gt;
show you how to test a Stack or a LinkedList, which is far simpler than
testing a typical N-tier application, especially if you are using
Entity Framework or Linq to SQL or some ORM in data access layer, and
doing logging, validation, caching, error handling at middle tier.
There are &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163982.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/cc163982.aspx"&gt;many articles&lt;/a&gt;, &lt;a href="http://www.codeplex.com/xunit#blog" mce_href="http://www.codeplex.com/xunit#blog"&gt;blog posts&lt;/a&gt;, &lt;a href="http://www.youtube.com/watch?v=f60aIlNhMoE" mce_href="http://www.youtube.com/watch?v=f60aIlNhMoE"&gt;video tutorials&lt;/a&gt;
on how to write unit tests, which I believe are all very good starting
points. But all these examples show you basic tests, not good enough to
let your QA team go. So, let me try to show you some realistic unit and
integration test examples which should help you write tests that gives
you confidence and helps you gradually move towards TDD.&amp;nbsp;&amp;nbsp; &lt;/p&gt;  &lt;p&gt;I will show you tests done on my open source project &lt;a href="http://dropthings.omaralzabir.com/" mce_href="http://dropthings.omaralzabir.com/"&gt;Dropthings&lt;/a&gt;,
which is a Web 2.0 AJAX portal built using jQuery, ASP.NET 3.5, Linq to
SQL, Dependency Injection using Unity, caching using Microsoft
Enterprise Library, Velocity and so on. Basically all the hot techs you
can grasp in one shot. The project is a typical N-tier application
where there’s a web layer, a business layer and a data access layer.
Writing unit tests, integration tests and load tests for this project
was challenging, and thus interesting to share so that you can see how
you can implement Unit Testing and Integration Testing in a real
project and gradually get into Test Driven Development.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/omar.metablogapi/7450.image_5F00_4552A35B.png" mce_href="http://weblogs.asp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/omar.metablogapi/7450.image_5F00_4552A35B.png"&gt;&lt;img src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/omar.metablogapi/0272.image_5F00_thumb_5F00_3050FB1B.png" style="border-width: 0px; display: inline;" mce_style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" alt="image" mce_src="http://weblogs.asp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/omar.metablogapi/0272.image_5F00_thumb_5F00_3050FB1B.png" width="438" border="0" height="494"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Read
this codeproject article of mine to learn how I did Integration Tests
and Unit Tests using Behavior Driven Development approach:&lt;/p&gt;  &lt;p&gt;Unit Testing and Integration Testing in business applications&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.codeproject.com/KB/testing/realtesting.aspx" title="http://www.codeproject.com/KB/testing/realtesting.aspx" mce_href="http://www.codeproject.com/KB/testing/realtesting.aspx"&gt;http://www.codeproject.com/KB/testing/realtesting.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you like it, please vote for me.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin: 0px; padding: 0px;" mce_style="margin:0px; padding:0px 0px 0px 0px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fmsmvps.com%2fblogs%2fomar%2farchive%2f2009%2f11%2f21%2funit-testing-and-integration-testing-in-real-projects.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fmsmvps.com%2fblogs%2fomar%2farchive%2f2009%2f11%2f21%2funit-testing-and-integration-testing-in-real-projects.aspx" rev="vote-for"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmsmvps.com%2fblogs%2fomar%2farchive%2f2009%2f11%2f21%2funit-testing-and-integration-testing-in-real-projects.aspx" mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmsmvps.com%2fblogs%2fomar%2farchive%2f2009%2f11%2f21%2funit-testing-and-integration-testing-in-real-projects.aspx" style="border: 0px none ;" mce_style="border:0px" alt="kick it"&gt;&lt;/a&gt;&amp;nbsp;&lt;a href="http://dotnetshoutout.com/Submit?url=http%3a%2f%2fmsmvps.com%2fblogs%2fomar%2farchive%2f2009%2f11%2f21%2funit-testing-and-integration-testing-in-real-projects.aspx" rev="vote-for" mce_href="http://dotnetshoutout.com/Submit?url=http%3a%2f%2fmsmvps.com%2fblogs%2fomar%2farchive%2f2009%2f11%2f21%2funit-testing-and-integration-testing-in-real-projects.aspx"&gt;&lt;img src="http://dotnetshoutout.com/image.axd?url=http%3a%2f%2fmsmvps.com%2fblogs%2fomar%2farchive%2f2009%2f11%2f21%2funit-testing-and-integration-testing-in-real-projects.aspx" alt="Shout it" mce_src="http://dotnetshoutout.com/image.axd?url=http%3a%2f%2fmsmvps.com%2fblogs%2fomar%2farchive%2f2009%2f11%2f21%2funit-testing-and-integration-testing-in-real-projects.aspx" style="border: 0px none ;" mce_style="border:0px"&gt;&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7262490" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/omarzabir/archive/tags/.net/default.aspx">.net</category><category domain="http://weblogs.asp.net/omarzabir/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/omarzabir/archive/tags/General+Software+Development/default.aspx">General Software Development</category><category domain="http://weblogs.asp.net/omarzabir/archive/tags/unit+test/default.aspx">unit test</category><category domain="http://weblogs.asp.net/omarzabir/archive/tags/testing/default.aspx">testing</category><category domain="http://weblogs.asp.net/omarzabir/archive/tags/TDD/default.aspx">TDD</category><category domain="http://weblogs.asp.net/omarzabir/archive/tags/BDD/default.aspx">BDD</category></item><item><title>Visual Studio 2010: Generating sequence diagrams on the fly</title><link>http://weblogs.asp.net/gunnarpeipman/archive/2009/11/20/visual-studio-2010-generating-sequence-diagrams-on-the-fly.aspx</link><pubDate>Fri, 20 Nov 2009 12:28:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7261478</guid><dc:creator>DigiMortal</dc:creator><author>DigiMortal</author><slash:comments>11</slash:comments><description>&lt;p&gt;One nice feature that &lt;a href="http://weblogs.asp.net/gunnarpeipman/pages/visual-studio-2010-and-net-framework-4-0.aspx"&gt;Visual Studio 2010&lt;/a&gt; provides is generating sequence diagrams on the fly. Just point out method and choose diagram generating option from context menu. In this posting I will show you how to generate sequence diagrams on the fly.&lt;/p&gt;  &lt;p&gt;To keep example illustrative and simple I will use simple code. Let’s suppose we have &lt;a href="http://www.asp.net/mvc/"&gt;ASP.NET MVC&lt;/a&gt; application with following controller.&lt;/p&gt;  &lt;hr size="1" /&gt;  &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;PriceEnquiryController&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;Controller&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: green"&gt;// ... some properties and methods ...&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ActionResult&lt;/span&gt; Index()&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; model = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;PriceEnquiryListModel&lt;/span&gt;();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; model.PriceEnquiries = PriceEnquiryRepository.ListPriceEnquiries();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; View(model);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt;    &lt;hr size="1" /&gt; &lt;/div&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/gunnarpeipman/vs2010generatesequencediagram_47D1069C.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 0px 10px 10px; display: inline; border-top: 0px; border-right: 0px" title="Visual Studio 2010: Sequence diagram generation options" border="0" alt="Visual Studio 2010: Sequence diagram generation options" align="right" src="http://weblogs.asp.net/blogs/gunnarpeipman/vs2010generatesequencediagram_thumb_2EA58697.png" width="384" height="379" /&gt;&lt;/a&gt;Let’s say we want to generate sequence diagram for this method. All we have to do is to right click on method with mouse, select “Generate Sequence Diagram …” and modify some options. &lt;/p&gt;  &lt;p&gt;You can select what kind of calls you want to include and exclude. Setting these options you can make diagram to reflect only those parts of your code that you really need to visualize.&lt;/p&gt;  &lt;p&gt;If you look at the image you see that you can also set call depth. With more complex methods it may be very helpful because too large call depth causes huge diagram with too much knowledge on it.&lt;/p&gt;  &lt;p&gt;When we are done with options we have to click “OK” button and Visual Studio 2010 generates sequence diagram. You can click on image to see it in original size.&lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://weblogs.asp.net/blogs/gunnarpeipman/vs2010sequencediagram_2C1C54D9.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Visual Studio 2010: Sequence diagram" border="0" alt="Visual Studio 2010: Sequence diagram" src="http://weblogs.asp.net/blogs/gunnarpeipman/vs2010sequencediagram_thumb_37D19C0B.png" width="540" height="554" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This diagram is pretty simple and primitive but you can also generate more complex diagrams. Just set options you need and let Visual Studio 2010 generate – it works like charm. Let’s hope we get more diagrams when Visual Studio 2010 first stable version is released.&lt;/p&gt;

&lt;hr size="1" /&gt;

&lt;table border="0" cellpadding="0" cellspacing="2" width="100%"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fgunnarpeipman%2farchive%2f2009%2f11%2f20%2fvisual-studio-2010-generating-sequence-diagrams-on-the-fly.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fgunnarpeipman%2farchive%2f2009%2f11%2f20%2fvisual-studio-2010-generating-sequence-diagrams-on-the-fly.aspx" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td align="center"&gt;
&lt;a rev="vote-for" href="http://pimpthisblog.com/Visual-Studio-2010-Generating-sequence-diagrams-on-the-fly"&gt;&lt;img alt="pimp it" src="http://pimpthisblog.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fgunnarpeipman%2Farchive%2F2009%2F11%2F20%2Fvisual-studio-2010-generating-sequence-diagrams-on-the-fly.aspx" style="border:0px"/&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td align="center"&gt;
&lt;a rev="vote-for" href="http://www.9efish.com/Visual-Studio-2010-Generating-sequence-diagrams-on-the-fly"&gt;&lt;img alt="顶" src="http://www.9efish.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fgunnarpeipman%2Farchive%2F2009%2F11%2F20%2Fvisual-studio-2010-generating-sequence-diagrams-on-the-fly.aspx" style="border:0px"/&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td align="center"&gt;
&lt;a rev="vote-for" href="http://progg.ru/Visual-Studio-2010-Generating-sequence-diagrams-on-the-fly"&gt;&lt;img alt="Progg it" src="http://progg.ru/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fgunnarpeipman%2Farchive%2F2009%2F11%2F20%2Fvisual-studio-2010-generating-sequence-diagrams-on-the-fly.aspx" style="border:0px"/&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td align="right"&gt;
&lt;a rev="vote-for" href="http://dotnetshoutout.com/Visual-Studio-2010-Generating-sequence-diagrams-on-the-fly"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fgunnarpeipman%2Farchive%2F2009%2F11%2F20%2Fvisual-studio-2010-generating-sequence-diagrams-on-the-fly.aspx" style="border:0px"/&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="4"&gt;&lt;/td&gt;
&lt;td align="right"&gt;
&lt;a rev="vote-for" href="http://servefault.com/Visual-Studio-2010-Generating-sequence-diagrams-on-the-fly"&gt;&lt;img alt="Shout it!" src="http://servefault.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fgunnarpeipman%2Farchive%2F2009%2F11%2F20%2Fvisual-studio-2010-generating-sequence-diagrams-on-the-fly.aspx&amp;countBackColor=00cc00" style="border:0px"/&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7261478" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/gunnarpeipman/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://weblogs.asp.net/gunnarpeipman/archive/tags/Architecture+_2600_amp_3B00_+Design/default.aspx">Architecture &amp;amp; Design</category><category domain="http://weblogs.asp.net/gunnarpeipman/archive/tags/Analysis/default.aspx">Analysis</category></item><item><title>Can the C# ‘var’ Keyword be Misused?</title><link>http://weblogs.asp.net/stevewellens/archive/2009/11/19/can-the-c-var-keyword-be-misused.aspx</link><pubDate>Thu, 19 Nov 2009 13:52:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7260452</guid><dc:creator>SGWellens</dc:creator><author>SGWellens</author><slash:comments>20</slash:comments><description>&lt;P&gt;More and more often I've been seeing C# code like this: &lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P style="BACKGROUND: white"&gt;&lt;SPAN style="FONT-FAMILY: Courier New; FONT-SIZE: 10pt"&gt;&lt;SPAN style="COLOR: blue"&gt;var&lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt; Data = GetData(); &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What on earth does GetData() return? This code is not as maintainable as it could be and is not as maintainable as it should be. &lt;/P&gt;
&lt;P&gt;Doesn't explicitly declaring the variable type make the code more readable, understandable and ultimately more maintainable? &lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P style="BACKGROUND: white"&gt;&lt;SPAN style="FONT-FAMILY: Courier New; FONT-SIZE: 10pt"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;DataTable&lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt; Data = GetData(); &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Ahhh, GetData() returns a DataTable. &lt;/P&gt;
&lt;P&gt;I know that &lt;STRONG&gt;var&lt;/STRONG&gt; has uses but I wish it would have been named something much longer because typing 'var' is too easy. Perhaps it should have been named AutomaticTypeVar or even AutoVar to reduce the lazy misuse. &lt;/P&gt;
&lt;P&gt;Just my 2 cents. &lt;/P&gt;
&lt;P&gt;Steve Wellens &lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7260452" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/stevewellens/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/stevewellens/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/stevewellens/archive/tags/var/default.aspx">var</category></item><item><title>Visual WebGui for the web and cloud, is what Visual Basic was, for the desktop</title><link>http://weblogs.asp.net/visualwebgui/archive/2009/11/19/visual-webgui-for-the-web-and-cloud-is-what-visual-basic-was-for-the-desktop.aspx</link><pubDate>Thu, 19 Nov 2009 12:57:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7260483</guid><dc:creator>Visual WebGui</dc:creator><author>Visual WebGui</author><slash:comments>2</slash:comments><description>Just a decade and a half ago, the process of building a simple Windows-based application could have been described as a nightmare. The introduction of Visual Basic changed it so developers could for the first time implement Windows applications in an intuitive, graphical environment by dragging controls onto a form. The web revolution is here and now. Web had become very quickly the platform of choice for all kind of applications. The demand for web applications is ever growing and cloud computing...(&lt;a href="http://weblogs.asp.net/visualwebgui/archive/2009/11/19/visual-webgui-for-the-web-and-cloud-is-what-visual-basic-was-for-the-desktop.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7260483" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/AJAX/default.aspx">AJAX</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/WinForms/default.aspx">WinForms</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/web+development/default.aspx">web development</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/web+applications/default.aspx">web applications</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/vb+6.0/default.aspx">vb 6.0</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/vb.net/default.aspx">vb.net</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/web+2.0/default.aspx">web 2.0</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/WYSIWYG/default.aspx">WYSIWYG</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/windows+application/default.aspx">windows application</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/drag+and+drop/default.aspx">drag and drop</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/cloud/default.aspx">cloud</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/programming/default.aspx">programming</category><category domain="http://weblogs.asp.net/visualwebgui/archive/tags/developers/default.aspx">developers</category></item><item><title>ASP.NET 4.0: Writing custom output cache providers</title><link>http://weblogs.asp.net/gunnarpeipman/archive/2009/11/19/asp-net-4-0-writing-custom-output-cache-providers.aspx</link><pubDate>Thu, 19 Nov 2009 12:48:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7260390</guid><dc:creator>DigiMortal</dc:creator><author>DigiMortal</author><slash:comments>7</slash:comments><description>&lt;p&gt;Until now we can use ASP.NET default output cache. We don’t have any option to write our own output cache mechanisms. &lt;a href="http://weblogs.asp.net/gunnarpeipman/pages/visual-studio-2010-and-net-framework-4-0.aspx"&gt;ASP.NET 4.0&lt;/a&gt; introduces extensible output cache – programmers can write their own output cache providers. In this posting I will show you how to write your own output cache provider and give you my sample solution to download.&lt;/p&gt;  &lt;h3&gt;Preparing&lt;/h3&gt;  &lt;p&gt;Before we begin with caching we need Visual Studio 2010 solution that has two projects – one web application and one class library. Class library is for output cache provider and web application is for testing purposes. My solution uses following names:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Solution: CacheProviderDemo &lt;/li&gt;    &lt;li&gt;Web application: CacheProviderApp &lt;/li&gt;    &lt;li&gt;Class library: MyCacheProviders &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Before moving on let’s modify web application and add project reference to class library. In this case we don’t have to copy our cache provider to GAC after each build. &lt;/p&gt;  &lt;h3&gt;Configuring output caching&lt;/h3&gt;  &lt;p&gt;Now let’s change our web.config and add there the following configuration block under system.web section.&lt;/p&gt;  &lt;hr size="1" /&gt;  &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;caching&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;outputCache&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;defaultProvider&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;AspNetInternalProvider&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;providers&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;FileCache&lt;/span&gt;&amp;quot;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;MyCacheProviders.FileCacheProvider, MyCacheProviders&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;providers&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt; &lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;outputCache&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt; &lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;caching&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;hr size="1" /&gt;&lt;/div&gt;  &lt;p&gt;This configuration block tells ASP.NET that there is output cache provider called FileCache available but we want to use default provider calles AspNetInternalProvider. We will change this block later.&lt;/p&gt;  &lt;h3&gt;Writing output cache provider&lt;/h3&gt;  &lt;p&gt;Now let’s start with output cache provider. From output cache configuration block you can see that Class1.cs in our class library must be renamed to FileCacheProvider.cs. Don’t forget also change the class name. Add reference to System.Web to class library and open FileCacheProvider.cs. In the beginning of this file add using line for &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.caching.aspx"&gt;System.Web.Caching&lt;/a&gt; namespace. &lt;/p&gt;  &lt;p&gt;Our output cache provider class must extend &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.caching.outputcacheprovider(VS.100).aspx"&gt;OutputCacheProvider&lt;/a&gt; base class. This base class defines all methods that output cache providers must implement. Our output cache provider uses file system for cache storage. Output cache entries are serialized to binary format and back when writing and reading objects from files. &lt;/p&gt;  &lt;p&gt;Classes for our custom output cache provider are here.&lt;/p&gt;  &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;   &lt;hr size="1" /&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;FileCacheProvider&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;OutputCacheProvider&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; _cachePath;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; CachePath&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;if&lt;/span&gt; (!&lt;span style="color: blue"&gt;string&lt;/span&gt;.IsNullOrEmpty(_cachePath))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; _cachePath;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _cachePath = &lt;span style="color: #2b91af"&gt;ConfigurationManager&lt;/span&gt;.AppSettings[&lt;span style="color: #a31515"&gt;&amp;quot;OutputCachePath&amp;quot;&lt;/span&gt;];&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; context = &lt;span style="color: #2b91af"&gt;HttpContext&lt;/span&gt;.Current;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;if&lt;/span&gt; (context != &lt;span style="color: blue"&gt;null&lt;/span&gt;)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _cachePath = context.Server.MapPath(_cachePath);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;if&lt;/span&gt; (!_cachePath.EndsWith(&lt;span style="color: #a31515"&gt;&amp;quot;\\&amp;quot;&lt;/span&gt;))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _cachePath += &lt;span style="color: #a31515"&gt;&amp;quot;\\&amp;quot;&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; _cachePath;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;object&lt;/span&gt; Add(&lt;span style="color: blue"&gt;string&lt;/span&gt; key, &lt;span style="color: blue"&gt;object&lt;/span&gt; entry, &lt;span style="color: #2b91af"&gt;DateTime&lt;/span&gt; utcExpiry)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Cache.Add(&amp;quot;&lt;/span&gt; + key + &lt;span style="color: #a31515"&gt;&amp;quot;, &amp;quot;&lt;/span&gt; + entry + &lt;span style="color: #a31515"&gt;&amp;quot;, &amp;quot;&lt;/span&gt; + utcExpiry + &lt;span style="color: #a31515"&gt;&amp;quot;)&amp;quot;&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; path = GetPathFromKey(key);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;File&lt;/span&gt;.Exists(path))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; entry;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;using&lt;/span&gt; (&lt;span style="color: blue"&gt;var&lt;/span&gt; file = &lt;span style="color: #2b91af"&gt;File&lt;/span&gt;.OpenWrite(path))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; item = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;CacheItem&lt;/span&gt; { Expires = utcExpiry, Item = entry };&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; formatter = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;BinaryFormatter&lt;/span&gt;();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; formatter.Serialize(file, item);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; entry;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;object&lt;/span&gt; Get(&lt;span style="color: blue"&gt;string&lt;/span&gt; key)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Cache.Get(&amp;quot;&lt;/span&gt; + key + &lt;span style="color: #a31515"&gt;&amp;quot;)&amp;quot;&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; path = GetPathFromKey(key);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;if&lt;/span&gt; (!&lt;span style="color: #2b91af"&gt;File&lt;/span&gt;.Exists(path))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: blue"&gt;null&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;CacheItem&lt;/span&gt; item = &lt;span style="color: blue"&gt;null&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;using&lt;/span&gt; (&lt;span style="color: blue"&gt;var&lt;/span&gt; file = &lt;span style="color: #2b91af"&gt;File&lt;/span&gt;.OpenRead(path))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; formatter = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;BinaryFormatter&lt;/span&gt;();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; item = (&lt;span style="color: #2b91af"&gt;CacheItem&lt;/span&gt;)formatter.Deserialize(file);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;if&lt;/span&gt; (item == &lt;span style="color: blue"&gt;null&lt;/span&gt; || item.Expires &amp;lt;= &lt;span style="color: #2b91af"&gt;DateTime&lt;/span&gt;.Now.ToUniversalTime())&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Remove(key);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: blue"&gt;null&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; item.Item;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Remove(&lt;span style="color: blue"&gt;string&lt;/span&gt; key)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Cache.Remove(&amp;quot;&lt;/span&gt; + key + &lt;span style="color: #a31515"&gt;&amp;quot;)&amp;quot;&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; path = GetPathFromKey(key);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;File&lt;/span&gt;.Exists(path))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;File&lt;/span&gt;.Delete(path);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Set(&lt;span style="color: blue"&gt;string&lt;/span&gt; key, &lt;span style="color: blue"&gt;object&lt;/span&gt; entry, &lt;span style="color: #2b91af"&gt;DateTime&lt;/span&gt; utcExpiry)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Cache.Set(&amp;quot;&lt;/span&gt; + key + &lt;span style="color: #a31515"&gt;&amp;quot;, &amp;quot;&lt;/span&gt; + entry + &lt;span style="color: #a31515"&gt;&amp;quot;, &amp;quot;&lt;/span&gt; + utcExpiry + &lt;span style="color: #a31515"&gt;&amp;quot;)&amp;quot;&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; item = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;CacheItem&lt;/span&gt; { Expires = utcExpiry, Item = entry };&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; path = GetPathFromKey(key);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;using&lt;/span&gt; (&lt;span style="color: blue"&gt;var&lt;/span&gt; file = &lt;span style="color: #2b91af"&gt;File&lt;/span&gt;.OpenWrite(path))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; formatter = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;BinaryFormatter&lt;/span&gt;();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; formatter.Serialize(file, item);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; GetPathFromKey(&lt;span style="color: blue"&gt;string&lt;/span&gt; key)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; CachePath + MD5(key) + &lt;span style="color: #a31515"&gt;&amp;quot;.txt&amp;quot;&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; MD5(&lt;span style="color: blue"&gt;string&lt;/span&gt; s)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; provider = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;MD5CryptoServiceProvider&lt;/span&gt;();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; bytes = &lt;span style="color: #2b91af"&gt;Encoding&lt;/span&gt;.UTF8.GetBytes(s);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var&lt;/span&gt; builder = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;StringBuilder&lt;/span&gt;();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; bytes = provider.ComputeHash(bytes);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: blue"&gt;var&lt;/span&gt; b &lt;span style="color: blue"&gt;in&lt;/span&gt; bytes)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; builder.Append(b.ToString(&lt;span style="color: #a31515"&gt;&amp;quot;x2&amp;quot;&lt;/span&gt;).ToLower());&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;return&lt;/span&gt; builder.ToString();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt;    &lt;hr size="1" /&gt;&lt;/div&gt;  &lt;p&gt;With cached item we have to keep date and time that say us when cached object expires. I write simple CacheItem class that is marked as serializable (otherwise it is not possible to serialize it and therefore we cannot use binary formatter). CacheItem class is simple.&lt;/p&gt;  &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;   &lt;hr size="1" /&gt;    &lt;p style="margin: 0px"&gt;[&lt;span style="color: #2b91af"&gt;Serializable&lt;/span&gt;]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;internal&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;CacheItem&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DateTime&lt;/span&gt; Expires;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;object&lt;/span&gt; Item;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt;    &lt;hr size="1" /&gt;&lt;/div&gt;  &lt;p&gt;I made this class internal because we have no reason to show it to the world. We only use this class to store and restore cache entries with expiry date.&lt;/p&gt;  &lt;p&gt;Some notes for FileCacheProvider class.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;You must have appSetting called OutputCachePath that contains path to cache files folder. This path may contain ~ because in the case of web application this path goes through &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx"&gt;Server.MapPath()&lt;/a&gt; method. &lt;/li&gt;    &lt;li&gt;File names are made of MD5 hashed cache entry key and .txt extension. You can use whatever file extension you like. &lt;/li&gt;    &lt;li&gt;I am using binary formatter because it workes better for me than &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx"&gt;XmlSerializer&lt;/a&gt; (Add() method is used with internal classes that have no public constructor with empty argument list). &lt;/li&gt;    &lt;li&gt;My code uses calls to &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.debug.write.aspx"&gt;Debug.WriteLine()&lt;/a&gt; method. When you run web application with Visual Studio then you can see output cache messages in output window. I found that it is very easy and powerful way to debug provider because these messages show you what is going on. &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Preparing web application for testing&lt;/h3&gt;  &lt;p&gt;Let’s prepare now web application for testing. As a first thing we must make some changes to web.config. We have to add appSetting for cache folder and we have to make our file cache provider as default output cache provider. Here are XML-blocks for configuration.&lt;/p&gt;  &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;   &lt;hr size="1" /&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;appSettings&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;key&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;OutputCachePath&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;~/Cache/&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;appSettings&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;caching&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;outputCache&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;defaultProvider&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;FileCache&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;providers&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;FileCache&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;MyCacheProvider.FileCacheProvider, MyCacheProvider&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;providers&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;outputCache&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;caching&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;hr size="1" /&gt;&lt;/div&gt;  &lt;p&gt;I expect you know where to put these blocks in web.config file. We have one more change to make before running our web application. Let’s turn output caching on for it. Although there should be providerName attribute available it doesn’t work yet. At least for my installation of Visual Studio 2010 and ASP.NET 4.0. Add the following line to Default.aspx.&lt;/p&gt;  &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;   &lt;hr size="1" /&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;%&lt;span style="color: #a31515"&gt;@&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;OutputCache&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;VaryByParam&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ID&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Duration&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;300&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; &lt;/span&gt;%&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;hr size="1" /&gt;&lt;/div&gt;  &lt;p&gt;I added &lt;a href="http://msdn.microsoft.com/en-us/library/hdxfb6cy(VS.71).aspx"&gt;VaryByParam&lt;/a&gt; for one reason: to test caching with different ID-s. Cache duration is 300 seconds (5 minutes). You can change to attributes if you like.&lt;/p&gt;  &lt;h3&gt;Testing output cache provider&lt;/h3&gt;  &lt;p&gt;Now let’s test our output cache provider. Run web application.&lt;/p&gt;  &lt;p align="center"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Web application: we are using it to test output cache provider" border="0" alt="Web application: we are using it to test output cache provider" src="http://weblogs.asp.net/blogs/gunnarpeipman/myaspnetapplication_07DD6C3F.png" width="460" height="239" /&gt; &lt;/p&gt;  &lt;p&gt;When you see default page in your browser check out output window in Visual Studio 2010. You should see there something like this.&lt;/p&gt;  &lt;hr size="1" /&gt;&lt;code&gt;Cache.Get(a2/default.aspx)    &lt;br /&gt;Cache.Add(a2/default.aspx, System.Web.Caching.CachedVary, 31.12.9999 23:59:59)     &lt;br /&gt;Cache.Set(a2/default.aspxHQNidV+n+FCDE, System.Web.Caching.OutputCacheEntry, 19.11.2009 12:20:56)&lt;/code&gt;   &lt;hr size="1" /&gt;  &lt;p&gt;After refresh you should see something like this in output window.&lt;/p&gt;  &lt;hr size="1" /&gt;&lt;code&gt;Cache.Get(a2/default.aspx)    &lt;br /&gt;Cache.Get(a2/default.aspxHQNidV+n+FCDE)     &lt;br /&gt;Cache.Get(a2/styles/site.css)     &lt;br /&gt;Cache.Get(a2/webresource.axd)     &lt;br /&gt;Cache.Set(a2/styles/site.css, System.Web.Caching.OutputCacheEntry, 20.11.2009 12:17:09)     &lt;br /&gt;Cache.Add(a2/webresource.axd, System.Web.Caching.CachedVary, 31.12.9999 23:59:59)     &lt;br /&gt;Cache.Set(a2/webresource.axdHQNdVjnaEMMY-tPD2-oCbZFp7vHhVoQiB8SS98KHQMNKjUfs1FCDE, System.Web.Caching.OutputCacheEntry, 19.11.2010 12:17:09)     &lt;br /&gt;Cache.Get(a2/webresource.axd)     &lt;br /&gt;Cache.Get(a2/webresource.axdHQNdVqx_c6oOlTqymCAsGZh_8JA2FCDE)     &lt;br /&gt;Cache.Add(a2/webresource.axd, System.Web.Caching.CachedVary, 31.12.9999 23:59:59)     &lt;br /&gt;Cache.Set(a2/webresource.axdHQNdVqx_c6oOlTqymCAsGZh_8JA2FCDE, System.Web.Caching.OutputCacheEntry, 19.11.2010 12:17:10)&lt;/code&gt;   &lt;hr size="1" /&gt;  &lt;p&gt;You see that second request caches some more data. There requests to FileCacheProvider are made by ASP.NET. During additional refresh some resources get cached and the other resources are removed from output cache. &lt;/p&gt;  &lt;p&gt;Here is one simple screenshot fragment of file cache folder.&lt;/p&gt;  &lt;p align="center"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="List of files that contain cache entries" border="0" alt="List of files that contain cache entries" src="http://weblogs.asp.net/blogs/gunnarpeipman/filecacheproviderfiles_75D128B1.png" width="520" height="181" /&gt; &lt;/p&gt;  &lt;p&gt;You can open these files to see what is inside them. You should see there cache items in binary format as binary formatter serializes them.&lt;/p&gt;  &lt;h3&gt;Conclusion&lt;/h3&gt;  &lt;p&gt;Although there are not much informative and guiding documentation about custom output cache providers I got mine working seemlessly well. I am not sure about some aspects of my provider and I will consult with Microsoft about my doubts. Of course, I will let you know if I get some valuable feedback from Microsoft.&lt;/p&gt;  &lt;p&gt;The point of this posting was to show you how to write custom output cache provider. As we saw it is not something crucial or complex – we have to extend OutputCacheProvider class and implement some methods that store, edit and clear cached items. You can write your own implementations of output cache provider and keep your output cache wherever you like.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Sample solution&lt;/strong&gt;&lt;/p&gt;  &lt;table border="0" cellspacing="2" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;&lt;img alt="Visual Studio 2010 Solution" src="http://weblogs.asp.net/blogs/gunnarpeipman/vs2010-solution.png" /&gt; &lt;/td&gt;        &lt;td valign="top"&gt;&lt;strong&gt;&lt;a href="http://weblogs.asp.net/blogs/gunnarpeipman/downloads/CacheProviderDemo.zip"&gt;CacheProviderDemo.zip&lt;/a&gt;&lt;/strong&gt;           &lt;br /&gt;Visual Studio 2010 Solution | Size: 181 KB &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;

&lt;hr size="1" /&gt;

&lt;table border="0" cellpadding="0" cellspacing="2" width="100%"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fgunnarpeipman%2farchive%2f2009%2f11%2f19%2fasp-net-4-0-writing-custom-output-cache-providers.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fgunnarpeipman%2farchive%2f2009%2f11%2f19%2fasp-net-4-0-writing-custom-output-cache-providers.aspx" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td align="center"&gt;
&lt;a rev="vote-for" href="http://pimpthisblog.com/ASPNET-40-Writing-custom-output-cache-providers"&gt;&lt;img alt="pimp it" src="http://pimpthisblog.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fgunnarpeipman%2Farchive%2F2009%2F11%2F19%2Fasp-net-4-0-writing-custom-output-cache-providers.aspx" style="border:0px"/&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td align="center"&gt;
&lt;a rev="vote-for" href="http://www.9efish.com/ASPNET-40-Writing-custom-output-cache-providers"&gt;&lt;img alt="顶" src="http://www.9efish.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fgunnarpeipman%2Farchive%2F2009%2F11%2F19%2Fasp-net-4-0-writing-custom-output-cache-providers.aspx" style="border:0px"/&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td align="center"&gt;
&lt;a rev="vote-for" href="http://progg.ru/ASPNET-40-Writing-custom-output-cache-providers"&gt;&lt;img alt="Progg it" src="http://progg.ru/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fgunnarpeipman%2Farchive%2F2009%2F11%2F19%2Fasp-net-4-0-writing-custom-output-cache-providers.aspx" style="border:0px"/&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td align="right"&gt;
&lt;a rev="vote-for" href="http://dotnetshoutout.com/ASPNET-40-Writing-custom-output-cache-providers"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fgunnarpeipman%2Farchive%2F2009%2F11%2F19%2Fasp-net-4-0-writing-custom-output-cache-providers.aspx" style="border:0px"/&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7260390" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/gunnarpeipman/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/gunnarpeipman/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://weblogs.asp.net/gunnarpeipman/archive/tags/Web+development/default.aspx">Web development</category><category domain="http://weblogs.asp.net/gunnarpeipman/archive/tags/Performance/default.aspx">Performance</category></item><item><title>Daily tech links for .net and related technologies - November 18-20, 2009</title><link>http://weblogs.asp.net/sanjeevagarwal/archive/2009/11/19/daily-tech-links-for-net-and-related-technologies-november-18-20-2009.aspx</link><pubDate>Thu, 19 Nov 2009 07:25:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7260094</guid><dc:creator>SanjeevAgarwal</dc:creator><author>SanjeevAgarwal</author><slash:comments>0</slash:comments><description>Daily tech links for .net and related technologies - November 18-20, 2009 Web Development SharePoint 2010 Public Beta Available For Download ASP.NET MVC 2 Beta Released – Phil Haack Using the JQuery dialog widget in a custom SharePoint web part – Charles Lee Using Microsoft’s Chart Controls In An ASP.NET Application: Adding Statistical Formulas Deep Tracing of Internet Explorer The AJAX UpdatePanel Is it your worst enemy? Web Design How to Build a Custom jQuery Tabs Plugin: New Plus Tutorial 50 Fresh...(&lt;a href="http://weblogs.asp.net/sanjeevagarwal/archive/2009/11/19/daily-tech-links-for-net-and-related-technologies-november-18-20-2009.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7260094" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/JQuery/default.aspx">JQuery</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/CSS/default.aspx">CSS</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/VB.NET/default.aspx">VB.NET</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/WPF/default.aspx">WPF</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/WCF/default.aspx">WCF</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/MVC/default.aspx">MVC</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/XML/default.aspx">XML</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/Ajax/default.aspx">Ajax</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/Database/default.aspx">Database</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/ORM/default.aspx">ORM</category><category domain="http://weblogs.asp.net/sanjeevagarwal/archive/tags/Entity+Framework/default.aspx">Entity Framework</category></item><item><title>Silverlight 4</title><link>http://weblogs.asp.net/bryansampica/archive/2009/11/18/silverlight-4.aspx</link><pubDate>Thu, 19 Nov 2009 01:26:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7259807</guid><dc:creator>Freakyuno</dc:creator><author>Freakyuno</author><slash:comments>1</slash:comments><description>&lt;P mce_keep="true"&gt;So the Silverlight platform has been quite interesting for some time in concept, and had some niche abilities that made it perfect for streaming media, or writing simple rich applications.&amp;nbsp; Around the time of Silverlight 3 things started to get interesting;&amp;nbsp; as the tools developed, and the platform matured!&lt;/P&gt;
&lt;P mce_keep="true"&gt;Enter, Silverlight 4!&lt;/P&gt;
&lt;P mce_keep="true"&gt;For those of you that have been waiting to adopt this technology into your own development lifecycle, I truly believe your wait is over.&amp;nbsp; Difficult or downright impossible things inside Silverlight applications have now been overcome.&amp;nbsp; Limitations such as Printing, Local File Access, mouse scroll wheel support, and out of browser experiences.&lt;/P&gt;
&lt;P mce_keep="true"&gt;There has been a huge stir of Silverlight 4 activity at PDC09 this year (where they handed out free multi-touch windows 7 laptops to every attendee!!!) - yea, I know.&amp;nbsp; And some &lt;STRONG&gt;very&lt;/STRONG&gt; cool demo's being displayed.&amp;nbsp; Watching the live stream (&lt;A href="http://microsoftpdc.com/"&gt;http://microsoftpdc.com/&lt;/A&gt;) during conference hours, left me intrigued enough to want to fire up and start to prototype some applications on the Silverlight 4 platform.&lt;/P&gt;
&lt;P mce_keep="true"&gt;As I went looking, it took me a little longer than I would have liked to find all the things I needed to get started and give it an accurate test drive, so below is the link (link aggregation) on how to get started.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;A href="http://silverlight.net/getstarted/silverlight-4-beta/#tools"&gt;http://silverlight.net/getstarted/silverlight-4-beta/#tools&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;I know...the silverlight site.&amp;nbsp; Unfortunatly as a developer and MVP I'm used to finding what I need published under the MSDN downloads section, linear thinking FTW.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Dont forget as you get started to pop over to the videos located here:&amp;nbsp; All VERY good information&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;A href="http://silverlight.net/learn/videos/silverlight-4-beta-videos/"&gt;http://silverlight.net/learn/videos/silverlight-4-beta-videos/&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;I'm in process of wiring up an artist (photo) gallery currently, using Silverlight 4, RIA Services, and the new Toolkit, using Visual Studio 2010 of course.&amp;nbsp; So far I'm VERY impressed with the platform and where it's gone - it's finally at the point where I just dont feel like there's anything &lt;EM&gt;missing&lt;/EM&gt; as previously.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;Good luck!&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7259807" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/bryansampica/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/bryansampica/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://weblogs.asp.net/bryansampica/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category><category domain="http://weblogs.asp.net/bryansampica/archive/tags/Silverlight+4/default.aspx">Silverlight 4</category></item><item><title>Introduction to the Reactive Framework Part V</title><link>http://weblogs.asp.net/podwysocki/archive/2009/11/18/introduction-to-the-reactive-framework-part-v.aspx</link><pubDate>Wed, 18 Nov 2009 22:48:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7259680</guid><dc:creator>podwysocki</dc:creator><author>podwysocki</author><slash:comments>0</slash:comments><description>&lt;p&gt;In the previous post of the Introduction to the Reactive Framework series, we covered how to create new IObservable&amp;lt;T&amp;gt; instances, either from scratch or from existing sequences.&amp;nbsp; What this allowed us to do was turn an operation which was previously interactive, such as iterating over a collection, to a reactive, where I could have multiple listeners reacting to the same collection concurrently.&amp;nbsp; This has nice implications for allowing us to scale our application in interesting ways.&amp;nbsp; This time, let’s take another angle on making asynchronous programming easier.&lt;/p&gt;

&lt;p&gt;Let’s get caught up to where we are today:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://codebetter.com/blogs/matthew.podwysocki/archive/2009/10/19/f-october-2009-ctp-beta2-f-rx-together-at-last.aspx" mce_href="http://codebetter.com/blogs/matthew.podwysocki/archive/2009/10/19/f-october-2009-ctp-beta2-f-rx-together-at-last.aspx"&gt;Part I – Introduction&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://codebetter.com/blogs/matthew.podwysocki/archive/2009/11/03/introduction-to-the-reactive-framework-part-ii.aspx" mce_href="http://codebetter.com/blogs/matthew.podwysocki/archive/2009/11/03/introduction-to-the-reactive-framework-part-ii.aspx"&gt;Part II – Duality of Enumerable/Observable&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://codebetter.com/blogs/matthew.podwysocki/archive/2009/11/12/introduction-to-the-reactive-framework-part-iii.aspx" mce_href="http://codebetter.com/blogs/matthew.podwysocki/archive/2009/11/12/introduction-to-the-reactive-framework-part-iii.aspx"&gt;Part III – From Events to Observables&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://codebetter.com/blogs/matthew.podwysocki/archive/2009/11/15/introduction-to-the-reactive-framework-part-iv.aspx" mce_href="http://codebetter.com/blogs/matthew.podwysocki/archive/2009/11/15/introduction-to-the-reactive-framework-part-iv.aspx"&gt;Part IV – From Enumerables to Observables&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;From Asynchronous To Observables&lt;/h2&gt;

&lt;p&gt;In the first post in the series, we talked about some of the problems we face with asynchronous programming today.&amp;nbsp; For example, for any given operation, how do we handle exceptions, or handle cancellation, or even manage the lifetime of resources?&amp;nbsp; Let’s take a look at the story of asynchronous programming today.&amp;nbsp; For example, let’s take the fairly straight forward approach of sending a tweet in Twitter, but with the added pressure of non-blocking calls for all IO operations.&amp;nbsp; Now we took an example which should have been straight forward, and now it looks something like this anti-pattern:&lt;/p&gt;

&lt;div style="padding: 0px; margin: 0px; display: inline; float: none;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:6d00f6bb-d89f-4d21-87e9-284327b63e6b" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color: rgb(255, 255, 255); white-space: pre-wrap; word-wrap: break-word; overflow: auto;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; request &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; WebRequest.Create(&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;http://twitter.com/statuses/update.xml&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;);
request.Credentials &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; NetworkCredential(&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;foo&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;bar&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;);
request.Method &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;POST&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;

request.BeginGetRequestStream(rsAr &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
{
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; requestStream &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; request.EndGetRequestStream(rsAr);
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; tweet &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; HttpUtility.HtmlEncode(&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;status=Hello from an async method #bacon&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;);
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; bytes &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Encoding.UTF8.GetBytes(tweet);
    requestStream.BeginWrite(bytes, &lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, bytes.Length, beginWriteAr &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    {
        requestStream.EndWrite(beginWriteAr);
        request.BeginGetResponse(responseAr &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
        {
            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; response &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; request.EndGetResponse(responseAr);
            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; responseStream &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; response.GetResponseStream();

            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; readBuffer &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[response.ContentLength];
            responseStream.BeginRead(readBuffer, &lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, readBuffer.Length, readAr &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
            {
                &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; read &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; responseStream.EndRead(readAr);
                &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; readText &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Encoding.UTF8.GetString(readBuffer);
                ResultsText.Text &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; readText;
            }, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;);
        }, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;);
    }, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;);
}, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Not only is this code an absolute mess, but it has a number of bad practices, including not handling cleanup of our resources, as well as not handling exceptions, cancellation checking, or even checking if our buffer was completely read.&amp;nbsp; Adding those constraints to the above code would make it a bit more unreadable.&amp;nbsp; The situation we run into is that programming in a non-blocking fashion has caused all sorts of heartache where we become so wrapped up in the non-blocking code that we lose sight easily of the domain logic we should have been interested in, in the first place.&lt;/p&gt;

&lt;p&gt;I’ve covered in the past that with F# async workflows, solving this is a rather easy task and that kind of rich functionality has been unavailable to C# developers directly.&amp;nbsp; But, with the Reactive Extensions for .NET, we have the ability to also take advantage of composable asynchronous actions as well.&amp;nbsp; So, where do we get started?&lt;/p&gt;

&lt;p&gt;Let’s take a simple example of creating a function and then invoking it asynchronously.&lt;/p&gt;

&lt;div style="padding: 0px; margin: 0px; display: inline; float: none;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:742903f2-e391-48c3-86d0-554ce2d7c2c3" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color: rgb(255, 255, 255); white-space: pre-wrap; word-wrap: break-word; overflow: auto;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Func&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; add &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (x, y) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; x &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;+&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; y;

add.BeginInvoke(&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;4&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, ar &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
{
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; result &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; add.EndInvoke(ar);
    Console.WriteLine(result);
}, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Many asynchronous methods in .NET are written in this way that their signature has a BeginXXX and EndXXX where the XXX is the method name that is being executed asynchronously.&amp;nbsp; The Begin takes the arguments to execute the method, an AsyncCallback which is an action that takes an IAsyncResult and returns nothing, and finally object state.&amp;nbsp; The End method takes the IAsyncResult which is passed in from the AsyncCallback in order to retrieve the value of the asynchronous call.&lt;/p&gt;

&lt;div style="padding: 0px; margin: 0px; display: inline; float: none;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:7b4bfa8d-cb53-4313-8e25-6ab5c1244331" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color: rgb(255, 255, 255); white-space: pre-wrap; word-wrap: break-word; overflow: auto;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; BeginXXX(args, AsyncCallback, state);

Value EndXXX(IAsyncResult);&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Luckily, the Reactive Extensions give us a couple of ways to make this happen.&amp;nbsp; First, let’s take an existing method such as the System.IO.Stream.WriteAsync.&amp;nbsp; In this example, we’ll create an extension method which allows us to turn this asynchronous method into a IObservable&amp;lt;T&amp;gt;.&lt;/p&gt;

&lt;div style="padding: 0px; margin: 0px; display: inline; float: none;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:66b21f24-0090-4362-a498-9b8fd0e8eddb" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color: rgb(255, 255, 255); white-space: pre-wrap; word-wrap: break-word; overflow: auto;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; IObservable&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Unit&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; WriteAsync(
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Stream stream, 
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[] buffer, 
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; offset, 
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; count)
{
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Observable.FromAsyncPattern&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[], &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(
        stream.BeginWrite,
        stream.EndWrite)(buffer, offset, count);
}&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Because the Write method returns void, we have issues in C# as we cannot have a generic type as being void.&amp;nbsp; To get around this, much like F#, the Reactive Extensions introduced the Unit type to express that we have no value.&amp;nbsp; Quite frankly this is the way I think C# should have been to allow for this and not need these unnecessary hacks.&amp;nbsp; Anyways, the Observable class has a method called FromAsyncPattern which takes in both the BeginXXX and EndXXX and returns a Func delegate that takes the arguments required to execute it.&amp;nbsp; In this case, the Observable.FromAsyncPattern returns a Func which takes the buffer, offset and count and returns an IObservable&amp;lt;Unit&amp;gt;.&amp;nbsp; &lt;/p&gt;

&lt;p&gt;There is also another way in that we can take our existing add function from above and using an extension method called ToAsync, can also work the IObservable magic.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/p&gt;

&lt;div style="padding: 0px; margin: 0px; display: inline; float: none;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:5840af4f-e707-4492-88b1-bbb3f46abb9c" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color: rgb(255, 255, 255); white-space: pre-wrap; word-wrap: break-word; overflow: auto;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Func&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; add &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (x, y) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; x &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;+&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; y;
Func&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, IObservable&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; obvervableAdd &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; add.ToAsync();

IObservable&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; result &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;from&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; added &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; obvervableAdd(&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;4&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)
                          &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;select&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; added;
IDisposable sub &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; result
    .SubscribeOnDispatcher()
    .Subscribe(added &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Results.Text &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; added.ToString());&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;In this instance, we took our existing add method and then turned it into an asynchronous method by using the ToAsync extension method.&amp;nbsp; That returns a Func delegate which takes our two arguments and returns an IObservable&amp;lt;int&amp;gt; which contains our asynchronous result.&amp;nbsp; We can then take our new observableAdd and execute it inside of a LINQ statement, then subscribe to it on the Dispatcher thread in order to rid ourselves of synchronization context issues in WPF.&lt;/p&gt;

&lt;p&gt;Going back to our original example here, let’s see how we might follow some of the ideas presented here into creating a way to send a tweet completely in a LINQ statement.&amp;nbsp; &lt;/p&gt;

&lt;div style="padding: 0px; margin: 0px; display: inline; float: none;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:e04b7ec5-7fd2-435f-b65a-526ac5711c24" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color: rgb(255, 255, 255); white-space: pre-wrap; word-wrap: break-word; overflow: auto;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; tweetObservable &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;from&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; request &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; 
        CreateWebRequest(
            &lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;http://twitter.com/statuses/update.xml&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, 
            userName, 
            password, 
            &lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;POST&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;let&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; tweet &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; HttpUtility.HtmlEncode(&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;status= Hi! #bacon&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;let&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; buffer &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Encoding.UTF8.GetBytes(tweet)
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;from&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; _ &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; request.SetContentLength(buffer.Length)
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;from&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; requestStream &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; request.GetRequestStreamAsync()
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;from&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; __ &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; requestStream.WriteAsync(buffer, &lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, buffer.Length)
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;from&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; response &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; request.GetResponseAsync()
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;let&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; responseStream &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; response.GetResponseStream()
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;let&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; reader &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; StreamReader(responseStream)
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;select&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; reader.ReadToEnd();
    
&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; tweetsObservable &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; tweetObservable
    .Throttle(TimeSpan.FromMinutes(&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;))
    .Repeat(&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;25&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;We can create extension methods to the WebRequest for GetRequestStream and GetResponse to enable observable behavior via the Begin/End methods that the WebRequest exposes.&amp;nbsp; As well, we can extend the System.IO.Stream as well to both write and read streams asynchronously.&amp;nbsp; We have other more trivial methods such as setting the content length and creating a web request as an observable as well, and in order to do that was covered in the previous post using the Observable.Create method.&amp;nbsp; After we create this IObservable value, we can then throttle it to every three minutes and to repeat 25 times.&amp;nbsp; One concern we might have is around the resource usage and ensuring the cleanup, and we’ll cover that next time.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;As I’ve stated before, the LiveLabs Reactive Framework gives us the ability to harness reactive programming and treat events as the first class citizens they should have been using LINQ expressions and other standard LINQ combinators.&amp;nbsp; Still, there is much to cover in this series with the standard LINQ combinators, the monadic heritage of this solution as well as managing resources, and turning Tasks Observables.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7259680" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/podwysocki/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/podwysocki/archive/tags/Concurrency/default.aspx">Concurrency</category><category domain="http://weblogs.asp.net/podwysocki/archive/tags/Reactive+Framework/default.aspx">Reactive Framework</category></item></channel></rss>