<?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>Jonathan Cisneros &#187; .NET</title>
	<atom:link href="http://blogs.southworks.net/jcisneros/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.southworks.net/jcisneros</link>
	<description>.net from the trenches</description>
	<lastBuildDate>Fri, 25 Jun 2010 19:36:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Associating a URL Protocol to your Application</title>
		<link>http://blogs.southworks.net/jcisneros/2010/06/25/associating-a-url-protocol-to-your-application/</link>
		<comments>http://blogs.southworks.net/jcisneros/2010/06/25/associating-a-url-protocol-to-your-application/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 19:28:16 +0000</pubDate>
		<dc:creator>jcisneros</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[moniker]]></category>
		<category><![CDATA[Protocol]]></category>
		<category><![CDATA[URL]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/jcisneros/2010/06/25/associating-a-url-protocol-to-your-application/</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/jcisneros/2010/06/25/associating-a-url-protocol-to-your-application/" class="more-link">read more<img src="http://blogs.southworks.net/jcisneros/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>This is something done by <em>WebPI</em> (wpi://) and many <em>p2p</em> apps that you can do with your own application also: associate a URL protocol to your application. Let&#8217;s say you want to use URLs beginning with <strong>myapp://</strong> to launch your own application and perform a certain task (i.e. download a file and open it). This is simply done by adding some entries in the registry, the following steps guides you on how to configure your setup project to do this.</p>
<p><img style="float: none;margin-left: auto;margin-right: auto" src="http://blogs.southworks.net/jcisneros/files/2010/06/image.png" border="0" alt="image" width="599" height="147" /></p>
<ol>
<li>Right click on the <strong>Setup project</strong> of your solution, go to <strong>View </strong>and select <strong>Registry</strong>.</li>
<li>Under <strong>HKEY_CLASSES_ROOT</strong> create a new key and use the name for your protocol, let&#8217;s say &#8220;<strong>myapp</strong>&#8220;.</li>
<li>Add a new String value and delete the name, now it should appear with the name <strong>(Default)</strong>.</li>
<li>Set the value to &#8220;URL:myapp Protocol&#8221;.</li>
<li>Add another String value and name it &#8220;<strong>URL Protocol</strong>&#8220;. Leave its value blank. The registry view should now look like the following screenshot:<br /><img style="float: none;margin-left: auto;margin-right: auto" src="http://blogs.southworks.net/jcisneros/files/2010/06/image1.png" border="0" alt="image" width="488" height="154" /></li>
<li>Under the &#8220;myapp&#8221; key created on step 2, create a new key and named it &#8220;<strong>shell</strong>&#8220;.</li>
<li>Under the &#8220;shell&#8221; key create a new one named &#8220;<strong>open</strong>&#8220;.</li>
<li>Under the &#8220;open&#8221; key create a new one named &#8220;<strong>command</strong>&#8220;.</li>
<li>Add a new String value under the &#8220;command&#8221; key and delete its name to make it the default value.</li>
<li>Set the default value to &#8220;<strong>&#8220;[TARGETDIR]MyApplication.exe&#8221; &#8220;%1&#8243;</strong>&#8220;. The registry view should now look like the following screenshot:<br /><img style="float: none;margin-left: auto;margin-right: auto" src="http://blogs.southworks.net/jcisneros/files/2010/06/image2.png" border="0" alt="image" width="587" height="207" /></li>
</ol>
<p>That&#8217;s all!, each time the user hits a URL with your custom protocol, your application will be executed and will receive the URL. Now you have to parse it and act accordingly.</p>
<p>Additional reading: <a href="http://msdn.microsoft.com/en-us/library/aa767914%28VS.85%29.aspx" target="_blank">Registering an Application to a URL Protocol</a></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NET Framework 3.5 and Visual Studio 2008 SP1 released!</title>
		<link>http://blogs.southworks.net/jcisneros/2008/08/13/net-framework-35-and-visual-studio-2008-sp1-released/</link>
		<comments>http://blogs.southworks.net/jcisneros/2008/08/13/net-framework-35-and-visual-studio-2008-sp1-released/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 00:56:21 +0000</pubDate>
		<dc:creator>jcisneros</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[SP1]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/jcisneros/?p=38</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/jcisneros/2008/08/13/net-framework-35-and-visual-studio-2008-sp1-released/" class="more-link">read more<img src="http://blogs.southworks.net/jcisneros/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s awesome how fast time goes, a year ago, I was playing with <strong>.bat</strong> files (like putting messages in the autoexec.bat file), a month ago, I was building applications to do my accounting homework at highschool using <strong>C++ Builder</strong>, a week ago, I was making simple games with <strong>Visual Basic 6</strong> and then working with the same tool, yesterday, I was trying to learn the big <strong>.NET Framework 1.1</strong> and fighting against <strong>ADO.NET</strong> (20 lines to do the same thing that I used to do with three lines in ADO 6!), an hour ago, I was building <strong>ASP.NET 2.0</strong> web sites and <a href="http://www.railsenvy.com/" target="_blank">envying</a> the toys from the <strong>RoR</strong> and <strong>J2EE</strong> guys, now, a minute ago, I helped to create the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=355c80e9-fde0-4812-98b5-8a03f5874e96&amp;displaylang=en" target="_blank">Training Kit</a> for the <a href="http://msdn.microsoft.com/en-us/vstudio/products/cc533447.aspx" target="_blank">.NET Framework 3.5 SP1</a> that seconds ago was released the final version.</p>
<p><strong>A bunch of exiting things are included in the .NET Framework SP1 like:</strong></p>
<ul>
<li><a href="http://www.asp.net/mvc/" target="_blank">ASP.NET MVC Framework</a></li>
<li><a href="http://www.asp.net/dynamicdata/">ASP.NET Dynamic Data</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/bb399572.aspx" target="_blank">ADO.NET Entity Framework</a></li>
<li><a href="http://codebetter.com/blogs/david.hayden/archive/2008/01/08/getting-started-with-ado-net-data-services.aspx" target="_blank">ADO.NET Data Services</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/bb412169.aspx" target="_blank">WCF Web Programming Model</a> (RESTful services)</li>
<li>Improved AJAX Support</li>
<li>&#8230;<a href="http://www.microsoft.com/net/WhatsNew.aspx" target="_blank">and much more</a></li>
</ul>
<p><strong>You can get the bits at:</strong></p>
<ul>
<li><a href="http://msdn.microsoft.com/es-es/vstudio/cc533448(en-us).aspx" target="_blank">Visual Studio 2008 Service Pack 1 (SP1) and .NET Framework 3.5 SP1 Downloads</a></li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=355c80e9-fde0-4812-98b5-8a03f5874e96&amp;displaylang=en" target="_blank">.NET Framework 3.5 Enhancements Training Kit</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP.Net Dynamic Data (Scaffolding with .net)</title>
		<link>http://blogs.southworks.net/jcisneros/2008/08/05/aspnet-dynamic-data-scaffolding-with-net/</link>
		<comments>http://blogs.southworks.net/jcisneros/2008/08/05/aspnet-dynamic-data-scaffolding-with-net/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 23:40:49 +0000</pubDate>
		<dc:creator>jcisneros</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[SP1]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Dynamic Data]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/jcisneros/2008/08/05/aspnet-dynamic-data-scaffolding-with-net/</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/jcisneros/2008/08/05/aspnet-dynamic-data-scaffolding-with-net/" class="more-link">read more<img src="http://blogs.southworks.net/jcisneros/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://blogs.southworks.net/jcisneros/files/2008/08/image.png" border="0" alt="image" width="132" height="240" align="right" /> When you build data centric web applications, a big part of the code is related to the implementation of <a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete" target="_blank">CRUD</a> (Create, Read, Updated, Delete) operations. <a href="http://en.wikipedia.org/wiki/Scaffold_(programming)" target="_blank">Scaffolding</a> is a mechanism to generate fully functional data driven applications based on metadata inferred from a model, basically, all the CRUD operations are implemented by using the metadata obtained for each entity/table in the model, making it a very useful tool for prototyping.</p>
