tag:blogger.com,1999:blog-69371173093450200562024-03-12T22:51:23.291-07:00Do you like ITsharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.comBlogger19125tag:blogger.com,1999:blog-6937117309345020056.post-32190383131846150322009-09-18T04:25:00.000-07:002009-09-18T04:30:24.670-07:00WordPress doesn't bother to have a nice design on Google Chrome also<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiz64HgvpLuAzWZ8bz5Tln8IzcgJrqkNZGRTnOSKi8Oj1xQRAJOn_YGUKq4M74YKHFtDdoaWYLwuH4Z23lycfmkbtlcRgFW2Y8heJTvZM5C7Q_4SFFjqqTF29SsydrzCAXyBmZ2QTbFi2c/s1600-h/also-reproduced-for-search.png"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 293px; height: 120px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiz64HgvpLuAzWZ8bz5Tln8IzcgJrqkNZGRTnOSKi8Oj1xQRAJOn_YGUKq4M74YKHFtDdoaWYLwuH4Z23lycfmkbtlcRgFW2Y8heJTvZM5C7Q_4SFFjqqTF29SsydrzCAXyBmZ2QTbFi2c/s320/also-reproduced-for-search.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5382767943068664850" /></a>So word press doesn't like Google Chrome very much. Look at how they're Apple theme behaves.<br /><br /><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /><div><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH_dUFUKQz45GnsVr9fU23fVlvynaPGOqDqduGX6t7Wt3K4qxrsSOmus6UQYT2TgCZdJxivzWJHs1vBKwkDDsHsjV8yLriTM4tdPFC1qDeH5zqx36KLlKc7gmrVjUn11OeGPg8O7Ulkt8/s320/log-in-displayed-incorrectly-on-google-chrome.png" style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 293px; height: 120px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5382767344847988098" /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div>The same problem with the Search button. Guess there aren't enough Chrome users on line for wordpress to consider it being worth the attention.</div><div><br /></div></div>sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-4513408932056216222009-09-04T00:45:00.000-07:002009-09-04T00:48:03.877-07:00Did you think only Google Chrome has funny messages?<p>Today an interesting thing happen with firefox, it displayed the following message<p><br /><img height="300" width="444" src="http://geekswithblogs.net/images/geekswithblogs_net/Sharpoverride/10149/r_funny-firefox.png" title="funny firefox"/><br /><br />Looks like Google Chrome has a competitor for those Aw, Snap! messages.sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-72566369610551833672009-08-15T12:16:00.001-07:002009-08-15T12:18:45.609-07:00IoC in .NET part 1: Autofac<blockquote> <p>This is an interesting IoC project that I used in a couple of occasions, nothing big, but I sure enjoyed it immensely.</p> <p>Autofac is wrist friendly so to speak and it tries to solve your configuration problems in a simple and concise manner.</p> </blockquote> <p>Without further ado go at <a href="http://code.google.com/p/autofac/">http://code.google.com/p/autofac/</a> to get the latest version.</p> <p>Next I’ll try to create a simple example that I hope we’ll use for the most part of this series. </p> <blockquote> <p>In learning the inner workings of IoC containers we’ll develop a console application that provides some simple autocomplete for it’s features.</p> </blockquote> <p>The features of our application are:</p> <ul> <li><font color="#000000">Autocomplete for internal commands </font></li> <li><font color="#000000">Commands </font> <ul style="padding-left: 20px"> <li><font color="#000000">Alert – displays a message box </font></li> <li><font color="#000000">NewLine – goes to the next line </font></li> <li><font color="#000000">Calculator – with support for add </font></li> </ul> </li> </ul> <p><font color="#000000">All of this features will be organized under the <strong>Components</strong></font> folder as functions and services.</p> <p>In general you will want the concrete classes to be linked to an interface, and is by default the way I like to handle it. </p> <p>A lot of voices in the community are against the use of xml files for configuration, and to that regard Autofac offers the option of using a fluent interface for configuring the builder. Although good for contracts that you are not likely to change without recompiling the application, when you need to have functionality similar to that of a plug-in you will prefer to use an IoC capable of reading xml configuration. Obviously Autofac has support for xml files as well.</p> <blockquote> <p>Note xml configuration support is very limited in Autofac, so I’ll only show the bootstraping for this file</p> </blockquote> <p>As I said earlier an IoC is just a form of factory, the only real difference is that this is a factory with nice configuration capabilities.</p> <p>In more complex applications I recommend you use modules for configuring but for this example is sufficient to have everything configured in only one place.</p> <p>As a preference I always configure the IoC I’m using in a class called Bootstrap in my highest level module ( commonly identified as the assembly containing the Main function, or if in a web app the assembly that contains the Global.asax).</p> <p>The code for the Bootstrap.cs looks like this:</p> <pre class="code"><span style="background: #101a26; color: #40c4ff">public class </span><span style="background: #101a26; color: cyan">Bootstrap<br /> </span><span style="background: #101a26; color: #e0e0e0">{<br /> </span><span style="background: #101a26; color: #40c4ff">public static </span><span style="background: #101a26; color: cyan">IContainer </span><span style="background: #101a26; color: #eddac0">Components</span><span style="background: #101a26; color: #e0e0e0">(){<br /> </span><span style="background: #101a26; color: #40c4ff">var </span><span style="background: #101a26; color: #eddac0">builder </span><span style="background: #101a26; color: silver">= </span><span style="background: #101a26; color: #40c4ff">new </span><span style="background: #101a26; color: cyan">ContainerBuilder</span><span style="background: #101a26; color: #e0e0e0">(); <br /> <br /> </span><span style="background: #101a26; color: #eddac0">builder</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">Register</span><span style="background: #101a26; color: silver"><</span><span style="background: #101a26; color: cyan">ConsoleClearScreen</span><span style="background: #101a26; color: silver">></span><span style="background: #101a26; color: #e0e0e0">()</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">As</span><span style="background: #101a26; color: silver"><</span><span style="background: #101a26; color: cyan">IClearScreen</span><span style="background: #101a26; color: silver">></span><span style="background: #101a26; color: #e0e0e0">()</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">SingletonScoped</span><span style="background: #101a26; color: #e0e0e0">();<br /> </span><span style="background: #101a26; color: #eddac0">builder</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">Register</span><span style="background: #101a26; color: silver"><</span><span style="background: #101a26; color: cyan">ConsoleWriteString</span><span style="background: #101a26; color: silver">></span><span style="background: #101a26; color: #e0e0e0">()</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">As</span><span style="background: #101a26; color: silver"><</span><span style="background: #101a26; color: cyan">IWriteString</span><span style="background: #101a26; color: silver">></span><span style="background: #101a26; color: #e0e0e0">()</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">SingletonScoped</span><span style="background: #101a26; color: #e0e0e0">();<br /> <br /> </span><span style="background: #101a26; color: #eddac0">builder</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">Register</span><span style="background: #101a26; color: silver"><</span><span style="background: #101a26; color: cyan">AlarmFunctionState</span><span style="background: #101a26; color: silver">></span><span style="background: #101a26; color: #e0e0e0">()</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">As</span><span style="background: #101a26; color: silver"><</span><span style="background: #101a26; color: cyan">IFunctionState</span><span style="background: #101a26; color: silver">></span><span style="background: #101a26; color: #e0e0e0">()</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">Named</span><span style="background: #101a26; color: #e0e0e0">( </span><span style="background: #004566; color: #f55f16">"AlarmFunctionState"</span><span style="background: #101a26; color: #e0e0e0"> );<br /> </span><span style="background: #101a26; color: #eddac0">builder</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">Register</span><span style="background: #101a26; color: silver"><</span><span style="background: #101a26; color: cyan">NewLineFunctionState</span><span style="background: #101a26; color: silver">></span><span style="background: #101a26; color: #e0e0e0">()</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">As</span><span style="background: #101a26; color: silver"><</span><span style="background: #101a26; color: cyan">IFunctionState</span><span style="background: #101a26; color: silver">></span><span style="background: #101a26; color: #e0e0e0">()</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">Named</span><span style="background: #101a26; color: #e0e0e0">( </span><span style="background: #004566; color: #f55f16">"NewLineTransition"</span><span style="background: #101a26; color: #e0e0e0"> );<br /> </span><span style="background: #101a26; color: #eddac0">builder</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">Register</span><span style="background: #101a26; color: silver"><</span><span style="background: #101a26; color: cyan">CalculatorFunctionState</span><span style="background: #101a26; color: silver">></span><span style="background: #101a26; color: #e0e0e0">()</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">As</span><span style="background: #101a26; color: silver"><</span><span style="background: #101a26; color: cyan">IFunctionState</span><span style="background: #101a26; color: silver">></span><span style="background: #101a26; color: #e0e0e0">()</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">Named</span><span style="background: #101a26; color: #e0e0e0">( </span><span style="background: #004566; color: #f55f16">"CalculatorTransition"</span><span style="background: #101a26; color: #e0e0e0"> );<br /><br /><br /> </span><span style="background: #101a26; color: #eddac0">builder</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">Register</span><span style="background: #101a26; color: silver"><</span><span style="background: #101a26; color: cyan">IConsoleInputService</span><span style="background: #101a26; color: silver">></span><span style="background: #101a26; color: #e0e0e0">(<br /> </span><span style="background: #101a26; color: #eddac0">c </span><span style="background: #101a26; color: silver">=> </span><span style="background: #101a26; color: #40c4ff">new </span><span style="background: #101a26; color: cyan">ConsoleInputServiceImpl</span><span style="background: #101a26; color: #e0e0e0">(<br /> </span><span style="background: #101a26; color: #40c4ff">new </span><span style="background: #101a26; color: cyan">IFunctionState</span><span style="background: #101a26; color: #e0e0e0">[]{<br /> </span><span style="background: #101a26; color: #eddac0">c</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">Resolve</span><span style="background: #101a26; color: silver"><</span><span style="background: #101a26; color: cyan">IFunctionState</span><span style="background: #101a26; color: silver">></span><span style="background: #101a26; color: #e0e0e0">(</span><span style="background: #004566; color: #f55f16">"AlarmFunctionState"</span><span style="background: #101a26; color: #e0e0e0">),<br /> </span><span style="background: #101a26; color: #eddac0">c</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">Resolve</span><span style="background: #101a26; color: silver"><</span><span style="background: #101a26; color: cyan">IFunctionState</span><span style="background: #101a26; color: silver">></span><span style="background: #101a26; color: #e0e0e0">(</span><span style="background: #004566; color: #f55f16">"NewLineTransition"</span><span style="background: #101a26; color: #e0e0e0">),<br /> </span><span style="background: #101a26; color: #eddac0">c</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">Resolve</span><span style="background: #101a26; color: silver"><</span><span style="background: #101a26; color: cyan">IFunctionState</span><span style="background: #101a26; color: silver">></span><span style="background: #101a26; color: #e0e0e0">(</span><span style="background: #004566; color: #f55f16">"CalculatorTransition"</span><span style="background: #101a26; color: #e0e0e0">)<br /> } ) );<br /><br /> </span><span style="background: #101a26; color: #40c4ff">return </span><span style="background: #101a26; color: #eddac0">builder</span><span style="background: #101a26; color: silver">.</span><span style="background: #101a26; color: #eddac0">Build</span><span style="background: #101a26; color: #e0e0e0">();<br /> }<br /> }</span></pre><br /><br /><p><a href="http://11011.net/software/vspaste"></a><font color="#000000">Autofac uses the <strong>ContainerBuilder</strong> class to register services and it offers a simple method of directly creating those services through the use of lambda expressions.</font></p><br /><br /><p>For the actual implementation of the app you can download the source code <a href="http://iocquest.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=31609">here</a>.</p> sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-70013066764669279582009-08-13T00:57:00.001-07:002009-08-13T00:57:59.353-07:00Checkout the Windows 7 API Code Pack for .NET<h1></h1> <p>The individual features supported in this version (v1.0) of the library are:</p> <ul> <li>Windows 7 Taskbar Jump Lists, Icon Overlay, Progress Bar, Tabbed Thumbnails, and Thumbnail Toolbars. </li> <li>Windows 7 Libraries, Known Folders, non-file system containers. </li> <li>Windows Shell Search API support, a hierarchy of Shell Namespace entities, and Drag and Drop functionality for Shell Objects. </li> <li>Explorer Browser Control. </li> <li>Shell property system. </li> <li>Windows Vista and Windows 7 Common File Dialogs, including custom controls. </li> <li>Windows Vista and Windows 7 Task Dialogs. </li> <li>Direct3D 11.0, Direct3D 10.1/10.0, DXGI 1.0/1.1, Direct2D 1.0, DirectWrite, Windows Imaging Component (WIC) APIs. (DirectWrite and WIC have partial support) </li> <li>Sensor Platform APIs </li> <li>Extended Linguistic Services APIs </li> <li>Power Management APIs </li> <li>Application Restart and Recovery APIs </li> <li>Network List Manager APIs </li> <li>Command Link control and System defined Shell icons. </li> </ul> <p> </p> <p>More details at : <a href="http://code.msdn.microsoft.com/WindowsAPICodePack">http://code.msdn.microsoft.com/WindowsAPICodePack</a> and <a href="http://www.infoq.com/news/2009/08/WIndows-7-DotNET">http://www.infoq.com/news/2009/08/WIndows-7-DotNET</a></p> sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-80879748197882996922009-08-13T00:56:00.000-07:002009-08-13T00:57:09.598-07:00Javascript gotcha<blockquote><br /> <p>Usually the style you organize code is just that A MATTER OF STYLE, in javascript however it’s not.</p><br /></blockquote><br /><br /><p>If by any chance you end up writing the following code:</p><br /><br /><p> </p><br /><br /><pre class="code"><span style="background: #101a26; color: #40c4ff">var </span><span style="background: #101a26; color: #eddac0">display </span><span style="background: #101a26; color: silver">= </span><span style="background: #101a26; color: #40c4ff">function</span><span style="background: #101a26; color: #e0e0e0">() {<br /> </span><span style="background: #101a26; color: #40c4ff">this</span><span style="background: #101a26; color: #e0e0e0">.</span><span style="background: #101a26; color: #eddac0">x </span><span style="background: #101a26; color: silver">= </span><span style="background: #101a26; color: #ff80ff">10</span><span style="background: #101a26; color: #e0e0e0">;<br /> </span><span style="background: #101a26; color: #40c4ff">return<br /> </span><span style="background: #101a26; color: #e0e0e0">{<br /> </span><span style="background: #101a26; color: #eddac0">alert</span><span style="background: #101a26; color: silver">: </span><span style="background: #101a26; color: #40c4ff">function</span><span style="background: #101a26; color: #e0e0e0">(</span><span style="background: #101a26; color: #eddac0">message</span><span style="background: #101a26; color: #e0e0e0">) {<br /> </span><span style="background: #101a26; color: #eddac0">window</span><span style="background: #101a26; color: #e0e0e0">.</span><span style="background: #101a26; color: #eddac0">alert</span><span style="background: #101a26; color: #e0e0e0">(</span><span style="background: #101a26; color: #eddac0">message</span><span style="background: #101a26; color: #e0e0e0">);<br /> }<br /> }<br />}</span></pre><br /><br /><p>you might be in for a surprise but it won’t return anything because by default the javascript interpreter inserts <font face="Courier New"><font size="2">; <font face="Arial">after every line that doesn’t already contain it or <font size="3" face="Courier New">}</font>.</font></font></font></p><br /><br /><p><font size="2">Instead you should write:</font></p><br /><br /><pre class="code"><span style="background: #101a26; color: #40c4ff">var </span><span style="background: #101a26; color: #eddac0">display </span><span style="background: #101a26; color: silver">= </span><span style="background: #101a26; color: #40c4ff">function</span><span style="background: #101a26; color: #e0e0e0">() {<br /> </span><span style="background: #101a26; color: #40c4ff">this</span><span style="background: #101a26; color: #e0e0e0">.</span><span style="background: #101a26; color: #eddac0">x </span><span style="background: #101a26; color: silver">= </span><span style="background: #101a26; color: #ff80ff">10</span><span style="background: #101a26; color: #e0e0e0">;<br /> </span><span style="background: #101a26; color: #40c4ff">return </span><span style="background: #101a26; color: #e0e0e0">{<br /> </span><span style="background: #101a26; color: #eddac0">alert</span><span style="background: #101a26; color: silver">: </span><span style="background: #101a26; color: #40c4ff">function</span><span style="background: #101a26; color: #e0e0e0">(</span><span style="background: #101a26; color: #eddac0">message</span><span style="background: #101a26; color: #e0e0e0">) {<br /> </span><span style="background: #101a26; color: #eddac0">window</span><span style="background: #101a26; color: #e0e0e0">.</span><span style="background: #101a26; color: #eddac0">alert</span><span style="background: #101a26; color: #e0e0e0">(</span><span style="background: #101a26; color: #eddac0">message</span><span style="background: #101a26; color: #e0e0e0">);<br /> }<br /> }<br />}</span></pre><br /><br /><p><a href="http://11011.net/software/vspaste"></a>More interesting notes you can find in the next video:</p><br /><br /><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:e0ec5e44-500d-4605-98b9-4ac7f67382b3" class="wlWriterEditableSmartContent"><embed src="http://www.youtube.com/v/hQVTIJBZook" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></div><br /><br /><blockquote><br /> <p>Hope you enjoyed this I sure did :D.</p><br /></blockquote>sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-26951054236302117462009-08-13T00:55:00.001-07:002009-08-13T00:55:38.829-07:00What is an IoC ?<blockquote> <p>Disclaimer: This is a series of posts in which we’ll go through the IoC’s that are used in today’s applications</p> </blockquote> <p>The most simple answer I can give you is this: </p> <blockquote> <p>It’s an abstraction over Factory Method.</p> </blockquote> <p>It helps, in my opinion to think of this as a factory method, because then you know what to expect of it, since it constructs/resolves a specific implementation based on the configuration you provide it.</p> <p>In a factory method you write, aka “hard code”, the implementation you will be using. In an IoC container you basically do the same except it’s easier to change, if you write it in the xml file since using it in code leaves you with what you started and never got to changing it.</p> <p>However, an IoC has an additional plus over the hand coded factory, that is “It is able to construct objects  based on the configuration you supplied”.</p> <blockquote> <p>Does it help ?</p> </blockquote> <p>Oh yes it helps. There’s a principle in software that states “High level modules should not depend on low level modules, both should depend on abstractions”. And guess what the principle I just stated is the Dependecy Injection Principle, it is an important point to note since IoC containers are often referred  to as Dependency Injectors. So you will probably find the IoC/DI whenever reading about an IoC.</p> <p>With the help of an IoC you can declare dependencies of you object using abstractions, usually in the form of interfaces and/or base classes.</p> <blockquote> <p>In the next part will explore a couple of IoC’s that the .NET has to offer as well as from the outside of the .NET ecosistem.</p> <p>I hope that by the end of this series we can form a summary of benefits and deduct some ground rules for choosing a certain IoC, or deciding if we need it.</p></blockquote> sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-28397150399293466052009-06-25T00:59:00.001-07:002009-06-25T00:59:32.757-07:00Starting a simple ASP.NET Web App<h1>Summary: </h1> <p>In this post we will discuss the tooling that is at our disposal and also some of the benefits or not so beneficial features it brings to the table.</p> <p> </p> <h1>Content</h1> <p> </p> <ul> <li>Introduction </li> <li>Tooling </li> <li>Benefits of using it </li> </ul> <h1>Introduction</h1> <p>ASP.NET MVC is Microsoft's way of getting on the MVC wagon. It offers a lot more control over the application you're building, no more WebControls ( personally I never and hope to never have to use it ), pure XHTML as W3C would have you doing anyways.</p> <p>At this moment, and I suspect for years to come, the market of web-apps is under the heavy influence of dynamic languages like Ruby, PHP, Groovy, Python etc. Although scripting languages, a couple of strong frameworks have arisen, from them the most important of all is Rails, a MVC framework that set the bar for all the frameworks to come, so to speak. The other contestants that I find worth mentioning are Joomla (PHP), Grails ( Groovy ), Pylons and Django (Python).</p> <p>We, the .NET guys, needed something like that for a while, of course there was MonoRails for years, but it didn't get enough publicity. Now there is the Microsoft's solution ASP.NET MVC, and also another project from the OSS ( Open Source Space ) called FubuMVC, wich is an opinionated front-controller style framework. I'll talk about FubuMVC in another post though.</p> <p> </p> <h1>Tooling</h1> <p>First there is Visual Studio, and then there is <a title="ASP.NET download page" href="http://www.asp.net/MVC/download/">this</a> add-on you have to install from <a href="http://www.asp.net/MVC/download/">http://www.asp.net/MVC/download/</a>.</p> <p>Next you have to go to File->New Project. And select from the Web category the Asp.NET MVC Web Application projec type.</p> <p> </p> <p><img alt="Create-New-Project" src="http://geekswithblogs.net/images/geekswithblogs_net/Sharpoverride/10149/r_NewProjectScreen.png" width="430" height="362" /></p> <p>Next you'll be displayed the following screen that let's you decide if you'll be using tests or not</p> <p><img alt="Add-tests-project" src="http://geekswithblogs.net/images/geekswithblogs_net/Sharpoverride/10149/r_AddTestsScreen.png" width="475" height="317" /></p> <p>For this part of the post it is not needed. Press ok and a sample project is created for you.</p> <p>Let's have a look at the solution:</p> <p><img style="float: left" alt="Screen solution" src="http://geekswithblogs.net/images/geekswithblogs_net/Sharpoverride/10149/r_Solution-Screen.png" width="290" height="484" />You can see that the content is organized in</p> <p> </p> <ul> <li>Content </li> <li>Controllers </li> <li>Models </li> <li>Scripts </li> <li>Views </li> </ul> <div>There are three files left out, Default.aspx, Global.asax and Web.config. They are files that the ASP.NET engine expects to find in a web-project, kind'a like Java web-servers expect a certain layout of your project. It is a convention so we'll leave it at that.</div> <div> <br /></div> <div>In the Content directory you'll put your css files, images, documents and whatever else is considered to be content. The Scripts directory contains javascript files. This is the way they organize by default, you can roll your own, for instance you could have an Assets directory that has everything organized a certain way. There are no conventions so you're free to invent them.</div> <div> <br /></div> <div>The import part, the C in the MVC pattern, are the Controllers.They direct the flow and supply the models to the views, and that's enough of a responsability.</div> <div> <br /></div> <div>The nice part, the V in the MVC pattern, are the Views. They display data to the user and accept input through HTML Forms.</div> <div> <br /></div> <div>The core part, the M in the MVC pattern, are the Models. This layout is mostly inspired by the Domain Driven Design book, Eric Evans wrote a long time ago, but it changed the way many people, myself included, think about design.</div> <div>I think that the Model part of the application is the most missunderstood part of the hole MVC pattern. The model is, in my vision, composed of the distinct parts: The Domain and The Services. The Domain is composed of entites and value objects, more info on the subject you can find at <a title="Domain Driven Design Quickly" href="http://www.infoq.com/minibooks/domain-driven-design-quickly">InfoQ Domain Driven Design Quickly</a>. The Services are the business part of the model.</div> <div>Don't worry I'll talk a bit more on the subject on the next part of this post.</div> <div>Tools, tools and tools. If you left click a controller you'll see there's a button ready to generate the controller for you.</div> <div><img alt="add-controller" src="http://geekswithblogs.net/images/geekswithblogs_net/Sharpoverride/10149/r_AddController.png" width="290" height="118" /></div> <div>Next let's create a simple EchoController.</div> <div><img alt="add-controller-screen" src="http://geekswithblogs.net/images/geekswithblogs_net/Sharpoverride/10149/r_Add-controller-screen.png" width="385" height="160" /></div> <div>Don select the add actions for.. since we'll not use it, just press Add. As you'll se the controller already has a Index method provided. That's a convention set in the Global.asax.cs file, by default the Index method is assumed when accesing a controller. Just to shed some light on the matter let's Debug (F5) the project. Press Ok when it asks you if you're to enable debugging on the Web.config file.</div> <div> <br /></div> <div>By default the Home/Index action is executed when a request is sent to the http://localhost:{development-port}/. That's because it was registered as the Default controller and action in the Global.asax.cs file. If you want to access the EchoController you'll have to write http://localhost:{development-port}/Echo. That will match the request to the EchoController and the Index action. If you do this you'll se a nice Yellow Screen Of Death.</div> <div>Why? because we haven't added a view. The convention is that you have define in the Views folder, a Echo folder and add a Index.aspx page. Let's see to go about doing this. There are basically to options, but first stop the debugging ( since this is not a scripting language ).</div> <div>Option No.1 By adding the folder Echo to the Views directory and Add-> View from the context menu, or Option No.2, right click inside the Index method in the EchoController class. And select Add View from the context menu. That is going to create everything for us, </div> <div><img alt="" src="http://geekswithblogs.net/images/geekswithblogs_net/Sharpoverride/10149/r_Add-View_from-Controller.png" width="462" height="160" /></div> <div>and it let's us choose what type of view we want ( Details, Create, Edit, List, Empty), that's if we supply a model, but for the sake of simplicity we won't at this time</div> <div><img alt="" src="http://geekswithblogs.net/images/geekswithblogs_net/Sharpoverride/10149/r_Add-View-Screen.png" width="351" height="374" /> <br /></div> <div> <br /></div> <div>If you right click on the view, you'll have the option to go to the controller, similar, you can navigate from to the action to the view.</div> <div>The rest of the tooling support is the standard editing and intellisense you've probably used with .NET previously. The Editor for the aspx pages could use alot of improvements, but that's for VS2010 I suppose.</div> <h1>Benefits of using it</h1> <p>For one you get a much richer experience since you have :</p> <p> </p> <ul> <li>Friendly URLS </li> <li>Alot more control over the generated XHTML and Javascript ( since you write it ) </li> <li>Easier testing of you workflow and services </li> <li>Better separation of concerns </li> <li>A powerfull architecture that allows you to even ditch the hole View-Engine and implement your own, or you could try <a title="spark view engine" href="http://www.sparkviewengine.com/">Spark </a>for a run. </li> </ul> <div>In the next post I'll discuss how to set up a startup project on a simple theme that I've done with Spring MVC a couple of months back.</div> sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-77207717929928589292009-06-03T23:09:00.000-07:002009-06-03T23:28:49.819-07:00Finally Windows Mobile 6.5 is out<p>Too bad it didn't arive sooner, I had to make a small app using some mobile technology this year at the faculty and I had to settle on Windows 6 SDK, wich was well what you would have expected from something written in 2007.<br /></p><br /><p><br /><img src="http://www.productwiki.com/upload/images/windows_mobile_6_5.gif" style="float:left"/><br />It looks pretty nice, but that's to be expected since it will try to expand on the market that smartphones like iPhone is gaining more and more terrain. Microsoft is trying to keep it's products in line with the design that operating systems like Vista or Windows 7.<br /></p><br /><p><br />It's my feeling that this only the beggining of the other releases they have scheduled for this year (or the next), releases like: Windows 7, Visual Studio 2010, Office 2010, .NET 4.0. They might be comming with other things also, but I those I named are the ones I'm interested in, office not so much, but who knows what my work will lead me to.<br /></p>sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-78522700380628601142009-04-14T01:04:00.000-07:002009-04-14T03:10:35.046-07:00<h2> Another TCP/IP Server client </h2><br /><p><br /> Well, it seems I'm supposed to write another Socket based server client application. Since usually all you find on the web are Chat Clones, I decided<br />to use the time and get a really basic framework going.<br /></p><br /><p> First off, we have a basic client </p><br /><pre name="code" class="c-sharp"><br />namespace BaseNetworkProtocol<br />{<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> using System.Net;<br /> using System.Net.Sockets;<br /> using System.ComponentModel;<br /> using System.IO;<br /> /// <summary><br /> /// The class that contains some methods and properties to manage the remote clients.<br /> /// </summary><br /> public class Client<br /> {<br /> public ProtocolContext Context;<br /> <br /> /// <summary><br /> /// Gets the IP address of connected remote client.This is 'IPAddress.None' if the client is not connected.<br /> /// </summary><br /> public IPAddress IP<br /> {<br /> get<br /> {<br /> if ( this.socket != null)<br /> return ( (IPEndPoint)this.socket.RemoteEndPoint ).Address;<br /> else<br /> return IPAddress.None;<br /> }<br /> }<br /> /// <summary><br /> /// Gets the port number of connected remote client.This is -1 if the client is not connected.<br /> /// </summary><br /> public int Port<br /> {<br /> get<br /> {<br /> if ( this.socket != null)<br /> return ( (IPEndPoint)this.socket.RemoteEndPoint ).Port;<br /> else<br /> return -1;<br /> }<br /> }<br /> /// <summary><br /> /// [Gets] The value that specifies the remote client is connected to this server or not.<br /> /// </summary><br /> public bool Connected<br /> {<br /> get<br /> {<br /> if ( this.socket != null )<br /> return this.socket.Connected;<br /> else<br /> return false;<br /> }<br /> }<br /><br /> private Socket socket;<br /> <br /> NetworkStream networkStream;<br /> private BackgroundWorker bwReceiver;<br /><br /> #region Constructor<br /> /// <summary><br /> /// Creates an instance of ClientManager class to comunicate with remote clients.<br /> /// </summary><br /> /// <param name="clientSocket">The socket of ClientManager.</param><br /> public Client(Socket clientSocket, ProtocolContext context)<br /> {<br /> this.Context = context;<br /> <br /> this.socket = clientSocket;<br /> this.networkStream = new NetworkStream(this.socket);<br /> this.bwReceiver = new BackgroundWorker();<br /> this.bwReceiver.DoWork += new DoWorkEventHandler(StartReceive);<br /> this.bwReceiver.RunWorkerAsync();<br /> } <br /> #endregion<br /><br /> #region Private Methods<br /> private void StartReceive(object sender , DoWorkEventArgs e)<br /> {<br /> while ( this.socket.Connected )<br /> {<br /> //Read the command's Type.<br /> //byte [] buffer = new byte [sizeof(long)];<br /> //int readBytes = this.networkStream.Read(buffer , 0 , 4);<br /> //if ( readBytes == 0 )<br /> // break;<br /> <br /> BasePacket packet = new BasePacket();<br /> try<br /> {<br /> packet = Context.Reader.Read(networkStream);<br /> }<br /> catch (IOException ioex)<br /> {<br /> Disconnect();<br /> }<br /><br /> this.OnPacketReceived(new PacketEventArgs(packet));<br /> }<br /> this.OnDisconnected(new ClientEventArgs(this.socket));<br /> this.Disconnect();<br /> }<br /><br /> private void bwSender_RunWorkerCompleted(object sender , RunWorkerCompletedEventArgs e)<br /> {<br /> if ( !e.Cancelled && e.Error == null && ( (bool)e.Result ) )<br /> this.OnPacketSent(new EventArgs());<br /> else<br /> this.OnPacketFailed(new EventArgs());<br /><br /> ( (BackgroundWorker)sender ).Dispose();<br /> GC.Collect();<br /> }<br /><br /> private void bwSender_DoWork(object sender , DoWorkEventArgs e)<br /> {<br /> BasePacket packet = (BasePacket)e.Argument;<br /> e.Result = this.SendPacketToClient(packet);<br /> }<br /><br /> //This Semaphor is to protect the critical section from concurrent access of sender threads.<br /> System.Threading.Semaphore semaphor = new System.Threading.Semaphore(1 , 1);<br /> private bool SendPacketToClient(BasePacket packet)<br /> {<br /><br /> try<br /> {<br /> semaphor.WaitOne();<br /><br /> Context.Writer.Write(networkStream, packet);<br /> networkStream.Flush();<br /> #region Removed Source<br /> ////Type<br /> //byte [] buffer = new byte [4];<br /> //buffer = BitConverter.GetBytes((int)cmd.PacketType);<br /> //this.networkStream.Write(buffer , 0 , 4);<br /> //this.networkStream.Flush();<br /><br /> <br /> //if (cmd.PacketType != PacketType.Frame)<br /> //{<br /> // //Meta Data.<br /> // if (cmd.MetaData == null || cmd.MetaData == "")<br /> // cmd.MetaData = "\n";<br /><br /> // byte[] metaBuffer = Encoding.Unicode.GetBytes(cmd.MetaData);<br /> // buffer = new byte[4];<br /> // buffer = BitConverter.GetBytes(metaBuffer.Length);<br /> // this.networkStream.Write(buffer, 0, 4);<br /> // this.networkStream.Flush();<br /> // this.networkStream.Write(metaBuffer, 0, metaBuffer.Length);<br /> // this.networkStream.Flush();<br /> //}<br /> //else<br /> //{<br /><br /> // WepFrame encryptedFrame = new WepEncryption(this.Context).For(cmd.Frame);<br /><br /> // new WepFrameWriter(networkStream).Write(encryptedFrame);<br /> //}<br /> #endregion<br /> semaphor.Release();<br /> return true;<br /> }<br /> catch<br /> {<br /> semaphor.Release();<br /> return false;<br /> }<br /> }<br /> #endregion<br /><br /> #region Public Methods<br /> /// <summary><br /> /// Sends a command to the remote client if the connection is alive.<br /> /// </summary><br /> /// <param name="cmd">The command to send.</param><br /> public void SendPacket(BasePacket packet)<br /> {<br /> if ( this.socket != null && this.socket.Connected )<br /> {<br /> BackgroundWorker bwSender = new BackgroundWorker();<br /> bwSender.DoWork += new DoWorkEventHandler(bwSender_DoWork);<br /> bwSender.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bwSender_RunWorkerCompleted);<br /> bwSender.RunWorkerAsync(packet);<br /> }<br /> else<br /> this.OnPacketFailed(new EventArgs());<br /> }<br /><br /> <br /><br /> /// <summary><br /> /// Disconnect the current client manager from the remote client and returns true if the client had been disconnected from the server.<br /> /// </summary><br /> /// <returns>True if the remote client had been disconnected from the server,otherwise false.</returns><br /> public bool Disconnect()<br /> {<br /> if (this.socket != null && this.socket.Connected )<br /> {<br /> try<br /> {<br /> this.socket.Shutdown(SocketShutdown.Both);<br /> this.socket.Close();<br /> return true;<br /> }<br /> catch<br /> {<br /> return false;<br /> }<br /> }<br /> else<br /> return true;<br /> } <br /> #endregion<br /><br /> #region Events<br /> /// <summary><br /> /// Occurs when a command received from a remote client.<br /> /// </summary><br /> public event PacketReceivedEventHandler PacketReceived;<br /> /// <summary><br /> /// Occurs when a command received from a remote client.<br /> /// </summary><br /> /// <param name="e">Received command.</param><br /> protected virtual void OnPacketReceived(PacketEventArgs e)<br /> {<br /> if ( PacketReceived != null )<br /> PacketReceived(this , e);<br /> }<br /><br /> /// <summary><br /> /// Occurs when a command had been sent to the remote client successfully.<br /> /// </summary><br /> public event PacketSentEventHandler PacketSent;<br /> /// <summary><br /> /// Occurs when a command had been sent to the remote client successfully.<br /> /// </summary><br /> /// <param name="e">The sent command.</param><br /> protected virtual void OnPacketSent(EventArgs e)<br /> {<br /> if ( PacketSent != null )<br /> PacketSent(this , e);<br /> }<br /><br /> /// <summary><br /> /// Occurs when a command sending action had been failed.This is because disconnection or sending exception.<br /> /// </summary><br /> public event PacketSendingFailedEventHandler PacketFailed;<br /> /// <summary><br /> /// Occurs when a command sending action had been failed.This is because disconnection or sending exception.<br /> /// </summary><br /> /// <param name="e">The sent command.</param><br /> protected virtual void OnPacketFailed(EventArgs e)<br /> {<br /> if ( PacketFailed != null )<br /> PacketFailed(this , e);<br /> }<br /><br /> /// <summary><br /> /// Occurs when a client disconnected from this server.<br /> /// </summary><br /> public event DisconnectedEventHandler Disconnected;<br /> /// <summary><br /> /// Occurs when a client disconnected from this server.<br /> /// </summary><br /> /// <param name="e">Client information.</param><br /> protected virtual void OnDisconnected(ClientEventArgs e)<br /> {<br /> if ( Disconnected != null )<br /> Disconnected(this , e);<br /> }<br /><br /> #endregion<br /> }<br />}<br /><br /></pre><br /><p><br /> As you can see this is a basic wrapper for the System.Net.Socket class, and it uses a ProtcolContext (listed below ).<br /></p><br /><pre name="code" class="c-sharp"><br />namespace BaseNetworkProtocol<br />{<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> public class ProtocolContext<br /> {<br /> public IProtocolWriter Writer { get; set; }<br /> public IProtocolReader Reader { get; set; }<br /> }<br />}<br /></pre><br /><p>which in turn uses a ProtocolReader for reading, and ProtocolWriter for writing to the stream.</p><br /><pre name="code" class="c-sharp"><br />public interface IProtocolReader<br /> {<br /> BasePacket Read( Stream stream);<br /><br /> }<br /></pre><br /><p> and </p><br /><pre name="code" class="c-sharp"><br />public interface IProtocolWriter<br /> {<br /> void Write(Stream stream,BasePacket packet);<br /> }<br /></pre><br /><p> And they read everything into a </p><br /><pre name="code" class="c-sharp"><br />public class BasePacket<br /> {<br /> public byte[] Data { get; set; }<br /> }<br /></pre><br /><p> For convenience I've written down two implementations, that should be sufficient for any type of extension use </p><br /><pre name="code" class="c-sharp"><br />using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Text;<br />using System.IO;<br /><br />namespace BaseNetworkProtocol<br />{<br /> public class BaseProtocolReader:IProtocolReader<br /> {<br /> #region IProtocolReader Members<br /><br /> public virtual BasePacket Read(System.IO.Stream stream)<br /> {<br /> <br /> byte[] dataLength = new byte[sizeof(int)];<br /> stream.Read(dataLength, 0, dataLength.Length);<br /> int length = BitConverter.ToInt32(dataLength, 0);<br /><br /><br /> byte[] data = new byte[length];<br /> stream.Read(data, 0, length);<br /> BasePacket packet = new BasePacket();<br /> packet.Data = data;<br /> return packet;<br /> <br /> <br /> }<br /><br /> #endregion<br /> }<br />}<br /><br /></pre><br /><p> And </p><br /><pre name="code" class="c-sharp"><br />using System;<br />using System.Collections.Generic;<br />using System.Text;<br />using System.Linq;<br />namespace BaseNetworkProtocol<br />{<br /> public class BaseProtocolWriter : IProtocolWriter<br /> {<br /> #region IProtocolWriter Members<br /><br /> public virtual void Write(System.IO.Stream stream, BasePacket packet)<br /> {<br /> byte[] dataLength = BitConverter.GetBytes(packet.Data.Length);<br /> stream.Write(dataLength,0,dataLength.Length);<br /> stream.Write(<br /> packet.Data,<br /> 0,<br /> packet.Data.Length<br /> );<br /> }<br /><br /> #endregion<br /> }<br />}<br /><br /></pre><br /><p>As I said this should be very testable, and here is a simple test for it </p><br /><pre name="code" class="c-sharp"><br />using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Text;<br />using Microsoft.VisualStudio.TestTools.UnitTesting;<br />using BaseNetworkProtocol;<br />using System.IO;<br /><br />namespace BaseNetworkProtocolTests<br />{<br /> [TestClass]<br /> public class TestBaseProtcols<br /> {<br /> [TestMethod]<br /> public void should_write_and_read_the_packet_sent()<br /> {<br /> // Arrange<br /> IProtocolWriter writer = new BaseProtocolWriter();<br /> IProtocolReader reader = new BaseProtocolReader();<br /><br /> BasePacket packet = new BasePacket();<br /> packet.Data = new byte[] { 1, 2, 3 };<br /><br /> MemoryStream communicationChannel = new MemoryStream();<br /> // Act<br /><br /> writer.Write(communicationChannel, packet);<br /> communicationChannel.Position = 0;<br /> BasePacket receivedPacket = reader.Read(communicationChannel);<br /> // Assert<br /> Assert.IsNotNull(packet);<br /> Assert.IsNotNull(receivedPacket);<br /> Assert.IsNotNull(packet.Data);<br /> Assert.IsNotNull(receivedPacket.Data);<br /> Assert.AreEqual(packet.Data.Length, receivedPacket.Data.Length);<br /> for (int dataIndex = 0; dataIndex < packet.Data.Length; dataIndex++)<br /> {<br /> Assert.AreEqual(packet.Data[dataIndex],receivedPacket.Data[dataIndex]);<br /> }<br /> // Clean up<br /> communicationChannel.Close();<br /> communicationChannel.Dispose();<br /> }<br /> }<br /><br />}<br /><br /></pre><br /><p><br />All that's left is to provide some type of protocols to it. And, that's through the use of two Services the ClientService, and the ServerService.<br /></p><br /><pre name="code" class="c-sharp"><br />using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Text;<br />using System.Net.Sockets;<br />using System.Net;<br />using FinancialServer.Properties;<br />using BaseNetworkProtocol;<br />using Core.Utils;<br />using System.Threading;<br /><br />namespace FinancialServer.Services<br />{<br /> internal class ServerService : IServer<br /> {<br /> Socket _socket;<br /> Client _currentClient;<br /> ProtocolContext _context;<br /> public ServerService(ProtocolContext context)<br /> {<br /> _context = context;<br /> }<br /> #region IServerService Members<br /><br /> public void Start()<br /> {<br /> _socket = new Socket(<br /> AddressFamily.InterNetwork,<br /> SocketType.Stream,<br /> ProtocolType.Tcp);<br /> _socket.Bind(new IPEndPoint(<br /> IPAddress.Parse(Settings.Default.ServerAddress),<br /> Settings.Default.Port));<br /><br /> _socket.Listen(5);<br /> //using(var resolver = Program.Container.CreateInnerContainer()){<br /><br /> new Thread(AcceptClients).Start();<br /> //}<br /><br /> }<br /><br /> public void AcceptClients()<br /> {<br /> while (Program.Resolve<IServer>().IsConnected)<br /> {<br /> try<br /> {<br /> _currentClient = new Client(<br /> _socket.Accept(), Program.Resolve<ProtocolContext>());<br /> }<br /> catch (SocketException soex)<br /> {<br /> // TODO: Log it<br /> break;<br /> }<br /> _currentClient.PacketReceived +=<br /> (sender, @event) =><br /> {<br /> Client _sender = (Client)sender;<br /> string request = new ResponsePacket(@event.Packet).Message<string>();<br /> var result = Program.Resolve<IRequestProcessor>().Process(request);<br /> if (result != null)<br /> {<br /> _sender.SendPacket(<br /> new RequestPacket(<br /> result<br /> ).Packet<br /> );<br /> }<br /> //if (request.Equals("1 + 1"))<br /> //{<br /> // _sender.SendPacket<br /> // (new RequestPacket("2").Packet);<br /> //}<br /><br /> };<br /> }<br /> }<br /> <br /> public void Send(string message)<br /> {<br /> BasePacket packet = new BasePacket();<br /> packet.Data = System.Text.Encoding.Unicode.GetBytes(message);<br /> _currentClient.SendPacket(packet);<br /><br /> }<br /><br /> public bool IsConnected<br /> {<br /> get<br /> {<br /> return _socket.IsBound;<br /> }<br /> }<br /> public void Close()<br /> {<br /> if (IsConnected)<br /> _socket.Close();<br /> }<br /> #endregion<br /> }<br />}<br /><br /></pre><br /><br /><p> The client </p><br /><pre name="code" class="c-sharp"><br />using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Text;<br />using BaseNetworkProtocol;<br />using System.Net.Sockets;<br />using System.Net;<br />using FinancialClient.Properties;<br />using Core;<br />using Core.Services;<br /><br />namespace FinancialClient.Services<br />{<br /> public class ClientService : IClientService<br /> {<br /> ProtocolContext context;<br /> Client client;<br /> public ClientService(IProtocolReader reader,<br /> IProtocolWriter writer)<br /> {<br /> context = new ProtocolContext();<br /> context.Reader = reader;<br /> context.Writer = writer;<br /> }<br /><br /> #region IClientService Members<br /><br /> public bool Connect()<br /> {<br /> Socket socket =<br /> new Socket(AddressFamily.InterNetwork,<br /> SocketType.Stream,<br /> ProtocolType.Tcp);<br /> try<br /> {<br /> socket.Connect(<br /> IPAddress.Parse(Settings.Default.ServerAddress),<br /> Settings.Default.Port);<br /> client = new Client(<br /> socket,<br /> context);<br /> <br /><br /> }catch(SocketException ex){<br /> //using (var resolver = Program.Container.CreateInnerContainer())<br /> //{<br /> Program.Resolve<IErrorService>().Log(ex);<br /> //}<br /> return false;<br /> }<br /> return true;<br /> }<br /> public void SendPacket(BasePacket packet)<br /> {<br /> client.SendPacket(packet);<br /> <br /> }<br /> public void ReceivePacket(PacketReceivedEventHandler executeOnReceive)<br /> {<br /> client.PacketReceived += executeOnReceive;<br /> }<br /> public bool IsConnected<br /> {<br /> get<br /> {<br /> return client.Connected;<br /> }<br /> }<br /> <br /> #endregion<br /> }<br />}<br /><br /></pre><br /><p> The communication is done through serialized objects like this </p><br /><pre name="code" class="c-sharp"><br />using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Text;<br />using BaseNetworkProtocol;<br />using System.Runtime.Serialization;<br />using System.Runtime.Serialization.Formatters.Binary;<br />using System.IO;<br /><br />namespace Core.Utils<br />{<br /> public class RequestPacket<br /> {<br /> BasePacket basePacket;<br /> public RequestPacket(object request)<br /> {<br /> basePacket = new BasePacket();<br /><br /> IFormatter formatter = new BinaryFormatter();<br /> MemoryStream buffer = new MemoryStream();<br /> formatter.Serialize(buffer, request);<br /> this.basePacket.Data = buffer.ToArray();<br /> }<br /> public BasePacket Packet { get { return basePacket; } }<br /> }<br />}<br /><br /></pre><br /><p>And </p><br /><br /><pre name="code" class="c-sharp"><br />using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Text;<br />using BaseNetworkProtocol;<br />using System.Runtime.Serialization.Formatters.Binary;<br />using System.Runtime.Serialization;<br />using System.IO;<br /><br />namespace Core.Utils<br />{<br /> public class ResponsePacket<br /> {<br /> private readonly object message;<br /> public ResponsePacket(BasePacket response)<br /> {<br /> if (response.Data == null) {<br /> message = null;<br /> <br /> return; }<br /> IFormatter formatter = new BinaryFormatter();<br /> using(MemoryStream ms =<br /> new MemoryStream(response.Data.ToArray()))<br /> message = formatter.Deserialize(ms);<br /> }<br /> public TOBject Message<TOBject>(){<br /> <br /> return (TOBject) message;<br /> <br /> }<br /><br /> }<br />}<br /><br /></pre><br /><p><br /> <strong><em>Note:</em></strong> This has been an extreeemly loong post. And it's so for me to remind myself all of this classes, so I don't go and search the web for solutions that I don't find simple and extensible enough for my needs. At least it's my code, so if something doesn't work I know who to blame.<br /></p>sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-10972137222891314492009-04-13T00:43:00.000-07:002009-04-13T00:57:10.354-07:00Creating a 2 steps expression based linkThis is a simple post highliting how to build a quick extension to HtmlHelper.<br />You'll need to use the MVC Futures extensions<br /><br />For the extension all you need is this<br /><pre name="code" class="c-sharp"><br />namespace Microsoft.Web.Mvc<br />{<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Diagnostics.CodeAnalysis;<br /> using System.Linq.Expressions;<br /> using System.Web;<br /> using System.Web.Mvc;<br /> using System.Web.Mvc.Html;<br /> using System.Web.Routing;<br /> using Microsoft.Web.Mvc;<br /> public static class MyLinkExtensions<br /> {<br /> public static void BeginLink<TController>(this HtmlHelper helper,<br /> Expression<Action<TController>> action<br /> ) where TController : Controller<br /> {<br /> BeginLink(helper,<br /> action,<br /> new { });<br /> }<br /> public static void BeginLink<TController>(this HtmlHelper helper,<br /> Expression<Action<TController>> action,<br /> object htmlAttributes) where TController : Controller<br /> {<br /> BeginLink(helper,<br /> action,<br /> new RouteValueDictionary(htmlAttributes));<br /> }<br /> public static void BeginLink<TController>(this HtmlHelper helper,<br /> Expression<Action<TController>> action,<br /> IDictionary<string, object> htmlAttributes) where TController : Controller<br /> {<br /> TagBuilder builder = new TagBuilder("a");<br /> builder.MergeAttributes(htmlAttributes);<br /> string href = Microsoft.Web.Mvc.LinkExtensions.BuildUrlFromExpression(helper, action);<br /> builder.MergeAttribute("href", href);<br /><br /> HttpResponseBase httpResponse = helper.ViewContext.HttpContext.Response;<br /> httpResponse.Write(builder.ToString(TagRenderMode.StartTag));<br /><br /> }<br /><br /> public static void EndLink(this HtmlHelper helper)<br /> {<br /> TagBuilder tagBuilder = new TagBuilder("a");<br /> HttpResponseBase httpResponse = helper.ViewContext.HttpContext.Response;<br /> httpResponse.Write(tagBuilder.ToString( TagRenderMode.EndTag));<br /> }<br /> }<br />}<br /></pre><br /><p><br />And to use it, all you need is something like :<br /><pre name="code" class="html"><br /><% Html.BeginLink < HomeController >( c=> c.About() ); %><br />Link text<br /><% Html.EndLink(); ><br /></pre><br /></p><br /><p><strong>Note:</strong> Don't forget to add Microsoft.Web.Mvc to the namespaces that the view uses </p>sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-11586899343681961472008-09-27T13:21:00.001-07:002008-09-27T13:29:34.393-07:00Codesqueez<p>I've started reading about Agile Methodologies. I thought I knew all the stories. Man was I wrong. There is a lot more to Agile than what I thought.</p><br /><p><br />Right now I'm struggling with Velocity and assigning points to user stories. Well I'll find the solution maybe when it's not so late :D.</p><br /><p><br />For the moment I found this really cool post <a href="http://www.codesqueeze.com/my-agile-wall-plus-a-few-tricks/">here</a>. If you're interested in increasing your team's speed I urge you to have a look at Agile and learn it.</p><br /><p><br />As usual I'm learning by myself, university keeps disappointing me in this. For our collective project they asked us to use Agile and TDD. LOL - that was a nice. I ended up writing most of it myself. I won't do that never again! ( I hope :-s ).</p><br /><p> As usual I continue to babble and I like having a conclusion to what I'm pointing towards ( just in case I haven't already ). So give <a href="http://www.codesqueeze.com/">codesqueez</a> a try for some examples of applied agile.sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-55377594746964101642008-09-26T13:03:00.000-07:002008-09-26T13:29:19.356-07:00Why do developers choose Microsoft® ?<p><br /><b>Note:</b> This is a post I will probably update once I get more ideas or thoughts I want to share. :)<br /><p><br /><p><br /> It should come as no surprise that the majority of today's developer are mostly focused on technologies built on and for the frameworks offered by Microsoft®. <br /><br /> The topic of this post is why is that? <br/><br /> Basically we have an always evolving Market, that is always asking for better tooling and better software. Microsoft® is the biggest supplier of such software having their own operating system, as well as great development tools like Visual Studio and a platform like .Net that makes it easier, faster and funnier to develop programs.<br /></p> Microsoft also offers Visual Studio® as Express Edition. What this means is that you have people curios about developing on the platforms offered by Microsoft® some nice tools with obvious limitations that let's them test the products and even develop programs.<br /></p><br /><p><br /> Whenever you ask someone that is "old" in the industry ( by old I mean he has 10 years+ experience in the field ) they will always choose Microsoft® technologies because life is nicer when it's safer, and with Microsoft® you have the assurance that they will continue to improve the technologies that you are offered.<br /></p><br /><p> Most of the times they offer limitations to the products you are offered because there will always be those who will fill the loop holes for personal gain. <br /></p><br /><p> It's basically a symbiotic relationship, we pay Microsoft for the software we use. Others pay us to use and extend these products. To be honest I haven't really found any other software organization that gives so many extension points.<br /></p><br /><p> There are obviously those who hate that Microsoft® makes so much money and forces you to use their system and that it doesn't integrate nicely with stuff that was not built for their framework. I sometimes wish that I could write once deploy everywhere. <br/><br />Well There is Mono. And my hopes are that they will do what Microsoft didn't directly do. Novel is the firm that's behind Mono, although it's an open-source project funding comes from the private domain, and Novel has partnerships with Microsoft. <br/><br /> Thinking of conspiracies and such is beyond me. The point is that Microsoft® offers security and a lot of jobs. Since in order to live we require money, it's probably best to have security over hate ;). Just go with the flow and never settle for just one thing.<br /><p>sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-82822411572286972592008-09-17T02:18:00.000-07:002008-09-17T02:26:52.098-07:00Hidden gems of Generic TypesThis post could have been called "How to find that a type is of a certain generic type ?"<br />The solution is so simple I would like not to tell you about it, but just in case it will help someone here it goes :<br /><pre name="code" class="c-sharp"><br /><br />typeof(int?).GetGenericTypeDefinition() == typeof(Nullable<>)<br /><br /></pre><br /><br />The example is from something I needed to find out. Whenever you generate a nullable type it gets converted by the compiler into a Nullable<type>. E.g. int? --> Nullable<int>. So the example above should be suffice to point you in the right direction if you're searching for a way to find out if a certain object is of a nullable type ;).<br /><br />Enjoy and take care.sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-12777906041149594702008-09-01T02:35:00.001-07:002008-09-01T02:38:54.650-07:00I give upI've got to 22 words/minute with the keyboard. but since I need to write fast at work since I don't have the resilience to think fast and write slow.. I'm kind'a giving up on the new keyboard at least during the time I need to write fast code.<br /><br />The really funny part is when I switch from to the other. It's true that I can't expect to switch from something I've used 6+ years to a new layout over night.<br /><br />Well I'll see what I dosharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-21706020566738364842008-08-30T23:33:00.000-07:002008-08-30T23:55:40.059-07:00Rough changesI find that it's necessary to challenge yourself from time to time.<br /><br />I recently wrote about the qwerty layout, it's designed to make your fingers move allot because that's what solved an engineering problem with the typewriter patented by Sholes. <br /><blockquote>The QWERTY keyboard layout was devised and created in the early 1870s by Christopher Sholes, a newspaper editor and printer who lived in Milwaukee.<br /><br />With the assistance of his friends Carlos Glidden and Samuel W. Soule he built an early writing machine for which a patent application was filed in October 1867.[3] However, Sholes' "Type Writer" had many defects: the printing point was located beneath the paper carriage, and so was invisible to the operator. Consequently, the tendency of the typebars to clash and jam if struck in rapid succession was a particularly serious problem, in that the mishap would only be discovered when the typist raised the carriage to inspect what had been typed.[4]<br /><br />Sholes struggled for the next six years to perfect his invention, making many trial-and-error rearrangements of the original machine's alphabetical key arrangement in an effort to reduce the frequency of typebar clashes. Eventually he arrived at a four-row, upper case keyboard approaching the modern QWERTY standard. In 1873 Sholes' backer, James Densmore, succeeded in selling manufacturing rights for the Sholes-Glidden "Type Writer" with E. Remington and Sons and within the following few months the keyboard layout was finalised by Remington's mechanics. Their adjustments included placing the "R" key in the place previously allotted to the period mark, thus enabling salesmen to impress customers by pecking out the brand name "TYPE WRITER" from one keyboard row. Vestiges of the original alphabetical layout remained in the "home row" sequence FGHJKL.[4]</blockquote><br /><br />But where does that leave us? Computers don't have this problem. Why did we get stuck with this faulty layout? The reason is very obvious most people got so used with it that they just started demanding it. And where there's demand there is also offer ( a really symbiotic relationship ).<br /><br />Getting back on track.. since I found Colemak to be the nicest and newest layout I started learning it. After 5 years of only QWERTY you can imagine how hard learning to walk on the keyboard again has been. Plus that I don't look at the keyboard so I had to keep a mental representation of this new keyboard.<br /><br />But although the mental stress was hard after 2 days I was able to write this post ;) so all in all it was a nice experience. Are you reader up for it ?sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-19709735000744307082008-08-29T02:05:00.000-07:002008-08-29T05:46:26.548-07:00What Keyboard layout is best suited ?In school no one told us that there are more than one keyboard layout. The truth is I don't know how many people know this fact.<br /><br />Right about now you might be wondering what is the point of this post. A friend of mine asked me the other night how did they come to use the QWERTY layout? At time my thought was, what a dumb question to ask? What do I care how they've come to using it. I mean everyone has a QWERTY keyboard.<br /><br />The question stuck with me, and I decided to do a Google search. Of course the first thing I found was a Wikipedia article: <a href="http://en.wikipedia.org/wiki/Qwerty">http://en.wikipedia.org/wiki/Qwerty</a>. As it goes it looks like the QWERTY layout was the best layout for typewriters so they wouldn't get stuck. My thought was WTF!!! It looks like after several years of try-and-error Christopher Sholes found a pattern that would suit typewriters. By suit I mean they were ok since you weren't able to write too fast and the printing points wouldn't collide.<br /><br />Well it looks like since the first computer programs were written on a typewriter later when they had to have a keyboard for more evolved form of typewriters aka the PC they kept this format not because it was the best.. but because everyone got accustomed to it. Hurray for them, bad for us.<br /><br />Another dude known as Dr. August Dvorak published in 1963 after carefully studying the human hand and the frequency of certain letters came up with a new layout that doesn't require such wide movements of the fingers <a href="http://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard">http://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard</a>. <br /><br />Now we're taking this is something that resulted after studying certain patterns and that is supposed to increase the speed at which we write.<br /><br />The latest and probably the greatest layout is <a href="http://www.colemak.com/">Colemak</a>. You can read all you want about it on they're web site. And I strongly encourage you to give it a lot of thought and consideration to this issues especially if you're in the writers bench and if you're interested in improving you're speed.<br /><br />Also try learning how to write without looking at your keys. It's really easy and you can master it really fast. It's even better if you do this with one of the more advanced layouts.sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-45396786293904665622008-08-27T03:55:00.001-07:002008-08-29T05:46:01.359-07:00Writing meaningfull tests<p>Recently I came across a post from Phil Haack ( <a href="http://haacked.com/archive/2008/08/24/introducing-subspec.aspx">http://haacked.com/archive/2008/08/24/introducing-subspec.aspx</a> ) in wich he talked a bit about Behaviour Driven Development.<br />After that I reached Dan North's blog (<a href="http://dannorth.net/introducing-bdd">http://dannorth.net/introducing-bdd</a>) and I was sold.</p><br /><p><br />Today I started playing ( instead of working ) with Ninject to see what it was capable of. I have to say I love the site it's really fun. The Docs are also very well thought. After playing with the example a bit and doing testing of course so that I may reach a better understanding of the framework here's what I have :<br /></p><br /><code><!-- code formatted by http://manoli.net/csharpformat/ --><br /><br /><pre name="code" class="c-sharp"><br /><br />class NinjaSpec<br /> {<br /> IWarrior _warrior;<br /> IKernel _kernel;<br /> [Specification]<br /> public void TheNinjaShouldBeGivenAShuriken()<br /> {<br /> "There once was a great master".Context(<br /> ()=><br /> {<br /> _kernel = new StandardKernel(new BootstrapModule());<br /> }<br /> );<br /> "Given that the Ninja is Ninject's best range warrior".Do(<br /> () =><br /> {<br /><br /> _warrior = _kernel.Get<Ninja>();<br /> }<br /> );<br /> "He gave to the Ninja a mighty weapon called shuriken".Assert(<br /> () =><br /> {<br /> Assert.IsType<Shuriken>(((Ninja)_warrior).Weapon);<br /> }<br /> );<br /> }<br /> }<br /></pre><br /><br />You tell me now is that something or not. I mean even a child understands what's going on here :D.sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0tag:blogger.com,1999:blog-6937117309345020056.post-4224213853515745122008-08-19T05:05:00.000-07:002008-08-29T05:46:46.531-07:00WTF is wrong with Alt.NETI was going to visit http://altdotnet.org today. After reading the introduction, very excited I was trying to log in using my blogspot openid.<br /><br />Surprise "You must use an OpenID persona that specifies a valid email address."<br /><br />My mind was WTF!!! of course. I've used this in an ever growing number of websites without having problems.<br /><br />I've seen that I had problems using it on Scott Hanselman's blog also. I'm curios what the reason could be. :(sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com3tag:blogger.com,1999:blog-6937117309345020056.post-64531810280465206572008-07-17T10:41:00.000-07:002008-08-27T05:16:58.311-07:00Hello World!It's my first post. Since all thinks in my day to day life as a programmer start best with Hello World! this is what I use.<br /><br />I don't expect to blog to much but I do wanna start doing it. There are so many things and technologies I do wanna cover things I find interesting. Plus I don't expect anyone to read it.. at first anyway.<br /><br />Since there is not too much to cover for know this will have to do.sharpoverridehttp://www.blogger.com/profile/13551728913300865903noreply@blogger.com0