<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Brian Mains</title><subtitle type="html">Catch me on linked in at:  http://linkedin.com/in/brianmains, or follow me on twitter at: @brianmains.</subtitle><id>http://msmvps.com/blogs/bmains/atom.aspx</id><link rel="alternate" type="text/html" href="http://msmvps.com/blogs/bmains/default.aspx" /><link rel="self" type="application/atom+xml" href="http://msmvps.com/blogs/bmains/atom.aspx" /><generator uri="http://communityserver.org" version="4.1.40407.4157">Community Server</generator><updated>2009-07-06T20:32:00Z</updated><entry><title>Location Formats in ASP.NET MVC</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/11/16/location-formats-in-asp-net-mvc.aspx" /><id>/blogs/bmains/archive/2009/11/16/location-formats-in-asp-net-mvc.aspx</id><published>2009-11-17T01:49:00Z</published><updated>2009-11-17T01:49:00Z</updated><content type="html">&lt;p&gt;ASP.NET MVC is a wonderful thing.&amp;nbsp; One of the many great features is the ability to customize all of the .NET framework&amp;#39;s code by swapping out one implementation and using another.&amp;nbsp; One such instance is creating a custom view engine, which you can do as illustrated in this example: &lt;a href="http://www.singingeels.com/Articles/Creating_a_Custom_View_Engine_in_ASPNET_MVC.aspx"&gt;http://www.singingeels.com/Articles/Creating_a_Custom_View_Engine_in_ASPNET_MVC.aspx&lt;/a&gt;.&amp;nbsp; The point of my article is not to illustrate how this can be done, but about how to customize it for your needs.&amp;nbsp; By default, the web forms view engine looks for views in the folder&amp;nbsp;of the controller or the shared folder.&amp;nbsp; So if you try to trigger an action method &amp;quot;Index&amp;quot; within the controller of type CustomerController, a partial view (.ascx) or the view (.aspx) is sought for in the ~/Shared folder or ~/Customer folder.&lt;/p&gt;
&lt;p&gt;Now, I tend to like to use partial views in order to separate and reuse functionality a lot.&amp;nbsp; So I tend to have a lot of partial views that tend to get reused across pages and I don&amp;#39;t want everything to be in the shared folder (by default, partial views have to be in the shared folder or in the same folder as the controller).&amp;nbsp; So I added some code to the view engine that allowed me to create subfolders within the shared folder and for the view engine to look for the classes there.&amp;nbsp; Imagine this folder structure:&lt;/p&gt;
&lt;p&gt;Shared&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Customers&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Orders&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Products&lt;/p&gt;
&lt;p&gt;So the shared folder breaks up my partial views into the folder above.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thinking long-term, rather than hard-coding all these folder references and assigning them to the ViewLocationFormats and PartialViewLocationFormats properties, I wanted something that I wouldn&amp;#39;t have to worry about changing later.&amp;nbsp; So in true ASP.NET MVC framework form, I created some extra code to create the ability to automatically add references to subfolders too.&amp;nbsp; In order to do this, it&amp;#39;s required to use the VirtualPathProvider class to extract the URL, as in the following code:&lt;/p&gt;
&lt;p&gt;public MyViewEngine() {&lt;br /&gt;var locations&amp;nbsp;= new List&amp;lt;string&amp;gt;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;~/Views/{1}/{0}.aspx&amp;quot;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;~/Views/{1}/{0}.ascx&amp;quot;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;~/Views/Shared/{0}.aspx&amp;quot;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;~/Views/Shared/{0}.ascx&amp;quot;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;var dir = this.VirtualPathProvider.GetDirectory(&amp;quot;~/Views/Shared&amp;quot;);&lt;br /&gt;var subs = dir.Directories.OfType&amp;lt;VirtualDirectory&amp;gt;();&lt;br /&gt;&lt;br /&gt;foreach (var sub in subs)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; locations.Add(&amp;quot;~&amp;quot; + sub.VirtualPath.Substring(sub.VirtualPath.IndexOf(&amp;quot;/&amp;quot;, 2)) + &amp;quot;{0}.ascx&amp;quot;);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;base.ViewLocationFormats = locations.ToArray();&lt;br /&gt;base.PartialViewLocationFormats = base.ViewLocationFormats;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;This is the constructor for the custom view engine.&amp;nbsp; It contains some additional code to use the VirtualPathProvider property (a property of our custom view engine) to extract the subdirectories of the shared folder.&amp;nbsp; You see the four hard-coded references&amp;nbsp;at the beginning, and so we need to create virtual path strings (which start with &amp;quot;~&amp;quot; and work from the beginning of the virtual directory) to add to the custom list.&amp;nbsp; When working with folders using VirtualPathProvider, the issue becomes the way paths are referenced.&amp;nbsp; By default, the path may be:&lt;/p&gt;
&lt;p&gt;/MyVirtualFolder/Views/Shared/Customers/&lt;/p&gt;
&lt;p&gt;When you need:&lt;/p&gt;
&lt;p&gt;~/Views/Shared/Customers/&lt;/p&gt;
&lt;p&gt;And so some additional work to format the path is needed (the substring strips off the virtual directory folder.&amp;nbsp; Now we have a component that will allow the MVC framework to look for partial views in all subdirectories in the shared folder.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1740126" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Web" scheme="http://msmvps.com/blogs/bmains/archive/tags/Web/default.aspx" /><category term="MVC" scheme="http://msmvps.com/blogs/bmains/archive/tags/MVC/default.aspx" /></entry><entry><title>Telerik's Compressing and Combining Scripts in MVC</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/11/10/telerik-s-compressing-and-combining-scripts-in-mvc.aspx" /><id>/blogs/bmains/archive/2009/11/10/telerik-s-compressing-and-combining-scripts-in-mvc.aspx</id><published>2009-11-11T02:50:00Z</published><updated>2009-11-11T02:50:00Z</updated><content type="html">&lt;p&gt;The latest Telerik MVC set of components features a ScriptRegistrar component that&amp;#39;s responsible for compressing or combining scripts into a single file.&amp;nbsp; This compression utility is very easy to implement: to setup this component, use the following steps:&lt;/p&gt;
&lt;p&gt;1. In your configuration file, add the following line to the httpHandlers element in &amp;lt;system.web&amp;gt; and &amp;lt;system.webserver&amp;gt;:&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;color:blue;font-size:10pt;mso-no-proof:yes;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;color:#a31515;font-size:10pt;mso-no-proof:yes;"&gt;add&lt;/span&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;color:blue;font-size:10pt;mso-no-proof:yes;"&gt; &lt;/span&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;color:red;font-size:10pt;mso-no-proof:yes;"&gt;verb&lt;/span&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;color:blue;font-size:10pt;mso-no-proof:yes;"&gt;=&lt;/span&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;font-size:10pt;mso-no-proof:yes;"&gt;&amp;quot;&lt;span style="color:blue;"&gt;GET,HEAD&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;path&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;asset.axd&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;validate&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;/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;Telerik.Web.Mvc.WebAssetHttpHandler, Telerik.Web.Mvc&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="color:blue;"&gt;&lt;span style="font-family:Arial;color:#000000;"&gt;2. Use the ScriptRegistrar and groups to group scripts together.&amp;nbsp; Preferrably, put this in the master page at the very end of the page before the ending &amp;lt;/body&amp;gt; tag.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="color:blue;"&gt;&lt;span style="font-family:Arial;color:#000000;"&gt;&amp;lt;% Html.Telerik().ScriptRegistrar().Scripts((s) =&amp;gt;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; s.AddGroup(&amp;quot;MyGroup&amp;quot;, (g) =&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; g.Add(&amp;quot;script1.js&amp;quot;).Add(&amp;quot;script2.js&amp;quot;).Add(&amp;quot;script3.js&amp;quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}).Render(); %&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="color:blue;"&gt;&lt;span style="color:#000000;"&gt;Now we have our scripts defined, but if you run the app, you will be disappointed by finding out three script files were added.&amp;nbsp; Instead, we need to add some additional properties to the group definition.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="color:blue;"&gt;&lt;span style="color:#000000;"&gt;&lt;span style="font-family:Arial;"&gt;s.AddGroup(&amp;quot;MyGroup&amp;quot;, (g) =&amp;gt;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; g.Add(&amp;quot;script1.js&amp;quot;).Add(&amp;quot;script2.js&amp;quot;).Add(&amp;quot;script3.js&amp;quot;).Combined(true).Compress(true).CacheDurationInDays(10);&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="color:blue;"&gt;&lt;span style="font-family:Arial;color:#000000;"&gt;The Combined() method signals to combine all three scripts together within this group&amp;nbsp; The Compress() method signals to compress the scripts, and the CacheDurationInDays method specifies the number of days to cache the scripts.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="color:blue;"&gt;&lt;span style="font-family:Arial;color:#000000;"&gt;This can also be performed by stylesheets, without the ability to combine and compress them.&amp;nbsp; You can group them together using the same approach, except using the StyleSheets method.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="color:blue;"&gt;&lt;span style="color:#000000;"&gt;This setup produces the following output.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="color:blue;"&gt;
&lt;p class="MsoNormal" style="line-height:normal;text-indent:-6pt;margin:0in 0in 0pt;background:white;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:blue;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:maroon;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;script&lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:blue;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:red;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;type&lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:blue;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;=&amp;quot;text/javascript&amp;quot; &lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:red;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;src&lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:blue;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;=&amp;quot;/asset.axd?id=mwAAAB-LCAAAAAAABADtvQdgHEmWJSYvbcp7f0r1StfgdKEIgGATJNiQQBDswYjN5pLsHWlHIymrKoHKZVZlXWYWQMztnbz33nvvvffee--997o7nU4n99__P1xmZAFs9s5K2smeIYCqyB8_fnwfPyJ-8UfT9qNHH2WrVVlMs7aolnffbf90dpk107pYtR-NPrqkr_d2dh6O7413d3fujXfos-lHj9p6ndMvs48e3fv0_ugj-vm9X_zRitqeVMs2X7Z3XzOAhlqf83fVR492Rh8tqcVFXa1Xu-Ofbj76JSP-fNf7fI8___4v-f4v-X8AJmOKf5sAAAA%3d&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:maroon;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;script&lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:blue;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="line-height:normal;text-indent:-6pt;margin:0in 0in 0pt;background:white;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&lt;span style="color:#000000;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="line-height:normal;text-indent:-6pt;margin:0in 0in 0pt;background:white;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:blue;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:maroon;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;link&lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:blue;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt; &lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:red;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;type&lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:blue;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;=&amp;quot;text/css&amp;quot; &lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:red;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;href&lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:blue;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;=&amp;quot;/asset.axd?id=kwAAAB-LCAAAAAAABADtvQdgHEmWJSYvbcp7f0r1StfgdKEIgGATJNiQQBDswYjN5pLsHWlHIymrKoHKZVZlXWYWQMztnbz33nvvvffee--997o7nU4n99__P1xmZAFs9s5K2smeIYCqyB8_fnwfPyJ-8UfT9qNHH7X5u_butGk-Gn10SX_u7ew8HN8b7-7u3Bvv0GfTjx619TqnX2YfPbr36f3RR_Tze7_4oxW1PamWbb5s757w2-f8efXRo53RR0v69nXR5mMA_iUj_nhXPm7zMq-Lt-Pq_LyY5tTdA2n0_V_y_V_y_wCso4bJkwAAAA%3d%3d&amp;quot; &lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:red;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;rel&lt;/span&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:blue;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;=&amp;quot;stylesheet&amp;quot;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="line-height:normal;text-indent:-6pt;margin:0in 0in 0pt;background:white;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:blue;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="color:blue;"&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="line-height:normal;text-indent:-6pt;margin:0in 0in 0pt;background:white;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="font-family:&amp;#39;Courier New&amp;#39;;color:blue;font-size:10pt;mso-fareast-font-family:&amp;#39;Times New Roman&amp;#39;;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Courier New&amp;#39;;font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="color:blue;"&gt;&lt;span style="color:#000000;"&gt;The other option for adding scripts is to use the DefaultGroup method, a method that uses the default group to setup scripts for.&amp;nbsp; For instance, we setup a custom group, but if you only need one group, we can use the DefaultGroup method to define all our scripts in.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1738894" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Telerik" scheme="http://msmvps.com/blogs/bmains/archive/tags/Telerik/default.aspx" /><category term="MVC" scheme="http://msmvps.com/blogs/bmains/archive/tags/MVC/default.aspx" /></entry><entry><title>Working with Web Forms and MVC: Bridging the Gap - Context</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/11/07/working-with-web-forms-and-mvc-bridging-the-gap-context.aspx" /><id>/blogs/bmains/archive/2009/11/07/working-with-web-forms-and-mvc-bridging-the-gap-context.aspx</id><published>2009-11-07T17:02:00Z</published><updated>2009-11-07T17:02:00Z</updated><content type="html">&lt;p&gt;I&amp;#39;ve spent some time figuring out how to bridge the gap between web forms and ASP.NET MVC style of development.&amp;nbsp; Just because the UI works differently, doesn&amp;#39;t mean the actual framework works in a different way.&amp;nbsp; If you use .NET 3.5 SP 1 for both your web forms and MVC style development, it is helpful to come up with a helper component to serve up the context.&amp;nbsp; Why would I suggest this?&amp;nbsp; Well, in web forms, you can access the current context information by accessing System.Web.HttpContext.Current, which returns the current HttpContext being executed.&amp;nbsp; The HttpContext object has an array of services (request, response, etc.) that you can make use of.&amp;nbsp; This is available in ASP.NET MVC in the controller too, via the ControllerContext.HttpContext reference.&lt;/p&gt;
&lt;p&gt;The difference between the two is that the former uses an HttpContext object, while MVC uses an object of type&amp;nbsp;HttpContextBase in System.Web.Abstractions.DLL.&amp;nbsp; The context is a reference to HttpContextWrapper, which inherits from HttpContextBase, and provides you with all of the services previously mentioned.&amp;nbsp; So basically, you are working with the same thing, but not the same object.&amp;nbsp; But if you use 3.5 for all of your development, you can use the same object to leverage both, by creating a helper class and always referring to this for your context.&lt;/p&gt;
&lt;p&gt;public static class HttpWebContext&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static HttpContextBase GetContext()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new HttpContextWrapper(HttpContext.Current);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;This works in web forms because this is how it works anyway, while MVC uses this in its underlying architecture (if you use a tool like Reflector you can dig down into the code to find it).&amp;nbsp; And so this common component shares the context across two environments, and its isolated&amp;nbsp; and follows the Singular Repsonsibility Principle [SRP].&amp;nbsp; Now what about testability, because your internal components will be using this, and the http context won&amp;#39;t be available in a testing environment (since it&amp;#39;s web framework specific).&amp;nbsp; For instance, your controller may do something like:&lt;/p&gt;
&lt;p&gt;public ActionResult View()&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var context = HttpWebContext.GetContext();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //use the context in some way&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; return View();&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;So how can that type of method be mocked?&amp;nbsp; If you use TypeMock, this can be done easily:&lt;/p&gt;
&lt;p&gt;var&amp;nbsp;ctx = Isolate.Fake.Instance&amp;lt;HttpContextBase&amp;gt;();&lt;br /&gt;var requestFake = Isolate.Fake.Instance&amp;lt;HttpRequestFake&amp;gt;();&lt;br /&gt;Isolate.WhenCalled(() =&amp;gt; ctx.Request).WillReturn(requestFake);&lt;br /&gt;//Additional faking here&lt;/p&gt;
&lt;p&gt;Isolate.WhenCalled(() =&amp;gt; HttpWebContext.GetContext()).WillReturn(ctx);&lt;/p&gt;
&lt;p&gt;For Moq, this is harder because it doesn&amp;#39;t mock statics; so you could make it an instance-based approach, or you could use a provider approach.&amp;nbsp; For instance, create a provider that has:&lt;/p&gt;
&lt;p&gt;public abstract class ContextProvider&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public HttpContextBase GetContext();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Have two implementations, one for returning the current context like we have above, and have another returning a faked http context that inherits from HttpContextBase, and then store this reference in the configuration&amp;nbsp; file or pass it in as a parameter to a class. You could get kind of crazy with it, but by using the provider approach, it helps you differentiate the web environment and test environment without exceptions occurring.&lt;/p&gt;
&lt;p&gt;Would this approach work in .NET 2.0?&amp;nbsp; Well, the great feature about 3.5 is the System.Web.Abstractions, which contains the HttpContextBase class that handles this for you.&amp;nbsp; So if you can use 3.5, you can leverage this API for your needs.&amp;nbsp; Otherwise, you would have to create your own wrapper, which is possible but tedious (since it&amp;#39;s such a big class).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1738232" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Web" scheme="http://msmvps.com/blogs/bmains/archive/tags/Web/default.aspx" /><category term="MVC" scheme="http://msmvps.com/blogs/bmains/archive/tags/MVC/default.aspx" /></entry><entry><title>IServices service loader approach to loading services</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/11/04/iservices-service-loader-approach-to-loading-services.aspx" /><id>/blogs/bmains/archive/2009/11/04/iservices-service-loader-approach-to-loading-services.aspx</id><published>2009-11-05T02:38:00Z</published><updated>2009-11-05T02:38:00Z</updated><content type="html">&lt;p&gt;This is a continuation of a blog series on creating services.&amp;nbsp; You can find the previous articles here:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a target="_blank" href="http://msmvps.com/blogs/bmains/archive/2009/10/30/accessing-service-oriented-api-s-using-an-iservice-interface.aspx"&gt;Accessing Service Oriented API&amp;#39;s using an IService interface&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So the ApplicationContext object uses a service loader as one way to load the IService objects into it.&amp;nbsp; This class exists solely to load these services into the context.&amp;nbsp; This object is then linked into the Application context through the configuration file.&amp;nbsp; The below example is used for loading MVC services by default (you can inherit, override this method, and add additional ones you use&amp;nbsp;as a way to make it easier for loading the services you need).&amp;nbsp; This object already exists in the Nucleo.Web.Mvc DLL, in the Nucleo.Web.Context namespace.&lt;/p&gt;
&lt;p&gt;public class MvcApplicationContextServiceLoader : IApplicationContextServiceLoader&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;#region &amp;quot; Methods &amp;quot;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;public virtual void LoadServices(IApplicationContextProvider provider)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;provider.RegisterService&amp;lt;IApplicationStateService&amp;gt;(new MvcApplicationStateService());&lt;br /&gt;&amp;nbsp;&amp;nbsp;provider.RegisterService&amp;lt;IBrowserCapabilitiesService&amp;gt;(new WebFormsBrowserCapabilitiesService());&lt;br /&gt;&amp;nbsp;&amp;nbsp;provider.RegisterService&amp;lt;ICookieService&amp;gt;(new MvcCookieService());&lt;br /&gt;&amp;nbsp;&amp;nbsp;provider.RegisterService&amp;lt;INavigationService&amp;gt;(new MvcNavigationService());&lt;br /&gt;&amp;nbsp;&amp;nbsp;provider.RegisterService&amp;lt;IPostDataService&amp;gt;(new MvcPostDataService());&lt;br /&gt;&amp;nbsp;&amp;nbsp;provider.RegisterService&amp;lt;ISessionStateService&amp;gt;(new MvcSessionStateService());&lt;br /&gt;&amp;nbsp;&amp;nbsp;provider.RegisterService&amp;lt;IServerUtilityService&amp;gt;(new MvcServerUtilityService());&lt;br /&gt;&amp;nbsp;&amp;nbsp;provider.RegisterService&amp;lt;IUrlResolutionService&amp;gt;(new MvcUrlResolutionService());&lt;br /&gt;&amp;nbsp;}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;#endregion&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;The LoadServices method is where the action happens.&amp;nbsp; The application context provider is used to receive these services and supply them to the ApplicationContext.&amp;nbsp; You don&amp;#39;t actually have to worry about that; the service provider is used by the context to serve up these services.&amp;nbsp; This class is then linked up in the configuration file.&amp;nbsp; See the following example for the setup:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;lt;configSections&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;nucleo&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;section name=&amp;quot;contextSettings&amp;quot; type=&amp;quot;Nucleo.Context.Configuration.ContextSettingsSection,Nucleo&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;/nucleo&amp;gt;&lt;br /&gt;&amp;lt;/configSections&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&amp;lt;nucleo&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;contextSettings contextLoaderType=&amp;quot;Nucleo.SampleClasses.Context.SampleApplicationLoader,Nucleo.OnlineTests&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/nucleo&amp;gt;&lt;/p&gt;
&lt;p&gt;The context settings section is the configuration object for specifying the loader you would like to use.&amp;nbsp; At runtime, the ApplicationContext object uses this to load the relevant services, so when you do:&lt;/p&gt;
&lt;p&gt;context.GetService&amp;lt;ICookieService&amp;gt;();&lt;/p&gt;
&lt;p&gt;A valid service will be returned to you.&amp;nbsp; We&amp;#39;ll talk more later about the purpose of the context provider later, how that&amp;#39;s configured .&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1737722" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Web" scheme="http://msmvps.com/blogs/bmains/archive/tags/Web/default.aspx" /><category term="Nucleo" scheme="http://msmvps.com/blogs/bmains/archive/tags/Nucleo/default.aspx" /></entry><entry><title>Moq and TypeMock in Comparison</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/11/03/moq-and-typemock-in-comparison.aspx" /><id>/blogs/bmains/archive/2009/11/03/moq-and-typemock-in-comparison.aspx</id><published>2009-11-04T00:31:00Z</published><updated>2009-11-04T00:31:00Z</updated><content type="html">&lt;p&gt;I&amp;#39;ve been working on a new MVC project and man has it been enlightening!&amp;nbsp; It&amp;#39;s my first MVC project, so I get to go through all the things I thought I knew from reading Pro ASP.NET MVC Framework (Apress by Steve Sanderson) to realizing I don&amp;#39;t know squat,and have to really delve into the learning in order to finish the project, a task which I knew I was getting into and greatly accept the challenge.&amp;nbsp; Anyway, as I&amp;#39;ve been developing, I&amp;#39;ve been trying to use Moq to create my unit tests.&amp;nbsp; It&amp;#39;s a free mocking library that enables you to write code that mocks your existing objects.&amp;nbsp; While most libraries heavily use interfaces for writing mocks, Moq can mock classes that have the methods or properties to override marked as virtual (and there are some other conditions as well; you can see an example on &lt;a target="_blank" href="http://stephenwalther.com/blog/archive/2008/06/12/tdd-introduction-to-moq.aspx"&gt;Stephen Walther&amp;#39;s blog&lt;/a&gt;).&amp;nbsp; As you can see, Moq is great and is useful for MVC applications, and can be used in web forms in a more limited fashion.&lt;/p&gt;
&lt;p&gt;TypeMock, however, offers you a few more conveniences over mocking.&amp;nbsp; For instance, Moq doesn&amp;#39;t support mocking static methods, internal methods, and a few other scenarios.&amp;nbsp; In fact, Moq is a good approach if you design software using the DI pattern, as is illustrated below:&lt;/p&gt;
&lt;p&gt;public class TestClass&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public TestClass(IDependency dep) { }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;This is where a dependency is passed in to the constructor (or it can be via a property), which Moq can setup easily as in the following code:&lt;/p&gt;
&lt;p&gt;var depFake = new Mock&amp;lt;IDependency&amp;gt;();&lt;br /&gt;//Setup any mocking here&lt;/p&gt;
&lt;p&gt;var tc = new TestClas(depFake.Object); //fake gets inserted here&lt;br /&gt;// tc.Dep = depFake.Object; &amp;lt;-- this is an alternative approach&lt;/p&gt;
&lt;p&gt;However, TypeMock allows you to use other approaches as well, which fits closer to my development style.&amp;nbsp; For instance, suppose you have this type of class that uses the dependency:&lt;/p&gt;
&lt;p&gt;public class TestClass&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private TestClass() { }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static&amp;nbsp;TestClass Create()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var c = new TestClass();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;c.Dep =&amp;nbsp;DepResolver.Get();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return c;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;With Moq, we have no inherent way to tap into this method.&amp;nbsp; This is where TypeMock comes in.&amp;nbsp; TypeMock allows us to tap into this method a couple of ways.&amp;nbsp; First, we could skip the Create method altoghether using:&lt;/p&gt;
&lt;p&gt;var tc = Isolate.Fake.Instance&amp;lt;TestClass&amp;gt;();&lt;br /&gt;Isolate.WhenCalled(() =&amp;gt; TestClass.Create()).WillReturn(tc);&lt;/p&gt;
&lt;p&gt;The first line creates our fake, similar to Moq&amp;#39;s &amp;quot;new Mock&amp;lt;TestClass&amp;gt;&amp;quot; syntax.&amp;nbsp; Rather than returning a proxy, it returns an actual instance of our mocked class.&amp;nbsp; The second statement provides a way to override the static method and return directly our fake.&amp;nbsp; This may not be as useful, so let&amp;#39;s look at the next way to tap into this method:&lt;/p&gt;
&lt;p&gt;var dep = Isolate.Fake.Instance&amp;lt;IDependency&amp;gt;();&lt;br /&gt;Isolate.WhenCalled(() =&amp;gt; DepResolver.Get()).WillReturn(dep);&lt;/p&gt;
&lt;p&gt;var tc = TestClass.Create();&lt;/p&gt;
&lt;p&gt;When this code runs, the TestClass instance is actually created, and that code works as is.&amp;nbsp; But the code revolving around the IDependency is faked, so that the DepResolver returns our fake and doesn&amp;#39;t actually run.&amp;nbsp; So you can see some of the ways that TypeMock allows developers to tap into their code without forcing a design.&amp;nbsp; We&amp;#39;ll look at other ways this can happen later on.&lt;/p&gt;
&lt;p&gt;Note: This doesn&amp;#39;t mean Moq is bad by any means; designing your software for testability is a good thing, as it&amp;#39;s good to leverage unit tests&amp;nbsp;to ensure accuracy of your code doing what it was supposed to do.&amp;nbsp; It&amp;#39;s just that TypeMock gives you a few other options, and this is one of the additional features that TypeMock provides.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1737493" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Third Party Tools" scheme="http://msmvps.com/blogs/bmains/archive/tags/Third+Party+Tools/default.aspx" /><category term="General Frameworks" scheme="http://msmvps.com/blogs/bmains/archive/tags/General+Frameworks/default.aspx" /><category term="TypeMock" scheme="http://msmvps.com/blogs/bmains/archive/tags/TypeMock/default.aspx" /></entry><entry><title>Nucleo Link Control Overview</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/10/31/nucleo-link-control-overview.aspx" /><id>/blogs/bmains/archive/2009/10/31/nucleo-link-control-overview.aspx</id><published>2009-10-31T18:53:00Z</published><updated>2009-10-31T18:53:00Z</updated><content type="html">&lt;p&gt;My latest release at http://www.codeplex/nucleo also features a new Link control (in the Nucleo.Web.Controls namespace).&amp;nbsp; This control tries to integrate two kinds of links; clickable links which fire an event, and redirection links that navigate to another site.&amp;nbsp; The link control incorporates an enumeration to incorporate this: the ClickAction property of type LinkClickAction.&amp;nbsp; When set to FIreEvent, the client-side clicked event or server-side clicked event (depending on rendering mode set by the RenderMode property) of the control, whereas Redirect fires a Redirecting event.&lt;/p&gt;
&lt;p&gt;The redirecting parameters can be set by establishing the NavigateUrl property.&amp;nbsp; This property specifies the location to redirect to.&amp;nbsp; Another option, Target, specifies whether to use a new window to open the link in, or the same window.&amp;nbsp; The link also specifies a NavigateUrlFormatString that you can use to do something like this:&lt;/p&gt;
&lt;p&gt;&amp;lt;n:Link ... NavigateUrl=&amp;#39;&amp;lt;%# Eval(&amp;quot;Key&amp;quot;) %&amp;gt;&amp;#39; NavigateUrlFormatString=&amp;quot;products.aspx?id={0}&amp;quot; /&amp;gt;&lt;/p&gt;
&lt;p&gt;When a format string is specified, the navigateurl property is injected in the format string, as a convenience option.&amp;nbsp; Only one format placeholder is available.&amp;nbsp; The server component also has helper methods to get the final values for text (which has Text and TextFormat properties), navigate url, and more.&amp;nbsp; The GetText, GetNavigateUrl, and GetTarget methods are convenience methods for extracting this information as the control would need for rendering.&lt;/p&gt;
&lt;p&gt;These options can be changed on the client-side; each of the main properties (navigateUrl, clickAction, target, text, etc.) is available on the client except for the format strings.&amp;nbsp; So you can change the way the link reacts to clicks, change where it navigates to, and more.&lt;/p&gt;
&lt;p&gt;var link = $find(&amp;quot;&amp;lt;%= l1.ClientID %&amp;gt;&amp;quot;);&lt;br /&gt;link.set_text(&amp;quot;New Text&amp;quot;);&lt;br /&gt;link.set_clickAction(Nucleo.Web.Controls.LinkClickAction.Redirect);&lt;br /&gt;link.set_navigateUrl(&amp;quot;http://www.yahoo.com&amp;quot;);&lt;br /&gt;link.refreshUI();&lt;/p&gt;
&lt;p&gt;Note the refreshUI method; this is a method that&amp;#39;s used to perform the actual updates.&amp;nbsp; This is important because the UI changes won&amp;#39;t occur until that method calls.&amp;nbsp; The reason is because I created a batch method to perform these updates for performance reasons (updating on every setter would be cumbersome).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1736637" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Web" scheme="http://msmvps.com/blogs/bmains/archive/tags/Web/default.aspx" /><category term="Nucleo" scheme="http://msmvps.com/blogs/bmains/archive/tags/Nucleo/default.aspx" /></entry><entry><title>Accessing Service Oriented API's using an IService Interface</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/10/30/accessing-service-oriented-api-s-using-an-iservice-interface.aspx" /><id>/blogs/bmains/archive/2009/10/30/accessing-service-oriented-api-s-using-an-iservice-interface.aspx</id><published>2009-10-31T03:09:00Z</published><updated>2009-10-31T03:09:00Z</updated><content type="html">&lt;p&gt;If you&amp;#39;ve used MVC, you know the System.Web.Abstractions API offers you a lot of capabilities to make it easy to write unit tests in your MVC controllers.&amp;nbsp; It&amp;#39;s really easy to setup a Moq or TypeMock unit test to create a fake implementation of objects like HttpContextBase.&amp;nbsp; Some objects are not as testable.&amp;nbsp; For instance, UrlHelper may not be as easy to implement testing with (although TypeMock can test pretty much any object very easily since it doesn&amp;#39;t require a DI setup or interfaces).&amp;nbsp; Rather than leverage this approach, I chose an approach not just limited to web forms, and something that may be available in a windows, silverlight, or WPF environment as well.&amp;nbsp; Welcome the ApplicationContext object and the IService interface.&lt;/p&gt;
&lt;p&gt;ApplicationContext is a central object that is used to make services available to those who need it.&amp;nbsp; You have to go through a process of loading these services; however, this process isn&amp;#39;t that hard (will cover in another blog post).&amp;nbsp; To use the application context looks something like:&lt;/p&gt;
&lt;p&gt;ApplicationContext context = ApplicationContext.GetCurrent();&lt;br /&gt;ILoggerService service = context.GetService&amp;lt;ILoggerService&amp;gt;();&lt;/p&gt;
&lt;p&gt;Every service that the application context uses implements IService (this interface doesn&amp;#39;t really do anything, but simply is used as a marker).&amp;nbsp; ILoggerService happens to be one of the services available (ILoggerService implements IService) and so it&amp;#39;s retrievable vai the ApplicationContext object.&amp;nbsp; Built into the framework is the NucleoContext namespace (which contains environment-agnostic services) and Nucleo.Web.Context (web/MVC specific services) that you can use the ApplicationContext object to retrieve.&lt;/p&gt;
&lt;p&gt;The idea of this object is to make available core services.&amp;nbsp; For instance, in MVC, you can instantiate the service you need (HttpContextWrapper, HttpRequestWrapper, etc.).&amp;nbsp; Instead of using this, you can use the application context to request these services instead.&amp;nbsp; I don&amp;#39;t have all of the existing web services created; however, I do have services available for cookies, querystring, forms, and more.&amp;nbsp; Rather than create one big request object, I instead break up each of these into smaller services by function.&lt;/p&gt;
&lt;p&gt;How do you retrieve?&amp;nbsp; That&amp;#39;s the purpose of the service loader, a subject we&amp;#39;ll discuss next.&amp;nbsp; You can get the latest code base for this example from: &lt;a target="_blank" title="Nucleo Framework on CodePlex" href="http://www.codeplex.com/nucleo"&gt;http://www.codeplex.com/nucleo&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1736475" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Web" scheme="http://msmvps.com/blogs/bmains/archive/tags/Web/default.aspx" /><category term="Nucleo" scheme="http://msmvps.com/blogs/bmains/archive/tags/Nucleo/default.aspx" /></entry><entry><title>Using the Nucleo Button</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/10/27/using-the-nucleo-button.aspx" /><id>/blogs/bmains/archive/2009/10/27/using-the-nucleo-button.aspx</id><published>2009-10-28T02:26:00Z</published><updated>2009-10-28T02:26:00Z</updated><content type="html">&lt;p&gt;I&amp;#39;ve been working on a project available at for &lt;a href="http://www.codeplex.com/nucleo"&gt;http://www.codeplex.com/nucleo&lt;/a&gt;.&amp;nbsp; It&amp;#39;s a project I&amp;#39;ve had in the works for a while, and it&amp;#39;s finally coming to fruition.&amp;nbsp; So I am starting to create blog posts explaining features about these controls.&amp;nbsp; I am really excited about this button because I think it offers you more than what other control vendors offer you (at least the ones I seen, because I don&amp;#39;t know every control suite out there).&amp;nbsp; Anyway, my button comes with some nice features.&lt;/p&gt;
&lt;p&gt;First, it has a DisableUntilPageLoad property that will disable the button until page load scripts have run.&amp;nbsp; This is a useful feature I found in Professional ASP.NET AJAX from Wrox that really does make sense.&amp;nbsp; So I added it into my button control, which simply can be enabled via:&lt;/p&gt;
&lt;p&gt;&amp;lt;n:Button ... DisableUntilPageLoad=&amp;quot;True&amp;quot; /&amp;gt;&lt;/p&gt;
&lt;p&gt;And now the button doesn&amp;#39;t enable until page loads on the client.&amp;nbsp; Note: It&amp;#39;s up to you to ensure JavaScript works :-;&amp;nbsp; Next, we have the ability to disable the button when it clicks by setting the DisableOnFirstClick property to true.&amp;nbsp; This disables the button permanently, but can be re-enabled using the enabled client-side property.&amp;nbsp; The DisableOnFirstClickTimeout specifies a timeout in seconds, which will be used to re-enable a button.&amp;nbsp; This is a nice feature because often developers want to prevent double-clicks from happening, yet still ensure that they can click the button.&amp;nbsp;&amp;nbsp;Using these&amp;nbsp;setting:&lt;/p&gt;
&lt;p&gt;&amp;lt;n:Button DisableOnFirstClick=&amp;quot;True&amp;quot; DisableOnFirstClickTimeout=&amp;quot;300&amp;quot; /&amp;gt;&lt;/p&gt;
&lt;p&gt;This disables the button on click, then re-enables it at 300 milliseconds.&amp;nbsp; The button does support all the traditional IButtonControl implementations, but doesn&amp;#39;t use the ASP.NET implementation; rather, I use a cleaner approach that can be used on both the server and the client.&lt;/p&gt;
&lt;p&gt;The button also specifies a mode to render in, whether link button, push button, or image button.&amp;nbsp; This mode is then rendered appropriately.&amp;nbsp; This then requires only one button instance, and can be changed on the server.&amp;nbsp; It currently cannot be changed on the client, but should be something I implement in the future.&lt;/p&gt;
&lt;p&gt;This are some of the Button control&amp;#39;s available offerings.&amp;nbsp; More to come soon on some of the other controls.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1735751" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Web" scheme="http://msmvps.com/blogs/bmains/archive/tags/Web/default.aspx" /><category term="Nucleo" scheme="http://msmvps.com/blogs/bmains/archive/tags/Nucleo/default.aspx" /></entry><entry><title>Pro Asp.NET MVC Framework (Apress) by Steve Sanderson</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/10/19/pro-asp-net-mvc-framework-apress-by-steve-sanderson.aspx" /><id>/blogs/bmains/archive/2009/10/19/pro-asp-net-mvc-framework-apress-by-steve-sanderson.aspx</id><published>2009-10-20T02:08:00Z</published><updated>2009-10-20T02:08:00Z</updated><content type="html">&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Tahoma&amp;#39;,&amp;#39;sans-serif&amp;#39;;color:#444444;font-size:10pt;"&gt;Rating: 5 out of 5&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Tahoma&amp;#39;,&amp;#39;sans-serif&amp;#39;;color:#444444;font-size:10pt;"&gt;I believe Pro ASP.NET MVC Framework is one of the best books on the market about MVC.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;This book is crammed with a lot of information that you need to know as a developer.&amp;nbsp; While he doesn&amp;#39;t cover each subject fully (no book really does that), he does cover the major topic points related to MVC in-depth, and touches upon the other concerts that you need to be aware of to implement or customize MVC for your own purposes.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;I&amp;rsquo;ve broken up my review into several major subsections related to the book and analyze each one individually.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;From an overall level, I think the book really did well in its explanation and examples of MVC.&lt;br /&gt;&lt;br /&gt;Book&amp;#39;s Knowledge&lt;br /&gt;&lt;br /&gt;This book is really crammed with lots of valuable information.&amp;nbsp; I find myself referring back to the book when working with MVC, because it has a lot of various important sections about how to use JQuery to dynamically change MVC partial views within a view, how to customize the creation of a controller, and other important facts.&amp;nbsp; There is so many small or medium details regarding the MVC framework that is important to know about covered in this book, that it does really make it a very beneficial book.&lt;br /&gt;&lt;br /&gt;The chapters on each major feature (views, routing, controllers, etc.) are very long, which is great because they contain so much information about each of the subjects.&amp;nbsp; I was really impressed with the information packed into each of these chapters.&amp;nbsp; After reading the book, I felt comfortable enough to work on MVC and understand some of the concerns when implementing MVC for my own applications.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;I felt there was minimal downtime trying to play with MVC to understand its inner-workings; I really felt confortable jumping in.&lt;br /&gt;&lt;br /&gt;Writing Style&lt;br /&gt;&lt;br /&gt;I really like Steven&amp;#39;s ability to clearly articulate points about MVC.&amp;nbsp; If the writer is not fluent, I tend to lose interest, but I didn&amp;#39;t lose interest at all in this book.&amp;nbsp; This book doesn&amp;#39;t just talk about the functionality, but actually illustrates its use through examples and theory, which is important for such a big subject.&amp;nbsp; That&amp;#39;s not to say he doesn&amp;#39;t explain his code, which he does in the right amount of detail.&lt;br /&gt;&lt;br /&gt;Content Structure&lt;br /&gt;&lt;br /&gt;Though a pro book, the author ensures that he covers the basic prerequisites for the book, to fill in the user how MVC works.&amp;nbsp; The book continues on with three chapters of a sample MVC application, explaining it some as he goes, following up with most of the book detailing each features.&amp;nbsp; &lt;br /&gt;&lt;br /&gt;The main complaint of the book that I have is that Chapters 4, 5, and 6 cover the basics of creating an MVC sports store application and tries to get you familiar with MVC by jumping right in without a lot of preliminary discussion.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;While he does discuss what he&amp;rsquo;s illustrating, I feel it would have been helpful to cover the documentation of the features first, and then rolled through the example last, with a bigger/more complex example.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Tahoma&amp;#39;,&amp;#39;sans-serif&amp;#39;;color:#444444;font-size:10pt;"&gt;The plus to this design is that the sample walks you through the basics, and the subsequent materials enhance your understanding of routing, views, controllers and actions, data entry and model binding, AJAX and client-scripting, and security.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Tahoma&amp;#39;,&amp;#39;sans-serif&amp;#39;;color:#444444;font-size:10pt;"&gt;I found much use alone out of the chapters on using AJAX to use an unobtrusive JavaScript approach and the concerns to have with implementing security (since ASP.NET web forms handled certain security features for you automatically and MVC does not).&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Tahoma&amp;#39;,&amp;#39;sans-serif&amp;#39;;color:#444444;font-size:10pt;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;Implementation&lt;br /&gt;&amp;nbsp;&lt;br /&gt;While I do have a deep technical background, the concept of MVC is somewhat foreign to me; I had a familiarity to the pattern, but didn&amp;#39;t know anything about the product.&amp;nbsp; After reading this book, I felt very confident about my ability to create an MVC site.&amp;nbsp; There were some curveballs and I had to reference the book again and again, but I felt overall that this book was a fantastic resource to get me going.&amp;nbsp; It&amp;#39;s the only book I read on the subject (outside of the NerdDinner resource provided by Scott Guthrie).&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Tahoma&amp;#39;,&amp;#39;sans-serif&amp;#39;;color:#444444;font-size:10pt;"&gt;Conclusion&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="line-height:115%;font-family:&amp;#39;Tahoma&amp;#39;,&amp;#39;sans-serif&amp;#39;;color:#444444;font-size:10pt;"&gt;MVC is a great product.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;While in its infancy (2.0 has some great features coming), MVC gives you control over the UI that web forms took away.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;MVC is a big undertaking and does require some knowledge about how it works.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;I believe this book is a great way to take a big chunk out of the mystery of MVC, especially for those coming from a web forms world.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1733561" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Book Reviews" scheme="http://msmvps.com/blogs/bmains/archive/tags/Book+Reviews/default.aspx" /></entry><entry><title>ADO.NET Entity Model Helpers</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/10/01/ado-net-entity-model-helpers.aspx" /><id>/blogs/bmains/archive/2009/10/01/ado-net-entity-model-helpers.aspx</id><published>2009-10-02T01:17:00Z</published><updated>2009-10-02T01:17:00Z</updated><content type="html">&lt;p&gt;I&amp;#39;m starting to get into a project using ADO.NET entity model.&amp;nbsp; This is a pretty cool technology, and I like a lot of the features (especially the logical model approach).&amp;nbsp; There are some things I really dislike about Phase 1, like having to delete the entire model or edit SSDL manually (or with XML tool) - anybody know of some free tools available for this?&amp;nbsp; But overall, I like the approach, and the concept, so I look forward to adding features.&lt;/p&gt;
&lt;p&gt;Some features I want to add is automatic logging.&amp;nbsp; Sometimes, you just need to know what&amp;#39;s going on with your application to see if the logic is working correctly.&amp;nbsp; I often create a logger class, create an ILogger interface with a LogError and LogMessage methods, and create derived classes to log to event log, console, health monitoring, etc.&amp;nbsp; That is out of scope for this article, but I want to focus on the idea of extensibility.&amp;nbsp; I&amp;#39;ve been reading articles about how to plugin to the provider architecture and other approaches, but I don&amp;#39;t personally want to affect the architecture.&amp;nbsp; Rather, I&amp;#39;d rather take the wrapping approach.&amp;nbsp; This is separated and isolated from any provider architecture changes over the years.&amp;nbsp; While that&amp;#39;s not a major concern anyway (at least for me), a separate class seems like a good approach.&lt;/p&gt;
&lt;p&gt;So I use a class that does something like this:&lt;/p&gt;
&lt;p&gt;public class ObjectContextHelpers&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static&amp;nbsp;void&amp;nbsp;SaveNewObject(CustomObjectContext context, string entitySetName, object entity)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //get a reference to the logger - pass in as ref or via singleton, or some other approach&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;logger.LogMessage(&amp;quot;Attempting to save object for entity set &amp;quot; + entitySetName);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Can log other details, number of objects commiting,&amp;nbsp;details about object state entries,&amp;nbsp;and other information&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;context.AddObject(entitySetName,&amp;nbsp;entity);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch(Exception ex) { logger.LogMessage(&amp;quot;Saving object failed: &amp;quot; + ex.ToString());&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;logger.LogMessage(&amp;quot;Saved object for entity set &amp;quot; + entitySetName);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static CustomObjectContext Create()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new&amp;nbsp;CustomObjectContext(ConfigurationManager.ConnectionStrings[&amp;quot;ConnString&amp;quot;].ConnectionString);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;Here we have a Create method that uses one common connection string, which is a connection string pre-configured (assuming that you aren&amp;#39;t building a custom library that may require configurability).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1728864" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Entity Framework" scheme="http://msmvps.com/blogs/bmains/archive/tags/Entity+Framework/default.aspx" /></entry><entry><title>Facebook Connect and Localhost</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/09/23/facebook-connect-and-localhost.aspx" /><id>/blogs/bmains/archive/2009/09/23/facebook-connect-and-localhost.aspx</id><published>2009-09-24T02:36:00Z</published><updated>2009-09-24T02:36:00Z</updated><content type="html">&lt;p&gt;Most people may not realize, but you can use Facebook Connect with your http://localhost server.&amp;nbsp; This works great for ASP.NET and MVC (and other environments too, but I&amp;#39;m primarily a .NET guy so please pardon my favoritism).&amp;nbsp; You setup the localhost environment as the Facebook connect URL, as in http://localhost/&amp;lt;Virtual&amp;gt;.&amp;nbsp; I would recommend using a virtual directory, and not using the Cassini web server (the local web server which may reassing port addresses on you).&lt;/p&gt;
&lt;p&gt;You do have to be connected to the internet for this to work, as an FYI.&amp;nbsp; Not usually a problem, but just something to know about.&amp;nbsp; THis is because Facebook is making requests to its server, and there isn&amp;#39;t anything setup to use a local credentials store for development only.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1726112" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Web" scheme="http://msmvps.com/blogs/bmains/archive/tags/Web/default.aspx" /><category term="Facebook" scheme="http://msmvps.com/blogs/bmains/archive/tags/Facebook/default.aspx" /></entry><entry><title>Using FQL in SQL Server Over REST</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/09/23/using-fql-in-sql-server-over-rest.aspx" /><id>/blogs/bmains/archive/2009/09/23/using-fql-in-sql-server-over-rest.aspx</id><published>2009-09-24T02:29:00Z</published><updated>2009-09-24T02:29:00Z</updated><content type="html">&lt;p&gt;If you haven&amp;#39;t heard from my blog or Facebook WIKI&amp;#39;s before, there are two ways to query data from Facebook, using the ApiClient object to query the data from the Facebook server, or by using FQL to query against their propietary database directly.&amp;nbsp; In a recent app, I found that using FQL cut in half the number of calls to the server than what I would have had to made using the REST api.&amp;nbsp; So using FQL can be a great benefit.&amp;nbsp; Picture this query:&lt;/p&gt;
&lt;p&gt;select page_id, name, page_url, pic_small, website, location, bio, founded from page where page_id in (select page_id from page_fan where uid = &amp;#39;{0}&amp;#39;)&lt;/p&gt;
&lt;p&gt;This queries the database server looking for pages that you became a fan of, where you are a fan of that page.&amp;nbsp; There are two primary tables: page and page_fan, where page contains the page data, and the page_fan table links your user ID to the page that you are a fan of.&amp;nbsp; To do this via rest required two calls to the server, one to get the pages you are a fan of, while the other to get the details of the page.&amp;nbsp; This means you have to use callbacks within callbacks, and really creates a nested hierarchy.&amp;nbsp; This way, FQL cuts off that work.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve had other scenario&amp;#39;s where it was going to take many calls to have the same effect as one FQL query, where you end up making a rest call just to get the ID&amp;#39;s of your friends, then making a call to load your friend&amp;#39;s data, and then loading other data related to your friends.&amp;nbsp; You can see how that can be cumbersome without FQL.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1726109" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Web" scheme="http://msmvps.com/blogs/bmains/archive/tags/Web/default.aspx" /><category term="Facebook" scheme="http://msmvps.com/blogs/bmains/archive/tags/Facebook/default.aspx" /></entry><entry><title>Adding an Effective/End Date CodeSmith Template</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/09/14/adding-an-effective-end-date-codesmith-template.aspx" /><id>/blogs/bmains/archive/2009/09/14/adding-an-effective-end-date-codesmith-template.aspx</id><published>2009-09-15T00:55:00Z</published><updated>2009-09-15T00:55:00Z</updated><content type="html">&lt;p&gt;I really like CodeSmith, a great tool for generating templates.&amp;nbsp; It comes with a variety of default templates, all managed in a Visual Studio-like environments, complete with intellisense that&amp;#39;s good, but not quite as powerful as Visual Studio.&amp;nbsp; I do a lot of scripting, so I wanted to make stored procedure generation easier.&amp;nbsp; One scenario not covered is reference tables, where the reference tables happen to have two specific columns all the time:&lt;/p&gt;
&lt;p&gt;EffectiveDate&amp;nbsp; datetime not null,&lt;br /&gt;EndDate datetime null&lt;/p&gt;
&lt;p&gt;The effective and end dates determine which entries are in process at the given time.&amp;nbsp; I don&amp;#39;t want to be having to write this code all the time.&amp;nbsp; Instead, I added this to the default template (StoredProcedures.cst) that comes with CodeSmith.&amp;nbsp; These are the modifications I made.&amp;nbsp; First, I need to be able to use the IEnumerable&amp;lt;T&amp;gt; interface, and thus we need the mscorlib assembly.&amp;nbsp; So I added these two declarations at the top.&amp;nbsp; More on why in a little bit.&lt;/p&gt;
&lt;p&gt;&amp;lt;%@ Assembly Name=&amp;quot;mscorlib&amp;quot; %&amp;gt;&lt;br /&gt;&amp;lt;%@ Import Namespace=&amp;quot;System.Collections.Generic&amp;quot; %&amp;gt;&lt;/p&gt;
&lt;p&gt;I added a new property for this method that can be used to turn it off or on.&amp;nbsp; This is a boolean, with a default to true:&lt;/p&gt;
&lt;p&gt;&amp;lt;%@ Property Name=&amp;quot;IncludeSelectByEffectiveEndDate&amp;quot; Type=&amp;quot;System.Boolean&amp;quot; Default=&amp;quot;True&amp;quot; Category=&amp;quot;3. Procedure Types&amp;quot;&lt;br /&gt;&amp;nbsp;Description=&amp;quot;If true a SELECT procedure will be generated to select by effective/end dates, if the table has these fields.&amp;quot; %&amp;gt;&lt;/p&gt;
&lt;p&gt;If you are unfamiliar with this, CodeSmith uses the @Property attribute to allow a configurable setting that can be changed in the property window (shown below).&amp;nbsp; This property window makes it easy to add all sorts of configuration capabilities to your scripts.&amp;nbsp; Note the description appears within the description window.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/bmains/5873.codesmithaddon.jpg"&gt;&lt;img src="http://msmvps.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/bmains/5873.codesmithaddon.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;So now we have a property&amp;nbsp;to turn our feature on and off, we need some supporting methods, such as a method to generate the proc name.&amp;nbsp; The existing template has a variety of method that do this, and working in straight copy-and-adapt mode, I added a method that follows suit as shown below.&amp;nbsp; Note: if you aren&amp;#39;t aware, CodeSmith allows code segments within its &amp;lt;script runat=&amp;#39;server&amp;quot;&amp;gt; tags, following an inline code approach that ASP.NET uses.&amp;nbsp; This makes for a great place to stick in helper methods that return text, or write a response directly to the output.&lt;/p&gt;
&lt;p&gt;public string GetSelectByEffectiveEndDateProcedureName()&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;return String.Format(&amp;quot;{0}[{1}{2}ReadByEffectiveEndDate]&amp;quot;, GetTableOwner(), ProcedurePrefix, GetEntityName(true));&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;Our first task in using this is to drop the proc, if it exists, via the GenerateDropStatement method.&amp;nbsp; This work&amp;nbsp;is already done, and needs a simple call to first check if the conditions are met (the flag is set to true and we indeed have an EffectiveDate/EndDate fields because not all tables will).&amp;nbsp; Note that SourceTable is a TableSchema object that represents that individual table.&lt;/p&gt;
&lt;p&gt;if (IncludeSelectByEffectiveEndDate &amp;amp;&amp;amp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;this.SourceTable.Columns.Contains(&amp;quot;EffectiveDate&amp;quot;) &amp;amp;&amp;amp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;this.SourceTable.Columns.Contains(&amp;quot;EndDate&amp;quot;))&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;GenerateDropStatement(GetSelectByEffectiveEndDateProcedureName());&lt;br /&gt;&amp;nbsp;}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Next, the process for creating the proc is pretty simple too.&amp;nbsp; It starts off with a generic comment and header (as repeated from other examples.&amp;nbsp; I must do the same flag/effective/end date check, and if all is well, then we can begin by generating the header (already done via GenerateProcedureHeader).&amp;nbsp; Take a look at the body below.&lt;/p&gt;
&lt;p&gt;&amp;lt;%------------------------------------------------------------------------------------------&lt;br /&gt;*&lt;br /&gt;* SelectByEffectiveEndDate Procedure&lt;br /&gt;*&lt;br /&gt;------------------------------------------------------------------------------------------%&amp;gt;&lt;br /&gt;&amp;lt;%&lt;br /&gt;if (IncludeSelectByEffectiveEndDate &amp;amp;&amp;amp; &lt;br /&gt;&amp;nbsp;this.SourceTable.Columns.Contains(&amp;quot;EffectiveDate&amp;quot;) &amp;amp;&amp;amp;&lt;br /&gt;&amp;nbsp;this.SourceTable.Columns.Contains(&amp;quot;EndDate&amp;quot;))&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;GenerateProcedureHeader(GetSelectByEffectiveEndDateProcedureName());&lt;br /&gt;%&amp;gt;&lt;/p&gt;
&lt;p&gt;CREATE PROCEDURE &amp;lt;%= GetSelectByEffectiveEndDateProcedureName() %&amp;gt;&lt;br /&gt;(&lt;br /&gt;&amp;nbsp;@EffectiveDate&amp;nbsp;&amp;nbsp;datetime,&lt;br /&gt;&amp;nbsp;@EndDate&amp;nbsp;&amp;nbsp;&amp;nbsp;datetime&lt;br /&gt;)&lt;br /&gt;AS&lt;/p&gt;
&lt;p&gt;SET NOCOUNT ON&lt;br /&gt;&amp;lt;% GenerateSetTransactionIsolationLevelStatement(IsolationLevel); %&amp;gt;&lt;/p&gt;
&lt;p&gt;SELECT&lt;br /&gt;&amp;nbsp;&amp;lt;% GenerateColumns(SourceTable.Columns, 1); %&amp;gt;&lt;br /&gt;FROM&lt;br /&gt;&amp;nbsp;&amp;lt;%= GetTableOwner() %&amp;gt;[&amp;lt;%= SourceTable.Name %&amp;gt;]&lt;br /&gt;WHERE&lt;br /&gt;&amp;nbsp;ISNULL(EffectiveDate, &amp;#39;1/1/1900&amp;#39;) &amp;lt;= @EffectiveDate AND&lt;br /&gt;&amp;nbsp;ISNULL(EndDate, &amp;#39;12/31/9999&amp;#39;) &amp;gt;= @EndDate&lt;/p&gt;
&lt;p&gt;&amp;lt;%&lt;br /&gt;&amp;nbsp;GenerateProcedureFooter(GetSelectProcedureName());&lt;br /&gt;&amp;nbsp;this.Progress.PerformStep();&lt;br /&gt;}&lt;br /&gt;%&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;In this case, I know the fields already, so I don&amp;#39;t need to generate them dynamically since I&amp;#39;m assuming they exist.&amp;nbsp; The GenerateColumns methods generates all columns for select, GetTableOwner returns dbo or the schema name for whatever the case may be, and the table name is accessible via SourceTable.Name property (SourceTable, as I said before is a TableSchema object).&lt;/p&gt;
&lt;p&gt;For more information about using CodePlex and the database schema objects, check out this article: &lt;a href="http://aspalliance.com/1580_Creating_Code_Smith_Templates.all"&gt;http://aspalliance.com/1580_Creating_Code_Smith_Templates.all&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1723358" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Third Party Tools" scheme="http://msmvps.com/blogs/bmains/archive/tags/Third+Party+Tools/default.aspx" /></entry><entry><title>MVC Controller Context - Where does it come from?</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/09/12/mvc-controller-context-where-does-it-come-from.aspx" /><id>/blogs/bmains/archive/2009/09/12/mvc-controller-context-where-does-it-come-from.aspx</id><published>2009-09-13T04:03:00Z</published><updated>2009-09-13T04:03:00Z</updated><content type="html">&lt;p&gt;The Controller class maintains a reference to the HttpContext property, and object of HttpContextBase.&amp;nbsp; HttpContextBase is a great class because now we have an abstract way to replace default logic if needed (but generally that wouldn&amp;#39;t be recommended).&amp;nbsp; Ideally, it&amp;#39;s great for fake environments.&amp;nbsp; But I digress, HttpContextBase is the main object for accessing context-specific information.&amp;nbsp; But where does this actually get created?&amp;nbsp; I went digging around the API in Reflector, and found where the MVC handlers that create the request.&amp;nbsp; The MVCHttpHandler uses theMvcHandler object, along with the HttpContext.Current reference as a way to instantiate the context.&amp;nbsp; So while in ASP.NET you would directly reference HttpContext.Current to access the context, here in MVC references to HttpContextBase comes from HttpContext.Current.&lt;/p&gt;
&lt;p&gt;If , for whatever reason, you wanted to instantiate the HttpContext object directly, you would do this via: new HttpContextWrapper(HttpContext.Current).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1722929" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Web" scheme="http://msmvps.com/blogs/bmains/archive/tags/Web/default.aspx" /><category term="MVC" scheme="http://msmvps.com/blogs/bmains/archive/tags/MVC/default.aspx" /></entry><entry><title>Facebook Location Object</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/09/12/facebook-location-object.aspx" /><id>/blogs/bmains/archive/2009/09/12/facebook-location-object.aspx</id><published>2009-09-12T05:04:00Z</published><updated>2009-09-12T05:04:00Z</updated><content type="html">&lt;p&gt;If you have used the Facebook FQL syntax to query the location column of a table, or have requested the location parameter from the friends_get or other API methods, what you need to know is location is a complex object consisting of the following properties:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;city&lt;/li&gt;
&lt;li&gt;country&lt;/li&gt;
&lt;li&gt;state&lt;/li&gt;
&lt;li&gt;street&lt;/li&gt;
&lt;li&gt;zip&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These properties can be directly accessed via location.zip, location.city, etc.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1722715" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Third Party Tools" scheme="http://msmvps.com/blogs/bmains/archive/tags/Third+Party+Tools/default.aspx" /><category term="Web" scheme="http://msmvps.com/blogs/bmains/archive/tags/Web/default.aspx" /><category term="Facebook" scheme="http://msmvps.com/blogs/bmains/archive/tags/Facebook/default.aspx" /></entry><entry><title>Facebook FQL</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/09/11/facebook-fql.aspx" /><id>/blogs/bmains/archive/2009/09/11/facebook-fql.aspx</id><published>2009-09-12T04:49:00Z</published><updated>2009-09-12T04:49:00Z</updated><content type="html">&lt;p&gt;Facebook supports a variant of SQL called FQL, or Facebook Query Language.&amp;nbsp; If you know anything about Facebook&amp;#39;s data storage center, Facebook has moved away from the traditional relational database and created their own custom application for storing data, which has the ability to query petaflops worth of data in seconds.&amp;nbsp; So what is FQL?&amp;nbsp; FQL looks very like SQL.&amp;nbsp; It has a select and select list, a from, a where clause, which makes it seem like its ordinary SQL.&amp;nbsp; However, it cannot use inner joins or outer joins, and its limited on the number of fields that it can query.&amp;nbsp; For more information on the language itself, please consult this: &lt;a href="http://wiki.developers.facebook.com/index.php/FQL"&gt;http://wiki.developers.facebook.com/index.php/FQL&lt;/a&gt;.&amp;nbsp; For a list of tables, see this. &lt;a href="http://wiki.developers.facebook.com/index.php/FQL_Tables"&gt;http://wiki.developers.facebook.com/index.php/FQL_Tables&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;One way FQL can be executed is in JavaScript, through the fql_query method.&amp;nbsp;&amp;nbsp;Below is a sample query where pages are queried for its page id, name, small picture, location, and website.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-size:small;"&gt;var api = FB.Facebook.apiClient; &lt;br /&gt;api.fql_query(&amp;#39;SELECT page_id, name, pic_small, location, website FROM page WHERE name in \&amp;quot;&amp;#39; + name + &amp;#39;\&amp;quot;&amp;#39;, &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-size:small;"&gt;function (results, ex) { .. }); &lt;span style="font-size:small;"&gt;&lt;span style="font-size:small;"&gt;
&lt;p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;This is one way to query the Facebook database for a list of pages.&amp;nbsp; The name field is queryable using in, or could also be used with an equal sign, as you see in SQL.&amp;nbsp; However, there aren&amp;#39;t very many other constructs supported (if any than = and in).&amp;nbsp; The results returned are in the form of JSON, and can be processed like any other JavaScript would process the code.&amp;nbsp; This brings quite a number of possible options for using queries in your data.&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/p&gt;
&lt;p&gt;Note that FQL may not allow you to restrict input to the exact results you want due to limitations in FQL.&amp;nbsp; This has been posted around the internet, about having to bring back more results from the database, and limiting the results in your code.&amp;nbsp; To test out the query that you may want to setup, try it out in the Facebook Tools section.&amp;nbsp; Selecting the method to execute as fql_query allows you to test database queries against the backend to see what is allowed and what is not.&lt;/p&gt;
&lt;p&gt;For some sample queries, check out this page: &lt;a href="http://wiki.developers.facebook.com/index.php/Sample_FQL_Queries"&gt;http://wiki.developers.facebook.com/index.php/Sample_FQL_Queries&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1722714" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Third Party Tools" scheme="http://msmvps.com/blogs/bmains/archive/tags/Third+Party+Tools/default.aspx" /><category term="Web" scheme="http://msmvps.com/blogs/bmains/archive/tags/Web/default.aspx" /><category term="Facebook" scheme="http://msmvps.com/blogs/bmains/archive/tags/Facebook/default.aspx" /></entry><entry><title>Facebook Connect JavaScript API</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/08/28/facebook-javascript-api.aspx" /><id>/blogs/bmains/archive/2009/08/28/facebook-javascript-api.aspx</id><published>2009-08-29T02:36:00Z</published><updated>2009-08-29T02:36:00Z</updated><content type="html">&lt;p&gt;I recently submitted a Facebook development article to ASP.NET Pro magazine.&amp;nbsp; It was quite the challenge initially to get it started.&amp;nbsp; But once I got going (I think I&amp;#39;ll blog on this later), I was off and running but there aren&amp;#39;t a lot of examples on the WIKI.&amp;nbsp; I put a combination of items together in order to figure it all out.&lt;/p&gt;
&lt;p&gt;First, the core content I used to extract user&amp;#39;s information was the Facebook JavaScript API, available here: &lt;a href="http://wiki.developers.facebook.com/index.php/JS_API_Index"&gt;http://wiki.developers.facebook.com/index.php/JS_API_Index&lt;/a&gt;.&amp;nbsp; The core object in Facebook to extract data from its servers is the ApiClient object (&lt;a href="http://wiki.developers.facebook.com/index.php/JS_API_T_FB.ApiClient"&gt;http://wiki.developers.facebook.com/index.php/JS_API_T_FB.ApiClient&lt;/a&gt;).&amp;nbsp; Unfortunately, for most method calls, there isn&amp;#39;t any documentation.&amp;nbsp; A few things to note:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you google on these methods (like groups_get, friends_get, or photos_getAlbums), you&amp;#39;re likely to come up with something.&amp;nbsp; Usually, it&amp;#39;s PHP examples, but it&amp;#39;s something you can go off of.&lt;/li&gt;
&lt;li&gt;You can post in the forums, but in the questions I had, there really wasn&amp;#39;t any movement.&lt;/li&gt;
&lt;li&gt;If you see the method return FB.PendingResult, this is because it returns data asynch from the server.&amp;nbsp; In most cases that I saw, it fires a callback with the signature function(results, ex) { }.&amp;nbsp; This callback can be specified in the parameter list where the SequencerBase parameter is defined.&lt;/li&gt;
&lt;li&gt;Speaking of SequencerBase, the WIKI has an example of how you can use a SequencerBase class&amp;nbsp;to download all of the user data on one shot simultaneously.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Some other notes/general issues I found are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The user ID of the user is a long that represents them.&amp;nbsp; When logged in, you can get this via the ApiClient.&amp;nbsp; Assuming the ApiClient object is stored in the api variable, the code to get the user&amp;#39;s ID would be: api.get_session().uid.&lt;/li&gt;
&lt;li&gt;However, a lot of the rest API&amp;#39;s use a string for the user, so you need to ensure it&amp;#39;s a string.&amp;nbsp; Don&amp;#39;t know why.&lt;/li&gt;
&lt;li&gt;The ApiClient.users_getInfo method takes a concatenated list of strings of fields to download for the user.&amp;nbsp; There is a long list of information that can be retrieved can be found here: &lt;a href="http://wiki.developers.facebook.com/index.php/Users.getInfo"&gt;http://wiki.developers.facebook.com/index.php/Users.getInfo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;The groups_get method returns a collection of groups, each group with a specific API: &lt;a href="http://www.app-developers.com/index.php?topic=11.0"&gt;http://www.app-developers.com/index.php?topic=11.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;The photos_getAlbums objects also has a specific API: &lt;a href="http://www.app-developers.com/index.php?topic=13.0"&gt;http://www.app-developers.com/index.php?topic=13.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Certain features require permissions, which means a call to FB.Connect.showPermissionDialog: &lt;a href="http://wiki.developers.facebook.com/index.php/JS_API_M_FB.Connect.ShowPermissionDialog"&gt;http://wiki.developers.facebook.com/index.php/JS_API_M_FB.Connect.ShowPermissionDialog&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I hope this helps, and more content will be coming.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1719029" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Third Party Tools" scheme="http://msmvps.com/blogs/bmains/archive/tags/Third+Party+Tools/default.aspx" /><category term="JavaScript" scheme="http://msmvps.com/blogs/bmains/archive/tags/JavaScript/default.aspx" /><category term="Web" scheme="http://msmvps.com/blogs/bmains/archive/tags/Web/default.aspx" /><category term="Facebook" scheme="http://msmvps.com/blogs/bmains/archive/tags/Facebook/default.aspx" /></entry><entry><title>TypeMock Isolation Members - CallOriginal</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/08/17/mocking-configuration-with-typemock.aspx" /><id>/blogs/bmains/archive/2009/08/17/mocking-configuration-with-typemock.aspx</id><published>2009-08-18T01:26:00Z</published><updated>2009-08-18T01:26:00Z</updated><content type="html">&lt;p&gt;This post assumes you are familiar with TypeMock&amp;#39;s Arrange-Act-Assert method of test creation.&amp;nbsp; If you are not, please read my overview at:&amp;nbsp;&lt;a href="http://dotnetslackers.com/articles/designpatterns/TypeMocks-Arrange-Act-Assert.aspx"&gt;http://dotnetslackers.com/articles/designpatterns/TypeMocks-Arrange-Act-Assert.aspx&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;When creating your fakes with TypeMock, you have to be careful which member your choose as the default mocking level.&amp;nbsp; For instance, when you create the following class:&lt;/p&gt;
&lt;p&gt;var cls = Isolate.Fake.Instance&amp;lt;TestClass&amp;gt;();&lt;/p&gt;
&lt;p&gt;The variable cls has a fake reference to our test class.&amp;nbsp; All calls to any method are mocked (no code actually runs for that method), unless you do:&lt;/p&gt;
&lt;p&gt;Isolate.WhenCalled(() =&amp;gt; cls.MyMethod()).CallOriginal();&lt;/p&gt;
&lt;p&gt;You can also control the results through the other methods available from Isolate.WhenCalled, such as using WillReturn to return a pre-specified value.&amp;nbsp; That is out of scope, but a good subject for a future blog post.&amp;nbsp; Anyway, back to the subject, you may wonder why certain methods fail, especially if you use Isolate.Verify to verify method calls.&amp;nbsp; I had the same issue, and it turns out its because of the default behavior of the fake.&amp;nbsp; For instance, if I would have done:&lt;/p&gt;
&lt;p&gt;var cls = Isolate.Fake.Instance&amp;lt;TestClass&amp;gt;(Members.CallOriginal);&lt;/p&gt;
&lt;p&gt;The default behavior is to call the original instance of methods within the class, and not to mock their calls.&amp;nbsp; This was the solution to an issue was having; I had an internal collection of objects like:&lt;/p&gt;
&lt;p&gt;private ACollection AList&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; get&lt;br /&gt;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (_aList == null)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _aList = new ACollection();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return _aList;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;Because I didn&amp;#39;t do the following statement during the default level of mocking access:&lt;/p&gt;
&lt;p&gt;Isolate.NonPublic.Property.WhenGetCalled(cls, &amp;quot;AList&amp;quot;).CallOriginal();&lt;/p&gt;
&lt;p&gt;AList was mocked in my test and my test failed.&amp;nbsp; Adding Members.CallOriginal caused AList original implementation to be called, and then the test succeeded.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1716402" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Third Party Tools" scheme="http://msmvps.com/blogs/bmains/archive/tags/Third+Party+Tools/default.aspx" /><category term="TypeMock" scheme="http://msmvps.com/blogs/bmains/archive/tags/TypeMock/default.aspx" /></entry><entry><title>Paging Table Columns Using JavaScript</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/08/04/paging-table-columns-using-javascript.aspx" /><id>/blogs/bmains/archive/2009/08/04/paging-table-columns-using-javascript.aspx</id><published>2009-08-04T22:41:00Z</published><updated>2009-08-04T22:41:00Z</updated><content type="html">&lt;p&gt;I recently have been thinking about tabular displays and how to make them better.&amp;nbsp; For instance, suppose that your final output of an application looked like the following:&lt;/p&gt;
&lt;p&gt;&amp;lt;table id=&amp;quot;tbl&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;thead&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;tr&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;th&amp;gt;One Header&amp;lt;/th&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;th&amp;gt;Two Header&amp;lt;/th&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;th&amp;gt;Three Header&amp;lt;/th&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;th&amp;gt;Four Header&amp;lt;/th&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;th&amp;gt;Five Header&amp;lt;/th&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;th&amp;gt;Six Header&amp;lt;/th&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;th&amp;gt;Seven Header&amp;lt;/th&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;th&amp;gt;Eight Header&amp;lt;/th&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;/thead&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;tbody&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;tr&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;tr&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Value&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;nbsp; .&lt;br /&gt;&amp;nbsp; .&lt;br /&gt;&amp;nbsp; .&lt;br /&gt;&amp;nbsp; .&lt;/p&gt;
&lt;p&gt;&amp;lt;/table&amp;gt;&lt;/p&gt;
&lt;p&gt;Imagine this is for&amp;nbsp;a form of some sort.&amp;nbsp; Think in reverse of a GridView control in ASP.NET; the&amp;nbsp;GridView control renders&amp;nbsp;a dynamic number of rows; this example is more suited for an application you may build that is columns-based, say to render a comparison between products, or maybe the headers a representative of people, and the rows contains some attributes about them (name, height, weight, and other stats).&lt;/p&gt;
&lt;p&gt;So, this&amp;nbsp;example using JavaScript and JQuery is&amp;nbsp; meant to enable a new way of paging columns-based data; however, it could be adapted to page row-based data.&amp;nbsp; Now, if you have a lot of data in the column-based form, it will&amp;nbsp; force a horizontal scrollbar, something that is against standards in most organizations (and is not a preferred approach anyway unless culturally significant).&amp;nbsp; To offset this, the script I&amp;#39;m about to show you will show only 4 columns at a time, allowing the user to page left/right.&amp;nbsp; To do this, I will use a looping construct to loop through the columns and rows to change visibility.&amp;nbsp; The script looks like:&lt;/p&gt;
&lt;p&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;var leftColumn = 0;&lt;br /&gt;&amp;nbsp;var columnCount = 4;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;$(document).ready(function() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;var t = $(&amp;quot;#tbl&amp;quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;$(&amp;quot;#output&amp;quot;).html(t.outerWidth().toString() + &amp;quot;, &amp;quot; + t.outerHeight().toString());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;refresh();&lt;br /&gt;&amp;nbsp;});&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;function refresh() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;var table = $(&amp;quot;#tbl&amp;quot;)[0];&lt;br /&gt;&amp;nbsp;&amp;nbsp;var headerRow = tbl.getElementsByTagName(&amp;quot;THEAD&amp;quot;)[0].rows[0];&lt;br /&gt;&amp;nbsp;&amp;nbsp;var rightColumn = leftColumn + columnCount;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;if (leftColumn &amp;lt;= 0) leftColumn = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;if (leftColumn &amp;gt;= headerRow.cells.length - 3) leftColumn--;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;for (var r = 0, rlen = table.rows.length; r &amp;lt; rlen; r++) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;for (var c = 0, clen = headerRow.cells.length; c &amp;lt; clen; c++) {&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;table.rows[r].cells&lt;img src="http://msmvps.com/emoticons/emotion-44.gif" alt="Coffee" /&gt;.style.display = ((leftColumn &amp;lt;= c &amp;amp;&amp;amp; c &amp;lt; rightColumn) ? &amp;quot;table-cell&amp;quot; : &amp;quot;none&amp;quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/p&gt;
&lt;p&gt;To begin, to figure out which&amp;nbsp;4 columns to show is determined by the leftColumn variable; it stores the current column index of the far left&amp;nbsp;visible column.&amp;nbsp; The column count stores the number of columns to display, so that is configurable and can be something other than 4 columns.&amp;nbsp; When the document loads (using JQuery&amp;#39;s document ready event), the UI initializes to show the 4 columns.&amp;nbsp; The refresh method actually shifts the columns, and it does this using math.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;The THEAD definition is special, because that is the easy way to figure out how many columns their are; there isn&amp;#39;t any explicit way to figure columns (unless a COLGROUP is specified); so the header easily figures out there are 8 columns available.&amp;nbsp; Two loops take place; first, it loops through each row to show/hide the appropriate cells, while the rest get hidden.&amp;nbsp; It iterates through the rows first, then the columns, and changes the display accordingly.&lt;/p&gt;
&lt;p&gt;To page, I included two buttons that will page left/right.&amp;nbsp; You may have notice the if checkes in the previous JS code; it simply ensures the paging isn&amp;#39;t out of the valid range of values.&lt;/p&gt;
&lt;p&gt;&amp;lt;button id=&amp;quot;navleft&amp;quot;&amp;gt;Move Left&amp;lt;/button&amp;gt;&lt;br /&gt;&amp;lt;button id=&amp;quot;navright&amp;quot;&amp;gt;Move Right&amp;lt;/button&amp;gt;&lt;/p&gt;
&lt;p&gt;JQuery hooks up to the click event, and refreshes the UI after it increments or decrements the left column index.&lt;/p&gt;
&lt;p&gt;$(&amp;quot;#navleft&amp;quot;).click(function() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;leftColumn--;&lt;br /&gt;&amp;nbsp;&amp;nbsp;refresh();&lt;br /&gt;&amp;nbsp;});&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;$(&amp;quot;#navright&amp;quot;).click(function() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;leftColumn++;&lt;br /&gt;&amp;nbsp;&amp;nbsp;refresh();&lt;br /&gt;&amp;nbsp;});&lt;/p&gt;
&lt;p&gt;And that is all that it takes to use JavaScript, and JQuery (even if I don&amp;#39;t fully take advantage of it) to create a way to page columns of a table.&amp;nbsp; It works really well and is fast.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1713047" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="JavaScript Libraries" scheme="http://msmvps.com/blogs/bmains/archive/tags/JavaScript+Libraries/default.aspx" /><category term="JavaScript" scheme="http://msmvps.com/blogs/bmains/archive/tags/JavaScript/default.aspx" /><category term="Web" scheme="http://msmvps.com/blogs/bmains/archive/tags/Web/default.aspx" /></entry><entry><title>Book Review for Pro Silverlight 2 in C# 2008 By Matthew McDonald</title><link rel="alternate" type="text/html" href="/blogs/bmains/archive/2009/07/06/book-review-for-pro-silverlight-2-in-c-2008-by-matthew-mcdonald.aspx" /><id>/blogs/bmains/archive/2009/07/06/book-review-for-pro-silverlight-2-in-c-2008-by-matthew-mcdonald.aspx</id><published>2009-07-07T01:32:00Z</published><updated>2009-07-07T01:32:00Z</updated><content type="html">&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="font-family:Calibri;font-size:small;"&gt;I read Matthew McDonald&amp;rsquo;s book Pro WPF to bone up on WPF, XAML, and everything .NET 3.5 has to offer.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;I have to say that I was impressed by Matthew&amp;rsquo;s writing style, level of detail, and general knowledge that he passed onto the reader. &lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/span&gt;This fact is also the case with Pro Silverlight 2.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;While WPF has some similarities to Silverlight, the author points out some of the differences (like the lack for EventTrigger support for any event but the Loaded event in the current version).&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="font-family:Calibri;font-size:small;"&gt;The book covers all of the major topics, starting with an overview of the basic elements: XAML elements, properties (simple and attached), moving into the subjects of Layout containers, dependency properties, and routed events.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;He then moves into an overview of the various controls.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;This overview isn&amp;rsquo;t exhaustive, but gives you a firm foundation.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;I thought his chapters on shapes, brushes, transforms, audio/video, and animation to be very helpful.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;It can be difficult to understand how to setup these various features, and Pro Silverlight 2 clarifies it well.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="font-family:Calibri;font-size:small;"&gt;The next section of the book covers the more advanced topics that you would need to know to use Silverlight, such as using web services within ASP.NET/silverlight (a useful topic since Silverlight doesn&amp;rsquo;t use ViewState or server-side technologies because it&amp;rsquo;s running on the client), databinding (which can be challenging due to various levels of nested Silverlight structures), multithreading, and more.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;He really doesn&amp;rsquo;t leave very many stones unturned in his explanation of the features.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="font-family:Calibri;font-size:small;"&gt;I would highly recommend this book from Apress.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;Although Silverlight 3 is coming soon, this book will help you understand those fundamentals that will be in the next version.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1698523" width="1" height="1"&gt;</content><author><name>bmains</name><uri>http://msmvps.com/members/bmains/default.aspx</uri></author><category term="Book Reviews" scheme="http://msmvps.com/blogs/bmains/archive/tags/Book+Reviews/default.aspx" /></entry></feed>