<p>That is what <a href="http://www.asp.net/dynamicdata/" target="_blank">ASP.Net Dynamic Data</a> does, it is a scaffolding technology that uses templates (ASP.Net Web Pages) to dynamically generate functional CRUD pages. Like <a href="http://www.rubyonrails.org/" target="_blank">Ruby on Rails</a>, Dynamic Data makes a high use of conventions to infer how the results will be rendered, but it can be highly customized in an really easy way by adding metadata to the model or modifying/adding templates. This allows to start with a raw prototype and continue customizing and tuning it &#8217;till a mature application.</p>
<h2>Getting Started</h2>
<p>Once you got the <a href="http://www.asp.net/dynamicdata/" target="_blank">bits</a> installed, you are able to create a new project using one of these two templates:</p>
<ul>
<li><strong>Dynamic Data Web Application</strong>: Creates a Dynamic Data web application using a <strong><a href="http://msdn.microsoft.com/en-us/library/bb386976.aspx" target="_blank">LINQ to SQL</a></strong> data model to generate the scaffolds.</li>
<li><strong>Dynamic Data Entities Web Application</strong>: Creates a Dynamic Data web application using a <strong>Entity Data Model</strong> (<a href="http://msdn.microsoft.com/en-us/library/bb399572.aspx" target="_blank">ADO.NET Entity Framework</a>) to generate the scaffolds.</li>
</ul>
<p>The main difference between both, is the data model that Dynamic Data will use as data source and to infer the metadata needed to do the scaffolding.</p>
<h3>The Data Model</h3>
<p><a href="http://blogs.southworks.net/jcisneros/files/2008/08/image1.png"><img src="http://blogs.southworks.net/jcisneros/files/2008/08/image-thumb.png" border="0" alt="image" width="134" height="244" align="left" /></a> As said before, the data model can be LINQ to SQL or Entity Data Model depending on the project type selected.</p>
<p>While LINQ to SQL is tightly bound to the database schema (each property is bound to a specific field in a table), Entity Framework is more flexible and loosely coupled and you can query for entities using either <a href="http://msdn.microsoft.com/en-us/library/bb308959.aspx" target="_blank">LINQ</a> or <a href="http://msdn.microsoft.com/en-us/library/bb387145.aspx" target="_blank">Entity-SQL</a>.</p>
<p>When creating the data model is recommendable to create a <strong>Model</strong> folder to place the data model file (<strong>.dbml</strong> or <strong>.edmx</strong>) and the additional classes that we will create through the development to enhance the metadata.</p>
<h3>Enabling Scaffolding</h3>
<p>This is the easiest thing, to enable the scaffolding you just need to modify a simple line of code.</p>
<p>In the <strong>global.asax.cs</strong> file is a method named <strong>RegisterRoutes</strong> where you will find a big section of commented description on how to register a data context to be used as the model to generate the scaffolds.</p>
<p>To enable scaffolding for all the classes/tables in the data model, you need to register the model in this way: (un-comment the following line and modify the <strong>bold</strong> parts)</p>
<blockquote><p>model.RegisterContext(typeof(Model.<strong>MyDataModelContext</strong>), new ContextConfiguration() { ScaffoldAllTables = <strong>true</strong> });</p></blockquote>
<p>Just modifying the previous line your application is ready to run, just press F5 and enjoy the magic!</p>
<p>If you want to generate scaffolds for specific classes/tables you have to set the <strong>ScaffoldAllTables</strong> property to <strong>false</strong> and then decorate the classes you want to scaffold with the <strong>[Scaffold(true)]</strong> attribute.</p>
<p><img src="http://blogs.southworks.net/jcisneros/files/2008/08/image2.png" border="0" alt="image" width="470" height="398" /></p>
<h3>Adding Metadata</h3>
<p>The generated scaffolds have all the common functions of a data-driven application, the list are filtered, sorted and paged, the fields in the edit and insert forms are validated according to its data types, etc., but it only does the best it can with all the metadata that can retrieve from the data model, therefore you will find that many things that can be improved or refined.</p>
<p>To add metadata to the model, Dynamic Data provides a full set of attributes under the <strong>System.ComponentModel.DataAnnotations</strong> namespace to be applied to the classes in the data model. But instead of applying the attributes directly over the generated code of the model you have to create partial classes aimed just to add metadata to the model.</p>
<p>Here, we&#8217;ll face a problem since a partial class can not redefine a property, thus we won&#8217;t be able to add metadata to the properties. This problem is solved by using an inner class and associating it to the data model class with the <strong>MetadataType</strong> attribute.</p>
<p>The following is a sample of a data model class using an inner class to refine the model:</p>
<blockquote><p><strong>[MetadataType(typeof(ProductMetadata))] </strong><br />
public partial class Product<br />
{<br />
private class ProductMetadata<br />
{<br />
<strong>[StringLength(30)]<br />
[Required(ErrorMessage = "Product name is required.")]<br />
[DisplayName("Product Name")] </strong><br />
public object Name { get; set; }</p>
<p><strong>[Range(0, 10000, ErrorMessage = "Standard Cost should be between {1} and {2}.")] </strong><br />
public object Price { get; set; }<br />
}<br />
}</p></blockquote>
<p>Since the inner class porpoise is to add meta data, the properties only need to match in name and not in type (in the sample, all the properties are of object type).</p>
<p>In this post by <a href="http://blogs.msdn.com/mairaw/default.aspx" target="_blank">María Wenzel</a> you will find a list with some of the attributes available: <a href="http://blogs.msdn.com/mairaw/archive/2008/04/24/dynamic-data-attributes.aspx" target="_blank">Dynamic Data Attributes</a>.</p>
<h3>Customizing the Templates</h3>
<p>Under the folder <strong>DynamicData</strong> you will find all the templates that Dynamic Data uses to generate the scaffolds. You can modify them to change the look and feel, or to add new functions for all the tables, but if you want to customize the templates for an specific table, you can, just follow these simple steps:<a href="http://blogs.southworks.net/jcisneros/files/2008/08/image3.png"><img src="http://blogs.southworks.net/jcisneros/files/2008/08/image-thumb1.png" border="0" alt="image" width="137" height="244" align="right" /></a></p>
<ol>
<li>Create a new folder with the name of the table you want to customize under the <strong>DynamicData\CustomPages</strong>.</li>
<li>Copy from <strong>DynamicData\PageTemplates</strong> the <strong>aspx</strong> templates you want to customize (i.e. <em>List.aspx</em>) and paste in the new folder.</li>
<li>Delete the code behind file of the new template (i.e. <em>List.aspx.cs</em> and <em>List.aspx.designer.cs</em>).</li>
<li>Customize the new template at your desire and using all of your creativity.</li>
</ol>
<p>Notice the use of conventions in this case that allows a friendly development experience. Dynamic Data will look for the templates, first under <strong>DynamicData\CustomPages\[TableToRender]</strong> and then under <strong>DynamicData\PageTemplates</strong>.</p>
<h2>Conclusions</h2>
<p>With ASP.NET Dynamic Data you can experience a nice development experience, it is easy to learn and to use. Some people may say that scaffolding is just for prototyping, I agree on that, but I found Dynamic Data very flexible and customizable, you may use it for a part of the application (where only CRUD operations are needed) and, for the rest of the application, continue developing as you are used to. Something that I noticed is a little of lack of performance, I think that it is caused by the use of reflection to get the metadata from the model. Anyway, it is a very interesting and nice framework that worth the try.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>.NET Framework 3.5 SP1 &#8211; Client Profile</title>
		<link>http://blogs.southworks.net/jcisneros/2008/07/25/net-framework-35-sp1-client-profile/</link>
		<comments>http://blogs.southworks.net/jcisneros/2008/07/25/net-framework-35-sp1-client-profile/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 11:47:11 +0000</pubDate>
		<dc:creator>jcisneros</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[SP1]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/jcisneros/?p=30</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/jcisneros/2008/07/25/net-framework-35-sp1-client-profile/" class="more-link">read more<img src="http://blogs.southworks.net/jcisneros/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>The .NET Framework 3.5 Client Profile is a lightweight subset of the full .NET Framework 3.5 aimed to be deployed in Client machines. Therefore, it only have the assemblies that are commonly used on client boxes and does not contains any server or development related assemblies.</p>
