<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Brian J. Cardiff</title>
	<atom:link href="http://weblogs.manas.com.ar/bcardiff/feed/" rel="self" type="application/rss+xml" />
	<link>http://weblogs.manas.com.ar/bcardiff</link>
	<description>Keep in touch</description>
	<lastBuildDate>Fri, 24 Jul 2009 12:27:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>C# from 1.0 to 4.0 talk</title>
		<link>http://weblogs.manas.com.ar/bcardiff/2009/06/csharp-from-1-to-4-talk/</link>
		<comments>http://weblogs.manas.com.ar/bcardiff/2009/06/csharp-from-1-to-4-talk/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 05:05:52 +0000</pubDate>
		<dc:creator>bcardiff</dc:creator>
				<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/bcardiff/2009/06/c-from-10-to-40-talk/</guid>
		<description><![CDATA[On June 10th I had the chance to talk about the evolution the C# language had since its first RTM version. This talk was in the context of the Microsoft academic program, here at Argentina, and took place at the UAI of Lomas de Zamora. Although the talk lasted a couple of hours I think [...]]]></description>
			<content:encoded><![CDATA[<p>On June 10th I had the chance to talk about the evolution the C# language had since its first RTM version.</p>
<p>This talk was in the context of the <a href="http://www.ms-universidades.com/" target="_blank">Microsoft academic program</a>, here at Argentina, and took place at the <a href="http://www.vaneduc.edu.ar/uai/" target="_blank">UAI of Lomas de Zamora</a>.</p>
<p>Although the talk lasted a couple of hours I think the slides are suitable for a crash course. Just to have a taste about syntax and things that C# team take care of during last years.</p>
<p>We have chance to see same nice Lambda expression things in C# 3.0 with sample of <a href="http://code.google.com/p/netfx/" target="_blank">NetFX</a>, <a href="http://code.google.com/p/moq/" target="_blank">Moq</a> and Linq-to-SQL; and also some unit testing concepts (using Moq, of course)</p>
<p>Downloads:</p>
<ul>
<li><a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2009/06/slides.pdf">Slides</a> 228KB (powered by <a href="http://www.latex-project.org/" target="_blank">LaTeX</a>)</li>
<li><a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2009/06/handout.pdf">Handout</a> 194KB</li>
<li><a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2009/06/vs2008-samplecode.zip">VS2008 Sample Code</a> 578KB</li>
<li><a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2009/06/vs2010-samplecode.zip">VS2010 Sample Code</a> 11KB</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/bcardiff/2009/06/csharp-from-1-to-4-talk/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RUN09: Jugando dentro del browser: AJAX Client Templates y jQuery en ASP.NET</title>
		<link>http://weblogs.manas.com.ar/bcardiff/2009/03/run09-jugando-dentro-del-browser-ajax-client-templates-y-jquery-en-aspnet/</link>
		<comments>http://weblogs.manas.com.ar/bcardiff/2009/03/run09-jugando-dentro-del-browser-ajax-client-templates-y-jquery-en-aspnet/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 00:39:00 +0000</pubDate>
		<dc:creator>bcardiff</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[MSP]]></category>
		<category><![CDATA[Talks]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/bcardiff/?p=58</guid>
		<description><![CDATA[Martín Salías and I participated at RUN09. The talk was named &#8220;Jugando dentro del browser: AJAX Client Templates y jQuery en ASP.NET&#8221;. We had the chance to show how Microsoft Ajax Client Templates works with JsonResult of ASP.NET MVC and jQuery datepicker plugin. You can download the source code of the demo: run09-b1-sourcecode Here are the resources [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.salias.com.ar/">Martín Salías</a> and I participated at <a href="http://www.puertadeenlace.net/run09/">RUN09</a>. The talk was named &#8220;Jugando dentro del browser: AJAX Client Templates y jQuery en ASP.NET&#8221;. We had the chance to show how <a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24887">Microsoft Ajax Client Templates</a> works with JsonResult of <a href="http://www.asp.net/mvc/">ASP.NET MVC</a> and <a href="http://jquery.com/">jQuery</a> <a href="http://jqueryui.com/demos/datepicker/">datepicker plugin</a>.</p>
<p>You can download the source code of the demo: <a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2009/03/run09-b1-sourcecode.zip">run09-b1-sourcecode</a></p>
<p>Here are the resources we suggest to get started with all this:</p>
<ul>
<li><a href="http://www.asp.net/mvc">http://www.asp.net/mvc</a></li>
<li><a href="http://www.codeplex.com/aspnet">http://www.codeplex.com/aspnet</a></li>
<li><a href="http://jquery.com">http://jquery.com</a></li>
<li><a href="http://www.codeplex.com/nerddinner">http://www.codeplex.com/nerddinner</a></li>
<li><a href="http://weblogs.asp.net/bleroy">http://weblogs.asp.net/bleroy</a></li>
<li><a href="http://weblogs.asp.net/infinitiesloop">http://weblogs.asp.net/infinitiesloop</a></li>
<li><a href="http://delicious.com/msalias/run09">http://delicious.com/msalias/run09</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/bcardiff/2009/03/run09-jugando-dentro-del-browser-ajax-client-templates-y-jquery-en-aspnet/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC Guidelines: Notifications</title>
		<link>http://weblogs.manas.com.ar/bcardiff/2009/03/aspnet-mvc-guidelines-notifications/</link>
		<comments>http://weblogs.manas.com.ar/bcardiff/2009/03/aspnet-mvc-guidelines-notifications/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 14:42:23 +0000</pubDate>
		<dc:creator>bcardiff</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[MSP]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/bcardiff/?p=49</guid>
		<description><![CDATA[While developing a web application a developer should build some infrastructure for the whole system. ASP.NET MVC is not the exception. The fact that ASP.NET MVC is a framework, it doesn&#8217;t mean that covers 100% of the necessity a developer will have during the development, but it should let you fill the gap. This gap [...]]]></description>
			<content:encoded><![CDATA[<p>While developing a web application a developer should build some infrastructure for the whole system. <a href="http://www.asp.net/mvc/" target="_blank">ASP.NET MVC</a> is not the exception. The fact that <a href="http://www.asp.net/mvc/" target="_blank">ASP.NET MVC</a> is a framework, it doesn&#8217;t mean that covers 100% of the necessity a developer will have during the development, but it should let you fill the gap. This gap could be filled by third party libraries or just by something ad-hoc you develop.</p>
<p>I saw (and develop) some kind of notifications solutions in order to tell the user that something (good or bad) have just happened due to his action eg.: &#8220;your password has been changed&#8221;, &#8220;you have new messages&#8221;, etc. These implementations were constrained to the MVC-way, letting the model has a notification property, letting the view show that property, etc. They could, but as soon as you reach some <a href="http://blog.eworldui.net/post/2008/05/ASPNET-MVC---Using-Post2c-Redirect2c-Get-Pattern.aspx" target="_blank">Post-Redirect-Get</a>, or <strong>some partial page AJAX</strong> call, or <strong>JSON AJAX</strong> call you will get into troubles.</p>
<p>Along this post I will show a notification solution that play nice with all these scenarios with a unify way. I don&#8217;t I&#8217;m telling something new here, just sharing the experience and thuoghts. I will assume that the notifications are plain strings, but it could be extended to include a kind field (info, warning, error).</p>
<p>Download <a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2009/03/mvcguidelines.zip">sample code</a> for <a href="http://go.microsoft.com/fwlink/?LinkId=144443" target="_blank">ASP.NET MVC RC 2</a>. Try test buttons and changing your password.</p>
<h3>Interface</h3>
<p>The first thing is how we expect to leave a notification. Since the notification capability should be used a lot I prefer to make them available without needing to change the <strong>Model</strong> or <strong>ActionResult</strong>, so lets create a <strong>INotificationService</strong>. In order to play nice with designs and testing prefer to let the controllers get a reference to:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">interface</span> INotificationService
{
    <span class="kwrd">void</span> Send(<span class="kwrd">string</span> message);
}</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p><!--</p>
<p>.csharpcode, .csharpcode pre<br />
{<br />
font-size: small;<br />
color: black;<br />
font-family: consolas, "Courier New", courier, monospace;<br />
background-color: #ffffff;<br />
/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
background-color: #f4f4f4;<br />
width: 100%;<br />
margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; } --></p>
<h3>How to use it</h3>
<p>All the controllers should have <strong>HandleNotificationAttribute</strong> applied, later we will see what is this for. The controller that want to send a notification will need to get a reference to an <strong>INotificationService</strong>. During the execution of the action, the method <strong>Send</strong> could be called as many times as you want. You are able to return what ever <strong>ActionResult</strong> you want. But if doing a redirect, be sure to use a <strong>RedirectToRouteResult</strong> (i.e. suggesting <a href="http://asp.net/mvc" target="_blank">ASP.NET MVC</a> way to send HTTP Redirects).</p>
<pre class="csharpcode">[HandleNotification]
<span class="kwrd">public</span> <span class="kwrd">class</span> SomeController : Controller
{
    INotificationService notification;

    <span class="kwrd">public</span> SomeController(INotificationService notification)
    {
        <span class="kwrd">this</span>.notification = notification;
    }

    <span class="kwrd">public</span> ViewResult Index()
    {
        notification.Send(<span class="str">"Welcome!"</span>);
        <span class="rem">// Create some model for the view</span>
        <span class="kwrd">return</span> View();
    }

    <span class="kwrd">public</span> ActionResult RedirectCall()
    {
        <span class="rem">// Perform changes</span>
        notification.Send(<span class="str">"data saved"</span>);
        <span class="kwrd">return</span> RedirectToAction(<span class="str">"Index"</span>, <span class="str">"Home"</span>);
    }

    <span class="kwrd">public</span> JsonResult JsonAjaxCall()
    {
        notification.Send(<span class="str">"Lorem ipsum"</span>);
        notification.Send(<span class="str">"dolor sit amet"</span>);
        <span class="kwrd">return</span> Json(<span class="kwrd">new</span> { A = 1, B = <span class="str">"lorem"</span> });
    }

}</pre>
<p><!--</p>
<p>.csharpcode, .csharpcode pre<br />
{<br />
font-size: small;<br />
color: black;<br />
font-family: consolas, "Courier New", courier, monospace;<br />
background-color: #ffffff;<br />
/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
background-color: #f4f4f4;<br />
width: 100%;<br />
margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; } --></p>
<p>As it can be seen, it is straight forward the usage. The <strong>INotificationService</strong> only expose a method to add notification, but not to clear them.</p>
<h3>Client side</h3>
<p>Just for encapsulation I choose to create a <strong>ViewUserControl</strong> that it should be included at the <strong>MasterPage</strong>, or at every respose page of a non-AJAX HTTP Request.</p>
<pre class="csharpcode"><span class="asp">&lt;%@ Master ... %&gt;</span>
<span class="asp">&lt;%@ Register TagPrefix="core" TagName="notifications"
    Src="~/Core/Notifications/ShowNotifications.ascx" %&gt;</span>
<span class="kwrd">&lt;!</span><span class="html">DOCTYPE</span> <span class="attr">html</span> <span class="attr">PUBLIC</span> <span class="kwrd">...</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">xmlns</span><span class="kwrd">="http://www.w3.org/1999/xhtml"</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">head</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!-- ... --&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">core:notifications</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span>
<span class="rem">&lt;!-- ... --&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span></pre>
<p><!--</p>
<p>.csharpcode, .csharpcode pre<br />
{<br />
font-size: small;<br />
color: black;<br />
font-family: consolas, "Courier New", courier, monospace;<br />
background-color: #ffffff;<br />
/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
background-color: #f4f4f4;<br />
width: 100%;<br />
margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; } --></p>
<p>The client side use Javascript to display notification, in the sample below I use <a href="http://www.stanlemon.net/projects/jgrowl.html" target="_blank">jGrowl</a> (and <a href="http://jquery.com/" target="_blank">jQuery</a>). It is easy to change it to generate some just plain divs inside an identified element if you prefer.</p>
<p>Somewhere in the code of <strong>ShowNotifications.ascx</strong> the following code defines how a notification is shown:</p>
<pre class="csharpcode"><span class="kwrd">function</span> showNotification(msg) {
    $.jGrowl(msg);
}</pre>
<p>The <strong>HandleNotificationAttribute</strong> has the responsibility to expose the recent notifications in the way the <strong>ShowNotifications.ascx</strong> is expecting them.</p>
<p>The following section goes trough implementation details, which is not the most interesting part in the article.</p>
<h3>How it works</h3>
<p>I will detail how each scenarios is supported:</p>
<h4>non-AJAX/non-redirect Actions</h4>
<p>The action have just store some notifications. The <strong>HandleNotificationAttribute</strong> add to the <strong>ViewData</strong> a <strong>HandleNotificationInfo</strong> that the <strong>ShowNotifications.ascx</strong> will use to render some calls to the <strong>showNotification</strong> functions.</p>
<h4>AJAX Actions (JSON or Partial View)</h4>
<p>The JSON calls force us to send the notification out-of-the-band, I choose to use cookies. So, if the <strong>HandleNotificationInfo</strong> detects that the request is an AJAX request, it serialize the <strong>HandleNotificationInfo</strong> using JSON. The <strong>ShowNotifications.ascx</strong> attach to <a href="http://docs.jquery.com/Ajax/ajaxComplete" target="_blank">AJAX Complete event</a> (using jQuery) and pulls recently added cookie, and remove it.</p>
<p>Up to this point the storage of the notifications (<strong>INotificationRepository</strong>) could be implemented inside the request life cycle, but in order to support the next scenario we will use an implementation of <strong>INotificationRepository</strong> that use the HTTP Session object.</p>
<h4>Post-Redirect-Get</h4>
<p>When the action tells the <strong>INotificationService</strong> to send a notification, it is stored (as in every call) using the <strong>INotificationRepository</strong>. In this case, the <strong>HandleNotification</strong> performs no action, remember it was a POST request. The client receives a Redirect which performs a GET that will fall in the previous cases. Since the <strong>INotificationRepository</strong> use HTTP Session object, upon the action executed by the GET is completed, the <strong>HandleNotification</strong> will perform the usual task: pop the stored notifications in <strong>INotificationRepository</strong> and expose them to the client.</p>
<p>A final remark is that since Attributes can&#8217;t be injected with dependencies I expose a static property that is set upon Application_Start, in <strong>Global.asax</strong>.</p>
<p>Hope you find it useful. I&#8217;m more interesting in the overall solution than in the actual implementation: that is, enhancing the <a href="http://asp.net/mvc" target="_blank">ASP.NET MVC</a> framework with some services you would need for a better application development.</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/bcardiff/2009/03/aspnet-mvc-guidelines-notifications/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Latam Windows Day &#8211; El futuro de la plataforma de desarrollo Web hoy</title>
		<link>http://weblogs.manas.com.ar/bcardiff/2009/03/latam-windows-day-el-futuro-de-la-plataforma-de-desarrollo-web-hoy/</link>
		<comments>http://weblogs.manas.com.ar/bcardiff/2009/03/latam-windows-day-el-futuro-de-la-plataforma-de-desarrollo-web-hoy/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 13:51:09 +0000</pubDate>
		<dc:creator>bcardiff</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[MSP]]></category>
		<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/bcardiff/?p=38</guid>
		<description><![CDATA[Today is the Windows Day event. With Sergio we are presenting some new features that will be part of ASP.NET 4.0 and other stuff: ASP.NET MVC Dynamic Data Client Templates IE Developers Tools jQuery First of  all a disclaimer is mandatory, the session was recorded during January, and as expected some improvements happened since that [...]]]></description>
			<content:encoded><![CDATA[<p>Today is the <a href="http://www.microsoft.com/latam/windowsday/">Windows Day event</a>. With <a href="http://weblogs.manas.com.ar/smedina">Sergio</a> we are presenting some new features that will be part of ASP.NET 4.0 and other stuff:</p>
<ul>
<li>ASP.NET MVC</li>
<li>Dynamic Data</li>
<li>Client Templates</li>
<li>IE Developers Tools</li>
<li>jQuery</li>
</ul>
<p>First of  all a disclaimer is mandatory, the session was recorded during January, and as expected some improvements happened since that day:</p>
<ol>
<li>ASP.NET MVC move from Beta to RC (and to RC Refresh)</li>
<li>IE8 move from Beta to RC</li>
<li>jQuery move from 1.2.6 to 1.3.2 (with a brand new jQuery UI)</li>
</ol>
<p>One the my preferred slides is the one where we compare ASP.NET WebForms with ASP.NET MVC:</p>
<table border="0">
<tbody>
<tr>
<th></th>
<th>ASP.NET MVC</th>
<th>ASP.NET WebForms</th>
</tr>
<tr>
<td>URLs</td>
<td>/Users/jdoe</td>
<td>/UserProfile.aspx?id=jdoe</td>
</tr>
<tr>
<td>Testing</td>
<td>straightforward</td>
<td>not so easy</td>
</tr>
<tr>
<td>Markup</td>
<td>full control</td>
<td>always ViewState</td>
</tr>
<tr>
<td>User actions</td>
<td>HTTP Request</td>
<td>PostBacks</td>
</tr>
<tr>
<td>Request Life Cycle</td>
<td>M &#8211; V &#8211; C</td>
<td>PageLifeCycle</td>
</tr>
<tr>
<td>Integration with jQuery, Protoype, etc.</td>
<td>100%</td>
<td>some dificulties</td>
</tr>
<tr>
<td>AJAX</td>
<td>grained control</td>
<td>UpdatePanel</td>
</tr>
</tbody>
</table>
<p>This shows which thing you should have in mind if you are coming from WebForms in order to have a smooth transition to MVC.</p>
<p>Here are some resources:</p>
<ul>
<li><a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2009/03/el-futuro-de-la-plataforma-de-desarrollo-web-hoy.pdf">Slides [757 KB]</a></li>
<li><a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2009/03/todolist-sourcecode.zip">TODO list demo (Source Code) [648 KB]<br />
</a></li>
</ul>
<p>Sergio will post in <a href="http://weblogs.manas.com.ar/smedina">his blog</a> the other demo.</p>
<p>You can leave comments and questions in this post or <a href="http://200.58.118.10/post/Sesion-MSDN-2El-futuro-de-la-plataforma-de-desarrollo-Web-hoy.aspx">the one in windows day blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/bcardiff/2009/03/latam-windows-day-el-futuro-de-la-plataforma-de-desarrollo-web-hoy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>(Re)improved argument matchers in Moq</title>
		<link>http://weblogs.manas.com.ar/bcardiff/2009/02/reimproved-argument-matchers-in-moq/</link>
		<comments>http://weblogs.manas.com.ar/bcardiff/2009/02/reimproved-argument-matchers-in-moq/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 13:47:16 +0000</pubDate>
		<dc:creator>bcardiff</dc:creator>
				<category><![CDATA[Moq]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/bcardiff/?p=37</guid>
		<description><![CDATA[In the past I wrote about MatcherAttibute in Moq allows developers to create quite easy argument matchers. Due to a suggestion, community opinions and Kzu&#8216;s implementation, the matchers were improved again. In an scenario with a Customer class and a IFooService: 1: public class Customer 2: { 3: public string Name { get; set; } [...]]]></description>
			<content:encoded><![CDATA[<p>In the past I wrote about <a target="_blank" href="http://weblogs.manas.com.ar/bcardiff/2008/04/improoved-argument-matchers-in-moq/">MatcherAttibute</a> in <a target="_blank" href="http://code.google.com/p/moq/">Moq</a> allows developers to create quite easy argument matchers. Due to a <a target="_blank" href="http://moq.uservoice.com/pages/general/suggestions/122731-simplify-custom-matchers">suggestion</a>, community opinions and <a target="_blank" href="http://www.clariusconsulting.net/blogs/kzu/">Kzu</a>&#8216;s implementation, the matchers were improved <strong>again</strong>.</p>
<p>In an scenario with a Customer class and a IFooService:</p>
<div class="csharpcode">
<pre><span class="lnum">   1:  </span><span class="kwrd">public</span> <span class="kwrd">class</span> Customer</pre>
<pre><span class="lnum">   2:  </span>{</pre>
<pre><span class="lnum">   3:  </span>    <span class="kwrd">public</span> <span class="kwrd">string</span> Name { get; set; }</pre>
<pre><span class="lnum">   4:  </span>    <span class="kwrd">public</span> <span class="kwrd">int</span> Age { get; set; }</pre>
<pre><span class="lnum">   5:  </span>    <span class="rem">// ...</span></pre>
<pre><span class="lnum">   6:  </span>}</pre>
<pre><span class="lnum">   7:  </span>&nbsp;</pre>
<pre><span class="lnum">   8:  </span><span class="kwrd">public</span> <span class="kwrd">interface</span> IFooService</pre>
<pre><span class="lnum">   9:  </span>{</pre>
<pre><span class="lnum">  10:  </span>    <span class="kwrd">void</span> Bar(Customer c);</pre>
<pre><span class="lnum">  11:  </span>}</pre>
</div>
<p>If in a test you need an expectation on Bar method that stands for a Customer c where c.Age &gt;= 18 you<br />needed to do something like this:</p>
<div class="csharpcode">
<pre><span class="lnum">   1:  </span>[Test]</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">public</span> <span class="kwrd">void</span> Test1()</pre>
<pre><span class="lnum">   3:  </span>{</pre>
<pre><span class="lnum">   4:  </span>    var mock = <span class="kwrd">new</span> Mock&lt;IFooService&gt;(MockBehavior.Strict);</pre>
<pre><span class="lnum">   5:  </span>    mock.Setup(x =&gt; x.Bar(It.Is&lt;Customer&gt;(c =&gt; c.Age &gt;= 18)));</pre>
<pre><span class="lnum">   6:  </span>    <span class="rem">// this will success</span></pre>
<pre><span class="lnum">   7:  </span>    <span class="rem">// mock.Object.Bar(new Customer { Age = 21 });</span></pre>
<pre><span class="lnum">   8:  </span>    <span class="rem">// this will fail</span></pre>
<pre><span class="lnum">   9:  </span>    <span class="rem">// mock.Object.Bar(new Customer { Age = 17 });</span></pre>
<pre><span class="lnum">  10:  </span>}</pre>
</div>
<p>but from now on, using the Matcher factory the same expectation could be written as follows:</p>
<div class="csharpcode">
<pre><span class="lnum">   1:  </span>[Test]</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">public</span> <span class="kwrd">void</span> Test2()</pre>
<pre><span class="lnum">   3:  </span>{</pre>
<pre><span class="lnum">   4:  </span>    var mock = <span class="kwrd">new</span> Mock&lt;IFooService&gt;(MockBehavior.Strict);</pre>
<pre><span class="lnum">   5:  </span>    mock.Setup(x =&gt; x.Bar(GrownUp()));</pre>
<pre><span class="lnum">   6:  </span>    <span class="rem">// this will success</span></pre>
<pre><span class="lnum">   7:  </span>    <span class="rem">// mock.Object.Bar(new Customer { Age = 21 });</span></pre>
<pre><span class="lnum">   8:  </span>    <span class="rem">// this will fail</span></pre>
<pre><span class="lnum">   9:  </span>    <span class="rem">// mock.Object.Bar(new Customer { Age = 17 });</span></pre>
<pre><span class="lnum">  10:  </span>}</pre>
<pre><span class="lnum">  11:  </span>&nbsp;</pre>
<pre><span class="lnum">  12:  </span><span class="kwrd">public</span> <span class="kwrd">static</span> Customer GrownUp()</pre>
<pre><span class="lnum">  13:  </span>{</pre>
<pre><span class="lnum">  14:  </span>    <span class="kwrd">return</span> Match&lt;Customer&gt;.Create(c =&gt; c.Age &gt;= 18);</pre>
<pre><span class="lnum">  15:  </span>}
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
</pre>
</div>
<p>There is some tricky stuff around type here (returning a Match&lt;T&gt; in a method with return type). If you want to see how this work go to the code and read <a target="_blank" href="http://groups.google.com/group/moqdisc/browse_thread/thread/f707263997cbf275">this discussion</a>. All in all is to have a good experience with the compiler.</p>
<p>Continue to read the post and you will see some other alternatives!</p>
<h2>Use property as matchers</h2>
<p>Last sample could be rewritten with less parenthesis using property getters.</p>
<div class="csharpcode">
<pre><span class="lnum">   1:  </span>[Test]</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">public</span> <span class="kwrd">void</span> Test2()</pre>
<pre><span class="lnum">   3:  </span>{</pre>
<pre><span class="lnum">   4:  </span>    var mock = <span class="kwrd">new</span> Mock&lt;IFooService&gt;(MockBehavior.Strict);</pre>
<pre><span class="lnum">   5:  </span>    mock.Setup(x =&gt; x.Bar(GrownUp));</pre>
<pre><span class="lnum">   6:  </span>    <span class="rem">// this will success</span></pre>
<pre><span class="lnum">   7:  </span>    <span class="rem">// mock.Object.Bar(new Customer { Age = 21 });</span></pre>
<pre><span class="lnum">   8:  </span>    <span class="rem">// this will fail</span></pre>
<pre><span class="lnum">   9:  </span>    <span class="rem">// mock.Object.Bar(new Customer { Age = 17 });</span></pre>
<pre><span class="lnum">  10:  </span>}</pre>
<pre><span class="lnum">  11:  </span>&nbsp;</pre>
<pre><span class="lnum">  12:  </span><span class="kwrd">public</span> <span class="kwrd">static</span> Customer GrownUp</pre>
<pre><span class="lnum">  13:  </span>{</pre>
<pre><span class="lnum">  14:  </span>    get { <span class="kwrd">return</span> Match&lt;Customer&gt;.Create(c =&gt; c.Age &gt;= 18); }</pre>
<pre><span class="lnum">  15:  </span>}</pre>
</div>
<h2>More arguments </h2>
<p>Also you could have more arguments involved in the matching, just add them as method arguments and use them in the lambda expression. <br />For example to match older than a certain age:</p>
<div class="csharpcode">
<pre><span class="lnum">   1:  </span>[Test]</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">public</span> <span class="kwrd">void</span> Test3()</pre>
<pre><span class="lnum">   3:  </span>{</pre>
<pre><span class="lnum">   4:  </span>    var mock = <span class="kwrd">new</span> Mock&lt;IFooService&gt;(MockBehavior.Strict);</pre>
<pre><span class="lnum">   5:  </span>    mock.Setup(x =&gt; x.Bar(OlderThan(18)));</pre>
<pre><span class="lnum">   6:  </span>    <span class="rem">// this will success</span></pre>
<pre><span class="lnum">   7:  </span>    <span class="rem">// mock.Object.Bar(new Customer { Age = 21 });</span></pre>
<pre><span class="lnum">   8:  </span>    <span class="rem">// this will fail</span></pre>
<pre><span class="lnum">   9:  </span>    <span class="rem">// mock.Object.Bar(new Customer { Age = 17 });</span></pre>
<pre><span class="lnum">  10:  </span>}</pre>
<pre><span class="lnum">  11:  </span>&nbsp;</pre>
<pre><span class="lnum">  12:  </span><span class="kwrd">public</span> <span class="kwrd">static</span> Customer OlderThan(<span class="kwrd">int</span> minimumAge)</pre>
<pre><span class="lnum">  13:  </span>{</pre>
<pre><span class="lnum">  14:  </span>    <span class="kwrd">return</span> Match&lt;Customer&gt;.Create(c =&gt; c.Age &gt;= minimumAge);</pre>
<pre><span class="lnum">  15:  </span>}</pre>
</div>
<h2>Your own helper class</h2>
<p>To reuse some matchers, you could define them in a separate a class instead of inside the fixture.</p>
<div class="csharpcode">
<pre><span class="lnum">   1:  </span>[Test]</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">public</span> <span class="kwrd">void</span> Test4()</pre>
<pre><span class="lnum">   3:  </span>{</pre>
<pre><span class="lnum">   4:  </span>    var mock = <span class="kwrd">new</span> Mock&lt;IFooService&gt;(MockBehavior.Strict);</pre>
<pre><span class="lnum">   5:  </span>    mock.Setup(x =&gt; x.Bar(An.OlderThan(18)));</pre>
<pre><span class="lnum">   6:  </span>    <span class="rem">// this will success</span></pre>
<pre><span class="lnum">   7:  </span>    <span class="rem">// mock.Object.Bar(new Customer { Age = 21 });</span></pre>
<pre><span class="lnum">   8:  </span>    <span class="rem">// this will fail</span></pre>
<pre><span class="lnum">   9:  </span>    <span class="rem">// mock.Object.Bar(new Customer { Age = 17 });</span></pre>
<pre><span class="lnum">  10:  </span>}</pre>
<pre><span class="lnum">  11:  </span>&nbsp;</pre>
<pre><span class="lnum">  12:  </span><span class="kwrd">static</span> <span class="kwrd">class</span> An</pre>
<pre><span class="lnum">  13:  </span>{</pre>
<pre><span class="lnum">  14:  </span>    <span class="kwrd">public</span> <span class="kwrd">static</span> Customer OlderThan(<span class="kwrd">int</span> minimumAge)</pre>
<pre><span class="lnum">  15:  </span>    {</pre>
<pre><span class="lnum">  16:  </span>        <span class="kwrd">return</span> Match&lt;Customer&gt;.Create(c =&gt; c.Age &gt;= minimumAge);</pre>
<pre><span class="lnum">  17:  </span>    }</pre>
<pre><span class="lnum">  18:  </span>}</pre>
</div>
<p><font color="#000000" size="2" face="Consolas"></font></p>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<h2>Non static method </h2>
<p>Finally, the matchers declaration and implementation don&#8217;t need to be static. So you could have additional context of matching. <br />Although I suggest this last only in certain scenarios, for example, match enumeration of values:</p>
<div class="csharpcode">
<pre><span class="lnum">   1:  </span>[Test]</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">public</span> <span class="kwrd">void</span> Test5()</pre>
<pre><span class="lnum">   3:  </span>{</pre>
<pre><span class="lnum">   4:  </span>    var mock = <span class="kwrd">new</span> Mock&lt;IFooService&gt;(MockBehavior.Strict);</pre>
<pre><span class="lnum">   5:  </span>    var names = <span class="kwrd">new</span> E(<span class="str">"John Doe"</span>, <span class="str">"Brian Cardiff"</span>);</pre>
<pre><span class="lnum">   6:  </span>    mock.Setup(x =&gt; x.Bar(names.Some));</pre>
<pre><span class="lnum">   7:  </span>&nbsp;</pre>
<pre><span class="lnum">   8:  </span>    <span class="rem">// this will success</span></pre>
<pre><span class="lnum">   9:  </span>    <span class="rem">// mock.Object.Bar(new Customer { Name = "Brian Cardiff" });</span></pre>
<pre><span class="lnum">  10:  </span>&nbsp;</pre>
<pre><span class="lnum">  11:  </span>    <span class="rem">// this will fail</span></pre>
<pre><span class="lnum">  12:  </span>    <span class="rem">// mock.Object.Bar(new Customer { Name = "Sandy" });</span></pre>
<pre><span class="lnum">  13:  </span>}</pre>
<pre><span class="lnum">  14:  </span>&nbsp;</pre>
<pre><span class="lnum">  15:  </span><span class="kwrd">public</span> <span class="kwrd">class</span> E</pre>
<pre><span class="lnum">  16:  </span>{</pre>
<pre><span class="lnum">  17:  </span>    <span class="kwrd">string</span>[] names;</pre>
<pre><span class="lnum">  18:  </span>    <span class="kwrd">public</span> E(<span class="kwrd">params</span> <span class="kwrd">string</span>[] names)</pre>
<pre><span class="lnum">  19:  </span>    {</pre>
<pre><span class="lnum">  20:  </span>        <span class="kwrd">this</span>.names = names;</pre>
<pre><span class="lnum">  21:  </span>    }</pre>
<pre><span class="lnum">  22:  </span>&nbsp;</pre>
<pre><span class="lnum">  23:  </span>    <span class="kwrd">public</span> Customer Some</pre>
<pre><span class="lnum">  24:  </span>    {</pre>
<pre><span class="lnum">  25:  </span>        get { <span class="kwrd">return</span> Match&lt;Customer&gt;.Create(s =&gt; names.Contains(s.Name)); }</pre>
<pre><span class="lnum">  26:  </span>    }</pre>
<pre><span class="lnum">  27:  </span>}</pre>
</div>
<h2>More lines in matcher code</h2>
<p>There is no need that the matcher code is a one-line lambda, in case you are not familiar writing lambdas, here is another sample:</p>
<div class="csharpcode">
<pre><span class="lnum">   1:  </span>[Test]</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">public</span> <span class="kwrd">void</span> Test6()</pre>
<pre><span class="lnum">   3:  </span>{</pre>
<pre><span class="lnum">   4:  </span>    var mock = <span class="kwrd">new</span> Mock&lt;IFooService&gt;(MockBehavior.Strict);</pre>
<pre><span class="lnum">   5:  </span>    mock.Setup(x =&gt; x.Bar(Between(20, 30)));</pre>
<pre><span class="lnum">   6:  </span>    <span class="rem">// this will success</span></pre>
<pre><span class="lnum">   7:  </span>    <span class="rem">// mock.Object.Bar(new Customer { Age = 25 });</span></pre>
<pre><span class="lnum">   8:  </span>    <span class="rem">// this will fail</span></pre>
<pre><span class="lnum">   9:  </span>    <span class="rem">// mock.Object.Bar(new Customer { Age = 40 });</span></pre>
<pre><span class="lnum">  10:  </span>}</pre>
<pre><span class="lnum">  11:  </span>&nbsp;</pre>
<pre><span class="lnum">  12:  </span><span class="kwrd">private</span> Customer Between(<span class="kwrd">int</span> from, <span class="kwrd">int</span> to)</pre>
<pre><span class="lnum">  13:  </span>{</pre>
<pre><span class="lnum">  14:  </span>    <span class="kwrd">return</span> Match&lt;Customer&gt;.Create(c =&gt;</pre>
<pre><span class="lnum">  15:  </span>    {</pre>
<pre><span class="lnum">  16:  </span>        <span class="kwrd">if</span> (c.Age &lt; from)</pre>
<pre><span class="lnum">  17:  </span>            <span class="kwrd">return</span> <span class="kwrd">false</span>;</pre>
<pre><span class="lnum">  18:  </span>        <span class="kwrd">if</span> (c.Age &gt; to)</pre>
<pre><span class="lnum">  19:  </span>            <span class="kwrd">return</span> <span class="kwrd">false</span>;</pre>
<pre><span class="lnum">  20:  </span>        <span class="kwrd">return</span> <span class="kwrd">true</span>;</pre>
<pre><span class="lnum">  21:  </span>    });</pre>
<pre><span class="lnum">  22:  </span>}</pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/bcardiff/2009/02/reimproved-argument-matchers-in-moq/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Declarative jQuery (with Microsoft Ajax)</title>
		<link>http://weblogs.manas.com.ar/bcardiff/2008/12/declarative-jquery-with-microsoft-ajax/</link>
		<comments>http://weblogs.manas.com.ar/bcardiff/2008/12/declarative-jquery-with-microsoft-ajax/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 18:36:56 +0000</pubDate>
		<dc:creator>bcardiff</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/bcardiff/2008/12/declarative-jquery-with-microsoft-ajax/</guid>
		<description><![CDATA[Almost everybody likes jQuery, I&#8217;m one of them. Recently Microsoft publish Client Templates preview 3 which is a awesome client side template engine. One of the best aspects of Client Templates is it&#8217;s declarative syntax for attaching behaviors (Sys.UI.Behavior) to a DOM element. Following I expose the plugin jquery.declarative which allows you to use in [...]]]></description>
			<content:encoded><![CDATA[<p>Almost everybody likes <a href="http://jquery.com/" target="_blank">jQuery</a>, I&#8217;m one of them. Recently Microsoft publish <a href="http://www.codeplex.com/aspnet/Wiki/View.aspx?title=AJAX&amp;referringTitle=Home" target="_blank">Client Templates preview 3</a> which is a awesome client side template engine. One of the best aspects of Client Templates is it&#8217;s declarative syntax for attaching behaviors (<a href="http://msdn.microsoft.com/en-us/library/bb311020.aspx" target="_blank">Sys.UI.Behavior</a>) to a DOM element.</p>
<p>Following I expose the plugin jquery.declarative which allows you to use in a declarative way another jQuery plugin.</p>
<p>N.B.: Along this post I will use a plugin called wajbar, which is near to be published in jQuery plugins directory.</p>
<p>You can download the <a href="http://bcardiff.googlepages.com/jQueryDeclarative.zip" target="_blank">source code</a> here.</p>
<h3>jQuery way</h3>
<p>Usually jQuery plugins extend the jQuery interface in simple way:</p>
<p><code>$(&lt;selector&gt;).&lt;method&gt;(&lt;options&gt;)</code>
<p>for example:</p>
<p><code>&lt;input type="text" maxlength="60" size="30" id="text1" /&gt;<br />&lt;script type="text/javascript"&gt;<br />&nbsp;&nbsp;&nbsp; $(function() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $('#text1').wajbar();<br />&nbsp;&nbsp;&nbsp; });<br />&lt;/script&gt; </code>
<p>Nothing wrong, but thing could turn ugly if you have a lot of plugins and components all around.</p>
<h3>declarative way</h3>
<p>In order to use a declarative syntax for a plugin named <em>P</em>, you have the following requirements:</p>
<ul>
<li>jQuery core
<li><strong>Microsoft Ajax (MicrosoftAjax.js)</strong>
<li><strong>Microsoft Ajax Templates (MicrosoftAjaxTemplates.js)</strong>
<li><strong>jQuery Declarative plugin (jquery.declarative.js)</strong>
<li>jQuery <em>P</em> plugin which should use syntax: $(&lt;selector&gt;).&lt;method&gt;(&lt;options&gt;);
<li>Add <strong>xmlns:sys=&#8221;javascript:Sys&#8221; sys:activate=&#8221;*&#8221;</strong> attributes to your body tag.</li>
</ul>
<p>Note: If you are using a ScriptManager you already have Microsoft Ajax. Microsoft Ajax Templates and jQuery Declarative plugin in must be referenced within the ScriptManager. Otherwise just include the references in that order.</p>
<p>After referencing, you would need to expose the plugin <em>P</em> to jquery.declarative:</p>
<p><code>//general syntax <br />// $.declare(&lt;entry method name of P&gt;); <br />$.declare('wajbar'); </code>
<p>This is need just once, usually when DOM ready is ready.</p>
<p>Now, for using a wajbar you need to <strong>attach</strong> it.</p>
<p><code>&lt;input type="text" maxlength="60" size="30" <strong>sys:attach="wajbar"</strong> /&gt;</code>
<p>That&#8217;s it. Have in mind that using multiple times jquery plugins will be less obstructive this way. No need for additional CSS classname or IDs for later selecting the desired element.</p>
<h3>using arguments in plugin initialization</h3>
<p>I mention before that jquery plugins usually supports options to be passed in initialization: $(&lt;selector&gt;).&lt;method&gt;(<strong>&lt;options&gt;</strong>);. For example the wajbar support passing a &#8216;submit&#8217; property to indicate a DOM that should be disabled if the input value is longer than maxlength.</p>
<p>Given:</p>
<p><code>&lt;input type="text" maxlength="20" size="40" id="text1" /&gt;<br />&lt;input type="submit" value="submit" id="button1" /&gt;</code>
<p>using plain jQuery you would need to call </p>
<p><code>$('#text1').wajbar({submit: $('#button1')});</code>
<p>but the declarative alternative is now </p>
<p><code>&lt;input type="text" maxlength="20" size="40"<br /><strong>&nbsp;&nbsp; sys:attach="wajbar"</strong> <br /><strong>&nbsp;&nbsp; wajbar:submit="{{ $('#button1') }}"</strong> /&gt;<br />&lt;input type="submit" value="submit" id="button1" /&gt; </code>
<p>you can even get further and remove all the ids of your code and make them really reusable!</p>
<p><code>&lt;input type="text" maxlength="20" size="40" <br />&nbsp;&nbsp; sys:key="self" <br />&nbsp;&nbsp; sys:attach="wajbar"&nbsp; <br />&nbsp;&nbsp; <strong>wajbar:submit="{{ $(self).next('input:submit') }}"</strong>&nbsp; <br />/&gt; <br />&lt;input type="submit" value="submit" /&gt; </code>
<p>It&#8217;s a bit more complicated the last, but is 100% reusable. With <strong>sys:key</strong> attribute you said how you want to expose the current DOM element in the evaluation within {{ }}.</p>
<h3>ajax partial page load</h3>
<p>In order to use the declarative syntax in with partial page rendering you need to call</p>
<p><code>Sys.Application.processNode(&lt;the new dom element&gt;); </code>
<p>Either the partial page executes that or hook per ajax loaded content, this depends on site conventions.</p>
<h3>more than one plugin</h3>
<p>This new syntax allows more than one plugin, each with their initialization options. You just need to enumerate the plugins separated by a comma.</p>
<p>For example using the <a href="http://remysharp.com/2008/02/28/upgraded-jquery-tag-suggestions/" target="_blank">tagSuggestion</a> plugin:</p>
<p><code>&lt;script src="tag.js" type="text/javascript"&gt;&lt;/script&gt;<br />&lt;link href="tag.css" rel="stylesheet" type="text/css" /&gt; &lt;script type="text/javascript"&gt;<br />&nbsp;&nbsp;&nbsp; $(function() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $.declare('wajbar'); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // fake suggestions<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setGlobalTags(['javascript', 'jquery', 'java', 'json']); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $.declare('tagSuggest');<br />&nbsp;&nbsp;&nbsp; });<br />&lt;/script&gt; </code>
<p>Create an input with wajbar and tag suggestion:</p>
<p><code>&lt;input type="text" maxlength="30" <strong>sys:attach="tagsuggest, wajbar"</strong> /&gt;</code>
<p>Note that the declarative names are lowercase always, no matter the case of the method name, since the namespaces are always lowercase.</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/bcardiff/2008/12/declarative-jquery-with-microsoft-ajax/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>PDC Essentials @ Buenos Aires</title>
		<link>http://weblogs.manas.com.ar/bcardiff/2008/11/pdc-essentials-buenos-aires/</link>
		<comments>http://weblogs.manas.com.ar/bcardiff/2008/11/pdc-essentials-buenos-aires/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 12:38:27 +0000</pubDate>
		<dc:creator>bcardiff</dc:creator>
				<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/bcardiff/?p=34</guid>
		<description><![CDATA[Updated November 20th, you can download slide and demos here. On Tuesday 18th, Juan and I will be presenting ASP.NET 4.0 Roadmap. Check which other talks are available and register here. This is the event information: Horario: martes, 18 de noviembre de 2008 16:00 &#8211; 22:00 p.m. Lugar: ITTC. Sarmiento 1113 Piso 5. Buenos Aires [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-weight: bold;">Updated November 20th, you can download slide and demos </span><a href="http://bcardiff.googlepages.com/ASP.NET4.0Roadmap.zip"><span style="font-weight: bold;">here</span></a><span style="font-weight: bold;">.</span></p>
<p>On Tuesday 18th, <a href="http://weblogs.manas.com.ar/waj/" target="_blank">Juan</a> and I will be presenting ASP.NET 4.0 Roadmap. Check which other talks are available and register <a href="http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032394696&amp;Culture=es-AR" target="_blank">here</a>.</p>
<p>This is the event information:</p>
<ul>
<li>Horario: martes, 18 de noviembre de 2008 16:00 &#8211; 22:00 p.m.</li>
<li>Lugar: ITTC. Sarmiento 1113 Piso 5. Buenos Aires Argentina.</li>
<li><a href="http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032394696&amp;Culture=es-AR" target="_blank">Registración</a></li>
<li>Descripción:Durante los días del 27 al 30 de Octubre se lleva a cabo la Professional Developer Conference en Los Angeles, Estados Unidos. Durante este evento Microsoft realiza grandes anuncios sobre novedades en la plataforma de desarrollo, presentando su visión de Cloud Computing, construyendo aplicaciones que desdibujan las barreras entre la PC, la Web y los dispositivos móviles, lo nuevo en VS 2010, .net Framework 4, distintos avances sobre Windows 7, la siguiente mayor versión de la plataforma cliente Windows y mucho más. En este evento, estaremos presentando algunas de las novedades develadas durante el evento, contando con disertantes asistentes al mismo.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/bcardiff/2008/11/pdc-essentials-buenos-aires/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery for Script#</title>
		<link>http://weblogs.manas.com.ar/bcardiff/2008/11/jquery-for-script/</link>
		<comments>http://weblogs.manas.com.ar/bcardiff/2008/11/jquery-for-script/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 04:20:54 +0000</pubDate>
		<dc:creator>bcardiff</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Script#]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/bcardiff/?p=33</guid>
		<description><![CDATA[Quite a good title . Some weeks ago I find the time to create proof of concept for that task: create a jQuery wrapper for Script#. The result is a partial wrapper that could be completed to support all in all jQuery functionality. The main issues I encountered while developing were: Write a Script# adapter [...]]]></description>
			<content:encoded><![CDATA[<p>Quite a good title <img src='http://weblogs.manas.com.ar/bcardiff/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . Some weeks ago I find the time to create proof of concept for that task: create a <a href="http://jquery.com/">jQuery</a> wrapper for <a href="http://projects.nikhilk.net/ScriptSharp/">Script#</a>. The result is a partial wrapper that could be completed to support all in all jQuery functionality.</p>
<p>The main issues I encountered while developing were:</p>
<ul>
<li>Write a Script# adapter</li>
<li>Adapt event handlers interfaces</li>
<li>Support jQuery overloads</li>
</ul>
<p>At the same time I was learning a bit of <a href="http://www.codeplex.com/aspnet/Wiki/View.aspx?title=AJAX">Microsoft Ajax Client-Side Templates</a> (preview 2), part of ASP.NET AJAX 4.0, which are not in preview 3 stage. I also had to to a minimal script# adapter for this, but it was totally ad-hoc.</p>
<p>Due to the dependence with Microsoft Ajax, aacorlib Script# engine is used, which doesn&#8217;t support some C# features like foreach.</p>
<h3>Write a Script# adapter</h3>
<p>First of all you need to read some Script#. Then need realize that anycode that depends on a Script# adapter is not testable unless you implement some basic behavior of the adapted component.</p>
<p>For example the wrappers usually returns <b>null</b>, or <b>default(T)</b>, for a function that it&#8217;s return type is <b>T</b>.</p>
<p>jQuery use a fluent interface, so returning <b>this</b> instead of <b>null</b><br />
will allow a minimal chance be testable (to avoid spurious runtime null pointer exceptions.</p>
<h3>Adapt event handlers interfaces</h3>
<p>With jQuery an event handler is declared as follows:</p>
<p><code>var anchors = $("a");<br />
anchors.click(function(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;var target = $(this).attr('href');<br />
&nbsp;&nbsp;&nbsp;&nbsp;alert('anchor to ' + target + 'clicked.');<br />
});<br />
</code></p>
<p>In C# the <b>this</b> keyword is binding to the current class, not as in Javascript. This force the full creation of a wrapper, previously I tried to just have a trivial wrapper with the <b>ImportedAttribute</b><br />
in every method, but wasn&#8217;t enough.</p>
<p>After some tweaks I finally got this to work:</p>
<p><code>jQuery anchors = jQueryApi.Select("a");<br />
anchors.click(delegate(object sender){<br />
&nbsp;&nbsp;&nbsp;&nbsp;string target = jQueryApi.Select(sender);<br />
&nbsp;&nbsp;&nbsp;&nbsp;Script.Alert("anchor to " + target + "clicked.")<br />
});</code></p>
<p>And the &#8220;implementation&#8221; magic code is:</p>
<p><code>public class jQuery {<br />
&nbsp;&nbsp;&nbsp;&nbsp;// ...<br />
&nbsp;&nbsp;&nbsp;&nbsp;public jQuery click(EventCallback fn){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Script.Literal("{0}.click(function(){{ return {1}(this); }})", _jquery, fn);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return this;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></p>
<h3>Support jQuery overloads</h3>
<p>In Script#, Javascript overloads are declared as <b>extern</b><br />
methods with <b>AlternateSignatureAttribute</b><br />
. What I try to get was a easy way to implement jQuery overloads. The<br />
<b>Function.apply</b><br />
method was very useful.</p>
<p>In the following code it is shown how jQuery.attr methods are adapted, and how jQuery wrapper is maintained. It&#8217;s not very nice, but is what is needed to get this works.</p>
<p><code>public class jQuery<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;[AlternateSignature]<br />
&nbsp;&nbsp;&nbsp;&nbsp;public extern string attr(string key);<br />
&nbsp;&nbsp;&nbsp;&nbsp;public jQuery attr(string key, string value)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;object r = Script.Literal("{0}.attr.apply({0}, arguments)", _jquery);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (r == _jquery) // preserve jQuery wrapper<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return this;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return (jQuery) r; // cast for compilation, it will return corresponding type<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
</code></p>
<h3>Sample Application</h3>
<p>Doesn&#8217;t do much:</p>
<ol>
<li>Gets a hardcoded list of TODOs in JSON</li>
<li>Unfold template using Client-Side Teamplates</li>
<li>Add behavior to unfolded DOM</li>
</ol>
<p>All this is implemented in Script# using an MVP pattern. Algo in Views/Tasks/Layout.aspx there is a commented Javascript implementation.</p>
<p>You can download the solution <a href="http://bcardiff.googlepages.com/TodoSharp.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/bcardiff/2008/11/jquery-for-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Haskell Monads on the web</title>
		<link>http://weblogs.manas.com.ar/bcardiff/2008/09/haskell-monads-on-the-web/</link>
		<comments>http://weblogs.manas.com.ar/bcardiff/2008/09/haskell-monads-on-the-web/#comments</comments>
		<pubDate>Mon, 29 Sep 2008 17:23:05 +0000</pubDate>
		<dc:creator>bcardiff</dc:creator>
				<category><![CDATA[Functional Programming]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/bcardiff/2008/09/haskell-monads-on-the-web/</guid>
		<description><![CDATA[Yesterday I spent some time reading about Haskell implementations of Monads because I want to prepare some exercise. I share some links and snippets. http://www.haskell.org/tutorial/monads.html http://www.haskell.org/haskellwiki/Monad Laws &#38; syntax Monads in other languages Philip Wadler / Monads The essence of functional programming This paper explores the use monads to structure functional programs. No prior knowledge [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I spent some time reading about Haskell implementations of Monads because I want to prepare some exercise. I share some links and snippets.</p>
<ul>
<li><a title="http://www.haskell.org/tutorial/monads.html" href="http://www.haskell.org/tutorial/monads.html">http://www.haskell.org/tutorial/monads.html</a></li>
<li><a href="http://www.haskell.org/haskellwiki/Monad">http://www.haskell.org/haskellwiki/Monad</a>
<ul>
<li>Laws &amp; syntax</li>
<li>Monads in other languages</li>
</ul>
</li>
<li><a href="http://homepages.inf.ed.ac.uk/wadler">Philip Wadler</a> / <a href="http://homepages.inf.ed.ac.uk/wadler/topics/monads.html">Monads</a>
<ul>
<li><a href="http://homepages.inf.ed.ac.uk/wadler/papers/essence/essence.dvi">The essence of functional programming</a>
<ul>
<li>This paper explores the use monads to structure functional programs. No prior knowledge of monads or category theory is required.</li>
<li>Monads increase the ease with which programs may be modified. They can mimic the effect of impure features such as exceptions, state, and continuations; and also provide effects not easily achieved with such features. The types of a program reflect which effects occur.</li>
<li>The first section is an extended example of the use of monads. A simple interpreter is modified to support various extra features: error messages, state, output, and non-deterministic choice. The second section describes the relation between monads and continuation-passing style. The third section sketches how monads are used in a compiler for Haskell that is written in Haskell.</li>
</ul>
</li>
<li><a href="http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/baastad.dvi">Monads for functional programming</a>
<ul>
<li>The use of monads to structure functional programs is described. Monads provide a convenient framework for simulating effects found in other languages, such as global state, exception handling, output, or non-determinism. Three case studies are looked at in detail: how monads ease the modification of a simple evaluator; how monads act as the basis of a datatype of arrays subject to in-place update; and how monads can be used to build parsers.</li>
</ul>
</li>
</ul>
</li>
<li><a title="http://www.engr.mun.ca/~theo/Misc/haskell_and_monads.htm" href="http://www.engr.mun.ca/~theo/Misc/haskell_and_monads.htm">http://www.engr.mun.ca/~theo/Misc/haskell_and_monads.htm</a>
<ul>
<li>So far we&#8217;ve seen the monad concept applied to implicitly passing state. However monads can be used to implement several other programming features including: consuming input, producing output, exceptions and exception handling, nondeterminisim. To handle this variety, the basic operations of &gt;&gt;= and return are overloaded functions.</li>
<li><strong>Monads and Software Engineering</strong>
<ul>
<li>The key to engineering a large software project is to make changes easy..</li>
<li>Monads can be used to make functional programs far more adaptable.  You need to insert another processing step? Go right ahead, don&#8217;t worry about plumbing the state. You need another variable in the state? No problem, just change the underlying state and the basic members of the monad. You need to output messages from your computation? No problem, just change the monad to add an output string. You need to handle exceptions or nondeterminism? No problem, just change the monad.</li>
<li>It might be said that Haskell with monads does not give you much that you won&#8217;t find in an imperative, nondeterministic language, with extensible, strong, but generic typing, and a powerful applicative expression sublanguage. The problem is there is no such language in common use. Monads make up for many of the drawbacks of Haskell relative to imperative languages, but without giving up any of its strengths.</li>
</ul>
</li>
</ul>
</li>
<li><a title="http://en.wikibooks.org/wiki/Programming:Haskell_monads" href="http://en.wikibooks.org/wiki/Programming:Haskell_monads">http://en.wikibooks.org/wiki/Programming:Haskell_monads</a>
<ul>
<li>Simple example for generation random numbers with a seed.</li>
</ul>
</li>
<li><a title="http://logic.csci.unt.edu/tarau/research/PapersHTML/monadic.html" href="http://logic.csci.unt.edu/tarau/research/PapersHTML/monadic.html">http://logic.csci.unt.edu/tarau/research/PapersHTML/monadic.html</a>
<ul>
<li>`monad-based&#8217; approach to the definition of all-solution predicates in <a href="http://logic.csci.unt.edu/tarau/research/PapersHTML/monadic.html#f10">\lambdaProlog</a>. As a follow-up, we obtain a clarification of Prolog&#8217;s high-order operators and their similarities and differences with monad comprehensions in functional languages.</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/bcardiff/2008/09/haskell-monads-on-the-web/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax Widgets with ASP.NET MVC Preview 3</title>
		<link>http://weblogs.manas.com.ar/bcardiff/2008/07/ajax-widgets-with-aspnet-mvc-preview-3/</link>
		<comments>http://weblogs.manas.com.ar/bcardiff/2008/07/ajax-widgets-with-aspnet-mvc-preview-3/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 18:36:31 +0000</pubDate>
		<dc:creator>bcardiff</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Ajax]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/bcardiff/?p=29</guid>
		<description><![CDATA[Since some time ago I&#8217;ve been working with ASP.NET MVC in a project for InSTEDD. The whole project includes quite a lot infrastructure (e.g.: little MVC projects that are plug-ins of the main website), but in this post I will try to show the approach we choose to accomplish Ajax Widgets that are governed by [...]]]></description>
			<content:encoded><![CDATA[<p>Since some time ago I&#8217;ve been working with ASP.NET MVC in a project for <a href="http://www.instedd.org">InSTEDD</a>. The whole project includes quite a lot infrastructure (e.g.: little MVC projects that are plug-ins of the main website), but in this post I will try to show the approach we choose to accomplish Ajax Widgets that are governed by a controller. The design was also though to have a good developer experience (this mainly defines the signature of the ViewUserControls that represents the desired widgets). Also, two other goal were achieved, a) the first load of the page includes the widget rendering (so the user doesn&#8217;t need to wait longer than the main page loads), b) it is easy to notify the user about some actions: information, warnings and errors messages regarding the last action performed.</p>
<p>I&#8217;ve prepared a sample tagging application that runs with an in-memory storage. I will describe how the application works as a guidance for this post.</p>
<p><strong><a href="http://weblogs.manas.com.ar/bcardiff/?attachment_id=31">Download the source code</a></strong></p>
<p>As you would expect I have an <strong>ItemsController</strong> which decides the Items to show (but only the items, not the tags).</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; float: none; border-bottom-width: 0px; border-right-width: 0px" src="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2008/07/image.png" border="0" alt="image" width="286" height="249" /></p>
<p>A simple List view implementation for displaying the items would be as follows:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; float: none; border-bottom-width: 0px; border-right-width: 0px" src="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2008/07/image1.png" border="0" alt="image" width="522" height="174" /></p>
<p>If now we want to add Tagging capability to this view, what should be developed? a) the View for displaying tags of each item, and b) a Controller to both perform actions and render the updated view.</p>
<p>Since in the List view of items the model are just items, without tags, to keep the view markup simple, and be easy to include the Tags Edit widget in any part an item is displayed the widget should inherit from <strong>ViewUserControl&lt;Item&gt;</strong>. (actually I&#8217;ve develop a base class for widgets: <strong>MvcWidget</strong> which I will introduce later). So, the final version of List view is as follows:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; float: none; border-bottom-width: 0px; border-right-width: 0px" src="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2008/07/image2.png" border="0" alt="image" width="523" height="190" /></p>
<p>But if the Tags Edit widget has just an <strong>Item</strong> as model, how does the tags come from? Every <strong>ViewUserControl</strong> has a reference to the <strong>Controller</strong> through the <strong>ViewUserControl.ViewContext</strong> property. So we decide that the <strong>TagsController</strong> which will be the ajax endpoint, also is responsible for augmenting the <strong>Item</strong> with the list of tags. So the markup of the Tags Edit widget would be something like this:</p>
<p><a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2008/07/image3.png"><img style="border-top-width: 0px; border-left-width: 0px; float: none; border-bottom-width: 0px; border-right-width: 0px" src="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2008/07/image-thumb.png" border="0" alt="image" width="619" height="263" /></a></p>
<p>I didn&#8217;t show the full source here to be more clear in the presentation (in the downloadable file the solution is complete of course). As you could see in the tooltip, the new Controller property of the view is strongly typed as <strong>TagsController</strong>. The view base class did that:</p>
<p><a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2008/07/image4.png"><img style="border-top-width: 0px; border-left-width: 0px; float: none; border-bottom-width: 0px; border-right-width: 0px" src="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2008/07/image-thumb1.png" border="0" alt="image" width="454" height="60" /></a></p>
<p>The final result will be that the root div (with class UpdatePanel) will be replaced upon an ajax request to the server. This could be done with your favorite JavaScript library (<a href="http://jquery.com/">jQuery</a> is mine). I&#8217;ve done some helper functions to treat link navigation and form submit to ajax request and perform UI update as needed.</p>
<p>A minimal <strong>TagsController</strong> implementation would be something like this:</p>
<p><a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2008/07/image5.png"><img style="border-top-width: 0px; border-left-width: 0px; float: none; border-bottom-width: 0px; border-right-width: 0px" src="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2008/07/image-thumb2.png" border="0" alt="image" width="416" height="276" /></a></p>
<p>Upon ajax request, Add and Remove methods will perform the appropriate actions in <strong>Repository</strong> and then Renders the Tags Edit view with an Item as a model, without tags, the same controller instance will be used to retrieve the tags for the item.</p>
<p>For the first load, we don&#8217;t have a <strong>TagsController</strong> instance, since the request was processed by a <strong>ItemsController</strong>. The <strong>MvcWidget</strong> class simply instantiate a <strong>TagsController</strong> for this case (of course, you should plug your DI framework here).</p>
<p>This depicts mostly the main design. To provide feedback to the user regarding the last action I implement two new kinds of <strong>ActionResult</strong>.</p>
<ul>
<li><strong>JavaScriptActionResult</strong> which renders a &lt;script type=&#8221;text/javascript&gt;&#8230;&lt;/script&gt; element with a specified scripts.</li>
<li><strong>CompositeActionResult</strong> which completes the ActionResult type hierarchy to implement a Composite pattern.</li>
</ul>
<p>Also, ad-hoc for the site I implement <strong>ClientStatusActionResult</strong> which inherits from <strong>JavaScriptActionResult</strong> to have a nicer controller code. An implementation without error handling of the Add method could be like this:</p>
<p><a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2008/07/image6.png"><img style="border-top-width: 0px; border-left-width: 0px; float: none; border-bottom-width: 0px; border-right-width: 0px" src="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2008/07/image-thumb3.png" border="0" alt="image" width="485" height="186" /></a></p>
<p>I suggest to look at the downloadable source to get a better implementation with error handling. For example, the repository may throw an exception when the maximum amount of tags is exceeded, in this scenario a <strong>ClientStatusActionResult</strong> with <strong>ClientStatus.Error</strong> is returned in composition with the Tag Edit view as was submitted from the user.</p>
<p><strong>BatchResults</strong> method is just a Controller extension method that returns a <strong>CompositeActionResult</strong> for the given argumetns.</p>
<p><a href="http://jquery.com">jQuery</a> runs the script element when it arrives from the server, so the JavaScript that update the status DOM element is execute.</p>
<p>A final note, the whole idea and implementation was a result of some pairing sessions with <a href="http://weblogs.manas.com.ar/waj/">Juan Wajnerman</a>.</p>
<p>Any kind of feedback is welcomed!</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/bcardiff/2008/07/ajax-widgets-with-aspnet-mvc-preview-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
