<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>csharp &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/csharp/</link>
	<description>Feed of posts on WordPress.com tagged "csharp"</description>
	<pubDate>Wed, 23 Dec 2009 18:00:51 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[C# Regular Expression Helper]]></title>
<link>http://markour.net/2009/12/22/regexui/</link>
<pubDate>Tue, 22 Dec 2009 06:48:27 +0000</pubDate>
<dc:creator>alibad</dc:creator>
<guid>http://markour.net/2009/12/22/regexui/</guid>
<description><![CDATA[One component of an application I&#8217;m writing uses a lot of regular expressions. To be sure I wa]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>One component of an application I&#8217;m writing uses a lot of regular expressions. To be sure I was using the right regular expressions, I&#8217;ve created this simple tiny tool to help me learn and verify regular expressions against my input data. Nothing fancy, but it might help someone out there.</p>
<p>For example, it took me a little while trying to find the proper regular expression to match all comments in an Xml file.</p>
<p><a title="Download" href="http://cid-e38f9fc6490b29d9.skydrive.live.com/self.aspx/Public/Code/RegexHelper/RegexUI.exe"><img src="http://alibad.wordpress.com/files/2009/12/regexhelp.jpg" alt="C# Regular Expression Helper" /></a></p>
<p>Download <a title="Regular Expression Helper Executable" href="http://cid-e38f9fc6490b29d9.skydrive.live.com/self.aspx/Public/Code/RegexHelper/RegexUI.exe">exe</a> or <a title="Regular Expression Helper C# Source Code" href="http://cid-e38f9fc6490b29d9.skydrive.live.com/self.aspx/Public/Code/RegexHelper/RegexUI.zip">source</a>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Speeding Up Linq To Sql Queries Using Custom Objects]]></title>
<link>http://atheladev.wordpress.com/2009/12/21/speeding-up-linqtosql-queries-using-custom-objects/</link>
<pubDate>Mon, 21 Dec 2009 22:21:47 +0000</pubDate>
<dc:creator>soniiic</dc:creator>
<guid>http://atheladev.wordpress.com/2009/12/21/speeding-up-linqtosql-queries-using-custom-objects/</guid>
<description><![CDATA[It might seem like a sudden change for me to blog about C# and ASP.NET MVC but it&#8217;s what I wor]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>It might seem like a sudden change for me to blog about C# and ASP.NET MVC but it&#8217;s what I work with at my work and I&#8217;m loving it.  Plus I haven&#8217;t had the inspiration to use django in months.  From now on, most posts will be about C#, ASP.NET MVC, HTML, CSS, and many other acronyms&#8230;</p>
<p>This may be already have been obvious to you but I had been working with a slow query for a number of days before I really realised what was going on.</p>
<p>Here&#8217;s the scenario: You want to show a list of two or more fields from different sql tables on a single page but for some reason the longer the list gets, the page just keeps taking longer and longer to load.</p>
<p><!--more--> In this example the fields to be demonstrated will be the forename, surname and city of residence of people.  The db contains three tables: person, personname and address.</p>
<p>Simply put, you may do something like this in your controller:</p>
<pre class="brush: csharp;">
public ActionResult ViewAll() {
    IQueryable&#60;Person&#62; persons = (from person in this.db.Persons
                                  select person);
    return View(persons);
}
</pre>
<p>and this in your view:</p>
<pre class="brush: csharp; html-script: true;">
&#60;table&#62;
&#60;% foreach(Person person in Model) { %&#62;
&#60;tr&#62;
&#60;td&#62;&#60;%= person.PersonName.Forename %&#62;&#60;/td&#62;
&#60;td&#62;&#60;%= person.PersonName.Surname %&#62;&#60;/td&#62;
&#60;td&#62;&#60;%= person.Address.City %&#62;&#60;/td&#62;
&#60;/tr&#62;
&#60;%}%&#62;
&#60;/table&#62;
</pre>
<p>If you code this up and use <a href="http://www.u2u.info/Blogs/Kris/Lists/Posts/Post.aspx?ID=11">Vandermotten&#8217;s DebuggerWriter</a> you&#8217;ll see that it goes to the db each time it needs to look up the entry for the personname table or the address table.  On a very long list, you can imagine that so many db calls (although quick to execute) can take up a huge chunk of time.</p>
<p>This is where we use a custom object to be filled with the specific fields we require.  This means as soon as the variable is enumerated, it&#8217;s populated with everything we need!</p>
<pre class="brush: csharp;">
public class MyPerson {
    public MyPerson(string forename, string surname, string city) {
        this.Forename = forename;
        this.Surname = surname;
        this.City = city;
    }

    public string Forename {get; private set;}
    public string Surname {get; private set;}
    public string City {get; private set;}
}

public ActionResult ViewAll() {
    IQueryable&#60;MyPerson&#62; fasterPersons = (from person in this.db.Persons
                               select new MyPerson(person.PersonName.Forename, person.PersonName.Surname, person.Address.City));
    return View(fasterPersons);
}
</pre>
<p>This new Linq will execute just the once and enumerate the MyPerson object with just the right info for each and every person in the table.</p>
<p>The view will have to be changed just slightly to:</p>
<pre class="brush: csharp; html-script: true;">
&#60;table&#62;
&#60;% foreach(MyPerson myPerson in Model) { %&#62;
&#60;tr&#62;
&#60;td&#62;&#60;%= myPerson.Forename %&#62;&#60;/td&#62;
&#60;td&#62;&#60;%= myPerson.Surname %&#62;&#60;/td&#62;
&#60;td&#62;&#60;%= myPerson.City %&#62;&#60;/td&#62;
&#60;/tr&#62;
&#60;%}%&#62;
&#60;/table&#62;
</pre>
<p>And there you have it.  This finished code will just execute the once and so will speed up the page load incredibly!  In a development platform I was seeing page load times dropping from ~2secs to 12ms.</p>
<p>Hope this helps anyone out there who just managed to find themselves here</p>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:228px;width:1px;height:1px;overflow:hidden;">
<pre> htmlscript="true"</pre>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Performance tips - minification and deferred JavaScript loading]]></title>
<link>http://nraykov.wordpress.com/2009/12/09/performance-tips-minification-and-deferred-javascript-loading/</link>
<pubDate>Tue, 08 Dec 2009 22:03:20 +0000</pubDate>
<dc:creator>Nikolay Raykov</dc:creator>
<guid>http://nraykov.wordpress.com/2009/12/09/performance-tips-minification-and-deferred-javascript-loading/</guid>
<description><![CDATA[In the past few years a lot of research has been done on page load times and where the hot spots occ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In the past few years a lot of research has been done on page load times and where the hot spots occur. Surprisingly around 90% of the page load time is spent inside the browser. Why could this be happenning and what can be done in order to reduce these numbers?</p>
<p><span style="text-decoration:underline;"><strong>How browsers work?</strong></span></p>
<p>When a page is requested it is downloaded, parsed and rendered. During the rendering phase a lot is going on behind the scenes &#8211; static resources referenced by the page are downloaded, parsed and executed (in case of CSS and JavaScript). These static resources require additional HTTP requests which might dramatically slow down the loading of the page. Browsers have a limit of requests that could be performed in parallel, hence the resources are downloaded somewhat sequentially. The numbers differ from browser to browser, but in general two image files could be downloaded in parallel from a single domain, only a single JavaScript file could be downloaded at a time which also blocks the rendering of the page.</p>
<p><span style="text-decoration:underline;"><strong>JavaScript hot spots</strong></span></p>
<p>In this article the subject of interest are the bottlenecks that arise from requesting JavaScript files. There are different steps that could be taken to tune the page load time that is influenced by script files &#8211; minification and compression, combining all scripts in a single file (this is the recommended approach for CSS as well). There are several tools that are available for this purpose &#8211; <a href="http://www.crockford.com/javascript/jsmin.html" target="_blank">JSMin</a> and <a href="http://developer.yahoo.com/yui/compressor/" target="_blank">YUI Compressor</a> (there is a <a href="http://www.codeplex.com/YUICompressor" target="_blank">.NET version</a> that could be used in a MSBuild task) are some of them. You could make significant performance gains by minimizing and compressing &#8211; that could really be felt if your users are on a slow internet connection. By combining your scripts the browser will make only a single HTTP request which results in faster load times.</p>
<p>I will show you how to use YUI Compressor for .NET to combine and minify JavaScript files with MSBuild. To get started you need to copy Yahoo.Yui.Compressor.dll and EcmaScript.NET.modified.dll assemblies to your project. Create a so called project file (XML file that is constructed according to the MSBuild XML Schema definition) that is used to instruct the build engine what to do. I will not get into the details because MSBuild is not the subject of this post. Here is the project file:</p>
<pre style="font-size:small;color:black;font-family:Consolas;background-color:#ffffff;overflow:auto;"><span style="color:#0000ff;">&#60;?</span><span style="color:#800000;">xml</span> <span style="color:#ff0000;">version</span><span style="color:#0000ff;">="1.0"</span> <span style="color:#ff0000;">encoding</span><span style="color:#0000ff;">="utf-8"</span> ?<span style="color:#0000ff;">&#62;</span>
<span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Project</span> <span style="color:#ff0000;">xmlns</span><span style="color:#0000ff;">="http://schemas.microsoft.com/developer/MsBuild/2003"</span><span style="color:#0000ff;">&#62;</span>
  <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">UsingTask</span>
      <span style="color:#ff0000;">TaskName</span><span style="color:#0000ff;">="CompressorTask"</span>
      <span style="color:#ff0000;">AssemblyFile</span><span style="color:#0000ff;">="Yahoo.Yui.Compressor.dll"</span> <span style="color:#0000ff;">/&#62;</span>

  <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Target</span> <span style="color:#ff0000;">Name</span><span style="color:#0000ff;">="MyTaskTarget"</span><span style="color:#0000ff;">&#62;</span>
    <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">ItemGroup</span><span style="color:#0000ff;">&#62;</span>
      <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">JavaScriptFiles</span> <span style="color:#ff0000;">Include</span><span style="color:#0000ff;">="..\Scripts\jquery-1.3.2.js"</span><span style="color:#0000ff;">/&#62;</span>
      <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">JavaScriptFiles</span> <span style="color:#ff0000;">Include</span><span style="color:#0000ff;">="..\Scripts\MicrosoftAjax.js"</span><span style="color:#0000ff;">/&#62;</span>
      <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">JavaScriptFiles</span> <span style="color:#ff0000;">Include</span><span style="color:#0000ff;">="..\Scripts\MicrosoftMvcAjax.js"</span><span style="color:#0000ff;">/&#62;</span>
    <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">ItemGroup</span><span style="color:#0000ff;">&#62;</span>
    <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">CompressorTask</span>
        <span style="color:#ff0000;">CssFiles</span><span style="color:#0000ff;">="@(CssFiles)"</span>
        <span style="color:#ff0000;">DeleteCssFiles</span><span style="color:#0000ff;">="false"</span>
        <span style="color:#ff0000;">CssOutputFile</span><span style="color:#0000ff;">="$(CssOutputFile)"</span>
        <span style="color:#ff0000;">CssCompressionType</span><span style="color:#0000ff;">="YuiStockCompression"</span>
        <span style="color:#ff0000;">JavaScriptFiles</span><span style="color:#0000ff;">="@(JavaScriptFiles)"</span>
        <span style="color:#ff0000;">ObfuscateJavaScript</span><span style="color:#0000ff;">="True"</span>
        <span style="color:#ff0000;">PreserveAllSemicolons</span><span style="color:#0000ff;">="False"</span>
        <span style="color:#ff0000;">DisableOptimizations</span><span style="color:#0000ff;">="Nope"</span>
        <span style="color:#ff0000;">EncodingType</span><span style="color:#0000ff;">="Default"</span>
        <span style="color:#ff0000;">DeleteJavaScriptFiles</span><span style="color:#0000ff;">="false"</span>
        <span style="color:#ff0000;">LineBreakPosition</span><span style="color:#0000ff;">="-1"</span>
        <span style="color:#ff0000;">JavaScriptOutputFile</span><span style="color:#0000ff;">="$(JavaScriptOutputFile)"</span>
        <span style="color:#ff0000;">LoggingType</span><span style="color:#0000ff;">="ALittleBit"</span>
        <span style="color:#ff0000;">ThreadCulture</span><span style="color:#0000ff;">="en-us"</span>
        <span style="color:#ff0000;">IsEvalIgnored</span><span style="color:#0000ff;">="false"</span>
            <span style="color:#0000ff;">/&#62;</span>
  <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Target</span><span style="color:#0000ff;">&#62;</span>
<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Project</span><span style="color:#0000ff;">&#62;</span></pre>
<p>The important part is the ItemGroup element in which you specify the scripts that will be acted upon by YUI Compressor. Next you should edit the Build event script in order to run the MSBuild task. Right-click the project and choose Properties, then select Build Events. In the Post-build event command line enter the following script:</p>
<pre style="overflow:auto;">$(MSBuildBinPath)\msbuild.exe "$(ProjectDir)MSBuild\MSBuildXML.xml" /p:JavaScriptOutputFile="$(TargetDir)..\Scripts\JavaScriptFinal.js"</pre>
<div id="attachment_158" class="wp-caption aligncenter" style="width: 610px"><a href="http://nraykov.wordpress.com/files/2009/12/build_events.png"><img class="size-full wp-image-158" title="Project Properties - Build Events" src="http://nraykov.wordpress.com/files/2009/12/build_events.png" alt="Project Properties - Build Events" width="600" height="221" /></a><p class="wp-caption-text">Project Properties - Build Events</p></div>
<p>Now when you build your project your JavaScript files would be combined and minified &#8211; the output can be seen in this screenshot:</p>
<div id="attachment_145" class="wp-caption aligncenter" style="width: 610px"><a href="http://nraykov.wordpress.com/files/2009/12/msbuild.png"><img class="size-full wp-image-145" title="MSBuild output" src="http://nraykov.wordpress.com/files/2009/12/msbuild.png" alt="MSBuild output" width="600" height="178" /></a><p class="wp-caption-text">MSBuild output</p></div>
<p>Another important aspect is where exactly in the page are the references for the JavaScript files. You should put them in the head section of the HTML document only if the scripts are essential for the page rendering phase (generation of HTML), otherwise you should put them at the end of the page to prevent blocking of the rendering. If you know that your script won&#8217;t be needed until a specific time on your page you could defer its loading. This way the browser won&#8217;t make a request for it and you will improve the page load time. It is really easy to accomplish &#8211; all you need to do is to attach an event handler to the onload event and download the file after a specified amount of time. Here is a sample HTML extension method for ASP.NET MVC that I wrote but this could be easily rewritten for ASP.NET:</p>
<pre style="font-size:small;color:black;font-family:Consolas;background-color:#ffffff;overflow:auto;"><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">string</span> RegisterDeferredLoader(<span style="color:#0000ff;">this</span> HtmlHelper helper)
{
    HttpContextBase context = helper.ViewContext.HttpContext;
    <span style="color:#0000ff;">if</span> (context.Items.Contains(<span style="color:#006080;">"__DeferredLoader"</span>))
        <span style="color:#0000ff;">return</span> <span style="color:#006080;">""</span>;

    context.Items.Add(<span style="color:#006080;">"__DeferredLoader"</span>, <span style="color:#006080;">"__DeferredLoader"</span>);

    StringBuilder strBuilder = <span style="color:#0000ff;">new</span> StringBuilder();
    strBuilder.AppendLine(<span style="color:#006080;">"&#60;script type=\"text/javascript\"&#62;"</span>);
    strBuilder.AppendLine(<span style="color:#006080;">"function loadScript(file){"</span>);
    strBuilder.AppendLine(<span style="color:#006080;">"var script = document.createElement('script');"</span>);
    strBuilder.AppendLine(<span style="color:#006080;">"script.type = \"text/javascript\";"</span>);
    strBuilder.AppendLine(<span style="color:#006080;">"script.src = file;"</span>);
    strBuilder.AppendLine(<span style="color:#006080;">"document.body.appendChild(script);"</span>);
    strBuilder.AppendLine(<span style="color:#006080;">"};"</span>);
    strBuilder.AppendLine(<span style="color:#006080;">"&#60;/script&#62;"</span>);

    <span style="color:#0000ff;">return</span> strBuilder.ToString();
}</pre>
<p>This private helper method outputs a JavaScript function on the page that initiates the request for the script file itself &#8211; it simply creates a SCRIPT DOM element and sets its src attribute to the URI of the file. When it is appended to the document the script file is downloaded automatically. The method also ensures that the JavaScript function is written only once in the HTML document &#8211; we do not want it multiple times which increases the overall size of the document that would be transferred.</p>
<p>Here is the extension method that would be used to defer the loading of  scripts on the page:</p>
<pre style="font-size:small;color:black;font-family:Consolas;background-color:#ffffff;overflow:auto;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">string</span> RegisterScript(<span style="color:#0000ff;">this</span> HtmlHelper helper, <span style="color:#0000ff;">string</span> resourceUri, <span style="color:#0000ff;">int</span> delayInMilliseconds)
{
    HttpContextBase context = helper.ViewContext.HttpContext;
    <span style="color:#0000ff;">if</span> (context.Items.Contains(resourceUri))
        <span style="color:#0000ff;">return</span> <span style="color:#006080;">""</span>;

    context.Items.Add(resourceUri, resourceUri);
    StringBuilder strBuilder = <span style="color:#0000ff;">new</span> StringBuilder();
    strBuilder.AppendLine(helper.RegisterDeferredLoader());

    strBuilder.AppendLine(<span style="color:#006080;">"&#60;script type=\"text/javascript\"&#62;"</span>);
    strBuilder.AppendFormat(<span style="color:#006080;">"if (window.addEventListener) window.addEventListener('load', function(){{window.setTimeout(function(){{loadScript(\"{0}\");}}, {1});}}, false);"</span>, resourceUri, delayInMilliseconds);
    strBuilder.AppendFormat(<span style="color:#006080;">"else if (window.attachEvent) window.attachEvent('onload', function(){{window.setTimeout(function(){{loadScript(\"{0}\");}}, {1});}});"</span>, resourceUri, delayInMilliseconds);
    strBuilder.AppendLine(<span style="color:#006080;">"&#60;/script&#62;"</span>);

    <span style="color:#0000ff;">return</span> strBuilder.ToString();
}</pre>
<p>This method outputs JavaScript code that attaches an event handler to the onload event of the window in which the loadScript function is called after a specified number of milliseconds. As you can see all of this is accomplished with a minimum amount of code and there is no complex logic. In order to use the extension method in your pages you should add its namespace to the pages/namespaces element inside the web.config file:</p>
<pre style="font-size:small;color:black;font-family:Consolas;background-color:#ffffff;overflow:auto;"><span style="color:#0000ff;">&#60;</span><span style="color:#800000;">pages</span><span style="color:#0000ff;">&#62;</span>
    ...
    <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">namespaces</span><span style="color:#0000ff;">&#62;</span>
        ...
        <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">add</span> <span style="color:#ff0000;">namespace</span><span style="color:#0000ff;">="JSOptimizations.Helpers"</span><span style="color:#0000ff;">/&#62;</span>
    <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">namespaces</span><span style="color:#0000ff;">&#62;</span>
<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">pages</span><span style="color:#0000ff;">&#62;</span></pre>
<p>What follows is a simple test of the extension method. This is a very simple JavaScript file that renders the time at which it is executed:</p>
<pre style="font-size:small;color:black;font-family:Consolas;background-color:#ffffff;overflow:auto;">document.body.innerHTML += 'I am now loaded at ' + new Date();</pre>
<p>And the HTML for the page is as follows:</p>
<pre style="font-size:small;color:black;font-family:Consolas;background-color:#ffffff;overflow:auto;"><span style="background-color:#ffff00;">&#60;%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %&#62;</span>

<span style="color:#0000ff;">&#60;!</span><span style="color:#800000;">DOCTYPE</span> <span style="color:#ff0000;">html</span> <span style="color:#ff0000;">PUBLIC</span> <span style="color:#0000ff;">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span> <span style="color:#0000ff;">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span><span style="color:#0000ff;">&#62;</span>

<span style="color:#0000ff;">&#60;</span><span style="color:#800000;">html</span> <span style="color:#ff0000;">xmlns</span><span style="color:#0000ff;">="http://www.w3.org/1999/xhtml"</span> <span style="color:#0000ff;">&#62;</span>
<span style="color:#0000ff;">&#60;</span><span style="color:#800000;">head</span> <span style="color:#ff0000;">runat</span><span style="color:#0000ff;">="server"</span><span style="color:#0000ff;">&#62;</span>
    <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">title</span><span style="color:#0000ff;">&#62;</span>DeferLoading<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">title</span><span style="color:#0000ff;">&#62;</span>
    <span style="background-color:#ffff00;">&#60;%</span>= Html.RegisterScript(<span style="color:#006080;">"../../Scripts/DeferLoading.js"</span>, 5000) <span style="background-color:#ffff00;">%&#62;</span>
<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">head</span><span style="color:#0000ff;">&#62;</span>
<span style="color:#0000ff;">&#60;</span><span style="color:#800000;">body</span><span style="color:#0000ff;">&#62;</span>
    <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">script</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text/javascript"</span><span style="color:#0000ff;">&#62;</span>
        document.body.innerHTML += <span style="color:#006080;">'Page is rendered at: '</span> + <span style="color:#0000ff;">new</span> Date() + <span style="color:#006080;">'&#60;br/&#62;'</span>;
    <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">script</span><span style="color:#0000ff;">&#62;</span>
<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">body</span><span style="color:#0000ff;">&#62;</span>
<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">html</span><span style="color:#0000ff;">&#62;</span></pre>
<p>When you open it you would see something similar to the screenshot:</p>
<div id="attachment_139" class="wp-caption aligncenter" style="width: 610px"><a href="http://nraykov.wordpress.com/files/2009/12/deferloading.png"><img class="size-full wp-image-139" title="Deferred Loading of JavaScript" src="http://nraykov.wordpress.com/files/2009/12/deferloading.png" alt="Deferred Loading of JavaScript" width="600" height="408" /></a><p class="wp-caption-text">Deferred Loading of JavaScript</p></div>
<p>As you can see the JavaScript file is loaded exactly 5 seconds after the page is rendered.</p>
<p>You could download the sample test project with both the MSBuild task and the extension methods from <a href="http://www.box.net/shared/xx0qcypjyt" target="_blank">here</a>.</p>
<p><span style="text-decoration:underline;"><strong>Summary</strong></span></p>
<p>Simply by utilizing some techniques for loading JavaScript files you could dramatically increase the load times of your pages. Both minifying and combining several files into a single one can save significant amount of bandwidth. Deferred loading allows you to download scripts after the page has loaded thus reducing the network round trips to the server while rendering the page. There is no single golden rule that will help you achieve the best performance but when you use different techniques for your specific scenario you could really make great improvements.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[ASP.NET MVC Custom Compression Action Filter]]></title>
<link>http://nraykov.wordpress.com/2009/12/02/asp-net-mvc-custom-compression-action-filter/</link>
<pubDate>Wed, 02 Dec 2009 20:07:13 +0000</pubDate>
<dc:creator>Nikolay Raykov</dc:creator>
<guid>http://nraykov.wordpress.com/2009/12/02/asp-net-mvc-custom-compression-action-filter/</guid>
<description><![CDATA[Action filters are a powerful mechanism in ASP.NET MVC to add an additional layer of control to your]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Action filters are a powerful mechanism in ASP.NET MVC to add an additional layer of control to your action methods by attaching to the request-response pipeline. Just by decorating an action method or controller class you can perform a custom authorization based on specific rights and roles, cache and/or compress the response, localization, etc.</p>
<p><span style="text-decoration:underline;"><strong>Implementation</strong></span></p>
<p>In order to implement a custom action filter you need to inherit from <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.actionfilterattribute.aspx" target="_blank">ActionFilterAttribute</a> &#8211; this is an abstract class that has four methods that you can override:</p>
<ul>
<li>OnActionExecuting</li>
<li>OnActionExecuted</li>
<li>OnResultExecuting</li>
<li>OnResultExecuted</li>
</ul>
<p>As their names imply a custom logic can be performed before/after an action method is executed and before/after the result is executed. Action filters have an Order property which specifies the order in which the filter is applied when multiple filters are used to decorate an action method.</p>
<p><span style="text-decoration:underline;"><strong>Performance Optimizations</strong></span></p>
<p>Nowadays with broadband internet a lot of people do not care about the performance of their web sites but they are wrong. Every single byte counts when you want to stand out &#8211; the end users do not care about what technology is powering up your system, they do care about performance. One of the first things that you could do to reduce the payload of your site is to do gzip or deflate compression &#8211; it will reduce the size of the server response by 60-65%. Compression is only applicable if the end user&#8217;s browser supports it &#8211; all major browsers support it so you do not need to worry. Gzip is more widely accepted and performs better than deflate, hence it should be your first choice.</p>
<p><em>Note: Do not apply compression to images and PDF files &#8211; they are already compressed and you will only waste CPU time to do so.</em></p>
<p><span style="text-decoration:underline;"><strong>Compression Filter</strong></span></p>
<p>Here is the code for the compression filter:</p>
<pre style="font-size:small;color:black;font-family:Consolas;overflow:auto;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> CompressionAttribute : ActionFilterAttribute
{
    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> OnActionExecuting(ActionExecutingContext filterContext)
    {
        <span style="color:#0000ff;">base</span>.OnActionExecuting(filterContext);

        HttpRequestBase request = filterContext.HttpContext.Request;
        <span style="color:#0000ff;">string</span> acceptEncoding = request.Headers[<span style="color:#006080;">"Accept-Encoding"</span>].ToLowerInvariant();
        <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">string</span>.IsNullOrEmpty(acceptEncoding))
            <span style="color:#0000ff;">return</span>;

        HttpResponseBase response = filterContext.HttpContext.Response;
        <span style="color:#0000ff;">if</span> (acceptEncoding.Contains(<span style="color:#006080;">"gzip"</span>))
        {
            response.AppendHeader(<span style="color:#006080;">"Content-Encoding"</span>, <span style="color:#006080;">"gzip"</span>);
            response.Filter = <span style="color:#0000ff;">new</span> GZipStream(response.Filter, CompressionMode.Compress);
        }
        <span style="color:#0000ff;">else</span> <span style="color:#0000ff;">if</span> (acceptEncoding.Contains(<span style="color:#006080;">"deflate"</span>))
        {
            response.AppendHeader(<span style="color:#006080;">"Content-Encoding"</span>, <span style="color:#006080;">"deflate"</span>);
            response.Filter = <span style="color:#0000ff;">new</span> DeflateStream(response.Filter, CompressionMode.Compress);
        }
    }
}</pre>
<p>The <em>Accept-Encoding </em>header of the request shows whether the browser supports compression &#8211; if it is empty the CompressionAttribute class returns and does nothing. If the value is <strong>gzip </strong>or <strong>deflate </strong>the HttpResponseBase class&#8217;s property Filter which is of type Stream is wrapped by GZipStream or DeflateStream respectively. A <em>Content-Encoding </em>response header is set to the value of the compression method that is used so that the browser will know how to decompress the response.</p>
<p>Here is a sample usage of the Compression filter:</p>
<pre style="font-size:small;color:black;font-family:Consolas;overflow:auto;">[Compression]
<span style="color:#0000ff;">public</span> ActionResult Index()
{
    <span style="color:#0000ff;">return</span> View();
}</pre>
<p><strong><span style="text-decoration:underline;">Summary</span></strong></p>
<p>Custom action filters give some extra power in the hands of developers to perform additional tasks along the ASP.NET MVC pipeline. You saw how simple it is to write a custom action filter that is applicable to real world scenarios. This is one of the performance optimization techniques that you could apply to improve the overall performance of your site.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[The Poor Developer's Object DataStore: Iteration 000]]></title>
<link>http://just3ws.wordpress.com/2009/12/02/the-poor-developers-object-datastore-iteration-000/</link>
<pubDate>Wed, 02 Dec 2009 02:32:10 +0000</pubDate>
<dc:creator>just3ws</dc:creator>
<guid>http://just3ws.wordpress.com/2009/12/02/the-poor-developers-object-datastore-iteration-000/</guid>
<description><![CDATA[This is part zero of a multi-part series. Jump to The Poor Developer&#8217;s Object DataStore: Itera]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><b>This is part zero of a multi-part series. Jump to <a href="http://wp.me/pijpG-7f">The Poor Developer&#8217;s Object DataStore: Iteration 001</a> for the first code drop.</b></p>
<p>What is an object datastore? For an object-oriented developer it&#8217;s as easy to use as a typed collection. No need to build and maintain a complex relational model to simulate the native object functionality. Just create your object, modify it, store it, query for it and delete it. All the complicated work is handled by the object database engine. But let&#8217;s consider a situation where you may want to &#8220;roll your own&#8221; light-weight object datastore. And depending on your situation, it might make sense. <i>CAVEAT: Rule #1 of Software Engineering: If You Can Use A Proven Product Don&#8217;t Write Your Own. They Did It First And They Did It Better.</i> But for the sake of exercise and trying something new let&#8217;s just ignore that rule and keep on going.</p>
<p>Consider the following scenario. You&#8217;re a .NET developer and you&#8217;ve been tasked with creating an archiving system. The system needs to take a snapshot of the data and store it to be queried against and reported on later.</p>
<p>How would you implement this? Would you copy the data structure you&#8217;re looking to archive and pull the data state into there? How do you manage foreign keys? Do you squish the data into a single table? Do you recreate all the tables with annotations to identify the archived records? Now, it&#8217;s a few months later and the original data structure has changed. How do you handle that change in your archiving?</p>
<p>Do you really want to recreate that complex data structure and try to wrangle the data into it and manage it over time? No, neither did I and I think there is a better way. Let&#8217;s consider a new way: an <strong>object datastore</strong>.</p>
<p>Let&#8217;s get this out of the way. Object databases aren&#8217;t just for ninjas although they are often wielded by ninjas. An object database is exactly what it sounds like, a <em>database</em> for your <em>objects</em>. No sql, no tables, no object-relational impedance. Just objects persisted similar to how a relational database allows you to store and persist tabular information offline without all the grief of mapping your object-oriented structure onto a relational model. Instead you create your objects and using the database&#8217;s API you can save and query for your data without worrying about sql or any of that mess. My personal favorite OODBMS (object-oriented database management system) is <a href="http://developer.db4o.com/Resources/">db4o</a>. I recommend downloading and playing around with it to get a feel for how simple it is to use. (If you want to learn more about various types of *DBMS check out the great presentation by Ben Scoffield at WindyCityRails 2009 &#8211; <a href="http://windycityrails.org/videos#3">&#8220;Comics&#8221; is Hard</a>.)</p>
<p>There&#8217;s one catch to using db4o in a closed source or proprietary project. You can either pay to license the product. It&#8217;s not too expensive for bringing into a medium sized project. Or you can release your project under GPL. For the project I was working on, neither option was palatable for our client. Also, I didn&#8217;t want to introduce yet another external dependency that our client would have to manage. Instead I created the simplest possible implementation of an object datastore I could using only native .NET and Microsoft Sql Server functionality.</p>
<p>Continued in <a href="http://wp.me/pijpG-7f">The Poor Developer&#8217;s Object DataStore: Iteration 001</a>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[C# Coding Style Guide]]></title>
<link>http://neraa.wordpress.com/2009/11/30/c-coding-style-guide/</link>
<pubDate>Mon, 30 Nov 2009 04:28:04 +0000</pubDate>
<dc:creator>neraa</dc:creator>
<guid>http://neraa.wordpress.com/2009/11/30/c-coding-style-guide/</guid>
<description><![CDATA[Biar ngodingnya rapih, bersih dan gaya (apaan sih ), alangkah baiknya baca Coding Style Guidenya dul]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Biar ngodingnya rapih, bersih dan gaya (apaan sih <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ), alangkah baiknya baca Coding Style Guidenya dulu.</p>
<div id="attachment_8" class="wp-caption aligncenter" style="width: 435px"><a href="http://neraa.wordpress.com/files/2009/11/csharpcodingstyleguide.png"><img class="size-full wp-image-8" title="csharpcodingstyleguide" src="http://neraa.wordpress.com/files/2009/11/csharpcodingstyleguide.png" alt="C# Coding Style Guide" width="425" height="175" /></a><p class="wp-caption-text">C# Coding Style Guide v0.4 by Mike Krüger</p></div>
<blockquote><p><!--more-->This document may be read as a guide to writing robust and reliable programs. It focuses on programs written in C♯, but many  of the rules and principles are useful even if you write in another programming language.</p></blockquote>
<p>Link downloadnya di sini:</p>
<p><a href="http://www.mediafire.com/?bcymh2mo1n2" target="_blank">http://www.mediafire.com/?bcymh2mo1n2</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Using Ext JS Grid with ASP.NET MVC]]></title>
<link>http://nraykov.wordpress.com/2009/11/29/using-ext-js-grid-with-asp-net-mvc/</link>
<pubDate>Sun, 29 Nov 2009 13:51:14 +0000</pubDate>
<dc:creator>Nikolay Raykov</dc:creator>
<guid>http://nraykov.wordpress.com/2009/11/29/using-ext-js-grid-with-asp-net-mvc/</guid>
<description><![CDATA[ASP.NET MVC is the new cool kid on the block of Microsoft platforms. I have been using it for a litt]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>ASP.NET MVC is the new cool kid on the block of Microsoft platforms. I have been using it for a little over half an year and I can say that I like it much more than ASP.NET. Why is that?</p>
<ol>
<li>No more viewstate which adds an additional overhead on your page</li>
<li>Clean separation of concerns through the MVC pattern</li>
<li>Going back to the basics (standard HTML controls) &#8211; most of the ASP.NET server controls do not work with ASP.NET MVC because there is no viewstate and the notion of postbacks</li>
</ol>
<p>This would be the first of a series of blog posts that I would write about ASP.NET MVC and some performance techniques that could get the most out of it. We will start by building a simple application that uses Ext JS Grid to display employees data that is fetched from the AdventureWorks database. Since jQuery is being shipped with Visual Studio for over a year now I will be using it as well &#8211; as an adapter to Ext JS (I am a big fan of jQuery).</p>
<p>I am going to create my app using Visual Stidio 2010 Beta 2 which ships with ASP.NET MVC 2 Beta. If you are using Visual Studio 2008 you have to download the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=4817cdb2-88ea-4af4-a455-f06b4c90fd2c&#38;displaylang=en" target="_blank">Beta</a> and install it on your machine. First we start by creating a new ASP.NET MVC Project.</p>
<p style="text-align:center;">
<div id="attachment_65" class="wp-caption aligncenter" style="width: 610px"><a href="http://nraykov.wordpress.com/files/2009/11/step_11.png"><img class="size-full wp-image-65" title="New ASP.NET MVC Project" src="http://nraykov.wordpress.com/files/2009/11/step_11.png" alt="New ASP.NET MVC Project" width="600" height="413" /></a><p class="wp-caption-text">New ASP.NET MVC Project</p></div>
<p>Next I am copying the necessary files that are needed for Ext JS &#8211; ext-all.debug.js and ext-jquery-adapter.js to an extjs folder I created under my Scripts folder which was created for me by the ASP.NET MVC project template. I will use the latest version of the library &#8211; <a href="http://www.extjs.com/" target="_blank">Ext JS 3.0.3</a>.</p>
<p>In the next step we need to include the css and js files &#8211; I will put them in the master page (located under Views/Shared folder):</p>
<pre style="overflow:auto;"><span style="color:#0000ff;">&#60;</span><span style="color:#800000;">link</span> <span style="color:#ff0000;">href</span><span style="color:#0000ff;">="../../Content/resources/css/ext-all.css"</span> <span style="color:#ff0000;">rel</span><span style="color:#0000ff;">="stylesheet"</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text/css"</span> <span style="color:#0000ff;">/&#62;</span>
<span style="color:#0000ff;">&#60;</span><span style="color:#800000;">script</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text/javascript"</span> <span style="color:#ff0000;">src</span><span style="color:#0000ff;">="../../Scripts/jquery-1.3.2.js"</span><span style="color:#0000ff;">&#62;&#60;/</span><span style="color:#800000;">script</span><span style="color:#0000ff;">&#62;</span>
<span style="color:#0000ff;">&#60;</span><span style="color:#800000;">script</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text/javascript"</span> <span style="color:#ff0000;">src</span><span style="color:#0000ff;">="../../Scripts/extjs/ext-jquery-adapter.js"</span><span style="color:#0000ff;">&#62;&#60;/</span><span style="color:#800000;">script</span><span style="color:#0000ff;">&#62;</span>
<span style="color:#0000ff;">&#60;</span><span style="color:#800000;">script</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text/javascript"</span> <span style="color:#ff0000;">src</span><span style="color:#0000ff;">="../../Scripts/extjs/ext-all-debug.js"</span><span style="color:#0000ff;">&#62;&#60;/</span><span style="color:#800000;">script</span><span style="color:#0000ff;">&#62;</span></pre>
<p>The order in which you include the JavaScript files is important.</p>
<p><em>Note: Please remember that it is essential to put all your css files in the head section of the page &#8211; this improves the loading of your page. All js files that are needed for the page rendering should also be put in the head, otherwise they should be put at the end of your page. I will talk more about this in a future blog post.</em></p>
<p>For the purpose of this sample application I will use the AdventureWorks database alongside with the Entity Framework for my data model. First we have to add the database into the App_Data folder and then create our data model in the Models folder. The Entity Framework will generate all the necessary entities and a context class and we are ready to write our data access code &#8211; I will write my LINQ queries against the database in the controller classes though you will not do this in a real world application. You would use for example the Repository pattern, put your data access logic in a separate assembly, maybe write your own services that will abstract away the business logic and inject them with some Dependency Injection framework, etc.</p>
<div id="attachment_63" class="wp-caption aligncenter" style="width: 610px"><a href="http://nraykov.wordpress.com/files/2009/11/ef_datamodel.png"><img class="size-full wp-image-63" title="Entity Framework Data Model" src="http://nraykov.wordpress.com/files/2009/11/ef_datamodel.png" alt="Entity Framework Data Model" width="600" height="414" /></a><p class="wp-caption-text">Entity Framework Data Model</p></div>
<p>Now that we have everything in place we can write an action method which would return a subset of employees:</p>
<pre style="overflow:auto;">[AcceptVerbs(HttpVerbs.Get)]
[ActionName(<span style="color:#006080;">"Employees"</span>)]
<span style="color:#0000ff;">public</span> JsonResult GetEmployees()
{
   <span style="color:#0000ff;">int</span> start = Convert.ToInt32(Request.QueryString[<span style="color:#006080;">"start"</span>]);
   <span style="color:#0000ff;">int</span> limit = Convert.ToInt32(Request.QueryString[<span style="color:#006080;">"limit"</span>]);

   <span style="color:#0000ff;">using</span> (AdventureWorksEntities dbContext = <span style="color:#0000ff;">new</span> AdventureWorksEntities())
   {
      var query = dbContext.Employees
                              .Include(<span style="color:#006080;">"Contact"</span>)
                              .OrderBy(emp =&#62; emp.EmployeeID);
      var result = (from emp <span style="color:#0000ff;">in</span> query
                                  .Skip(start).Take(limit).ToList()
                    select <span style="color:#0000ff;">new</span>
                    {
                       ID = emp.EmployeeID,
                       FirstName = emp.Contact.FirstName,
                       LastName = emp.Contact.LastName,
                       BirthDate = emp.BirthDate.ToShortDateString(),
                       HireDate = emp.HireDate.ToShortDateString(),
                       VacationHours = emp.VacationHours,
                       SickLeaveHours = emp.SickLeaveHours,
                       Email = emp.Contact.EmailAddress,
                       Phone = emp.Contact.Phone
                    }).ToList();

      <span style="color:#0000ff;">return</span> Json(<span style="color:#0000ff;">new</span> { data = result, totalCount = query.Count() }, JsonRequestBehavior.AllowGet);
   }
}</pre>
<p>Notice the <strong>AcceptVerbs </strong>attribute that the method is decorated with &#8211; it tells the framework that only GET requests are allowed to call the method through the <strong>HttpVerbs </strong>enumeration. This was the way to constrain the requests so far but in the new version of ASP.NET MVC there are some new handy attributes that you could use as well &#8211; <strong>HttpGet</strong>, <strong>HttpPost</strong>, <strong>HttpPut </strong>and <strong>HttpDelete </strong>which do the same thing. I am using the <strong>ActionName </strong>attribute to explicitly add a name for my action method so that I could have a nice URL schema for my actions and use the same name for different CRUD operations (I just need to use different verb for the requests).</p>
<p>In the method itself I create an instance of the database context and based on the parameters received from the grid I do paging with the LINQ extension methods Skip and Take. The interesting part is when the data is returned as a JSON &#8211; in ASP.NET MVC 1 the JSON method required a single parameter while now you have to pass an additional parameter of type JsonRequestBehavior. It is introduced for security reasons and you as a developer should explicitly decide whether or not to support GET requests. The problem is that if you return a response in the form of a JSON Array for a GET request it could be easily compromised, so it is suggested to wrap it inside a JSON object or do POSTs instead of that. You could read more about this in <a title="JSON Hijacking" href="http://haacked.com/archive/2009/06/25/json-hijacking.aspx" target="_blank">Phil Haack&#8217;s post</a>.</p>
<p>Next we need to write the JavaScript code that will instantiate our grid and fetch the data from the server:</p>
<pre style="font-size:small;color:black;font-family:Consolas,;overflow:auto;"><span style="color:#0000ff;">&#60;</span><span style="color:#800000;">script</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text/javascript"</span><span style="color:#0000ff;">&#62;</span>
   $(document).ready(<span style="color:#0000ff;">function</span> () {
      <span style="color:#0000ff;">var</span> store = <span style="color:#0000ff;">new</span> Ext.data.Store({
         proxy: <span style="color:#0000ff;">new</span> Ext.data.HttpProxy({
            url: <span style="color:#006080;">'Home/Employees'</span>,
            dataType: <span style="color:#006080;">'json'</span>,
            method: <span style="color:#006080;">'GET'</span>
         }),
         reader: <span style="color:#0000ff;">new</span> Ext.data.JsonReader({
            root: <span style="color:#006080;">'data'</span>,
            totalProperty: <span style="color:#006080;">'totalCount'</span>
         }, Ext.data.Record.create([
            { name: <span style="color:#006080;">'ID'</span>, mapping: <span style="color:#006080;">'ID'</span> },
            { name: <span style="color:#006080;">'FirstName'</span>, mapping: <span style="color:#006080;">'FirstName'</span> },
            { name: <span style="color:#006080;">'LastName'</span>, mapping: <span style="color:#006080;">'LastName'</span> },
            { name: <span style="color:#006080;">'BirthDate'</span>, mapping: <span style="color:#006080;">'BirthDate'</span> },
            { name: <span style="color:#006080;">'HireDate'</span>, mapping: <span style="color:#006080;">'HireDate'</span> },
            { name: <span style="color:#006080;">'VacationHours'</span>, mapping: <span style="color:#006080;">'VacationHours'</span> },
            { name: <span style="color:#006080;">'SickLeaveHours'</span>, mapping: <span style="color:#006080;">'SickLeaveHours'</span> },
            { name: <span style="color:#006080;">'Email'</span>, mapping: <span style="color:#006080;">'Email'</span> },
            { name: <span style="color:#006080;">'Phone'</span>, mapping: <span style="color:#006080;">'Phone'</span> }
         ]))
      });

      <span style="color:#0000ff;">var</span> grid = <span style="color:#0000ff;">new</span> Ext.grid.GridPanel({
         store: store,
         columns: [
            { header: <span style="color:#006080;">'ID'</span>, dataIndex: <span style="color:#006080;">'ID'</span>, hidden: <span style="color:#0000ff;">true</span> },
            { header: <span style="color:#006080;">'First Name'</span>, dataIndex: <span style="color:#006080;">'FirstName'</span>, width: 100 },
            { header: <span style="color:#006080;">'Last Name'</span>, dataIndex: <span style="color:#006080;">'LastName'</span>, width: 100 },
            { header: <span style="color:#006080;">'Birth Date'</span>, dataIndex: <span style="color:#006080;">'BirthDate'</span>, width: 100 },
            { header: <span style="color:#006080;">'Hire Date'</span>, dataIndex: <span style="color:#006080;">'HireDate'</span>, width: 100 },
            { header: <span style="color:#006080;">'Vacation Hours'</span>, dataIndex: <span style="color:#006080;">'VacationHours'</span>, width: 100 },
            { header: <span style="color:#006080;">'Sick Leave Hours'</span>, dataIndex: <span style="color:#006080;">'SickLeaveHours'</span>, width: 100 },
            { header: <span style="color:#006080;">'Email'</span>, dataIndex: <span style="color:#006080;">'Email'</span>, width: 200 },
            { header: <span style="color:#006080;">'Phone'</span>, dataIndex: <span style="color:#006080;">'Phone'</span>, width: 200 }
         ],
         renderTo: <span style="color:#006080;">'grid'</span>,
         width: 1000,
         autoHeight: <span style="color:#0000ff;">true</span>,
         bbar: <span style="color:#0000ff;">new</span> Ext.PagingToolbar({
            store: store,
            pageSize: 25,
            displayInfo: <span style="color:#0000ff;">true</span>,
            displayMsg: <span style="color:#006080;">'Displaying employees {0} - {1} of {2}'</span>,
            emptyMsg: <span style="color:#006080;">"No employees to display"</span>
         }),
         pageSize: 20,
         title: <span style="color:#006080;">'Employees'</span>
      });

      grid.getStore().load({ <span style="color:#0000ff;">params</span>: {
         start: 0,
         limit: 25
      }
   });
});
<span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">script</span><span style="color:#0000ff;">&#62;</span></pre>
<p>When the DOM is ready to be manipulated I create a Store which will make the request to the server and use a JsonReader object which has all the necessary mappings in place to parse the data. Then an instance of the Grid is created with the store that was created in the previous step and columns which are mapped to the parsed JSON result object. That&#8217;s all you need to do &#8211; create these objects passing some configurations and you are ready to get your data. All the tricky parts of making an XmlHttpRequest, parsing the JSON, creating the HTML for the grid is done for you. Here is how the grid looks like when the application is run:</p>
<div id="attachment_78" class="wp-caption aligncenter" style="width: 610px"><a href="http://nraykov.wordpress.com/files/2009/11/ext_js_grid.png"><img class="size-full wp-image-78" title="Ext Js Grid" src="http://nraykov.wordpress.com/files/2009/11/ext_js_grid.png" alt="Ext Js Grid" width="600" height="382" /></a><p class="wp-caption-text">Ext Js Grid</p></div>
<p>This is a simple application in which I wanted to show you how to use Ext JS Grid to present data in a nice tabular fashion using ASP.NET MVC and Entity Framework. Here you could <a href="http://www.box.net/shared/f20o4ol724">download</a> the code for this app (I have not included the AdventureWorks database in order to keep the file size small, but you could download it from <a href="http://www.codeplex.com/MSFTDBProdSamples" target="_blank">here</a>).</p>
<p>In my next blog post I will show you how to write ASP.NET MVC HTML extension methods to include CSS and JavaScript files in your pages and how to instantiate some jQuery UI plugin widgets.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[The Poor Developer's Object DataStore : Iteration 001]]></title>
<link>http://just3ws.wordpress.com/2009/11/28/the-poor-developers-object-datastore-iteration-001/</link>
<pubDate>Sat, 28 Nov 2009 16:02:21 +0000</pubDate>
<dc:creator>just3ws</dc:creator>
<guid>http://just3ws.wordpress.com/2009/11/28/the-poor-developers-object-datastore-iteration-001/</guid>
<description><![CDATA[In The Poor Developer&#8217;s Object DataStore : Iteration 000 we proposed a possible motivation for]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In <a href="http://wp.me/pijpG-7T">The Poor Developer&#8217;s Object DataStore : Iteration 000</a> we proposed a possible motivation for wanting to store complex objects in a database without resorting to creating a complicated relational model.</p>
<p>For our first iteration we need only to be able to create and read the object from the database. It&#8217;s not going to be necessary to update or delete the data at this point. Only store and read. So why bother recreating the original data structure? Why not just query for the data with your ORM of choice and then serialize that result to Xml and store <em>that</em>? If you&#8217;re already using Microsoft Sql Server 2005 or later you&#8217;re already in a very good position as MSSQL provides the Xml datatype which makes storing, querying and retrieving Xml data very<br />
easy and efficient.</p>
<p>If you are using an ORM for your data-access (you *ARE* using an ORM aren&#8217;t you?) then you&#8217;re already halfway there. My original implementation utilized custom objects that implemented an IStorable interface. Basically, I used Linq to Sql to query the data I wanted to archive and mapped the query result to an object that implemented the interface. Using that I could save the object into the datastore in a similar manner to <a href="http://en.wikipedia.org/wiki/Active_record_pattern">Active Record</a>. This was very easy to do.</p>
<pre class="brush: csharp;">
public interface IStorable&#60;T&#62;
{
  string ConnectionString { get; set; }
  string Serialize();
  T Deserialize(string xml);
  XmlSerializer CreateSerializer();
  int Save();
}
</pre>
<p>So I could load up my data into a custom object, set the connectionstring and then automatically save it into the database.</p>
<pre class="brush: csharp;">
//a sample unit test demonstrating usage of the IStorable object.
public void TestStoreFoo()
{
  var foo = new Foo();
  foo.Id = 100;
  foo.Name = &#34;Penelope&#34;;
  foo.ConnectionString = &#34;__YourConnectionString__&#34;
  var objectId = foo.Save();
  Assert.That(objectId == 1);
}
</pre>
<p>So here&#8217;s the implementation. If you wish to grab the source code don&#8217;t try to cut and paste it from here. All the source code for this blog post can be browsed and downloaded from <a href="http://github.com/just3ws">GitHub</a>.</p>
<p><a href="http://github.com/just3ws/PoorDevsObjectDataStore/tree/master/src/PoorDevsObjectDataStore.Examples/Iteration001/">Source Code for Iteration 001</a></p>
<p>First we must implement the IStorable interface. The interface must take the implementing type as it&#8217;s generic argument. This is because we&#8217;re providing functionality for the object to serialize and store itself.</p>
<pre class="brush: csharp;">
public class Foo : IStorable&#60;Foo&#62;
{
</pre>
<p>The Foo.Id and Foo.Name are our data. They are not part of the IStorable implementation.</p>
<pre class="brush: csharp;">
  public int Id { get; set; }
  public string Name { get; set; }
</pre>
<p>We need to provide the connectionstring to the database where the objects are going to be stored.</p>
<pre class="brush: csharp;">
  public string ConnectionString { get; set; }
</pre>
<p>Now we&#8217;re getting to the fun part. We will use an in-memory stream to serialize this instance of the Foo object and then write it to a string.</p>
<pre class="brush: csharp;">
  public string Serialize()
  {
    string output;
    using(var buffer = new MemoryStream())
    {
      new XmlSerializer(typeof(Foo)).Serialize(buffer, this);
      buffer.Position = 0;
      output = new StreamReader(buffer).ReadToEnd();
    }
    return output;
  }
</pre>
<p>The deserialize method takes the xml as a string from a previous serialization and will attempt to convert it back into a Foo instance.</p>
<pre class="brush: csharp;">
  public Foo Deserialize(string xml)
  {
    return (Foo)new XmlSerializer(typeof(Foo)).Deserialize(new StringReader(xml));
  }
</pre>
<p>In order to serialize a type we must create a typed instance of a serializer object. Here we&#8217;re just creating a Foo serializer and setting the error event handlers to output it&#8217;s errors to standard output.</p>
<pre class="brush: csharp;">
  public XmlSerializer CreateSerializer()
  {
    var serializer = new XmlSerializer(typeof(Foo));
    //simply output error messages for types that we don't know how to serialize.
    serializer.UnknownAttribute += ((sender, e)=&#62;Console.Out.WriteLine(e));
    serializer.UnknownElement += ((sender, e)=&#62;Console.Out.WriteLine(e));
    return serializer;
  }
</pre>
<p>The save method is where we will kick off the work. We take this current instance and apply the Serialize() method to itself which converts the instance to a xml string. We also capture the fully-qualified name of the object type, both the namespace and the type name. This will be important when we are ready to pull the object back out of the datastore.</p>
<p>Here I&#8217;m using a Linq to Sql context, you may use any ORM as long as it supports the Microsoft Sql Server Xml datatype.</p>
<pre class="brush: csharp;">
  public int Save()
  {
    using(var context = new Example001DataContext(this.ConnectionString))
    {
      var entity = new Example001ObjectDataStore {
        Serialized = XElement.Parse(this.Serialize()),
        FullyQualifiedTypeName = this.GetType().FullName
      };
      context.Example001ObjectDataStores.InsertOnSubmit(entity);
      context.SubmitChanges();
      return entity.Id;
    }
  }
}
</pre>
<p>The underlying data table is very simple. Only a single table with a field for storing the serialized xml data and a field for storing the fully qualified name of the object.<br />
<div id="attachment_480" class="wp-caption aligncenter" style="width: 433px"><a href="http://just3ws.wordpress.com/files/2009/11/iteration_001_table_definition.png"><img src="http://just3ws.wordpress.com/files/2009/11/example_001.png" alt="The Poor Developer&#39;s Object DataStore: Iteration 001, diagram" title="poordevsobjectdatastore_iteration001_example_001_table" width="423" height="180" class="size-full wp-image-480" /></a><p class="wp-caption-text">The Iteration 001 Object DataStore Table Definition</p></div></p>
<p>In this post we&#8217;ve got the ball rolling for storing objects into some some table. We can create an object that knows how to write itself into a database without requiring the creation of an elaborate data structure in order to just to simulate the object structure.</p>
<p>Next post we&#8217;ll cover how to retrieve the data from the table and convert it back into an instance of the persisted type. Next post we&#8217;ll look at how we can really test the functionality and behavior of the system. And begin to explore how to abstract the datastore to support arbitrary objects (with some minor restrictions.)</p>
<p>The source code for this project is hosted on <a href="http://github.com/just3ws">GitHub </a>and can be downloaded from <a href="http://github.com/just3ws/PoorDevsObjectDataStore/tree/master/src/PoorDevsObjectDataStore.Examples/Iteration001/">here</a>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SCRIBEFIRELl0UJxpmR2SCRIBEFIRE]]></title>
<link>http://just3ws.wordpress.com/2009/11/28/scribefirell0ujxpmr2scribefire/</link>
<pubDate>Sat, 28 Nov 2009 01:58:45 +0000</pubDate>
<dc:creator>just3ws</dc:creator>
<guid>http://just3ws.wordpress.com/2009/11/28/scribefirell0ujxpmr2scribefire/</guid>
<description><![CDATA[SCRIBEFIREol26UBNsSCRIBEFIRE]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>SCRIBEFIREol26UBNsSCRIBEFIRE</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Port Scanner application in C#]]></title>
<link>http://hacktheugly.wordpress.com/2009/11/26/port-scanner-application-in-csharp/</link>
<pubDate>Fri, 27 Nov 2009 03:54:17 +0000</pubDate>
<dc:creator>Gopal</dc:creator>
<guid>http://hacktheugly.wordpress.com/2009/11/26/port-scanner-application-in-csharp/</guid>
<description><![CDATA[In Computer Networking, Ports are virtual data connection between clients and servers. Ports are ass]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In Computer Networking, Ports are virtual data connection between clients and servers. Ports are assigned port numbers which makes us easier to understand what kind of service is running on it.</p>
<p>A Port Scanner is a program which checks for open ports in a specified network host. For example: A printer with the IP Address of 10.44.55.17 may run a HTTP port in port number 80 to display the print configuration page. You can scan for open ports in a host to see what services are running in it. For example: A FTP client can be listening to Port 21. A port number can be a value from 0 to 65536, but the port numbers 0 to 1024 are reserved to be used by certain privileged services.</p>
<p><a href="http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers" target="_blank">List of &#8220;well-known ports&#8221;.</a></p>
<p>Additionally, In Windows XP,Vista and 7 you can type <strong>netstat </strong>in the command prompt to check for list of Active Connections with IP Address and Port Number.</p>
<p><strong>Writing a simple port scanner  in C#</strong></p>
<p style="text-align:center;"><a href="http://www.box.net/shared/tamx2k1cop" target="_blank"><img class="aligncenter size-full wp-image-565" title="csharp" src="http://hacktheugly.wordpress.com/files/2009/11/csharp1.png" alt="" width="67" height="75" /></a><strong><a href="http://www.box.net/shared/tamx2k1cop" target="_blank">Download Source Code</a><br />
</strong></p>
<p>First, add reference to System.Net.Sockets in you program and include a using statement(<span style="font-family:Courier New,Courier,mono;color:blue;font-size:x-small;">using</span><span style="font-family:Courier New,Courier,mono;color:#000000;font-size:x-small;"> System.Net.Sockets;)</span> in your list of using directives.</p>
<p>The program will have a button, which when pressed should start scanning for ports. Also four text boxes but one must have the multiline property enabled. One text box will have the IP Address of the host, two other text boxes will have the port start port and end point. The text box having multiline property enabled should be of suitable height so that it can accommodate 10-12  items without scrolling it. Lastly, You can add a progress bar to check the scan progress.</p>
<p><strong>Code</strong></p>
<p>When the user clicks the &#8216;Scan&#8217; button the button_Click event handler should execute the following lines of code.</p>
<p>//START CODE BLOCK</p>
<p>progressBar1.Value = 0;<br />
txtPortStats.Text = &#8220;&#8221;;<br />
int portLowerLimit = Convert.ToInt32(txtFromIP.Text);<br />
int portUpperLimit = Convert.ToInt32(txtToIP.Text);<br />
progressBar1.Maximum = portUpperLimit-portLowerLimit + 1;<br />
string ip = txtIPAddress.Text;</p>
<p>for (int i = portLowerLimit; i &#60;= portUpperLimit; i++)<br />
{<br />
TcpClient client = new TcpClient();<br />
try<br />
{<br />
client.Connect(ip, i);<br />
txtPortStats.Text += i.ToString() + &#8221; is Open&#8221;;<br />
txtPortStats.Text += Environment.NewLine;<br />
progressBar1.Value++;</p>
<p>}<br />
catch<br />
{<br />
txtPortStats.Text += i.ToString() + &#8221; is Closed&#8221;;<br />
txtPortStats.Text += Environment.NewLine;<br />
progressBar1.Value++;<br />
}<br />
}</p>
<p>//END CODE BLOCK</p>
<p><a href="http://hacktheugly.wordpress.com/files/2009/11/port_scanner.png"><img class="aligncenter size-full wp-image-558" title="port_scanner" src="http://hacktheugly.wordpress.com/files/2009/11/port_scanner.png" alt="" width="274" height="434" /></a></p>
<p><strong>From Here:</strong></p>
<ul>
<li>Enable the application to use the multi-threading capability of your CPU&#8230; multi-threading prevents the application UI from freezing and the scanning process can be completed faster.</li>
<li>Make the progress bar more accurate.</li>
</ul>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[C# İle İlgili Sık Sorulan Sorular(SSS)]]></title>
<link>http://sametcelikbicak.wordpress.com/2009/11/16/c-ile-ilgili-sik-sorulan-sorularsss/</link>
<pubDate>Mon, 16 Nov 2009 17:50:34 +0000</pubDate>
<dc:creator>sametcelikbicak</dc:creator>
<guid>http://sametcelikbicak.wordpress.com/2009/11/16/c-ile-ilgili-sik-sorulan-sorularsss/</guid>
<description><![CDATA[&nbsp; S &#8211; 1 : DllImport niteliğini neden çalıştıramıyorum? C &#8211; 1 : DllImport ile işaret]]></description>
<content:encoded><![CDATA[&nbsp; S &#8211; 1 : DllImport niteliğini neden çalıştıramıyorum? C &#8211; 1 : DllImport ile işaret]]></content:encoded>
</item>
<item>
<title><![CDATA[Send mail trong ASP.NET ]]></title>
<link>http://dyelvn.wordpress.com/2009/11/16/send-mail-trong-asp-net/</link>
<pubDate>Mon, 16 Nov 2009 06:11:44 +0000</pubDate>
<dc:creator>keithervn</dc:creator>
<guid>http://dyelvn.wordpress.com/2009/11/16/send-mail-trong-asp-net/</guid>
<description><![CDATA[Send mail trong ASP.NET sử dụng C# Class dùng để gửi mail tới 1 hay nhiều người, có cho phép đính kè]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Send mail trong ASP.NET sử dụng C#                     Class dùng để gửi mail tới 1 hay nhiều người, có cho phép đính kèm tệp tin vào email&#8230;</p>
<p>Việc gửi mail là 1 công việc thường ngày và viết ra 1 chương trình gửi mail thật đơn giản nhưng không phải ai cũng biết. Mình xin giới thiệu với các bạn class Email này.</p>
<p>using System;<br />
using System.Data;<br />
using System.Configuration;<br />
using System.Web;<br />
using System.Web.Security;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.WebControls.WebParts;<br />
using System.Web.UI.HtmlControls;<br />
using System.Net.Mail;</p>
<p>namespace EmailClass<br />
{<br />
public class Email<br />
{<br />
public string Send_Email(string SendFrom,string SendTo, string Subject, string Body)<br />
{<br />
try<br />
{<br />
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@&#8221;\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*&#8221;);</p>
<p>bool result = regex.IsMatch(to);<br />
if (result == false)<br />
{<br />
return &#8220;Địa chỉ email không hợp lệ.&#8221;;<br />
}<br />
else<br />
{<br />
System.Net.Mail.SmtpClient smtp = new SmtpClient();<br />
System.Net.Mail.MailMessage msg = new MailMessage(SendFrom,SendTo,Subject,Body);<br />
msg.IsBodyHtml = true;<br />
smtp.Host = &#8220;smtp.gmail.com&#8221;;//Sử dụng SMTP của gmail<br />
smtp.Send(msg);<br />
return &#8220;Email đã được gửi đến: &#8221; + SendTo + &#8220;.&#8221;;<br />
}<br />
}<br />
catch<br />
{<br />
return &#8220;&#8221;;<br />
}<br />
}</p>
<p>public string Send_Email_With_Attachment(string SendTo, string SendFrom, string Subject, string Body, string AttachmentPath)<br />
{<br />
try<br />
{<br />
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@&#8221;\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*&#8221;);</p>
<p>string from = SendFrom;<br />
string to = SendTo;<br />
string subject = Subject;<br />
string body = Body;</p>
<p>bool result = regex.IsMatch(to);</p>
<p>if (result == false)<br />
{<br />
return &#8220;Địa chỉ email không hợp lệ.&#8221;;<br />
}<br />
else<br />
{<br />
try<br />
{<br />
MailMessage em = new MailMessage(from, to,subject, body);<br />
Attachment attach = new Attachment(AttachmentPath);</p>
<p>em.Attachments.Add(attach);<br />
em.Bcc.Add(from);<br />
System.Net.Mail.SmtpClient smtp = new SmtpClient();<br />
smtp.Host = &#8220;smtp.gmail.com&#8221;;//Ví dụ xử dụng SMTP của gmail<br />
smtp.Send(em);<br />
return &#8220;&#8221;;<br />
}<br />
catch (Exception ex)<br />
{<br />
return ex.Message;<br />
}<br />
}<br />
}</p>
<p>catch (Exception ex)<br />
{<br />
return ex.Message;<br />
}<br />
}</p>
<p>public string Send_Email_With_BCC_Attachment(string SendTo, string SendBCC, string SendFrom, string Subject, string Body, string AttachmentPath)<br />
{<br />
try<br />
{<br />
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@&#8221;\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*&#8221;);<br />
string from = SendFrom;<br />
string to = SendTo; //Danh sách email được ngăn cách nhau bởi dấu &#8220;;&#8221;<br />
string subject = Subject;<br />
string body = Body;<br />
string bcc = SendBCC;</p>
<p>bool result = true;<br />
String[] ALL_EMAILS = to.Split(&#8216;;&#8217;);</p>
<p>foreach (string emailaddress in ALL_EMAILS)<br />
{<br />
result = regex.IsMatch(emailaddress);<br />
if (result == false)<br />
{<br />
return &#8220;Địa chỉ email không hợp lệ.&#8221;;<br />
}<br />
}</p>
<p>if (result == true)<br />
{<br />
try<br />
{<br />
MailMessage em = new MailMessage(from, to, subject, body);<br />
Attachment attach = new  Attachment(AttachmentPath);<br />
em.Attachments.Add(attach);<br />
em.Bcc.Add(bcc);</p>
<p>System.Net.Mail.SmtpClient smtp = new SmtpClient();<br />
smtp.Host = &#8220;smtp.gmail.com&#8221;;//Ví dụ xử dụng SMTP của gmail<br />
smtp.Send(em);</p>
<p>return &#8220;&#8221;;<br />
}<br />
catch (Exception ex)<br />
{<br />
return ex.Message;<br />
}<br />
}<br />
else<br />
{<br />
return &#8220;&#8221;;<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
return ex.Message;<br />
}<br />
}<br />
}<br />
}</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[How to get the path to the temporary folder?]]></title>
<link>http://michlg.wordpress.com/2009/11/15/how-to-get-the-path-to-the-temporary-folder/</link>
<pubDate>Sat, 14 Nov 2009 22:12:46 +0000</pubDate>
<dc:creator>michlG</dc:creator>
<guid>http://michlg.wordpress.com/2009/11/15/how-to-get-the-path-to-the-temporary-folder/</guid>
<description><![CDATA[Hello everybody, a few days ago a friend asked me how to get the temporary folder of the current sys]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Hello everybody,</p>
<p>a few days ago a friend asked me how to get the temporary folder of the current system.<br />
So I decided to write a short post on my Blog.</p>
<p>Well if you want to get the temporary folder you can use the following code as an example</p>
<pre class="brush: csharp;">
string tmp = Path.GetTempPath();

string tmp2 = Environment.GetEnvironmentVariable(&#34;TEMP&#34;);
//The two methods should return the same result
</pre>
<p>Regards<br />
Michael</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Meet RunDialog V2]]></title>
<link>http://ventspace.wordpress.com/2009/11/11/meet-rundialog-v2/</link>
<pubDate>Thu, 12 Nov 2009 03:19:42 +0000</pubDate>
<dc:creator>Promit</dc:creator>
<guid>http://ventspace.wordpress.com/2009/11/11/meet-rundialog-v2/</guid>
<description><![CDATA[I know what you&#8217;re thinking, and the answer is YES. It does remember all of the settings each ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I know what you&#8217;re thinking, and the answer is YES. It does remember all of the settings each time you open it! You&#8217;ll be able to save and load configurations shortly, too.<br />
<a href="http://ventspace.wordpress.com/files/2009/11/111109-rundialogv2.jpg"><img src="http://ventspace.wordpress.com/files/2009/11/111109-rundialogv2.jpg" alt="Run Dialog V2" title="Run Dialog V2" width="602" height="540" class="alignnone size-full wp-image-334" /></a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[List2Code]]></title>
<link>http://codesticks.wordpress.com/2009/11/08/list2code/</link>
<pubDate>Sun, 08 Nov 2009 19:56:47 +0000</pubDate>
<dc:creator>winglinglang</dc:creator>
<guid>http://codesticks.wordpress.com/2009/11/08/list2code/</guid>
<description><![CDATA[List2Code is very Simple Application that takes comma delimited list and runs it a template to creat]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>List2Code is very Simple Application that takes comma delimited list and runs it a template to create code that can be copied and pasted in your application. The Goal is to quickly create large amount of properties or xml files using a comma delimited list.</p>
<div id="attachment_19" class="wp-caption alignnone" style="width: 310px"><img class="size-medium wp-image-19 " title="List2Code" src="http://codesticks.wordpress.com/files/2009/11/list2code.png?w=300" alt="Screen shot" width="300" height="254" /><p class="wp-caption-text">List2Code Main Window</p></div>
<p>The Code and Source Code is available on CodePlex <a href="http://list2code.codeplex.com/">http://list2code.codeplex.com/</a></p>
<p>Here is some Template&#8217;s You can use.</p>
<h3>Template Example&#8217;s</h3>
<p><strong>Clone a Object Template</strong><br />
<code><br />
{0}=fromobj.{0};<br />
</code></p>
<p>*where the fromobj the object is that you want to clone from.</p>
<p><strong>Normal Property Template</strong><br />
<code><br />
public {0} {1} {get;set;}<br />
</code></p>
<p><span style="color:#000000;"><strong>INotifyPropertyChanged Property Template</strong></span></p>
<p><code><br />
private {0} m_{1};<br />
public {0} {1}<br />
{<br />
get { return m_{1}; }<br />
set<br />
  {<br />
  if (value != m_{1})<br />
  {<br />
  m_{1} = value;<br />
  if (PropertyChanged != null)<br />
    PropertyChanged(this, new PropertyChangedEventArgs("{1}"));<br />
    }<br />
  }<br />
}<br />
</code></p>
<div>a Usefull SQL Query to retrieve the column names from a database table, You can copy and paste the columns names into the list2code content box to generate properties.</div>
<pre class="brush: sql;">
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'TableNameGoesHere'
ORDER BY ORDINAL_POSITION
</pre>
<div>[thanks to <a href="http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=57418">http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=57418</a>]</div>
<div><span style="color:#888888;"><br />
</span></div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[EPiServer Extension methods, part 1 of many]]></title>
<link>http://thisisnothing.wordpress.com/2009/11/07/episerver-extension-methods-part-1-of-many/</link>
<pubDate>Sat, 07 Nov 2009 00:10:15 +0000</pubDate>
<dc:creator>hn</dc:creator>
<guid>http://thisisnothing.wordpress.com/2009/11/07/episerver-extension-methods-part-1-of-many/</guid>
<description><![CDATA[So Frederik Vig started a community project around EPiServer Extensions which I believe is a great i]]></description>
<content:encoded><![CDATA[So Frederik Vig started a community project around EPiServer Extensions which I believe is a great i]]></content:encoded>
</item>
<item>
<title><![CDATA[C# - Tipo de Variável]]></title>
<link>http://juarezsilva.wordpress.com/2009/11/05/cshap-tipo-de-variavel/</link>
<pubDate>Thu, 05 Nov 2009 18:30:25 +0000</pubDate>
<dc:creator>juarezsilva</dc:creator>
<guid>http://juarezsilva.wordpress.com/2009/11/05/cshap-tipo-de-variavel/</guid>
<description><![CDATA[Para quem está começando a desenvolver em uma linguagem, uma as principais dúvidas é sobre o tipo de]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Para quem está começando a desenvolver em uma linguagem, uma as principais dúvidas é sobre o tipo de variável que a linguagem suporta. No C# os tipos de variáveis podem ser:</p>
<table border="0" cellspacing="0" cellpadding="2" width="270">
<tbody>
<tr>
<td width="43%" valign="top"><strong>C# Type </strong></td>
<td width="56%" valign="top"><strong> .NET Framework type </strong></td>
</tr>
<tr>
<td width="43%" valign="top">bool</td>
<td width="56%" valign="top">System.Boolean</td>
</tr>
<tr>
<td width="43%" valign="top">byte</td>
<td width="56%" valign="top">System.Byte</td>
</tr>
<tr>
<td width="43%" valign="top">sbyte</td>
<td width="56%" valign="top">System.SByte</td>
</tr>
<tr>
<td width="43%" valign="top">char</td>
<td width="56%" valign="top">System.Char</td>
</tr>
<tr>
<td width="43%" valign="top">decimal</td>
<td width="56%" valign="top">System.Decimal</td>
</tr>
<tr>
<td width="43%" valign="top">double</td>
<td width="56%" valign="top">System.Double</td>
</tr>
<tr>
<td width="43%" valign="top">float</td>
<td width="56%" valign="top">System.Single</td>
</tr>
<tr>
<td width="43%" valign="top">int</td>
<td width="56%" valign="top">System.Int32</td>
</tr>
<tr>
<td width="43%" valign="top">uint</td>
<td width="56%" valign="top">System.UInt32</td>
</tr>
<tr>
<td width="43%" valign="top">long</td>
<td width="56%" valign="top">System.Int64</td>
</tr>
<tr>
<td width="43%" valign="top">ulong</td>
<td width="56%" valign="top">System.UInt64</td>
</tr>
<tr>
<td width="43%" valign="top">object</td>
<td width="56%" valign="top">System.Object</td>
</tr>
<tr>
<td width="43%" valign="top">short</td>
<td width="56%" valign="top">System.Int16</td>
</tr>
<tr>
<td width="43%" valign="top">ushort</td>
<td width="56%" valign="top">System.UInt16</td>
</tr>
<tr>
<td width="43%" valign="top">string</td>
<td width="56%" valign="top">System.String</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p>e abaixo tem a faixa de valores que cada tipo suporta</p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="2" width="574">
<tbody>
<tr>
<td valign="top"><strong> C# Type </strong></td>
<td valign="top"><strong> Valores possíveis de se armazenar </strong></td>
</tr>
<tr>
<td valign="top">bool</td>
<td valign="top">Verdadeiro ou Falso (Valores booleandos)</td>
</tr>
<tr>
<td valign="top">byte</td>
<td valign="top">0 a 255 (8 bits)</td>
</tr>
<tr>
<td valign="top">sbyte</td>
<td valign="top">-128 a 127 (8 bits)</td>
</tr>
<tr>
<td valign="top">char</td>
<td valign="top">Um caractere (16 bits)</td>
</tr>
<tr>
<td valign="top">decimal</td>
<td valign="top">±1.0 × 10−28 a ±7.9 × 1028 (128 bits)</td>
</tr>
<tr>
<td valign="top">double</td>
<td valign="top">±5.0 × 10−324 a ±1.7 × 10308 (64 bits)</td>
</tr>
<tr>
<td valign="top">float</td>
<td valign="top">±1.5 × 10−45 a ±3.4 × 1038 (32 bits)</td>
</tr>
<tr>
<td valign="top">int</td>
<td valign="top">-2,147,483,648 a 2,147,483,647 (32 bits)</td>
</tr>
<tr>
<td valign="top">uint</td>
<td valign="top">0 a 4,294,967,295 (32 bits)</td>
</tr>
<tr>
<td valign="top">long</td>
<td valign="top">–9,223,372,036,854,775,808 a 9,223,372,036,854,775,807 (64 bits)</td>
</tr>
<tr>
<td valign="top">ulong</td>
<td valign="top">0 a 18,446,744,073,709,551,615 (64 bits)</td>
</tr>
<tr>
<td valign="top">object</td>
<td valign="top">Qualquer tipo.</td>
</tr>
<tr>
<td valign="top">short</td>
<td valign="top">-32,768 a 32,767 (16 bits)</td>
</tr>
<tr>
<td valign="top">ushort</td>
<td valign="top">0 a 65,535 (16 bits)</td>
</tr>
<tr>
<td valign="top">string</td>
<td valign="top">Seqüência de caracteres (16 bits por caractere)</td>
</tr>
</tbody>
</table>
<p>C# &#8211; Simples, Objetivo e sem mistério.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Csharp Tutorial]]></title>
<link>http://diggsamachar.wordpress.com/2009/11/04/csharp-tutorial-2/</link>
<pubDate>Wed, 04 Nov 2009 13:52:36 +0000</pubDate>
<dc:creator>diggsamachar</dc:creator>
<guid>http://diggsamachar.wordpress.com/2009/11/04/csharp-tutorial-2/</guid>
<description><![CDATA[So many times I asked people to take a look at csharp tutorial, but nobody listens. Why ?]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>So many times I asked people to take a look at <a href="http://www.referencedesigner.com/tutorials/csharp/csharp_1.php">csharp tutorial</a>, but nobody listens. Why ?</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[New blog, dedicated to proxies!]]></title>
<link>http://otoom.wordpress.com/2009/10/31/new-blog-dedicated-to-proxies-2/</link>
<pubDate>Sat, 31 Oct 2009 16:10:37 +0000</pubDate>
<dc:creator>Ant</dc:creator>
<guid>http://otoom.wordpress.com/2009/10/31/new-blog-dedicated-to-proxies-2/</guid>
<description><![CDATA[Well, opened up a new blog. Banner looks professional. Anyone who needs proxy lists, we frequently u]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Well, opened up a new blog. Banner looks professional.<br />
Anyone who needs proxy lists, we frequently update them. Atleast 3 a day of around 100 proxies.<br />
As i speak i am scanning a proxy list of 200.</p>
<p>Anyways, head on over to it!<br />
<strong><a href="http://proxxy.wordpress.com">click here to head on over to the superb proxy blog</a></strong></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[New blog, dedicated to proxies!]]></title>
<link>http://otoom.wordpress.com/2009/10/31/new-blog-dedicated-to-proxies/</link>
<pubDate>Sat, 31 Oct 2009 16:05:35 +0000</pubDate>
<dc:creator>Ant</dc:creator>
<guid>http://otoom.wordpress.com/2009/10/31/new-blog-dedicated-to-proxies/</guid>
<description><![CDATA[Well, opened up a new blog. Banner looks professional. Anyone who needs proxy lists, we frequently u]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Well, opened up a new blog. Banner looks professional.<br />
Anyone who needs proxy lists, we frequently update them. Atleast 3 a day of around 100 proxies.<br />
As i speak i am scanning a proxy list of 200.</p>
<p>Anyways, head on over to it!<br />
<strong><a href="http://proxxy.wordpress.com">click here to head on over to the superb proxy blog</a></strong></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Enumerados mejorados en C#]]></title>
<link>http://fravelgue.wordpress.com/2009/10/28/enumerados-mejorados-en-c/</link>
<pubDate>Wed, 28 Oct 2009 23:06:20 +0000</pubDate>
<dc:creator>fravelgue</dc:creator>
<guid>http://fravelgue.wordpress.com/2009/10/28/enumerados-mejorados-en-c/</guid>
<description><![CDATA[Un par de artículos que explican como extender la funcionalidad de los Enumerados en c#. via.]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Un <a href="http://somewebguy.wordpress.com/2009/09/02/build-a-smarter-loop/">par</a> de <a href="http://msmvps.com/blogs/jon_skeet/archive/2007/07/27/smart-enumerations.aspx">artículos</a> que explican como extender la funcionalidad de los Enumerados en c#. <a href="http://stackoverflow.com/questions/1587120/challenge-c-foreach-before-after-even-odd-last-first">via</a>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Lựa chọn Webpart hay là User Control – Phần 2]]></title>
<link>http://kite203.wordpress.com/2009/10/26/l%e1%bb%b1a-ch%e1%bb%8dn-webpart-hay-la-user-control-%e2%80%93-ph%e1%ba%a7n-2/</link>
<pubDate>Mon, 26 Oct 2009 15:29:40 +0000</pubDate>
<dc:creator>kite203</dc:creator>
<guid>http://kite203.wordpress.com/2009/10/26/l%e1%bb%b1a-ch%e1%bb%8dn-webpart-hay-la-user-control-%e2%80%93-ph%e1%ba%a7n-2/</guid>
<description><![CDATA[Hoạt động của Webpart Với đa số mọi người, đây gần như là cách tiếp cận duy nhất. Có nhiều bài hướng]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>Hoạt động của Webpart<br />
</strong></p>
<p>Với đa số mọi người, đây gần như là cách tiếp cận duy nhất. Có nhiều bài hướng dẫn tạo ra Webpart. Các Webpart có nhiều điểm nổi trội so với những giải pháp cho vấn đề trong Sharepoint. Và trong vài trường hợp, chúng là giải pháp tốt nhất cho công việc.</p>
<p>Một ưu điểm lớn nhất của Webpart là mọi thứ đều có snawx. Bạn có thể thao tác với thanh công cụ, thay đổi mọi thứ theo cách của Webpart. Với control, bạn chỉ có thể thực hiện với những gì có sẵn mà thôi.</p>
<p>Mặt khác, điểm mạnh của User Control là điểm yếu của Sharepoint. Nó là một khái niệm mới, lạ lẫm, có thể mất thời gian để làm quen và tăng thời gian phát triển. Webpart lại có ưu điểm về hoạt động. Webpart là giải pháp có hiệu suất tối đa nhất, được hỗ trợ bởi kiến trúc khung trong cơ chế triển khai cơ sở hạ tầng Sharepoint. Tuy nhiên, như đã nói, điều này chỉ có ý nghĩa trong các tổ chức lớn, với các ứng dụng lớn đòi hỏi mở rộng. Trong thực tế,  sự khác nhau là không lớn.</p>
<p><strong>Đánh giá<br />
</strong></p>
<p>Vì sự hiểu biết cơ bản về sự khác nhau là không đủ. Mục này sẽ đề cập sâu hơn về điểm mạnh và yếu trong các trường hợp khác nhau.</p>
<p><strong>Lập trình trực quan</strong></p>
<p>Một khi yếu tố quen thuộc không còn là lợi thế để cho việc lập trình nhanh chóng hơn thì tôi sẽ nghiêng về chọn Webpart. Lập trình dao diện kéo thả được hỗ trợ rất mạnh bởi Visual Studio. Cái này sẽ khiến nhiều người suy nghĩ làm thế nào tận dụng hỗ trợ kéo thả đó.Tuy nhiên, theo tôi, muốn có một giao diện linh hoạt mềm dẻo. Thì chúng ta sẽ phải dùng những cách trang trí riêng, phù hợp với những hoàn cảnh khác nhau. Hoặc khi muốn hiển thị một tập các links hoặc thay thế một chuỗi trong ouput, những lợi thế của User Control trở nên vô dụng.  Trong trường hợp này, rõ ràng Webpart là sự lựa chọn hợp lý.</p>
<p><strong>Đồng bộ</strong></p>
<p>Một trong những ưu điểm của User Control là bạn có thể mang nó từ một trang Sharepoint vào trong một ứng dụng ASP.NET khác. Tuy nhiên, điều gì xảy ra nếu trong User Control đó lại sử dụng thư viện Microsoft.Sharepoint.dll. Tất nhiên là không thể dùng nó ngoài Sharepoint được nữa rồi.  Vì thế lợi thế sử dụng lại biến mất khi bạn sử dụng trực tiếp các tính năng trong Sharepoint. Trong trường hợp này, nếu giao diện là được giản thì hợp lý hơn là code bằng Webpart. Webpart có sự đồng bộ cần và tích hợp sâu vào Sharepoint.</p>
<p><strong>Hoạt động</strong></p>
<p>Mặc dù hiệu suất hoạt động của một ứng dụng luôn nằm trong đầu của người lập trình. Tuy nhiên, ngày nay, một cái Server có giá khoảng $5000, trong nhiều dự án, nó chỉ có giá trị rất nhỏ so với lương trả cho lập toàn bộ nhân công. Vì thế ngày nay, vấn đề hoạt động rất ít khi được chú ý nhiều.</p>
<p>Tuy nhiên vẫn có những trường hợp mà hiệu suất hoạt động được đặt lên tiên quyết. Những thành phần thường xuất hiện trên mọi trang tốt hơn nên dùng Webpart.  Ngay cả với những trang có lượng truy cập thấp. Một ví dụ khác, khi xây dụng một thành phần có chức năng lấy các đường dẫn tương đối và tăng khả năng tạo cache hợp lý. Nó sẽ được tạo ra nhờ Webpart chứ không phải là User Control. Vì nó được load ra ít nhất 2 lần trong một trang – 1 trong header và 1 trong footer. Thành phần core này được sử dụng để đảm bảo hiệu suất hoạt động của Site mặc cho sử dụng một User Control sẽ dễ dàng hơn.</p>
<p><strong>Cơ chế tích hợp</strong></p>
<p>Xem xét cuối cùng là Webpart phải dựa vào cấu hình của mẫu thiết kế. Nói cách khác, chúng ta nên tạo ra một ứng dụng cho phép lấy nội dung từ URL hơn là tạo ra từng Webpart riêng biệt cho từng URL được gọi đến. Cấu hình cơ bản này rất hữu ích trong việc giảm code trùng lặp vào nâng cao giải pháp tổng thể.</p>
<p>Với Smartpart(Xem phần 1), có một vấn đề đó là quản lý cách thức mà thông tin được đẩy vào cho User Control. Giải pháp đó là tạo một đối tượng để chứa Control hoặc là tạo ra lớp con của SmartPart để thêm vào khải năng đẩy thông tin vào thuộc tính từ Sharepoint, Câu truy vấn từ URL hay là từ FORM POST. Điều này cho phép bạn cân bằng các tính năng của SharePoint và không cần tạo ra các liên kết trực tiếp giữa Control và Sharepoint.</p>
<p>Ví dụ, User Control có một thuộc tính Public để chứa ID của bản ghi (record) hiện tại. Những trang nào mà có ID cho bản ghi hiện tại lấy ra từ Sharepoint sẽ lấy được nó vì đó là thuộc tính Public. Nó có thể đẩy ID đó vào thuộc tính public của User Control. Điều này cho phép User Control không bị dính chặt với Sharepoint mà vẫn tận dụng được các tính năng của Sharepoint.</p>
<p><strong>Kết luận<br />
</strong></p>
<p>Như vậy, hầu hết những quan điểm cho rằng viết một chức năng cho Sharepoint là phải dùng Webpart là sai. Thích hợp hơn là chúng ta sử dụng ASP.NET user Control để tân dụng chúng trong Sharepoint bằng những kỹ thuật như là SmartPart.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Shrouding CSharp and Java Source Code with AWK]]></title>
<link>http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/</link>
<pubDate>Sun, 25 Oct 2009 22:32:11 +0000</pubDate>
<dc:creator>Jim Lawless</dc:creator>
<guid>http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/</guid>
<description><![CDATA[I enjoy tinkering with both Java and C# and publish a lot of my source on this blog under a very lib]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I enjoy tinkering with both Java and C# and publish a lot of my source on this blog under a very liberal open-source license.</p>
<p>I have wondered, however, what I would do if I had to protect a commercial program written in either of the two. The obvious choice would be to purchase a professional obfuscation program that defeats most decompilers.  Fair enough.  Most of these work on the compiled intermediate code.</p>
<p>What, however, if I just wanted to put some mild protection into the compiled product?  The mild protection I refer to would still allow the code to be decompiled back to source form, but the person decompiling would have to work hard to make use of the bulk of the code.</p>
<p>My solution was to try a simple <em>shrouding</em> utility.</p>
<p>Shrouding ( also referred to as <em>fogging</em> ) is a kind of source-level obfuscation that was somewhat popular years ago for C programs sold in source form.  The programs would generally compile but would be unreadable enough that they would discourage someone from using portions of unlicensed code in other programs.</p>
<p>A lot of these source-level shroud utilities are language-aware and determine what variables, functions, methods, and classes are locally-scoped.  The shroud utility then replaces these with generated identifiers.</p>
<p>Most shrouding utilities go a step further and obfuscate literal strings as well as rewriting flow-control constructs.</p>
<p>All I had intended to do was to change the locally-scoped identifier-names to something that my script generates.</p>
<p>My proof-of-concept is an AWK script called <strong>foggy.awk</strong>.  foggy.awk replaces any identifier it finds beginning with two underscore characters with a new identifier containing the prefix &#8220;i_&#8221; and a sequentially generated number.</p>
<p>This means that in my code, I have to observe a coding convention.  I will have to prefix the name of any identifier that should be shrouded with two underscores.</p>
<p>First, here&#8217;s the shrouding script:</p>
<p><strong>foggy.awk</strong></p>
<pre class="brush: cpp;">
# Foggy.awk
# A source-code shrouding utility.
# Replace any &#34;identifier&#34; beginning with __ with a sequentially-
# numbered new identifier
#
# License: MIT / X11
# Copyright (c) 2009 by James K. Lawless
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the &#34;Software&#34;), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED &#34;AS IS&#34;, WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
BEGIN {
   legal=&#34;abcdefghijklmnopqrstuvwxyz&#34;;
   legal=legal &#34;ABCDEFGHIJKLMNOPQRSTUVWXYZ&#34;;
   legal=legal &#34;_0123456789&#34; ;
   id_counter=0;
   id_list[&#34;__&#34;]=&#34;__&#34;;
}
{
   state=0;
   s=&#34;&#34;;
   for(i=1;i&#60;=length($0);i++) {
      c=substr($0,i,1);
      if(state==0) {
         if(c==&#34;_&#34;) {
            state=1;
         }
         else {
            s=s c;
         }
      }
      else {
         if(state==1) {
            if(c==&#34;_&#34;) {
               state=2;
               id=&#34;__&#34;;
            }
            else {
               s=s &#34;_&#34; c;
               state=0;
            }
         }
         else {
            # state == 2
            if(index(legal,c)&#60;1) {
               if(id_list[id]==&#34;&#34;) {
                  tmp_id=&#34;i_&#34; id_counter;
                  id_counter++;
                  id_list[id]=tmp_id;
               }
               s=s id_list[id];
                  # decrement the index to forget the current
                  # character we're looking at
               i--;
               state=0;
            }
            else {
               id=id c;
            }
         }
      }
   }
   if(state==0) {
      printf(&#34;%s\n&#34;,s);
   }
   else {
      if(state==1) {
         printf(&#34;%s_\n&#34;,s);
      }
      else {
         if(state==2) {
            if(id_list[id]==&#34;&#34;) {
               tmp_id=&#34;i_&#34; id_counter;
               id_counter++;
               id_list[id]=tmp_id;
            }
            printf(&#34;%s%s\n&#34;,s,id_list[id]);
         }
      }
   }
}
</pre>
<p>As a side note, I have compiled the above script with the Thompson Automation AWK (TAWK) compiler for Windows into the exe <strong>foggy.exe</strong> available in the foggy.zip file referenced at the end of this post.</p>
<p>Unfortunately, TAWK is no longer commercially available.  I reviewed this compiler years ago in Dr. Dobbs Journal.  ( See <em>Examining the TAWK Compiler, DDJ May &#8216;97</em> here: <a href="http://www.ddj.com/architect/184410193">http://www.ddj.com/architect/184410193</a> &#8230;)</p>
<p>I also tested with GNU GAWK for Windows.</p>
<p>I would have preferred to use a regular expression with captured groups, but the AWK tools I have do not support those sorts of regex features.  This likely would have been a smaller Perl script, but I wanted to try it in AWK.  The necessary parser state transitions didn&#8217;t seem to be too deep, so I gave it a go.</p>
<p>To use the above script either type:<br />
<font face="Courier New" color="blue"><br />
gawk -f foggy.awk &#60; inputfle &#62; outputfile<br />
</font></code><br />
...or, if you're using foggy.exe<br />
<font face="Courier New" color="blue"><br />
foggy.awk &#60; inputfle &#62; outputfile<br />
</font></code></p>
<p>Let's first take a look at a Java program that now contains shroud-ready identifiers.  I took the source from MicroHttp1.java from my post here: <a href="http://jimlawless.wordpress.com/2009/08/23/tracing-xslt-with-a-tiny-java-web-server/">http://jimlawless.wordpress.com/2009/08/23/tracing-xslt-with-a-tiny-java-web-server/</a></p>
<pre class="brush: java;">
// MicroHttp1
// A small , specialized web server in Java
//
// License: MIT / X11
// Copyright (c) 2009 by James K. Lawless
// jimbo@radiks.net http://www.radiks.net/~jimbo
// http://www.mailsend-online.com
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the &#34;Software&#34;), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED &#34;AS IS&#34;, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

import java.io.*;
import java.net.*;
import java.util.Date;

public class MicroHttp1Obf {
   public static void main(String[] __args)
      throws IOException {
      ServerSocket __serv;
      Socket __s;
      String __str;
      PrintWriter __pw;
      BufferedReader __br;
      __serv=new ServerSocket(80);
      System.out.println(&#34;Micro HTTP Server v 0.1&#34;);
      System.out.println();
      for(;;){
         __s=__serv.accept();
         __br=new BufferedReader(
            new InputStreamReader(
               __s.getInputStream()));
         for(;;) {
            __str=__br.readLine();
            System.out.println(__str);
            if( ! __br.ready())
               break;
         }
         System.out.println();
         __pw=new PrintWriter(
            __s.getOutputStream(), true);

         __pw.print(&#34;HTTP 200 OK\r\n&#34;);
         __pw.print(&#34;Content-type: text/html\r\n\r\n&#34;);
         __pw.print(&#34;&#60;html&#62;&#60;head /&#62;&#60;body&#62;&#34;);
         __pw.print(&#34;Current date/time &#34; + new Date());
         __pw.print(&#34;&#60;/body&#62;&#60;/html&#62;&#34;);
         __pw.close();
      }
   }
}
</pre>
<p>Note that I had to change the class definition to what I would be targetting for my output filename, since the main Java class and source filename prefix must match.</p>
<p>There are lots of underscores now in this short script.  Here's the shrouded output:</p>
<pre class="brush: java;">
// MicroHttp1
// A small , specialized web server in Java
//
// License: MIT / X11
// Copyright (c) 2009 by James K. Lawless
// jimbo@radiks.net http://www.radiks.net/~jimbo
// http://www.mailsend-online.com
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the &#34;Software&#34;), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED &#34;AS IS&#34;, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

import java.io.*;
import java.net.*;
import java.util.Date;

public class MicroHttp1Obf {
   public static void main(String[] i_0)
      throws IOException {
      ServerSocket i_1;
      Socket i_2;
      String i_3;
      PrintWriter i_4;
      BufferedReader i_5;
      i_1=new ServerSocket(80);
      System.out.println(&#34;Micro HTTP Server v 0.1&#34;);
      System.out.println();
      for(;;){
         i_2=i_1.accept();
         i_5=new BufferedReader(
            new InputStreamReader(
               i_2.getInputStream()));
         for(;;) {
            i_3=i_5.readLine();
            System.out.println(i_3);
            if( ! i_5.ready())
               break;
         }
         System.out.println();
         i_4=new PrintWriter(
            i_2.getOutputStream(), true);

         i_4.print(&#34;HTTP 200 OK\r\n&#34;);
         i_4.print(&#34;Content-type: text/html\r\n\r\n&#34;);
         i_4.print(&#34;&#60;html&#62;&#60;head /&#62;&#60;body&#62;&#34;);
         i_4.print(&#34;Current date/time &#34; + new Date());
         i_4.print(&#34;&#60;/body&#62;&#60;/html&#62;&#34;);
         i_4.close();
      }
   }
}
</pre>
<p>There are really only about five shrouded identifiers in this program.  I suppose someone who really wanted to work at it could perform global search-and-replace operations to change them into something meaningful as they analyze the code.</p>
<p>Let's try something a little larger that has more local identifiers.  For this next test, I took the C# source code from my command-line Twitter client <strong>Twimmando</strong>.  See: <a href="http://jimlawless.wordpress.com/2009/05/24/twimmando-a-command-line-twitter-client/">http://jimlawless.wordpress.com/2009/05/24/twimmando-a-command-line-twitter-client/</a></p>
<p>Here's the shroud-ready source:</p>
<pre class="brush: cpp;">
// Twimmando - a command-line Twitter client

// License: MIT / X11
// Copyright (c) 2009 by James K. Lawless
// jimbo@radiks.net http://www.radiks.net/~jimbo
// http://www.mailsend-online.com
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the &#34;Software&#34;), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED &#34;AS IS&#34;, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Net;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Web;

namespace Twimmando
{

   public enum __RequestMethod
   {
      __Get,
      __Post,
      __Head
   }
   class __Config
   {
      public __RequestMethod __Method;
      public string __Uri;
      public string __UserName;
      public string __Password;
      public string __PostData;
   }

   class __Twimmando
   {
      public static string __Version = &#34;Twimmando v1.01 (obfuscated)&#34;;
      public static void Main(string[] __args)
      {
         __Config __config;
         try
         {
            __config=__processCommandLine(__args);
            if(__config.__Uri==null)
               Environment.Exit(1);
            __doHttpRequest(__config);
         }
         catch(Exception e)
         {
            Console.Error.WriteLine(e.ToString());
            Environment.Exit(1);
         }
         Environment.Exit(0);
      }

      public static __Config __processCommandLine(string[] __args)
      {
         int __i;
         __Config __config=new __Config();
         __config.__PostData=&#34;&#34;;
         __config.__Method=__RequestMethod.__Get;

         for(__i=0;__i&#60;__args.Length;__i++) {
            if(string.Compare(__args[__i],&#34;-head&#34;,true)==0) {
               __config.__Method=__RequestMethod.__Head;
            }
            else
            if(string.Compare(__args[__i],&#34;-post&#34;,true)==0) {
               __config.__Method=__RequestMethod.__Post;
            }
            else
            if(string.Compare(__args[__i],&#34;-uri&#34;,true)==0) {
               __config.__Uri=__args[++__i];
            }
            else
            if(string.Compare(__args[__i],&#34;-u&#34;,true)==0) {
               __config.__UserName=__args[++__i];
            }
            else
            if(string.Compare(__args[__i],&#34;-p&#34;,true)==0) {
               __config.__Password=__args[++__i];
            }
            else
            if(string.Compare(__args[__i],&#34;-f&#34;,true)==0) {
               if(__config.__PostData.Length&#62;0) {
                  __config.__PostData+=&#34;&#38;&#34;;
               }
               __config.__PostData+=__args[__i+1]+&#34;=&#34;+HttpUtility.UrlEncode(__args[__i+2]);
               __i+=2;
            }
         }
         if(__config.__Uri==null) {
            Console.WriteLine(__Twimmando.__Version + &#34;\nby Jim Lawless (@lawlessGuy)&#34;);
            Console.WriteLine(&#34;Usage:\n\ttwimmando [options]\nWhere options are:&#34;);
            Console.WriteLine(&#34;   -uri resourceURI   ; such as /statuses/public_timeline.xml&#34;);
            Console.WriteLine(&#34;   -u username        ; Twitter password&#34;);
            Console.WriteLine(&#34;   -p password        ; Twitter user name&#34;);
            Console.WriteLine(&#34;   -head              ; send HTTP HEAD request, default is GET&#34;);
            Console.WriteLine(&#34;   -post              ; send HTTP POST request, default is GET&#34;);
            Console.WriteLine(&#34;   -f name value      ; add POST data name/value pair to request&#34;);
         }
         return __config;
      }

      public static void __doHttpRequest(__Config __config)
      {

         HttpWebRequest __webRequest;
			HttpWebResponse __webResponse;
         Uri __uri=new Uri(&#34;http://twitter.com&#34; + __config.__Uri);
			__webRequest = (HttpWebRequest)HttpWebRequest.Create(__uri);
         if(__config.__Password!=null) {
            __webRequest.Credentials = new NetworkCredential(__config.__UserName, __config.__Password);
         }

	 __webRequest.UserAgent = __Twimmando.__Version;
         if(__config.__Method==__RequestMethod.__Post) {
            __webRequest.Method = &#34;POST&#34;;
               // remove Expect header
            __webRequest.ServicePoint.Expect100Continue = false;
            __webRequest.ContentType=&#34;application/x-www-form-urlencoded&#34;;
            __webRequest.ContentLength = __config.__PostData.Length;
            StreamWriter __sOut=new StreamWriter(__webRequest.GetRequestStream(),System.Text.Encoding.ASCII);
            __sOut.Write(__config.__PostData);
            __sOut.Close();
         }
         else
         if(__config.__Method==__RequestMethod.__Head) {
            __webRequest.Method=&#34;HEAD&#34;;
         }
	 __webResponse = (HttpWebResponse)__webRequest.GetResponse();
         if(__config.__Method==__RequestMethod.__Head) {
            Console.WriteLine(__webResponse.Headers.ToString());
         }
         else {
            Stream __stream = __webResponse.GetResponseStream();
            StreamReader __streamReader =
               new StreamReader(__stream, Encoding.ASCII);
            Console.WriteLine(__streamReader.ReadToEnd());
         }
         __webResponse.Close();
      }
   }
}
</pre>
<p>Here's the encoded result:</p>
<pre class="brush: plain;">
// Twimmando - a command-line Twitter client

// License: MIT / X11
// Copyright (c) 2009 by James K. Lawless
// jimbo@radiks.net http://www.radiks.net/~jimbo
// http://www.mailsend-online.com
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the &#34;Software&#34;), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED &#34;AS IS&#34;, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Net;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Web;

namespace Twimmando
{

   public enum i_0
   {
      i_1,
      i_2,
      i_3
   }
   class i_4
   {
      public i_0 i_5;
      public string i_6;
      public string i_7;
      public string i_8;
      public string i_9;
   }

   class i_10
   {
      public static string i_11 = &#34;Twimmando v1.01 (obfuscated)&#34;;
      public static void Main(string[] i_12)
      {
         i_4 i_13;
         try
         {
            i_13=i_14(i_12);
            if(i_13.i_6==null)
               Environment.Exit(1);
            i_15(i_13);
         }
         catch(Exception e)
         {
            Console.Error.WriteLine(e.ToString());
            Environment.Exit(1);
         }
         Environment.Exit(0);
      }

      public static i_4 i_14(string[] i_12)
      {
         int i_16;
         i_4 i_13=new i_4();
         i_13.i_9=&#34;&#34;;
         i_13.i_5=i_0.i_1;

         for(i_16=0;i_16&#60;i_12.Length;i_16++) {
            if(string.Compare(i_12[i_16],&#34;-head&#34;,true)==0) {
               i_13.i_5=i_0.i_3;
            }
            else
            if(string.Compare(i_12[i_16],&#34;-post&#34;,true)==0) {
               i_13.i_5=i_0.i_2;
            }
            else
            if(string.Compare(i_12[i_16],&#34;-uri&#34;,true)==0) {
               i_13.i_6=i_12[++i_16];
            }
            else
            if(string.Compare(i_12[i_16],&#34;-u&#34;,true)==0) {
               i_13.i_7=i_12[++i_16];
            }
            else
            if(string.Compare(i_12[i_16],&#34;-p&#34;,true)==0) {
               i_13.i_8=i_12[++i_16];
            }
            else
            if(string.Compare(i_12[i_16],&#34;-f&#34;,true)==0) {
               if(i_13.i_9.Length&#62;0) {
                  i_13.i_9+=&#34;&#38;&#34;;
               }
               i_13.i_9+=i_12[i_16+1]+&#34;=&#34;+HttpUtility.UrlEncode(i_12[i_16+2]);
               i_16+=2;
            }
         }
         if(i_13.i_6==null) {
            Console.WriteLine(i_10.i_11 + &#34;\nby Jim Lawless (@lawlessGuy)&#34;);
            Console.WriteLine(&#34;Usage:\n\ttwimmando [options]\nWhere options are:&#34;);
            Console.WriteLine(&#34;   -uri resourceURI   ; such as /statuses/public_timeline.xml&#34;);
            Console.WriteLine(&#34;   -u username        ; Twitter password&#34;);
            Console.WriteLine(&#34;   -p password        ; Twitter user name&#34;);
            Console.WriteLine(&#34;   -head              ; send HTTP HEAD request, default is GET&#34;);
            Console.WriteLine(&#34;   -post              ; send HTTP POST request, default is GET&#34;);
            Console.WriteLine(&#34;   -f name value      ; add POST data name/value pair to request&#34;);
         }
         return i_13;
      }

      public static void i_15(i_4 i_13)
      {

         HttpWebRequest i_17;
			HttpWebResponse i_18;
         Uri i_19=new Uri(&#34;http://twitter.com&#34; + i_13.i_6);
			i_17 = (HttpWebRequest)HttpWebRequest.Create(i_19);
         if(i_13.i_8!=null) {
            i_17.Credentials = new NetworkCredential(i_13.i_7, i_13.i_8);
         }

	 i_17.UserAgent = i_10.i_11;
         if(i_13.i_5==i_0.i_2) {
            i_17.Method = &#34;POST&#34;;
               // remove Expect header
            i_17.ServicePoint.Expect100Continue = false;
            i_17.ContentType=&#34;application/x-www-form-urlencoded&#34;;
            i_17.ContentLength = i_13.i_9.Length;
            StreamWriter i_20=new StreamWriter(i_17.GetRequestStream(),System.Text.Encoding.ASCII);
            i_20.Write(i_13.i_9);
            i_20.Close();
         }
         else
         if(i_13.i_5==i_0.i_3) {
            i_17.Method=&#34;HEAD&#34;;
         }
	 i_18 = (HttpWebResponse)i_17.GetResponse();
         if(i_13.i_5==i_0.i_3) {
            Console.WriteLine(i_18.Headers.ToString());
         }
         else {
            Stream i_21 = i_18.GetResponseStream();
            StreamReader i_22 =
               new StreamReader(i_21, Encoding.ASCII);
            Console.WriteLine(i_22.ReadToEnd());
         }
         i_18.Close();
      }
   }
}
</pre>
<p>This shrouded program was much more difficult for me to read, as I used some local class definitions and used more local variables and methods than I had used in the sample Java program.</p>
<p>My conclusion?</p>
<p>Well, if I <strong>had to</strong> employ this method, I think I could grow into learning to deal with the added noise of the extra underscores in the source.</p>
<p>However, I still think that language-aware shrouding utilities would be much less painful to use.</p>
<p>The source and Windows executable file for foggy.awk can be downloaded in a single archive at:<br />
<a href="http://www.mailsend-online.com/wp/foggy.zip">http://www.mailsend-online.com/wp/foggy.zip</a></p>
<p><a href="http://del.icio.us/post?url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/&#38;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank"><img title="del_icio_us" src="http://www.mailsend-online.com/wp/del_icio_us.png" alt="del_icio_us" /></a> <a href="http://del.icio.us/post?url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/&#38;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank">Save to del.icio.us</a><br /><a href="http://digg.com/submit?phase=2&#38;url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/&#38;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank"><img title="digg" src="http://www.mailsend-online.com/wp/digg.png" alt="digg" /></a> <a href="http://digg.com/submit?phase=2&#38;url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/&#38;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank">Digg it</a><br /><a href="http://reddit.com/submit?url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/&#38;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank"><img title="reddit" src="http://www.mailsend-online.com/wp/reddit.png" alt="reddit" /></a> <a href="http://reddit.com/submit?url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/&#38;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank">Save to Reddit</a><br /><a href="http://www.facebook.com/share.php?u=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/" target="_blank"><img title="facebook" src="http://www.mailsend-online.com/wp/facebook.png" alt="facebook" /></a> <a href="http://www.facebook.com/share.php?u=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/" target="_blank">Share on Facebook</a><br /><a href="http://twitter.com/home?status=Check+out+http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/"><img title="twitter" src="http://www.mailsend-online.com/wp/twitter.gif" alt="twitter" /></a> <a href="http://twitter.com/home?status=Check+out+http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/" target="_blank">Share on Twitter</a><br /><a href="http://www.addthis.com/bookmark.php?pub=dvd&#38;url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank"><img title="aolfav" src="http://www.mailsend-online.com/wp/aolfav.gif" alt="aolfav" /></a> <a href="http://www.addthis.com/bookmark.php?pub=dvd&#38;url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank">More bookmarks</a>
<p><img src="http://www.mailsend-online.com/cgi-bin/wphit.pl" /><br />
<em>Unless otherwise noted, all code and text entries are Copyright © 2009 by James K. Lawless</em></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Something that bothered me for 3 days...]]></title>
<link>http://jelendil.wordpress.com/2009/10/23/something-that-bothered-me-for-3-days/</link>
<pubDate>Fri, 23 Oct 2009 09:59:29 +0000</pubDate>
<dc:creator>jackeblagare</dc:creator>
<guid>http://jelendil.wordpress.com/2009/10/23/something-that-bothered-me-for-3-days/</guid>
<description><![CDATA[Three days ago, I thought of implementing an application that would be able to track the things I sp]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="text-align:justify;">Three days ago, I thought of implementing an application that would be able to track the things I spend my money on, my debts, and the debts of others to me.</p>
<p style="text-align:justify;">I thought of implementing it as a web application but a thought stopped me in my tracks. Why not use C# as the front end and MySQL as the back end? That would be something new. I have not tried connecting C# (or anything else except JSP and PHP) to a database yet. Then and there I searched the web on how to connect C# to MySQL . Relatively easy. Soon, I was able to connect successfully and started coding the user interface. It was then that a big stumbling block came up.</p>
<p style="text-align:justify;">In PHP, you do this to insert a new tuple into the database -&#62;  &#8220;insert into table1 values(&#8216;constant&#8217;,'$variable&#8217;)&#8221;;<br />
Thinking logically at first, I tried -&#62; &#8220;insert into table1 values(var1,var2,var3)&#8221;; (No errors but wrong values)<br />
After searching for a while, I tried &#8230;values(@var1,@var2,@var3); (Exception detected.T_T)</p>
<p style="text-align:justify;">Just an hour ago, I came along a blog and I thought of the old way of inserting variables in SQL queries in PHP. String concatenation. &#8220;This is it&#8221;,I thought to myself.</p>
<p style="text-align:justify;">I tried this at first: &#8220;INSERT INTO expenses values (&#8221; + expense + &#8220;,&#8221; + amount + &#8220;,&#8221; + date + &#8220;);&#8221;;<br />
(Looks great right? Error! Column name is invalid)<br />
Thinking&#8230;thinking&#8230;Supposedly right but very wrong. I started to consult my friend Google again and I came across a forum that says in order to insert a string variable into the query, there should be single quotes surrounding the variable name.Hmmm..<br />
Tried this (note the red single quotes): &#8220;INSERT INTO expenses values (<span style="color:#ff0000;">&#8216;</span> &#8221; + expense + &#8220;<span style="color:#ff0000;"> &#8216;</span>,&#8221; + amount + &#8220;,<span style="color:#ff0000;">&#8216;</span> &#8221; + date + &#8221; <span style="color:#ff0000;">&#8216;</span>);&#8221;;  (and it worked perfectly!)=)</p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