<p>This framework subset weight just 27Mb against the 200Mb of the full framework.</p>
<p>You can get the bits from here: <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=4F7AE6FE-F4D1-4196-A372-80EAB6D56332&amp;displaylang=en">Microsoft .NET Framework 3.5 Client Profile (BETA)</a></p>
<h3>How do you ensure your project will work for the .Net Framework Client Profile?</h3>
<p>It&#8217;s pretty easy, if you have installed the <a href="http://msdn.microsoft.com/en-us/vstudio/cc533448.aspx">Visual Studio 2008 SP1</a> in the project properties you will find a checkbox that allows to target your application to the Client Profile subset.</p>
<p><a href="http://blogs.southworks.net/jcisneros/files/2008/07/image.png"><img src="http://blogs.southworks.net/jcisneros/files/2008/07/image-thumb.png" border="0" alt="image" width="244" height="98" /></a></p>
<p>Visual Studio will verify all the references and will add an exclamation icon on the references that are not available for the client subset, also when building the project, warnings will be displayed for the unavailable assemblies.</p>
<p><a href="http://blogs.southworks.net/jcisneros/files/2008/07/image1.png"><img src="http://blogs.southworks.net/jcisneros/files/2008/07/image-thumb1.png" border="0" alt="image" width="209" height="244" /></a></p>
<p><a href="http://blogs.southworks.net/jcisneros/files/2008/07/image2.png"><img src="http://blogs.southworks.net/jcisneros/files/2008/07/image-thumb2.png" border="0" alt="image" width="244" height="59" /></a></p>
<p>If you got the beta version of the Visual Studio SP1 you have to take in mind that the subset list (Client.xml) that Visual Studio uses to validate the references is out of synch from the actually included assemblies (VS generate warnings for some assemblies that really are in the Client Profile). To solve this issue, you may find useful the Justin Van Patten&#8217;s blog post: <a href="http://blogs.msdn.com/bclteam/archive/2008/05/21/net-framework-client-profile-justin-van-patten.aspx">.NET Framework Client Profile</a>.</p>
<p><a href="http://technorati.com/claim/dfupkzeefw" rel="me">Technorati Profile</a></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# 3.0 new features</title>
		<link>http://blogs.southworks.net/jcisneros/2008/07/24/c-30-new-features/</link>
		<comments>http://blogs.southworks.net/jcisneros/2008/07/24/c-30-new-features/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 14:42:31 +0000</pubDate>
		<dc:creator>jcisneros</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/jcisneros/2008/07/24/c-30-new-features/</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/jcisneros/2008/07/24/c-30-new-features/" class="more-link">read more<img src="http://blogs.southworks.net/jcisneros/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>This post is aimed to be a quick abstract for all the new C# language constructs introduced with the version 3.0.</p>
<h2>Implicitly typed local variables</h2>
<p>By using <strong>var</strong> keyword to define a local (does not work at class level) variable is not needed to define its type, the compiler will infer it.</p>
<p><strong>Examples:</strong></p>
<p>var i = 0;    <br />var intArr = new[] { 0, 1, 2, 3 };</p>
<h2>Object and Collection Initializers</h2>
<p>Object&#8217;s properties can be initialized when creating the object and also the collection items.</p>
<p><strong>Examples:</strong></p>
<p>TextBox txt = new TextBox() { Text = &quot;John&quot;, Width = 200 };</p>
<p>List&lt;string&gt; colorspaces = new List&lt;string&gt; {&quot;RGB&quot;, &quot;CMYK&quot;, &quot;GreyScale&quot;, &quot;B/W&quot;};</p>
<h2>Anonymous types</h2>
<p>By combining the previous two features (<strong>Implicitly typed variables</strong> and <strong>Object initializers</strong>) you can create anonymous types (statically typed, with no name used in the code).</p>
<p><strong>Example:</strong></p>
<p>var guy = new { FirstName = &quot;John&quot;, LastName = &quot;Doe&quot; };    <br />Console.WriteLine(guy.FirstName);</p>
<h2>Automatically Implemented Properties</h2>
<p>You can create properties with no need for a private member to store its value.</p>
<p><strong>Examples:</strong></p>
<p>public string Name { get; set; } </p>
<p>//read-only property    <br />public byte Age { get; private set; }</p>
<h2>Extension methods</h2>
<p>By using the <strong>this</strong> keyword in a static method argument you can extend another class. You &quot;injects&quot; methods to an existing class from another one.</p>
<p><strong>Example:</strong></p>
<p>public static class ExtensionClass    <br />{     <br />&#160;&#160;&#160; //Extension method     <br />&#160;&#160;&#160; public static byte ToGray(<strong>this</strong> <strong>Color</strong> c)     <br />&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; return (byte)(0.3 * c.R + 0.59 * c.G + 0.11 * c.B);     <br />&#160;&#160;&#160; }     <br />}</p>
<p>byte pixelGray = Color.Green.ToGray();</p>
<h2>Lambda Expressions</h2>
<p>Lambda expressions are like pretty simple functions that takes input parameters and evaluates an expression.</p>
<p><strong>Syntax:</strong></p>
<pre>(input parameters) =&gt; expression</pre>
<p><strong>Examples:</strong></p>
<p>int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };<br />
  <br />int oddNumbers = numbers.Count(n =&gt; n % 2 == 1); </p>
<p>Console.WriteLine(oddNumbers.ToString()); </p>
<p>Func&lt;int, int&gt; duplicate = number =&gt; number * 2;<br />
  <br />Console.WriteLine(duplicate.Invoke(2).ToString());</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AOP with PostSharp</title>
		<link>http://blogs.southworks.net/jcisneros/2008/06/22/aop-with-postsharp/</link>
		<comments>http://blogs.southworks.net/jcisneros/2008/06/22/aop-with-postsharp/#comments</comments>
		<pubDate>Sun, 22 Jun 2008 04:49:58 +0000</pubDate>
		<dc:creator>jcisneros</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AOP]]></category>
		<category><![CDATA[PostSharp]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/jcisneros/?p=11</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/jcisneros/2008/06/22/aop-with-postsharp/" class="more-link">read more<img src="http://blogs.southworks.net/jcisneros/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.postsharp.org/" target="_blank">PostSharp</a> is a great open-source tool that allows you to encapsulate the non-business logic in custom attributes. That&#8217;s the <a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming" target="_blank">Aspect Oriented Programming</a> paradigm main goal: the separation of concerns.</p>
<p>This tool heps you to free the business logic from the infrastructure code such as:</p>
<ul>
<li>Transactions</li>
<li>Logging</li>
<li>Permissions / Security</li>
<li>Exceptions handling</li>
<li>Caching</li>
<li>Settings</li>
</ul>
<p>Your code will be cleaner than never.</p>
<p>&#8230;and why do I call it a &#8220;great tool&#8221;? Because, unlike other tools that uses reflection and other techniques that reduces performance, PostSharp works at <a href="http://en.wikipedia.org/wiki/Common_Intermediate_Language" target="_blank">MSIL</a> level!. It generates MSIL code to be injected in your code at compilation time, in that way it supports any .NET language and get the best performance possible.</p>
<p>Furthermore, this tool is really easy to learn. You can quickly get started by using the basic features, follow this simple quick start:</p>
<ul>
<li><strong><a href="http://www.postsharp.org/about/getting-started/">PostSharp &#8211; QuickStart</a></strong></li>
</ul>
<p>The following example shows a simple PostSharp aspect to trace the execution of the methods marked with that attribute:</p>
<p><span style="color: #0000ff">public</span> <span style="color: #0000ff"> class</span> <span style="color: #2b91af">SimplestTraceAttribute</span> : <span style="color: #2b91af">OnMethodBoundaryAspect<br />
</span>{<span style="color: #0000ff"><br />
public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff"> void</span> OnEntry( <span style="color: #2b91af">MethodExecutionEventArgs</span> eventArgs)<span style="font-size: small"> </span><br />
{<span style="color: #2b91af"><br />
Trace</span>.TraceInformation(<span style="color: #a31515">&#8220;Entering  					{0}.&#8221;</span>, eventArgs.Method);<span style="color: #2b91af"><br />
Trace</span>.Indent();<br />
}  <span style="color: #0000ff"><br />
public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff"> void</span> OnExit( <span style="color: #2b91af">MethodExecutionEventArgs</span> eventArgs)<br />
{<span style="color: #2b91af"><br />
Trace</span>.Unindent();<span style="color: #2b91af"><br />
Trace</span>.TraceInformation(<span style="color: #a31515">&#8220;Leaving  					{0}.&#8221;</span>, eventArgs.Method);<br />
}<br />
}</p>
<p>&#8230;and it works like a charm!</p>
<p><strong>The evidence:</strong></p>
<p><em>Building the project:</em></p>
<p><a href="http://blogs.southworks.net/jcisneros/files/2008/06/postsharp_build.jpg"><img class="alignnone size-medium wp-image-20" src="http://blogs.southworks.net/jcisneros/files/2008/06/postsharp_build.jpg" alt="" width="300" height="99" /></a></p>
<p><em>Inspecting the binaries:</em></p>
<p><a href="http://blogs.southworks.net/jcisneros/files/2008/06/postsharp_reflector.jpg"><img class="alignnone size-medium wp-image-19" src="http://blogs.southworks.net/jcisneros/files/2008/06/postsharp_reflector.jpg" alt="" width="300" height="208" /></a></p>
<p><em>Results:</em></p>
<p><a href="http://blogs.southworks.net/jcisneros/files/2008/06/postsharp_output.jpg"><img class="alignnone size-medium wp-image-21" src="http://blogs.southworks.net/jcisneros/files/2008/06/postsharp_output.jpg" alt="" width="300" height="108" /></a></p>
<h2>Resources:</h2>
<ul>
<li><a href="http://www.postsharp.org/" target="_blank">PostSharp Official WebSite</a> (see <a href="http://www.postsharp.org/about/" target="_blank">About PostSharp</a>)</li>
<li><a href="http://code.google.com/p/postsharp-user-samples/" target="_blank">Visual Basic PostSharp Samples</a></li>
</ul>
<p>Enjoy it!</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Managed Add-In Framework</title>
		<link>http://blogs.southworks.net/jcisneros/2008/06/16/managed-add-in-framework/</link>
		<comments>http://blogs.southworks.net/jcisneros/2008/06/16/managed-add-in-framework/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 21:05:32 +0000</pubDate>
		<dc:creator>jcisneros</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[AddIn]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/jcisneros/?p=9</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/jcisneros/2008/06/16/managed-add-in-framework/" class="more-link">read more<img src="http://blogs.southworks.net/jcisneros/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>In this post I will describe the basics of MAF to quickly introduce this framework.</p>
<p>The Managed Add-In Framework is an Add-In architecture built on top of the .Net Framework aimed to address the following problems:</p>
<ul>
<li>Loading/Unloading</li>
<li>Sandboxing (Add-ins can be sandboxed to a particular security permission set)</li>
<li>Isolation (isolation boundary between the Host and the Add-ins)</li>
<li>Lifetime Management</li>
<li>Discovery</li>
<li>Activation</li>
<li>Backwards compatibility</li>
<li>Forwards compatibility</li>
<li>Isolation changes (moving from AppDomain to Process isolation boundaries)</li>
<li>Sharing (taking an add-in built for one application and running it in another)</li>
</ul>
<p>A MAF solution usually have seven types of projects:</p>
<ul>
<li><strong>Host:<strong> </strong></strong>The main application that supports extensibility and manages the add-ins.</li>
<li><strong>Host View:</strong> Defines the functionalities that the host expects from the add-ins. The host will work against this view directly.</li>
<li><strong>Host Side Adapter: </strong>This is the glue between the Host View and the Contract. It has adapter classes that are used to convert to and from the host views and the contracts.</li>
<li><strong>Contract:</strong> The interfaces used to communicate between Host and Add-Ins.</li>
<li><strong>Add-In Side Adapter:</strong> This is the glue between the Add-In View and the Contract. It has adapter classes that are used to convert to and from the Add-In views and the contracts.</li>
<li><strong>Add-In View:</strong> Represents the Add-In view of the methods and object types used to communicate with the host.</li>
<li><strong>Add-In:</strong> An assembly loaded by the host to extend functionalities.</li>
</ul>
<p>For more details about contracts and adapters go to this post: <a href="http://blogs.msdn.com/jackg/archive/2005/09/15/468068.aspx">PDC05 &#8211; Managed AddIn Framework (MAF)</a></p>
<p>As you can deduce from the next picture the Host only references to the Host View and the Add-In only references to the Add-In view, so, each part hast its own view of the contract. In this way, if there is a new contract, it&#8217;s just necessary create new adapters to allow forward and backward compatibility.</p>
<p><a href="http://blogs.southworks.net/jcisneros/files/2008/06/maf.png"><img class="alignnone size-medium wp-image-10" src="http://blogs.southworks.net/jcisneros/files/2008/06/maf.png" alt="" width="300" height="60" /></a><br />
If you are thinking that it is too much effort to create so many projects I have good news for you, there is an Add-In for Visual Studio that generates the Add-In View, Add-In Adapter, Host View and the Host Adapter from the Contract project. You can find the add-in here: <a href="http://www.codeplex.com/clraddins/Wiki/View.aspx?title=Pipeline%20Builder&amp;referringTitle=Home">Pipeline Builder</a>.</p>
<h2>Creating a contract</h2>
<p>The first step to create a extensible host is to define a Contract. To do this you have to create a project with an Interface to define the functionalities that the host will expect from the add-ins. This interface have to derive from IContract and have to be marked with the AddInContract attribute. This is an example of an Contract:<br />
<code>using System;<br />
using System.AddIn.Pipeline;<br />
using System.AddIn.Contract;<br />
<br />
namespace Contracts<br />
{<br />
&nbsp;&nbsp;[AddInContract]<br />
&nbsp;&nbsp;public interface IHelloMAFContract : IContract<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;string SayHelloMAF();<br />
&nbsp;&nbsp;}<br />
}<br />
</code><br />
Then you can generate the basic Adapters and Views for the Host and Add-Ins using the  <a href="http://www.codeplex.com/clraddins/Wiki/View.aspx?title=Pipeline%20Builder&amp;referringTitle=Home">Pipeline Builder</a>.</p>
<p>The projects in a MAF solution should follow a defined file structure, for the Contract project, a possible output directory can be: &#8220;..\output\Contracts\&#8221;. You can find more details about the directory requirements in this topic: <a href="http://msdn.microsoft.com/en-us/library/bb384240.aspx" target="_blank">Pipeline Development Requirements</a>.</p>
<h2>Creating an Add-In</h2>
<p>To create an Add-In, you just have to create a project with a class implementing the contract from the AddInView project and marked with the AddIn attribute. The following is an example AddIn implementation:<br />
<code>using System;<br />
using System.AddIn;<br />
using Contracts.AddInViews;<br />
<br />
namespace AddInV1<br />
{<br />
&nbsp;&nbsp;[AddIn("AddInV1", Version="1.0.0.0")]<br />
&nbsp;&nbsp;public class AddInV1 : IHelloMAF<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;public string SayHelloMAF()<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return "Hello MAF!!";<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
}<br />
</code><br />
This project may be generated in the directory &#8220;..\Output\AddIns\AddInName\&#8221;.</p>
<h2>Discovering and activating the Add-Ins</h2>
<p>To discover the available Add-Ins the host can obtain a list of tokens that represents all the available Add-Ins of a specific type in a specific location. These tokens contains the Add-Ins information such as name and version, with that information then the host can decide which Add-Ins activate.</p>
<p>This is a sample code snippet for discovering and activating add ins:<br />
<code>static void Main()<br />
{<br />
&nbsp;&nbsp;// In this sample we expect the AddIns and components to<br />
&nbsp;&nbsp;// be installed in the current directory<br />
&nbsp;&nbsp;String addInRoot = Environment.CurrentDirectory;<br />
<br />
&nbsp;&nbsp;// Check to see if new AddIns have been installed<br />
&nbsp;&nbsp;AddInStore.Rebuild(addInRoot);<br />
<br />
&nbsp;&nbsp;// Look for Calculator AddIns in our root directory and<br />
&nbsp;&nbsp;// store the results<br />
&nbsp;&nbsp;Collection tokens =<br />
&nbsp;&nbsp;AddInStore.FindAddIns(typeof(Calculator), addInRoot);<br />
<br />
&nbsp;&nbsp;// Ask the user which AddIn they would like to use<br />
&nbsp;&nbsp;AddInToken calcToken = ChooseCalculator(tokens);<br />
<br />
&nbsp;&nbsp;// Activate the selected AddInToken in a new AppDomain set sandboxed<br />
&nbsp;&nbsp;// in the internet zone<br />
&nbsp;&nbsp;Calculator calculator = calcToken.Activate(AddInSecurityLevel.Internet);<br />
<br />
&nbsp;&nbsp;// Run the read-eval-print loop<br />
&nbsp;&nbsp;RunCalculator(calculator);<br />
}<br />
</code></p>
<h2>Further readings</h2>
<ul>
<li><a href="http://channel9.msdn.com/posts/DanielMoth/Managed-AddIn-Framework/" target="_blank">Channel 9 &#8211; Managed AddIn Framework, by Daniel Moth<br />
</a>(I highly recommend this video)</li>
<li><a title="CLR Add-In Team Blog" href="http://blogs.msdn.com/clraddins/default.aspx" target="_blank">CLR Add-In Team Blog</a></li>
<li><a href="http://msdn.microsoft.com/en-us/magazine/cc163476.aspx" target="_blank">CLR Inside Out &#8211; .NET Application Extensibility</a></li>
<li><a href="http://msdn.microsoft.com/en-us/magazine/cc163460.aspx" target="_blank">CLR Inside Out &#8211; .NET Application Extensibility, Part 2</a></li>
<li><a href="http://cskardon.wordpress.com/2008/04/08/managed-application-framework-part-1-the-beginnings/" target="_blank">Managed Application Framework &#8211; Part 1 &#8211; The Beginnings!</a> (this post has a quick MAF example)</li>
<li><a href="http://msdn.microsoft.com/en-us/library/bb384241.aspx" target="_blank">AddIn and Extensibility on MSDN</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
