<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Development</title>
        <link>http://www.ridgway.co.za/category/13.aspx</link>
        <description>Development</description>
        <language>en-ZA</language>
        <copyright>Eden Ridgway</copyright>
        <managingEditor>eden@ridgway.co.za</managingEditor>
        <generator>Subtext Version 1.9.5.176</generator>
        <item>
            <title>.Net Developer's Guide to Getting Started with Cassandra</title>
            <link>http://ridgway.co.za/archive/2009/11/06/net-developers-guide-to-getting-started-with-cassandra.aspx</link>
            <description>&lt;p&gt;I've been quite curious about the various &lt;a href="http://en.wikipedia.org/wiki/BigTable" target="_blank"&gt;BigTable&lt;/a&gt; like implementations as they could have some bearing on what I am involved with at work. After reading various write ups about the competing approaches (e.g. &lt;a href="http://www.vimeo.com/5198661" target="_blank"&gt;HyperTable&lt;/a&gt;, HBase, Dynomite, Voldemort, &lt;a href="http://www.vimeo.com/5184456" target="_blank"&gt;Mongodb&lt;/a&gt;) I decided that &lt;a href="http://incubator.apache.org/cassandra/" target="_blank"&gt;Cassandra&lt;/a&gt; looked like the best option for what I'm after. What I didn't realise was that it wasn't going to be as straight forward as it appears to set it all up as there is no end-to-end guide of getting started with it. So the objective of this post is not to explain Cassandra but save you several hours of jumping all over the web trying to work out what you should do next and how to generate the necessary C# Cassandra Thrift client code. If parts of the post don't apply, e.g. VM setup, simply skip ahead to the parts that do. If you want more information about Cassandra you should check out the following posts: &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://blog.evanweaver.com/articles/2009/07/06/up-and-running-with-cassandra/" target="_blank"&gt;Up and running with Cassandra&lt;/a&gt; &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://arin.me/code/wtf-is-a-supercolumn-cassandra-data-model" target="_blank"&gt;WTF is a SuperColumn? An Intro to the Cassandra Data Model&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;So to get Cassandra up and running in a Virtual Machine (or physical if you choose) you should follow the following steps (valid as at 5 Nov 2010):&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;Create a virtual machine to host &lt;a href="http://www.ubuntu.com/getubuntu/download" target="_blank"&gt;Ubuntu 9.10 x86 Desktop&lt;/a&gt;. I use &lt;a href="http://www.virtualbox.org/" target="_blank"&gt;VirtualBox&lt;/a&gt; as my VM host on windows so I will refer to this here but feel free to substitute it with you favourite VM software. The VM I created has 384MB allocated to it with an 8GB virtual hard drive using a bridged network adapter (so it can be accessed from the Windows XP host). Once you've gone through the install process install the client tools so that you change the screen resolution, share folders, etc. To do this with virtual box go to &lt;strong&gt;Devices &amp;gt; Install Guest Additions&lt;/strong&gt; and then open up a terminal window and execute       &lt;br /&gt;
    &lt;br /&gt;
    &lt;div style="background: black none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: white;"&gt;&lt;span style="color: rgb(0, 128, 255);"&gt;sudo&lt;/span&gt; /media/cdrom/VBoxLinuxAdditions-x86.run&lt;/div&gt;
    &lt;br /&gt;
    Once this is complete you will need to reboot your VM.       &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Now it is time to install Cassandra/Thrift prerequisites and software that we will to set everything up:      &lt;br /&gt;
    &lt;br /&gt;
    &lt;div style="background: black none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: white;"&gt;&lt;span style="color: rgb(0, 128, 255);"&gt;sudo&lt;/span&gt; apt-get install libboost-dev automake libtool flex bison pkg-config g++ -y         &lt;br /&gt;
    &lt;span style="color: rgb(0, 128, 255);"&gt;sudo&lt;/span&gt; apt-get install sun-java6-jdk -y         &lt;br /&gt;
    &lt;span style="color: rgb(0, 128, 255);"&gt;sudo&lt;/span&gt; apt-get apt-get install ant -y         &lt;br /&gt;
    &lt;/div&gt;
    &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Once that is done we can install other useful Ubuntu software that we will use:      &lt;br /&gt;
    &lt;br /&gt;
    &lt;div style="background: black none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: white;"&gt;&lt;span style="color: rgb(0, 128, 255);"&gt;sudo&lt;/span&gt; apt-get install rapidsvn -y         &lt;br /&gt;
    &lt;span style="color: rgb(0, 128, 255);"&gt;sudo&lt;/span&gt; apt-get install monodevelop -y &lt;/div&gt;
    &lt;br /&gt;
    I also like to install the following:       &lt;br /&gt;
    &lt;br /&gt;
    &lt;div style="background: black none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: white;"&gt;&lt;span style="color: rgb(0, 128, 255);"&gt;sudo&lt;/span&gt; apt-get install nautilus-open-terminal -y         &lt;br /&gt;
    &lt;span style="color: rgb(0, 128, 255);"&gt;sudo&lt;/span&gt; apt-get install samba smbfs smbclient winbind -y         &lt;br /&gt;
    &lt;span style="color: rgb(0, 128, 255);"&gt;sudo&lt;/span&gt; apt-get install nautilus-share -y&lt;/div&gt;
    &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;You may discover that there is an issue with your Java runtime home directory. If that occurs, select Sun's Java Runtime as the default Java version by running the following command from the terminal window and selecting the third option:      &lt;br /&gt;
    &lt;br /&gt;
    &lt;div style="background: black none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: white;"&gt;&lt;span style="color: rgb(0, 128, 255);"&gt;sudo&lt;/span&gt; update-alternatives --config java &lt;/div&gt;
    &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Now open up Nautilus by going to &lt;strong&gt;Places &amp;gt; Home&lt;/strong&gt; Folder. Right click and create a Development folder. Within the Development folder create another two folders: Cassandra and Thrift. &lt;/li&gt;
    &lt;li&gt;We can now get the source for Cassandra and Thrift. Run RapidSVN by going to &lt;strong&gt;Applications &amp;gt; Programming &amp;gt; RapidSVN&lt;/strong&gt;. Check out the source from SVN by going to the RapidSVN menu option &lt;strong&gt;Repository &amp;gt; Checkout&lt;/strong&gt;. In the URL enter &lt;a href="http://svn.apache.org/repos/asf/incubator/thrift/trunk" target="_blank"&gt;http://svn.apache.org/repos/asf/incubator/thrift/trunk&lt;/a&gt; and for the Destination Directory browse to the Thrift development folder. So it should look like this:       &lt;br /&gt;
    &lt;br /&gt;
    &lt;a href="http://www.ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/8fe.NetDevelopersGuidetoGettingStartedwi_4F37/image_4.png"&gt;&lt;img border="0" width="244" height="126" style="border-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto;" title="image" alt="image" src="http://www.ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/8fe.NetDevelopersGuidetoGettingStartedwi_4F37/image_thumb_1.png" /&gt;&lt;/a&gt;       &lt;br /&gt;
    Now get the Cassandra code by doing the same thing but entering &lt;a href="http://svn.apache.org/repos/asf/incubator/cassandra/trunk" target="_blank"&gt;http://svn.apache.org/repos/asf/incubator/cassandra/trunk&lt;/a&gt; as the URL and selecting the Cassandra directory. &lt;/li&gt;
    &lt;li&gt;Once we have all the code we are ready to compile Cassandra, so let's do that by executing the following commands from the terminal window:      &lt;br /&gt;
    &lt;br /&gt;
    &lt;div style="background: black none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: white;"&gt;&lt;span style="color: rgb(0, 128, 255);"&gt;cd&lt;/span&gt; ~/Development/Cassandra         &lt;br /&gt;
    ant         &lt;br /&gt;
    &lt;/div&gt;
    &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Start the Cassandra server by opening a new terminal window and running the following commands:      &lt;br /&gt;
    &lt;br /&gt;
    &lt;div style="background: black none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: white;"&gt;&lt;span style="color: rgb(0, 128, 255);"&gt;sudo&lt;/span&gt; ~/Development/Cassandra/bin/cassandra -f         &lt;br /&gt;
    &lt;/div&gt;
    &lt;br /&gt;
    The running server will look like the screenshot below. You should take note of the thrift binding address of localhost/127.0.0.1:9160.       &lt;br /&gt;
    &lt;br /&gt;
    &lt;a href="http://ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/8fe.NetDevelopersGuidetoGettingStartedwi_4F37/image_5.png"&gt;&lt;img border="0" width="367" height="218" style="border-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto;" title="image" alt="image" src="http://www.ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/8fe.NetDevelopersGuidetoGettingStartedwi_4F37/image_thumb.png" /&gt;&lt;/a&gt;       &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Now we want to get communicating with the server, so we will need to compile Thrift so that we can use it to generate our C# client:      &lt;br /&gt;
    &lt;br /&gt;
    &lt;div style="background: black none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: white;"&gt;&lt;span style="color: rgb(0, 128, 255);"&gt;cd&lt;/span&gt; ~/Development/Thrift         &lt;br /&gt;
    ./bootstrap.sh         &lt;br /&gt;
    ./configure         &lt;br /&gt;
    make         &lt;br /&gt;
    sudo make install         &lt;br /&gt;
    &lt;/div&gt;
    &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Now we can finally generate a C# client for the Thrift calls to Cassandra:      &lt;br /&gt;
    &lt;br /&gt;
    &lt;div style="background: black none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: white;"&gt;&lt;span style="color: rgb(0, 128, 255);"&gt;cd&lt;/span&gt; ~/Development/Cassandra/interface/         &lt;br /&gt;
    ~/Development/Thrift/compiler/cpp/thrift -gen csharp cassandra.thrift         &lt;br /&gt;
    &lt;/div&gt;
    &lt;br /&gt;
    This will create the following directories inside of the Cassandra/interface folder: &lt;strong&gt;gen-csharp/Apache/Cassandra&lt;/strong&gt;. These files along with the Thrift.dll will be copied into a new demo project we will create using MonoDevelop in the Development folder. So again in the terminal window execute:       &lt;br /&gt;
    &lt;br /&gt;
    &lt;div style="background: black none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: white;"&gt;&lt;span style="color: rgb(0, 128, 255);"&gt;mkdir&lt;/span&gt; ~/Development/CassandraDemo         &lt;br /&gt;
    &lt;span style="color: rgb(0, 128, 255);"&gt;cp &lt;/span&gt;~/Development/Cassandra/interface/gen-csharp ~/Development/CassandraDemo -R         &lt;br /&gt;
    &lt;span style="color: rgb(0, 128, 255);"&gt;cp &lt;/span&gt;~/Development/Thrift/lib/csharp/Thrift.dll ~/Development/CassandraDemo         &lt;br /&gt;
    &lt;/div&gt;
    &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Open up MonoDevelop and create a new console application by going to &lt;strong&gt;File &amp;gt; New &amp;gt; Solution&lt;/strong&gt;. Now do the following:
    &lt;ol&gt;
        &lt;li&gt;Select Console project &lt;/li&gt;
        &lt;li&gt;Enter CassandraDemo as the name &lt;/li&gt;
        &lt;li&gt;For the location browse to the Development folder that we created in your home directory. &lt;/li&gt;
        &lt;li&gt;Uncheck the 'Create separate Solution directory' check box. &lt;/li&gt;
        &lt;li&gt;Click the Forward button &lt;/li&gt;
        &lt;li&gt;Don't make any changes on the next screen and just click Ok. &lt;/li&gt;
        &lt;li&gt;Right click on the CassandraDemo project in the left tree view and select &lt;strong&gt;Add &amp;gt; Add Files...&lt;/strong&gt;. Navigate to ~/Development/CassandraDemo/gen-csharp/Apache/Cassandra and select all the files in the folder. You will now have a project that looks like this:         &lt;br /&gt;
        &lt;br /&gt;
        &lt;a href="http://ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/8fe.NetDevelopersGuidetoGettingStartedwi_4F37/image_7.png"&gt;&lt;img border="0" width="186" height="264" style="border-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto;" title="image" alt="image" src="http://www.ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/8fe.NetDevelopersGuidetoGettingStartedwi_4F37/image_thumb_2.png" /&gt;&lt;/a&gt; &lt;/li&gt;
        &lt;li&gt;Add a reference to the Thrift assembly by right clicking on References and selecting Edit References. Change to the .Net Assembly tab and double click on the Thrift.dll and click OK. &lt;/li&gt;
        &lt;li&gt;Now we can add the sample code to test it all out. So double click on Main.cs to ensure that is the class in focus in the editor. Replace the contents of the file with this:        &lt;br /&gt;
        &lt;div class="code"&gt;&lt;font color="#0000ff"&gt;namespace &lt;/font&gt;&lt;font color="#000000"&gt;CassandraDemo           &lt;br /&gt;
        {            &lt;br /&gt;
            &lt;/font&gt;&lt;font color="#0000ff"&gt;using &lt;/font&gt;&lt;font color="#000000"&gt;System&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
            using &lt;/font&gt;&lt;font color="#000000"&gt;System.Collections.Generic&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
            using &lt;/font&gt;&lt;font color="#000000"&gt;System.Diagnostics&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
        &lt;br /&gt;
            using &lt;/font&gt;&lt;font color="#000000"&gt;Apache.Cassandra&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
            using &lt;/font&gt;&lt;font color="#000000"&gt;Thrift.Protocol&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
            using &lt;/font&gt;&lt;font color="#000000"&gt;Thrift.Transport&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
        &lt;br /&gt;
            class &lt;/font&gt;&lt;font color="#000000"&gt;Program           &lt;br /&gt;
            {            &lt;br /&gt;
                &lt;/font&gt;&lt;font color="#0000ff"&gt;static void &lt;/font&gt;&lt;font color="#000000"&gt;Main(&lt;/font&gt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;font color="#000000"&gt;[] args)           &lt;br /&gt;
                {            &lt;br /&gt;
                    TTransport transport &lt;/font&gt;&lt;font color="#0000ff"&gt;= new &lt;/font&gt;&lt;font color="#000000"&gt;TSocket(&lt;/font&gt;&lt;font color="#808080"&gt;"localhost"&lt;/font&gt;&lt;font color="#000000"&gt;, &lt;/font&gt;&lt;font color="#800000"&gt;9160&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;TProtocol protocol &lt;/font&gt;&lt;font color="#0000ff"&gt;= new &lt;/font&gt;&lt;font color="#000000"&gt;TBinaryProtocol(transport)&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;Cassandra.Client client &lt;/font&gt;&lt;font color="#0000ff"&gt;= new &lt;/font&gt;&lt;font color="#000000"&gt;Cassandra.Client(protocol)&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
                     &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;Console.WriteLine(&lt;/font&gt;&lt;font color="#808080"&gt;"Opening connection"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;transport.Open()&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
        &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;System.Text.Encoding utf8Encoding &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#000000"&gt;System.Text.Encoding.UTF8&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
        &lt;br /&gt;
                    long &lt;/font&gt;&lt;font color="#000000"&gt;timeStamp &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#000000"&gt;DateTime.Now.Millisecond&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;ColumnPath nameColumnPath &lt;/font&gt;&lt;font color="#0000ff"&gt;= new &lt;/font&gt;&lt;font color="#000000"&gt;ColumnPath()  &lt;br /&gt;
                                                {  &lt;br /&gt;
                                                    Column_family &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#808080"&gt;"Standard1"&lt;/font&gt;&lt;font color="#000000"&gt;,  &lt;br /&gt;
                                                    Column &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#000000"&gt;utf8Encoding.GetBytes(&lt;/font&gt;&lt;font color="#808080"&gt;"name"&lt;/font&gt;&lt;font color="#000000"&gt;)           &lt;br /&gt;
                                                }&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
        &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;Console.WriteLine(&lt;/font&gt;&lt;font color="#808080"&gt;"Inserting name columns"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
        &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#006400"&gt;//Insert the data into the column 'name'           &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;client.insert(&lt;/font&gt;&lt;font color="#808080"&gt;"Keyspace1"&lt;/font&gt;&lt;font color="#000000"&gt;,           &lt;br /&gt;
                                  &lt;/font&gt;&lt;font color="#808080"&gt;"1"&lt;/font&gt;&lt;font color="#000000"&gt;,           &lt;br /&gt;
                                  nameColumnPath,            &lt;br /&gt;
                                  utf8Encoding.GetBytes(&lt;/font&gt;&lt;font color="#808080"&gt;"Joe Bloggs"&lt;/font&gt;&lt;font color="#000000"&gt;),           &lt;br /&gt;
                                  timeStamp,            &lt;br /&gt;
                                  ConsistencyLevel.ONE)&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
        &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;client.insert(&lt;/font&gt;&lt;font color="#808080"&gt;"Keyspace1"&lt;/font&gt;&lt;font color="#000000"&gt;,           &lt;br /&gt;
                                  &lt;/font&gt;&lt;font color="#808080"&gt;"2"&lt;/font&gt;&lt;font color="#000000"&gt;,           &lt;br /&gt;
                                  nameColumnPath,            &lt;br /&gt;
                                  utf8Encoding.GetBytes(&lt;/font&gt;&lt;font color="#808080"&gt;"Joe Soap"&lt;/font&gt;&lt;font color="#000000"&gt;),           &lt;br /&gt;
                                  timeStamp,            &lt;br /&gt;
                                  ConsistencyLevel.ONE)&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
        &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#006400"&gt;//Simple single value get using the key to get column 'name'           &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;ColumnOrSuperColumn returnedColumn &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#000000"&gt;client.&lt;/font&gt;&lt;font color="#0000ff"&gt;get&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#808080"&gt;"Keyspace1"&lt;/font&gt;&lt;font color="#000000"&gt;, &lt;/font&gt;&lt;font color="#808080"&gt;"1"&lt;/font&gt;&lt;font color="#000000"&gt;, nameColumnPath, ConsistencyLevel.ONE)&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;Console.WriteLine(&lt;/font&gt;&lt;font color="#808080"&gt;"Column Data in Keyspace1/Standard1: name: {0}, value: {1}"&lt;/font&gt;&lt;font color="#000000"&gt;,           &lt;br /&gt;
                                      utf8Encoding.GetString(returnedColumn.Column.Name),            &lt;br /&gt;
                                      utf8Encoding.GetString(returnedColumn.Column.Value))&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
        &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;Console.WriteLine(&lt;/font&gt;&lt;font color="#808080"&gt;"Getting splice range"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
        &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#006400"&gt;//Read an entire row           &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;SlicePredicate predicate &lt;/font&gt;&lt;font color="#0000ff"&gt;= new &lt;/font&gt;&lt;font color="#000000"&gt;SlicePredicate()           &lt;br /&gt;
                                               {            &lt;br /&gt;
                                                  Slice_range &lt;/font&gt;&lt;font color="#0000ff"&gt;= new &lt;/font&gt;&lt;font color="#000000"&gt;SliceRange()           &lt;br /&gt;
                                                                {            &lt;br /&gt;
                                                                    &lt;/font&gt;&lt;font color="#006400"&gt;//Start and Finish cannot be null           &lt;br /&gt;
                                                                    &lt;/font&gt;&lt;font color="#000000"&gt;Start &lt;/font&gt;&lt;font color="#0000ff"&gt;= new byte&lt;/font&gt;&lt;font color="#000000"&gt;[&lt;/font&gt;&lt;font color="#800000"&gt;0&lt;/font&gt;&lt;font color="#000000"&gt;],  &lt;br /&gt;
                                                                    Finish &lt;/font&gt;&lt;font color="#0000ff"&gt;= new byte&lt;/font&gt;&lt;font color="#000000"&gt;[&lt;/font&gt;&lt;font color="#800000"&gt;0&lt;/font&gt;&lt;font color="#000000"&gt;],           &lt;br /&gt;
                                                                    Count  &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#800000"&gt;10&lt;/font&gt;&lt;font color="#000000"&gt;,           &lt;br /&gt;
                                                                    Reversed &lt;/font&gt;&lt;font color="#0000ff"&gt;= false           &lt;br /&gt;
                                                                &lt;/font&gt;&lt;font color="#000000"&gt;}           &lt;br /&gt;
                                               }&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
        &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;ColumnParent parent &lt;/font&gt;&lt;font color="#0000ff"&gt;= new &lt;/font&gt;&lt;font color="#000000"&gt;ColumnParent() { Column_family &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#808080"&gt;"Standard1" &lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;Dictionary&amp;lt;&lt;/font&gt;&lt;font color="#0000ff"&gt;string &lt;/font&gt;&lt;font color="#000000"&gt;, List&amp;lt;ColumnOrSuperColumn&amp;gt;&amp;gt; results &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#000000"&gt;client.multiget_slice(&lt;/font&gt;&lt;font color="#808080"&gt;"Keyspace1"&lt;/font&gt;&lt;font color="#000000"&gt;,  &lt;br /&gt;
                                                                              &lt;/font&gt;&lt;font color="#0000ff"&gt;new &lt;/font&gt;&lt;font color="#000000"&gt;List&amp;lt;&lt;/font&gt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;font color="#000000"&gt;&amp;gt;() { &lt;/font&gt;&lt;font color="#808080"&gt;"1"&lt;/font&gt;&lt;font color="#000000"&gt;, &lt;/font&gt;&lt;font color="#808080"&gt;"2"&lt;/font&gt;&lt;font color="#000000"&gt;},  &lt;br /&gt;
                                                                              parent,  &lt;br /&gt;
                                                                              predicate,  &lt;br /&gt;
                                                                              ConsistencyLevel.ONE)&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
        &lt;br /&gt;
                    foreach &lt;/font&gt;&lt;font color="#000000"&gt;(KeyValuePair&amp;lt;&lt;/font&gt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;font color="#000000"&gt;, List&amp;lt;ColumnOrSuperColumn&amp;gt;&amp;gt; resultPair &lt;/font&gt;&lt;font color="#0000ff"&gt;in &lt;/font&gt;&lt;font color="#000000"&gt;results)           &lt;br /&gt;
                    {            &lt;br /&gt;
                        Console.WriteLine(&lt;/font&gt;&lt;font color="#808080"&gt;"Key: {0}"&lt;/font&gt;&lt;font color="#000000"&gt;, resultPair.Key)&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
        &lt;br /&gt;
                        foreach &lt;/font&gt;&lt;font color="#000000"&gt;(ColumnOrSuperColumn resultColumn &lt;/font&gt;&lt;font color="#0000ff"&gt;in &lt;/font&gt;&lt;font color="#000000"&gt;resultPair.Value)           &lt;br /&gt;
                        {            &lt;br /&gt;
                            Column column &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#000000"&gt;resultColumn.Column&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
                            &lt;/font&gt;&lt;font color="#000000"&gt;Console.WriteLine(&lt;/font&gt;&lt;font color="#808080"&gt;"name: {0}, value: {1}"&lt;/font&gt;&lt;font color="#000000"&gt;, utf8Encoding.GetString(column.Name), utf8Encoding.GetString(column.Value))&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
                        &lt;/font&gt;&lt;font color="#000000"&gt;}           &lt;br /&gt;
                    }            &lt;br /&gt;
        &lt;br /&gt;
                    Console.WriteLine(&lt;/font&gt;&lt;font color="#808080"&gt;"Closing connection"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
                    &lt;/font&gt;&lt;font color="#000000"&gt;transport.Close()&lt;/font&gt;&lt;font color="#0000ff"&gt;;           &lt;br /&gt;
                &lt;/font&gt;&lt;font color="#000000"&gt;}           &lt;br /&gt;
            }            &lt;br /&gt;
        }&lt;/font&gt; &lt;/div&gt;
        &lt;/li&gt;
        &lt;li&gt;Hit F5 and watch the Application Output window. This is what you should see:&lt;br /&gt;
        &lt;br /&gt;
        &lt;a href="http://ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/8fe.NetDevelopersGuidetoGettingStartedwi_4F37/image_9.png"&gt;&lt;img border="0" width="619" height="466" style="border: 0px none ; display: block; float: none; margin-left: auto; margin-right: auto;" title="image" alt="image" src="http://www.ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/8fe.NetDevelopersGuidetoGettingStartedwi_4F37/image_thumb_3.png" /&gt;&lt;/a&gt; &lt;/li&gt;
    &lt;/ol&gt;
    &lt;/li&gt;
    &lt;br /&gt;
    Hopefully this is enough to get you going and have you fill in the remaining gaps. If you found it useful please post a comment. If the Cassandra guys would like to use the C# example they are welcome to it. Good luck!&lt;br /&gt;
&lt;/ol&gt;&lt;img src="http://ridgway.co.za/aggbug/196.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Eden Ridgway</dc:creator>
            <guid>http://ridgway.co.za/archive/2009/11/06/net-developers-guide-to-getting-started-with-cassandra.aspx</guid>
            <pubDate>Thu, 05 Nov 2009 22:32:51 GMT</pubDate>
            <comments>http://ridgway.co.za/archive/2009/11/06/net-developers-guide-to-getting-started-with-cassandra.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://ridgway.co.za/comments/commentRss/196.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Are Database Migration Frameworks Worth the Effort?</title>
            <link>http://ridgway.co.za/archive/2009/01/03/are-database-migration-frameworks-worth-the-effort.aspx</link>
            <description>&lt;p&gt;I’ve always used SQL scripts to manage database creation and migration. At my current company we have a database project with patch scripts that conditionally execute based on the database version. These scripts are simply run in sequence by an installer which stores the current database version as a database extended property. The approach relies on version based naming of SQL scripts and developers to remember to update the patch script whenever they make a structure or stored procedure change. Of course one could try to use a tool such as Redgate SQL compare to generate diff patch scripts but that won’t always suffice as that won’t capture refactoring such as column name changes or data migration (for more read &lt;a target="_blank" href="http://blog.liquibase.org/2007/06/the-problem-with-database-diffs.html"&gt;The Problem with Database Diffs&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;The use of SQL scripts is not without it’s problems. The most annoying of these is that a patch script may break as SQL will parse and validate your script against the existing table structure even if the statements are not going to run due to version check condition. This forces one to use nasty EXEC/sp_execute alter/create statements with double escaped strings (Yuck!). I find the following particularly problematic with this approach:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;The string based SQL statements will always pass validation even though when they are executed they may be completely screwed &lt;/li&gt;
    &lt;li&gt;It is impractical to generate these by hand and the best way to create them is to use SQL Management Studio. &lt;/li&gt;
    &lt;li&gt;If your stored procedures are not wrapped in strings, to update the patch script requires you to script out the scripts from the database. Basically this increases development friction and discourages updating of the patch script. &lt;/li&gt;
    &lt;li&gt;It becomes difficult to determine when a structural change was made as one has to trawl through huge SQL scripts and it is not easy to use a regex search to find a change. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Hence I long for something a little more strongly typed, which is why the growing number of .Net based Database Migration frameworks have caught my eye. I want to be sure that there isn’t something obvious that I was missing out by not using one. Fortunately Ben Scheirman has done a fair amount of research already and wrote a fairly good round up of &lt;a target="_blank" href="http://flux88.com/blog/net-database-migration-tool-roundup/"&gt;available .Net migration tools&lt;/a&gt;. Looking at the tools there are clearly two different types of frameworks available:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;&lt;strong&gt;Structured SQL script execution&lt;/strong&gt; – These tools provide a framework under which SQL scripts will be executed to create and upgrade a database to a specific version. Examples of these are: &lt;a target="_blank" href="http://code.google.com/p/tarantino/wiki/DatabaseChangeManagement"&gt;Tarantino&lt;/a&gt; and &lt;a target="_blank" href="http://www.liquibase.org/"&gt;LiquiBase&lt;/a&gt;. &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Rails like Active Record Migration&lt;/strong&gt; – Commands to upgrade or downgrade the database schema and data can be coded in a .Net language, with the possibility of executing SQL statements if required. Tools that fall into this category are: &lt;a target="_blank" href="http://www.rikware.com/RikMigrations.html"&gt;RikMigrations&lt;/a&gt;, &lt;a target="_blank" href="http://subsonicproject.com/2-1-pakala/subsonic-using-migrations/"&gt;SubSonic Migrations&lt;/a&gt;, &lt;a target="_blank" href="http://codebetter.com/blogs/jacob.lewallen/archive/2008/04/25/a-first-look-at-machine-migrations.aspx"&gt;Machine.Migrations&lt;/a&gt; and &lt;a target="_blank" href="http://code.google.com/p/migratordotnet/"&gt;Migrator.Net&lt;/a&gt;. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The obvious question that springs to mind when looking at these frameworks is whether or not the additional development friction (additional tasks that must be performed during the course of development) is worth the benefit. To be honest I don’t see a massive difference between the structured SQL script execution approach and what I’ve been doing all along. However the likes of &lt;a target="_blank" href="http://www.liquibase.org/"&gt;LiquiBase&lt;/a&gt; do provide a functionality that nicely captures database refactorings and diffs, so maybe it could be used as more of a general toolset. However the Active Migration approach would be a more radical departure so I’d like to explore that more.&lt;/p&gt;
&lt;p&gt;Here are my thoughts on Active Record Migration like frameworks:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;Best paired with an ORM framework, such as &lt;a target="_blank" href="http://www.hibernate.org/343.html"&gt;NHibernate&lt;/a&gt; or &lt;a target="_blank" href="http://subsonicproject.com/"&gt;Subsonic&lt;/a&gt;, where one is not writing a lot of custom SQL and hence the the upgrade classes can be kept clean and focus on structural and data migration. That is not to say that there will not be benefit to having them execute a lot of SQL statements to add/update stored procedures, it is just that it may get a little messy and possibly tedious. &lt;/li&gt;
    &lt;li&gt;Using C# code to do database change would provide an opportunity to use something like log4net to dump out progress information. I've always longed for a decent way of doing this that doesn't involve a custom proc that inserts into a table. I really like the idea of having a degree of compile time checking for the database changes. Of course with SQL scripts you could always run them on each build and if they break, you fail the build. &lt;/li&gt;
    &lt;li&gt;The whole idea of downgrading a database scares me because if someone accidently points an old version of an application (with automatic migration logic) to the database (think xcopy deployment) you could end up losing tables and data. Of course one should always backup a database before doing a deployment, but I’m talking about a situation where one doesn’t know it is pointing to the wrong database until it is too late. I hope these tools backup the database before applying changes. In my mind a downgrade should only be performed if a rollout fails and one has to revert to a backup taken before the upgrade was undertaken.&lt;/li&gt;
    &lt;li&gt;I really like the idea of using anonymous objects to insert data into the database (&lt;a target="_blank" href="http://www.codethinked.com/post/2008/12/16/Migrations-in-C-using-RikMigrations.aspx"&gt;RikiMigration supports this&lt;/a&gt;) and avoiding the need to write insert statements. &lt;/li&gt;
    &lt;li&gt;Do you not run into potential development concurrency and structuring issues? So for example during a development cycle does one dump all changes into one class or into several? &lt;/li&gt;
    &lt;li&gt;The database vendor abstraction that is can provide is only attractive to a small number of projects. Furthermore one invariably will need to execute vendor specific statements and is best suited to a multi-vendor ORM such as NHibernate.&lt;/li&gt;
    &lt;li&gt;The approach may not fly in an organization where a DBA must review all SQL changes. Although I don’t see any reason why the frameworks couldn’t generate these for you.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I think if I was currently working on a project that used an ORM like NHibernate or LINQ to Entities, the migration frameworks would be a lot more appealing. However with other types of projects I’m worried that the additional effort isn’t really going to be worth the benefit.&lt;/p&gt;
&lt;p&gt;Am I missing any other potential benefits (or problems)? I would really like to hear if there are other compelling reasons to adopt the approach.&lt;/p&gt;&lt;img src="http://ridgway.co.za/aggbug/195.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Eden Ridgway</dc:creator>
            <guid>http://ridgway.co.za/archive/2009/01/03/are-database-migration-frameworks-worth-the-effort.aspx</guid>
            <pubDate>Sat, 03 Jan 2009 11:52:03 GMT</pubDate>
            <comments>http://ridgway.co.za/archive/2009/01/03/are-database-migration-frameworks-worth-the-effort.aspx#feedback</comments>
            <wfw:commentRss>http://ridgway.co.za/comments/commentRss/195.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Fibonacci Solution Approaches</title>
            <link>http://ridgway.co.za/archive/2008/01/30/fibonacci-solution-approaches.aspx</link>
            <description>&lt;p&gt;Looking at technical interview questions on the Internet it appears that getting candidates to write some code that prints out the Fibonacci series is quite popular. I personally prefer giving candidates slightly more relevant practical questions, but I thought I'd present the various solutions that one may take. For those of you who are unfamiliar with the Fibonacci series you should take a look at the &lt;a href="http://en.wikipedia.org/wiki/Fibonacci_number"&gt;Wikipedia page on it&lt;/a&gt;. Each number in the series is the sum of the previous two values except for the first and second numbers which are zero and one respectively. So the interviewer is expecting to see the following series of numbers:&lt;/p&gt;
&lt;p&gt;0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584...&lt;/p&gt;
&lt;p&gt;The Fibonacci series is often used by computer science teachers to teach recursion, even though this it is a poor fit (see: &lt;a href="http://blogs.msdn.com/ericlippert/archive/2004/05/19/135392.aspx"&gt;How Not To Teach Recursion&lt;/a&gt;). However in all likelihood this is what the interviewer is after, so the expected standard solution should look like this:&lt;/p&gt;
&lt;div class="code"&gt;&lt;font color="#0000ff"&gt;internal static int &lt;/font&gt;&lt;font color="#000000"&gt;GetFibonacciValue(&lt;/font&gt;&lt;font color="#0000ff"&gt;int &lt;/font&gt;&lt;font color="#000000"&gt;number)      &lt;br /&gt;
{       &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;if &lt;/font&gt;&lt;font color="#000000"&gt;(number &amp;lt; &lt;/font&gt;&lt;font color="#800000"&gt;0&lt;/font&gt;&lt;font color="#000000"&gt;)      &lt;br /&gt;
        &lt;/font&gt;&lt;font color="#0000ff"&gt;throw new &lt;/font&gt;&lt;font color="#000000"&gt;InvalidOperationException(&lt;/font&gt;&lt;font color="#808080"&gt;"Negative numbers are not supported by this implementation"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#0000ff"&gt;;      &lt;br /&gt;
&lt;br /&gt;
    if &lt;/font&gt;&lt;font color="#000000"&gt;(number &amp;lt;&lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#800000"&gt;1&lt;/font&gt;&lt;font color="#000000"&gt;)      &lt;br /&gt;
        &lt;/font&gt;&lt;font color="#0000ff"&gt;return &lt;/font&gt;&lt;font color="#000000"&gt;number&lt;/font&gt;&lt;font color="#0000ff"&gt;;      &lt;br /&gt;
&lt;br /&gt;
    return &lt;/font&gt;&lt;font color="#000000"&gt;GetFibonacciValue(number - &lt;/font&gt;&lt;font color="#800000"&gt;1&lt;/font&gt;&lt;font color="#000000"&gt;) + GetFibonacciValue(number - &lt;/font&gt;&lt;font color="#800000"&gt;2&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#0000ff"&gt;;      &lt;br /&gt;
&lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt; &lt;/div&gt;
&lt;p&gt;A lot of people forget to check for a negative number check, so including it may even earn you "bonus points". If you want to have a little fun you could always use a terse lambda expression to solve it like this:&lt;/p&gt;
&lt;div class="code"&gt;&lt;font color="#000000"&gt;Func&amp;lt;&lt;/font&gt;&lt;font color="#0000ff"&gt;int&lt;/font&gt;&lt;font color="#000000"&gt;, &lt;/font&gt;&lt;font color="#0000ff"&gt;int&lt;/font&gt;&lt;font color="#000000"&gt;&amp;gt; fibonacci &lt;/font&gt;&lt;font color="#0000ff"&gt;= null;      &lt;br /&gt;
&lt;/font&gt;&lt;font color="#000000"&gt;fibonacci &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#000000"&gt;n &lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&lt;font color="#000000"&gt;&amp;gt; n &amp;gt; &lt;/font&gt;&lt;font color="#800000"&gt;1 &lt;/font&gt;&lt;font color="#000000"&gt;? fibonacci(n - &lt;/font&gt;&lt;font color="#800000"&gt;1&lt;/font&gt;&lt;font color="#000000"&gt;) + fibonacci(n - &lt;/font&gt;&lt;font color="#800000"&gt;2&lt;/font&gt;&lt;font color="#000000"&gt;) : n&lt;/font&gt;&lt;font color="#0000ff"&gt;;&lt;/font&gt; &lt;/div&gt;
&lt;p&gt;The problem with the approaches above is that they perform really badly because of their recursive nature, so you could always show off and tell them that there is a closed form of the solution which allows you to solve it in the following manner:&lt;/p&gt;
&lt;div class="code"&gt;&lt;font color="#0000ff"&gt;private readonly static double &lt;/font&gt;&lt;font color="#000000"&gt;rootOfFive &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#000000"&gt;Math.Sqrt(&lt;/font&gt;&lt;font color="#800000"&gt;5&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#0000ff"&gt;;     &lt;br /&gt;
private readonly static double &lt;/font&gt;&lt;font color="#000000"&gt;goldenRatio &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#800000"&gt;1 &lt;/font&gt;&lt;font color="#000000"&gt;+ rootOfFive) / &lt;/font&gt;&lt;font color="#800000"&gt;2&lt;/font&gt;&lt;font color="#0000ff"&gt;;     &lt;br /&gt;
&lt;br /&gt;
internal static int &lt;/font&gt;&lt;font color="#000000"&gt;GetFinbonacciValue(&lt;/font&gt;&lt;font color="#0000ff"&gt;int &lt;/font&gt;&lt;font color="#000000"&gt;number)     &lt;br /&gt;
{      &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;return &lt;/font&gt;&lt;font color="#000000"&gt;Convert.ToInt32((Math.Pow(goldenRatio, number) - Math.Pow(-goldenRatio, -number)) / rootOfFive)&lt;/font&gt;&lt;font color="#0000ff"&gt;;     &lt;br /&gt;
&lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt; &lt;/div&gt;
&lt;p&gt;If you forget the closed form you could also tell the interviewer that using a simple for loop is far more efficient and ask him if he would be satisfied with that:&lt;/p&gt;
&lt;div class="code"&gt;&lt;font color="#0000ff"&gt;internal static int &lt;/font&gt;&lt;font color="#000000"&gt;GetFinbonacciValue(&lt;/font&gt;&lt;font color="#0000ff"&gt;int &lt;/font&gt;&lt;font color="#000000"&gt;number)      &lt;br /&gt;
{       &lt;/font&gt;&lt;font color="#000000"&gt;&lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;if &lt;/font&gt;&lt;font color="#000000"&gt;(number &amp;lt; &lt;/font&gt;&lt;font color="#800000"&gt;0&lt;/font&gt;&lt;font color="#000000"&gt;)      &lt;br /&gt;
        &lt;/font&gt;&lt;font color="#0000ff"&gt;throw new &lt;/font&gt;&lt;font color="#000000"&gt;InvalidOperationException(&lt;/font&gt;&lt;font color="#808080"&gt;"Negative numbers are not supported by this implementation"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#0000ff"&gt;;      &lt;br /&gt;
&lt;/font&gt;&lt;br /&gt;
&lt;font color="#000000"&gt;     &lt;/font&gt;&lt;font color="#0000ff"&gt;if &lt;/font&gt;&lt;font color="#000000"&gt;(number &amp;lt;&lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#800000"&gt;1&lt;/font&gt;&lt;font color="#000000"&gt;)      &lt;br /&gt;
        &lt;/font&gt;&lt;font color="#0000ff"&gt;return &lt;/font&gt;&lt;font color="#000000"&gt;number&lt;/font&gt;&lt;font color="#0000ff"&gt;;      &lt;br /&gt;
&lt;br /&gt;
    int &lt;/font&gt;&lt;font color="#000000"&gt;runningTotal &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#800000"&gt;1&lt;/font&gt;&lt;font color="#0000ff"&gt;;      &lt;br /&gt;
    int &lt;/font&gt;&lt;font color="#000000"&gt;twoValuesBack &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#800000"&gt;1&lt;/font&gt;&lt;font color="#0000ff"&gt;;      &lt;br /&gt;
&lt;br /&gt;
    for &lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#0000ff"&gt;int &lt;/font&gt;&lt;font color="#000000"&gt;n &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#800000"&gt;2&lt;/font&gt;&lt;font color="#0000ff"&gt;; &lt;/font&gt;&lt;font color="#000000"&gt;n &amp;lt; number&lt;/font&gt;&lt;font color="#0000ff"&gt;; &lt;/font&gt;&lt;font color="#000000"&gt;n++)      &lt;br /&gt;
    {       &lt;br /&gt;
        &lt;/font&gt;&lt;font color="#0000ff"&gt;int &lt;/font&gt;&lt;font color="#000000"&gt;previousTotal &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#000000"&gt;runningTotal&lt;/font&gt;&lt;font color="#0000ff"&gt;;      &lt;br /&gt;
        &lt;/font&gt;&lt;font color="#000000"&gt;runningTotal &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#000000"&gt;twoValuesBack + runningTotal&lt;/font&gt;&lt;font color="#0000ff"&gt;;      &lt;br /&gt;
&lt;br /&gt;
        &lt;/font&gt;&lt;font color="#000000"&gt;twoValuesBack &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#000000"&gt;previousTotal&lt;/font&gt;&lt;font color="#0000ff"&gt;;      &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#000000"&gt;}      &lt;br /&gt;
&lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;return &lt;/font&gt;&lt;font color="#000000"&gt;runningTotal&lt;/font&gt;&lt;font color="#0000ff"&gt;;      &lt;br /&gt;
&lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt; &lt;/div&gt;
&lt;p&gt;That should be enough for you to ace that question during your technical interview. You may be curious as to how significant the performance differences between the approaches are, so I timed how long each took to generated numbers from 0 to 121393. The graph below shows the average number of ticks it took to complete the operations.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/FibonacciSolutionApproaches_69A7/image_2.png"&gt;&lt;img width="443" height="278" border="0" src="http://ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/FibonacciSolutionApproaches_69A7/image_thumb.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;If you are busy doing interviews, I hope this helps you out. Good luck!&lt;/p&gt;&lt;img src="http://ridgway.co.za/aggbug/194.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Eden Ridgway</dc:creator>
            <guid>http://ridgway.co.za/archive/2008/01/30/fibonacci-solution-approaches.aspx</guid>
            <pubDate>Wed, 30 Jan 2008 06:06:08 GMT</pubDate>
            <comments>http://ridgway.co.za/archive/2008/01/30/fibonacci-solution-approaches.aspx#feedback</comments>
            <wfw:commentRss>http://ridgway.co.za/comments/commentRss/194.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Setting up an Optimised Deployment Version of your AJAX ASP.Net Application</title>
            <link>http://ridgway.co.za/archive/2008/01/28/setting-up-an-optimised-deployment-version-of-your-ajax-asp.net.aspx</link>
            <description>&lt;p&gt;With rich AJAX web applications one needs to look at optimising resources such as your CSS, JavaScript and image files. Yahoo has collected together a great &lt;a href="http://developer.yahoo.com/performance/rules.html"&gt;collection of best practices&lt;/a&gt; that have been put into their &lt;a href="http://developer.yahoo.com/yslow/"&gt;YSlow&lt;/a&gt; Firefox extension. These should be taken as a guideline and not gospel. In general however the core principals are as follows:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;&lt;strong&gt;Keep server roundtrips to a minimum&lt;/strong&gt;. The techniques for the various resource types are as follows:
    &lt;ul&gt;
        &lt;li&gt;&lt;em&gt;JavaScript&lt;/em&gt; - combine them into a single file if possible. One has to make certain they are combined in the correct order in the file. &lt;/li&gt;
        &lt;li&gt;&lt;em&gt;CSS&lt;/em&gt; - again merge them as far as possible. &lt;/li&gt;
        &lt;li&gt;&lt;em&gt;Images&lt;/em&gt; - Use &lt;a href="http://www.alistapart.com/articles/sprites"&gt;CSS sprites&lt;/a&gt; where one combines several images into one and uses the background image offset to display the one you are after. To create the sprites you can always use this online sprite generator. &lt;/li&gt;
    &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Reduce the size of each request&lt;/strong&gt;. This is done in two ways:
    &lt;ul&gt;
        &lt;li&gt;&lt;em&gt;GZip/Deflate&lt;/em&gt; compress text resources by configuring IIS and/or using an ASP.Net HTTP Module. &lt;/li&gt;
        &lt;li&gt;&lt;em&gt;Reduce file sizes&lt;/em&gt;. The tools I use for each type are:
        &lt;ul&gt;
            &lt;li&gt;JavaScript - &lt;a href="http://www.raboof.com/projects/Jazmin/"&gt;Jazmin&lt;/a&gt; provides pretty good minification by removing whitespace. If you want better minification then you should take a look at the Dojo &lt;a href="http://dojotoolkit.org/docs/shrinksafe"&gt;ShrinkSafe&lt;/a&gt; compressor which will shorten the name of local variables and functions to reduce the file size even more. The downside to this is it makes troubleshooting a production issue more difficult. &lt;/li&gt;
            &lt;li&gt;CSS - &lt;a href="http://csstidy.sourceforge.net/index.php"&gt;CSSTidy&lt;/a&gt; not only reduces whitespace but optimises the CSS expressions as well. &lt;/li&gt;
            &lt;li&gt;Images - As PNGs are my image format of choice I use &lt;a href="http://brh.numbera.com/software/pnggauntlet/"&gt;PNGGauntlet&lt;/a&gt; to reduce the image file size. &lt;/li&gt;
        &lt;/ul&gt;
        &lt;/li&gt;
    &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Ensure resources are cached&lt;/strong&gt;. If you know that the files are going to change infrequently then all you have to do is set IIS to enable content expiration for a folder/file to expire after a set number of days, say 10. This will ensure that the client browser caches the resources and does not re-download them. However depending on the frequency of your deployments and your server architecture you most likely want to ensure that your etags are setup correctly. These are used to indicate whether or not the cached browser resources have changed. When loading a page the browser will send a request to the server, with the etag, for each resource and if it has not changed then the server will only return a 304 status code. Note that this advice is contrary to Yahoo where they tell you to remove etags for a web farm scenario. What you should rather do is ensure that the etag change number is the same for each server in the web farm. This ensures that the etag generated for the same resource on a different server is the same (how to do this varies depending on your version of IIS - read this &lt;a href="http://www.lowtek.com/blog/2006/09/save-web-server-bandwidth-by-fixing.html"&gt;post&lt;/a&gt; for more IIS6 information). If you are using a single web server however the whole this is a non-issue for you. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Okay so we know we want to combine and minify our CSS and JavaScript files when we deploy to our test, staging and production environments, but we don't want to develop and debug our applications with monolithic files with no whitespace and cryptic names. The problem is that our pages contain references to these files and we are merge them them together for deployment our references will now be incorrect. Well this is quite easily solved using compiler directives, like so:&lt;/p&gt;
&lt;div class="code"&gt;&lt;span style="background-color: rgb(255, 255, 153);"&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;%&lt;/font&gt;&lt;font color="#ff0000"&gt; #if DEBUG %&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;      &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;script&lt;/font&gt;&lt;font color="#ff0000"&gt; type&lt;/font&gt;&lt;font color="#0000ff"&gt;="text/javascript"&lt;/font&gt;&lt;font color="#ff0000"&gt; src&lt;/font&gt;&lt;font color="#0000ff"&gt;='&amp;lt;%= ResolveUrl("~/JavaScript/File1.js") %&amp;gt;'&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#800000"&gt;script&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;      &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;script&lt;/font&gt;&lt;font color="#ff0000"&gt; type&lt;/font&gt;&lt;font color="#0000ff"&gt;="text/javascript"&lt;/font&gt;&lt;font color="#ff0000"&gt; src&lt;/font&gt;&lt;font color="#0000ff"&gt;='&amp;lt;%= ResolveUrl("~/JavaScript/File2.js") %&amp;gt;'&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#800000"&gt;script&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;      &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;script&lt;/font&gt;&lt;font color="#ff0000"&gt; type&lt;/font&gt;&lt;font color="#0000ff"&gt;="text/javascript"&lt;/font&gt;&lt;font color="#ff0000"&gt; src&lt;/font&gt;&lt;font color="#0000ff"&gt;='&amp;lt;%= ResolveUrl("~/JavaScript/File3.js") %&amp;gt;'&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#800000"&gt;script&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;      &lt;br /&gt;
&lt;/font&gt;&lt;span style="background-color: rgb(255, 255, 153);"&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;%&lt;/font&gt;&lt;font color="#ff0000"&gt; #else %&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;      &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;script&lt;/font&gt;&lt;font color="#ff0000"&gt; type&lt;/font&gt;&lt;font color="#0000ff"&gt;="text/javascript"&lt;/font&gt;&lt;font color="#ff0000"&gt; src&lt;/font&gt;&lt;font color="#0000ff"&gt;='&amp;lt;%= ResolveUrl("~/JavaScript/Section.minified.js") %&amp;gt;'&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#800000"&gt;script&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;      &lt;br /&gt;
&lt;/font&gt;&lt;span style="background-color: rgb(255, 255, 153);"&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;%&lt;/font&gt;&lt;font color="#ff0000"&gt; #endif %&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&lt;/font&gt; &lt;/div&gt;
&lt;p&gt;For CSS files you can either use the directives around alternative &amp;lt;link&amp;gt; elements or around @import statements, like this:&lt;/p&gt;
&lt;div class="code"&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;style&lt;/font&gt;&lt;font color="#ff0000"&gt; type&lt;/font&gt;&lt;font color="#0000ff"&gt;="text/css"&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;font color="#800000"&gt;      &lt;br /&gt;
&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;span style="background-color: rgb(255, 255, 153);"&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;%&lt;/font&gt;&lt;font color="#ff0000"&gt; #if DEBUG %&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font color="#800000"&gt;      &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;@&lt;/font&gt;&lt;font color="#800000"&gt;import '&amp;lt;%&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&lt;font color="#800000"&gt; ResolveUrl&lt;/font&gt;&lt;font color="#0000ff"&gt;(&lt;/font&gt;&lt;font color="#800000"&gt;"~&lt;/font&gt;&lt;font color="#0000ff"&gt;/&lt;/font&gt;&lt;font color="#800000"&gt;Css&lt;/font&gt;&lt;font color="#0000ff"&gt;/&lt;/font&gt;&lt;font color="#800000"&gt;File1&lt;/font&gt;&lt;font color="#0000ff"&gt;.&lt;/font&gt;&lt;font color="#800000"&gt;css"&lt;/font&gt;&lt;font color="#0000ff"&gt;)&lt;/font&gt;&lt;font color="#800000"&gt; %&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#800000"&gt;';      &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;@&lt;/font&gt;&lt;font color="#800000"&gt;import '&amp;lt;%&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&lt;font color="#800000"&gt; ResolveUrl&lt;/font&gt;&lt;font color="#0000ff"&gt;(&lt;/font&gt;&lt;font color="#800000"&gt;"~&lt;/font&gt;&lt;font color="#0000ff"&gt;/&lt;/font&gt;&lt;font color="#800000"&gt;Css&lt;/font&gt;&lt;font color="#0000ff"&gt;/&lt;/font&gt;&lt;font color="#800000"&gt;File2&lt;/font&gt;&lt;font color="#0000ff"&gt;.&lt;/font&gt;&lt;font color="#800000"&gt;css"&lt;/font&gt;&lt;font color="#0000ff"&gt;)&lt;/font&gt;&lt;font color="#800000"&gt; %&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#800000"&gt;';      &lt;br /&gt;
&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;span style="background-color: rgb(255, 255, 153);"&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;%&lt;/font&gt;&lt;font color="#ff0000"&gt; #else %&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font color="#800000"&gt;      &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;@&lt;/font&gt;&lt;font color="#800000"&gt;import '&amp;lt;%&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&lt;font color="#800000"&gt; ResolveUrl&lt;/font&gt;&lt;font color="#0000ff"&gt;(&lt;/font&gt;&lt;font color="#800000"&gt;"~&lt;/font&gt;&lt;font color="#0000ff"&gt;/&lt;/font&gt;&lt;font color="#800000"&gt;Css&lt;/font&gt;&lt;font color="#0000ff"&gt;/&lt;/font&gt;&lt;font color="#800000"&gt;CombinedStyles&lt;/font&gt;&lt;font color="#0000ff"&gt;.&lt;/font&gt;&lt;font color="#800000"&gt;minified&lt;/font&gt;&lt;font color="#0000ff"&gt;.&lt;/font&gt;&lt;font color="#800000"&gt;css"&lt;/font&gt;&lt;font color="#0000ff"&gt;)&lt;/font&gt;&lt;font color="#800000"&gt; %&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#800000"&gt;';      &lt;br /&gt;
&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;span style="background-color: rgb(255, 255, 153);"&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;%&lt;/font&gt;&lt;font color="#ff0000"&gt; #endif %&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&lt;/font&gt;       &lt;br /&gt;
&amp;lt;/&lt;/font&gt;&lt;font color="#800000"&gt;style&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;&lt;/font&gt; &lt;/div&gt;
&lt;p&gt;There is a catch to this however, since the aspx pages are compiled separately, setting your application to compile as a release build will not cause the references to change. What you need to do is change the compilation setting in the application web.config file, which should be set to debug="false" in the production environment:&lt;/p&gt;
&lt;div class="code"&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000"&gt;compilation&lt;/font&gt;&lt;font color="#ff0000"&gt; debug&lt;/font&gt;&lt;font color="#0000ff"&gt;="false"&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;      &lt;br /&gt;
  ...       &lt;br /&gt;
&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#800000"&gt;compilation&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#000000"&gt;&lt;/font&gt; &lt;/div&gt;
&lt;p&gt;Now on to the merging and minification. This could be accomplished using MsBuild or a batch file, but a batch file is simpler, so I'll discuss that. On one of the build steps for the web site(s) invoke the batch file which then ensures that the optimised files are always up to date. So you want to add something like this to your pre/post build compilation step in the project property window:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/SettingupanOptimisedDeplo.NetApplication_E3AF/image_4.png"&gt;&lt;img width="504" height="196" border="0" src="http://ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/SettingupanOptimisedDeplo.NetApplication_E3AF/image_thumb_1.png" alt="image" style="border-width: 0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;I setup the "Build Scripts" folder to contain the optimisation programs as well as text files with lists of files to merge, for example:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/SettingupanOptimisedDeplo.NetApplication_E3AF/image_12.png"&gt;&lt;img width="164" height="105" border="0" src="http://ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/SettingupanOptimisedDeplo.NetApplication_E3AF/image_thumb_5.png" alt="image" style="border-width: 0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;You'll notice that I group the JavaScript files on the site by Section of the site and not by page. The granularity of file grouping really depends on the application, but by section or function is a pretty good starting point. Each line of the file will contain a file name, like this:&lt;/p&gt;
&lt;p&gt; SubDir\File1.js&lt;br /&gt;
SubDir\File2.js &lt;/p&gt;
&lt;p&gt;I don't need to specify the full relative path of the files, in respect to the build folder because when I develop web sites all JavaScript files are placed within a JavaScript folder off the root of the web site.&lt;/p&gt;
&lt;p&gt;In my simplified scenario the "Optimise Web Resources.bat" batch file contains the following:&lt;/p&gt;
&lt;div class="code"&gt;
&lt;pre style="background: rgb(255, 255, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: rgb(0, 0, 0);"&gt;&lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;set&lt;/span&gt; OLDDIR&lt;span style="color: rgb(128, 128, 48);"&gt;=&lt;/span&gt;%CD%&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(105, 105, 105);"&gt;:: Change to the current directory&lt;/span&gt;&lt;span style="font-family: mon;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;cd&lt;/span&gt; &lt;span style="color: rgb(128, 128, 48);"&gt;/&lt;/span&gt;d &lt;span style="color: rgb(0, 140, 0);"&gt;%0&lt;/span&gt;&lt;span style="color: rgb(128, 128, 48);"&gt;\&lt;/span&gt;.. &lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(105, 105, 105);"&gt;::Ensure there are no old temporary files lying around&lt;/span&gt; &lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;del&lt;/span&gt; *.js&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;del&lt;/span&gt; *.css&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(105, 105, 105);"&gt;::Create a single file for the JavaScript in the admin section&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;for&lt;/span&gt; &lt;span style="color: rgb(128, 128, 48);"&gt;/&lt;/span&gt;F &lt;span style="color: rgb(0, 0, 230);"&gt;"tokens=*"&lt;/span&gt; %%f &lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(128, 128, 48);"&gt;(&lt;/span&gt;AdminJsFiles.txt&lt;span style="color: rgb(128, 128, 48);"&gt;)&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;do&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;call&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;type&lt;/span&gt; &lt;span style="color: rgb(0, 0, 230);"&gt;"..\Web Sites\Site\JavaScript\%%f"&lt;/span&gt; &lt;span style="color: rgb(128, 128, 48);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(128, 128, 48);"&gt;&amp;gt;&lt;/span&gt; AdminCombined.js&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;type&lt;/span&gt; AdminCombined.js &lt;span style="color: rgb(128, 128, 48);"&gt;|&lt;/span&gt; jazmin &lt;span style="color: rgb(128, 128, 48);"&gt;&amp;gt;&lt;/span&gt; AdminCombined.minified.js&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;copy&lt;/span&gt; AdminCombined.minified.js &lt;span style="color: rgb(0, 0, 230);"&gt;"..\Web Sites\Site\JavaScript\AdminCombined.minified.js"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(105, 105, 105);"&gt;::Combine the Stylesheets into a single file&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;for&lt;/span&gt; &lt;span style="color: rgb(128, 128, 48);"&gt;/&lt;/span&gt;F &lt;span style="color: rgb(0, 0, 230);"&gt;"tokens=*"&lt;/span&gt; %%f &lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(128, 128, 48);"&gt;(&lt;/span&gt;CssFilesToMerge.txt&lt;span style="color: rgb(128, 128, 48);"&gt;)&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;do&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;call&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;type&lt;/span&gt; &lt;span style="color: rgb(0, 0, 230);"&gt;"..\Web Sites\Site\CSS\%%f"&lt;/span&gt; &lt;span style="color: rgb(128, 128, 48);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(128, 128, 48);"&gt;&amp;gt;&lt;/span&gt; CombinedStyles.css&lt;br /&gt;csstidy.exe CombinedStyles.css &lt;span style="color: rgb(128, 128, 48);"&gt;-&lt;/span&gt;&lt;span style="color: rgb(128, 128, 48);"&gt;-&lt;/span&gt;template&lt;span style="color: rgb(128, 128, 48);"&gt;=&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;high&lt;/span&gt; CombinedStyles.minified.css&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;copy&lt;/span&gt; CombinedStyles.minified.css &lt;span style="color: rgb(0, 0, 230);"&gt;"..\Web Sites\Site\CSS\CombinedStyles.minified.css"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(105, 105, 105);"&gt;::Remove the temporary files&lt;/span&gt;&lt;span style="font-family: mon;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;del&lt;/span&gt; *.js&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;del&lt;/span&gt; *.css&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(105, 105, 105);"&gt;::Restore the old "current directory"&lt;/span&gt; &lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(128, 0, 0);"&gt;chdir&lt;/span&gt; &lt;span style="color: rgb(128, 128, 48);"&gt;/&lt;/span&gt;d %OLDDIR%&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The one part of the batch file that confuses most people is the FOR /F "token=*" statement. That reads in a line at a time from the file specified in brackets and puts it in the %%f variable. The contents of each file is then appended into a single file using a "type SourceFile &amp;gt;&amp;gt; DestinationFile" statement. In the case of the JavaScript files they are then piped through the Jazmin compressor/minifier, the output of which is redirected in an output file, i.e. AdminCombined.minified.js. With the CSS files, the command line syntax is a little different, but the outcome is the same.&lt;/p&gt;
&lt;p&gt;Hopefully the rest of the batch file is pretty self evident and there is enough information here to get you started on implementing the approach yourself. If there are areas that need more explanation please leave a comment on the blog post.&lt;/p&gt;&lt;img src="http://ridgway.co.za/aggbug/193.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Eden Ridgway</dc:creator>
            <guid>http://ridgway.co.za/archive/2008/01/28/setting-up-an-optimised-deployment-version-of-your-ajax-asp.net.aspx</guid>
            <pubDate>Mon, 28 Jan 2008 04:02:57 GMT</pubDate>
            <comments>http://ridgway.co.za/archive/2008/01/28/setting-up-an-optimised-deployment-version-of-your-ajax-asp.net.aspx#feedback</comments>
            <wfw:commentRss>http://ridgway.co.za/comments/commentRss/193.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Using a CTE to Allocate Tickets to Timeslots</title>
            <link>http://ridgway.co.za/archive/2008/01/27/using-a-cte-to-allocate-tickets-to-timeslots.aspx</link>
            <description>&lt;p&gt;SQL Server Common Table Expressions (CTEs) are most often used to solve problems such as paging and hierarchical queries, however in this post I want to demonstrate another use: booking of timeslots. If you were writing a system for an attraction with predefined timeslots, say to see the damper in the Taipei 101 building, you would need to be able to distribute the allocation of tickets over these timeslots. So if a group of 16 people arrived, depending on the space available in the timeslot they may be allocated over several timeslots and would have to patiently wait until their turn came around.&lt;/p&gt;
&lt;p&gt;The most obvious way to solve this problem is to use a looping structure that moves through the timeslots, allocates the tickets and reduces the number of tickets available for that timeslot. Unfortunately to ensure that slots are not over booked while this is going on, one has to lock the tables affected by the allocation process. This can cause performance and concurrency issues as the number of requested tickets and therefore the lock duration increases. A more efficient and elegant solution is to use the inherent looping/recursive nature of a CTE to do this allocation in one step. So instead of doing a loop, insert into select, loop again cycle, the code can simply do a single insert into select statement to block out the allocated timeslots in one implicit transaction.&lt;/p&gt;
&lt;p&gt;To demonstrate the approach, let us take a scenario where we want to allocate 16 tickets. The number of remaining places available per timeslot are as per the diagram below.&lt;/p&gt;
&lt;p style="text-align: left;"&gt;&lt;a href="http://ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/UsingaCTEtoAllocateTicketstoTimeslots_9DC2/Timeslots.gif"&gt;&lt;img width="260" height="84" border="0" src="http://ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/UsingaCTEtoAllocateTicketstoTimeslots_9DC2/clip_image001_thumb.gif" alt="clip_image001" style="border-width: 0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Our simplified database would therefore have a Timeslot table that contains the time and the running available capacity for each one, like this:&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="2" border="1" style="border: 1px solid black;"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td width="188" valign="top"&gt;Time&lt;/td&gt;
            &lt;td width="210" valign="top"&gt;Available Capacity&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="188" valign="top"&gt;1 Jan 2008 08:00:00&lt;/td&gt;
            &lt;td width="210" valign="top"&gt;0&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="188" valign="top"&gt;1 Jan 2008 08:20:00&lt;/td&gt;
            &lt;td width="210" valign="top"&gt;5&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="188" valign="top"&gt;1 Jan 2008 08:40:00&lt;/td&gt;
            &lt;td width="210" valign="top"&gt;0&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="188" valign="top"&gt;1 Jan 2008 09:00:00&lt;/td&gt;
            &lt;td width="210" valign="top"&gt;7&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="188" valign="top"&gt;1 Jan 2008 09:20:00&lt;/td&gt;
            &lt;td width="210" valign="top"&gt;2&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="188" valign="top"&gt;1 Jan 2008 09:40:00&lt;/td&gt;
            &lt;td width="210" valign="top"&gt;10&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;We want to allocate 16 tickets across those timeslot. So the CTE we create should operate in the following manner:&lt;/p&gt;
&lt;p style="text-align: left;"&gt;&lt;a href="http://ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/UsingaCTEtoAllocateTicketstoTimeslots_9DC2/clip_image002_2.gif"&gt;&lt;img width="429" height="298" border="0" src="http://ridgway.co.za/images/ridgway_co_za/WindowsLiveWriter/UsingaCTEtoAllocateTicketstoTimeslots_9DC2/clip_image002_thumb.gif" alt="clip_image002" style="border: 0px none ;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The CTE to do this looks like this:&lt;/p&gt;
&lt;div class="code"&gt;&lt;font color="#0000ff"&gt;DECLARE &lt;/font&gt;&lt;font color="#000000"&gt;@SeatsRequested &lt;/font&gt;&lt;font color="#0000ff"&gt;SMALLINT     &lt;br /&gt;
&lt;br /&gt;
SET &lt;/font&gt;&lt;font color="#000000"&gt;@SeatsRequested &lt;/font&gt;&lt;font color="#0000ff"&gt;= &lt;/font&gt;&lt;font color="#800000"&gt;16&lt;/font&gt;&lt;font color="#0000ff"&gt;;     &lt;br /&gt;
&lt;br /&gt;
WITH &lt;/font&gt;&lt;font color="#000000"&gt;TimeSlotAllocation (Time, SeatsAllocated, SeatsLeftToAllocate) &lt;/font&gt;&lt;font color="#0000ff"&gt;as     &lt;br /&gt;
&lt;/font&gt;&lt;font color="#000000"&gt;(     &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#006400"&gt;--Find the first time slot to use     &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;SELECT TOP &lt;/font&gt;&lt;font color="#800000"&gt;1     &lt;br /&gt;
        &lt;/font&gt;&lt;font color="#000000"&gt;Time,     &lt;br /&gt;
        dbo.MinNumber(@SeatsRequested, AvailableCapacity) &lt;/font&gt;&lt;font color="#0000ff"&gt;as &lt;/font&gt;&lt;font color="#000000"&gt;SeatsAllocated,     &lt;br /&gt;
        @SeatsRequested - dbo.MinNumber(@SeatsRequested, AvailableCapacity) &lt;/font&gt;&lt;font color="#0000ff"&gt;as &lt;/font&gt;&lt;font color="#000000"&gt;SeatsLeftToAllocate     &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;FROM     &lt;br /&gt;
        &lt;/font&gt;&lt;font color="#000000"&gt;Timeslot     &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;WHERE     &lt;br /&gt;
        &lt;/font&gt;&lt;font color="#000000"&gt;AvailableCapacity &amp;gt; &lt;/font&gt;&lt;font color="#800000"&gt;0     &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;ORDER BY     &lt;br /&gt;
        &lt;/font&gt;&lt;font color="#000000"&gt;Time     &lt;br /&gt;
     &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;UNION ALL     &lt;br /&gt;
     &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#006400"&gt;--Sequentially find the other timeslots that can be used to fulfill the sale request     &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;SELECT  &lt;br /&gt;
        &lt;/font&gt;&lt;font color="#000000"&gt;TS.Time,     &lt;br /&gt;
        dbo.MinNumber(TSA.SeatsLeftToAllocate, TS.AvailableCapacity),      &lt;br /&gt;
        TSA.SeatsLeftToAllocate - dbo.MinNumber(TSA.SeatsLeftToAllocate, TS.AvailableCapacity)      &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;FROM     &lt;br /&gt;
        &lt;/font&gt;&lt;font color="#000000"&gt;Timeslot TS     &lt;br /&gt;
         &lt;br /&gt;
        &lt;/font&gt;&lt;font color="#006400"&gt;--Join on to the next timeslot     &lt;br /&gt;
        &lt;/font&gt;&lt;font color="#0000ff"&gt;INNER JOIN &lt;/font&gt;&lt;font color="#000000"&gt;TimeSlotAllocation TSA &lt;/font&gt;&lt;font color="#0000ff"&gt;ON     &lt;br /&gt;
            &lt;/font&gt;&lt;font color="#000000"&gt;TS.Time &lt;/font&gt;&lt;font color="#0000ff"&gt;= DATEADD&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#0000ff"&gt;MINUTE&lt;/font&gt;&lt;font color="#000000"&gt;, &lt;/font&gt;&lt;font color="#800000"&gt;20&lt;/font&gt;&lt;font color="#000000"&gt;, TSA.Time)     &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff"&gt;WHERE     &lt;br /&gt;
        &lt;/font&gt;&lt;font color="#000000"&gt;SeatsLeftToAllocate &amp;gt; &lt;/font&gt;&lt;font color="#800000"&gt;0     &lt;br /&gt;
&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt; &lt;/div&gt;
&lt;p&gt;You’ll notice the code relies on a user defined function, MinNumber which simply returns the minimum value of the two supplied parameters. As you can see the logic is pretty straight forward:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;Find the first available timeslot. &lt;/li&gt;
    &lt;li&gt;Allocate the lesser of the number of SeatsLeftToAllocate or the available timeslot capacity. &lt;/li&gt;
    &lt;li&gt;Store the number of tickets remaining in SeatsLeftToAllocate &lt;/li&gt;
    &lt;li&gt;Move on to the next timeslot by adding the number of minutes between timeslots. &lt;/li&gt;
    &lt;li&gt;Repeat steps 2 to 4 until there are no SeatsLeftToAllocate. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Of course the final solution would include other logic, such as bounding the allocation of timeslots by day and checking that all tickets had been allocated, but this is merely an illustration of an approach.&lt;/p&gt;
&lt;p&gt;If you want to play around with a working example, &lt;a href="http://www.ridgway.co.za/Demos/Timeslot Allocation with a CTE.zip"&gt;here is the code&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://ridgway.co.za/aggbug/192.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Eden Ridgway</dc:creator>
            <guid>http://ridgway.co.za/archive/2008/01/27/using-a-cte-to-allocate-tickets-to-timeslots.aspx</guid>
            <pubDate>Sun, 27 Jan 2008 09:25:41 GMT</pubDate>
            <comments>http://ridgway.co.za/archive/2008/01/27/using-a-cte-to-allocate-tickets-to-timeslots.aspx#feedback</comments>
            <wfw:commentRss>http://ridgway.co.za/comments/commentRss/192.aspx</wfw:commentRss>
        </item>
        <item>
            <title>An Updated LINQ to WMI Implementation</title>
            <link>http://ridgway.co.za/archive/2008/01/02/an-updated-linq-to-wmi-implementation.aspx</link>
            <description>I recently needed to do some WMI queries so I went hunting for a LINQ implementation. I found a great basic implementation that &lt;a target="_blank" href="http://bloggingabout.net/blogs/emile/"&gt;Emile Bosch&lt;/a&gt; did way back in 2005.  Once you have finished reading this post you should view his &lt;a target="_blank" href="http://bloggingabout.net/blogs/emile/archive/2005/12/12/10514.aspx"&gt;blog post&lt;/a&gt; for more detail on the implementation.&lt;br /&gt;
&lt;br /&gt;
Unfortunately Emile's WMILINQ implementation no longer works as it was based on a beta version of the framework so I brushed it off and upgraded it to work with the RTM release of .Net 3.5. I also made several other other improvements such as:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt; Updated the code generator to identify and generate array properties and emit a generated code attribute on the associated class&lt;/li&gt;
    &lt;li&gt;Fixed a bug with string where filter parameters&lt;/li&gt;
    &lt;li&gt; Improved the CIM Type mapping conversion logic&lt;/li&gt;
    &lt;li&gt;Added array mapping support to the LINQ query &lt;/li&gt;
    &lt;li&gt; Changed the name to match the new Microsoft LINQ to X naming convention&lt;/li&gt;
&lt;/ul&gt;
Once I had it working I could execute queries against the WMI objects like this:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="blue"&gt;var&lt;/font&gt;&lt;font color="black"&gt; query &lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;from account &lt;/font&gt;&lt;font color="blue"&gt;in &lt;/font&gt;&lt;font color="black"&gt;context.Source&amp;lt;&lt;span style="color: rgb(0, 0, 128);"&gt;Win32_UserAccount&lt;/span&gt;&amp;gt;()&lt;br /&gt;
            select account&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
foreach &lt;/font&gt;&lt;font color="black"&gt;(&lt;/font&gt;&lt;/font&gt;&lt;font color="black" style="color: rgb(51, 51, 153);"&gt;Win32_UserAccount&lt;/font&gt;&lt;font color="black"&gt;&lt;font color="black"&gt; account &lt;/font&gt;&lt;font color="blue"&gt;in &lt;/font&gt;&lt;font color="black"&gt;query)&lt;br /&gt;
{&lt;br /&gt;
    Console.WriteLine(account.Name)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;}&lt;/font&gt; 	&lt;/font&gt;&lt;/div&gt;
&lt;font color="black"&gt;&lt;br /&gt;
Doing basic queries with the provider is really easy, but be aware that the implementation is very limited. It does not support projections, nested queries and referenced variables. So for example the following query generates an incorrect WQL statement.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="blue"&gt;string &lt;/font&gt;&lt;font color="black"&gt;name &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="#808080"&gt;"Me"&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;var query &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;from account &lt;/font&gt;&lt;font color="blue"&gt;in &lt;/font&gt;&lt;font color="black"&gt;context.Source&amp;lt;&lt;/font&gt;&lt;font color="black" style="color: rgb(51, 51, 153);"&gt;Win32_UserAccount&lt;/font&gt;&lt;font color="black"&gt;&amp;gt;()&lt;br /&gt;
            where account.Name &lt;/font&gt;&lt;font color="blue"&gt;== &lt;/font&gt;&lt;font color="black"&gt;name&lt;br /&gt;
            select account&lt;/font&gt;&lt;font color="blue"&gt;;&lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
            &lt;br /&gt;
One would expect it to generate this statement:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;* &lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="black"&gt;Win32_UserAccount &lt;/font&gt;&lt;font color="blue"&gt;WHERE name = &lt;/font&gt;&lt;font color="#808080"&gt;'Me'&lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
but instead executes this:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;* &lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="black"&gt;Win32_UserAccount &lt;/font&gt;&lt;font color="blue"&gt;WHERE name = &lt;/font&gt;&lt;font color="#808080"&gt;'name'&lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
Regardless of these shortcomings I still found it quite useful, and I wanted to share the upgraded version with you. So if you'd like to grab it, here's the &lt;a href="http://www.ridgway.co.za/demos/LinqToWmi.zip"&gt;download&lt;/a&gt;. &lt;br /&gt;
&lt;br /&gt;
I am currently working on a rewrite of the implementation using Matt Warren's excellent set of &lt;a href="http://blogs.msdn.com/mattwar/archive/2007/07/30/linq-building-an-iqueryable-provider-part-i.aspx"&gt;Building an IQueryable Provider&lt;/a&gt; blog posts as a basis. So far it is not looking too bad and it overcomes several of the problems with this implementation, but it requires quite a bit more effort to finish it off, so it may be a while before I release it.&lt;br /&gt;
&lt;/font&gt;&lt;img src="http://ridgway.co.za/aggbug/191.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Eden Ridgway</dc:creator>
            <guid>http://ridgway.co.za/archive/2008/01/02/an-updated-linq-to-wmi-implementation.aspx</guid>
            <pubDate>Wed, 02 Jan 2008 07:51:56 GMT</pubDate>
            <comments>http://ridgway.co.za/archive/2008/01/02/an-updated-linq-to-wmi-implementation.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://ridgway.co.za/comments/commentRss/191.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Using a Common Table Expression (CTE) to Generate a Date Range</title>
            <link>http://ridgway.co.za/archive/2007/11/23/using-a-common-table-expression-cte-to-generate-a-date.aspx</link>
            <description>There are times when you date reliant data that has gaps in it but you need a query that includes days even where data is missing. The data source may be a sales table where there may be days that no sales where made but you want to generate a calendar like cross-tab query for every day in a period. When I was asked by a colleague to help him with a similar problem it struck me that we could leverage a SQL 2005 CTE in a user defined function to act as a date range source for the query on which we could left join and fill in the missing days.&lt;br /&gt;
&lt;br /&gt;
The solution is quite simple, all you need is a CTE that starts and the start date and recursively joins on to itself using DATEADD plus a day until it reaches the end date. Here is the function that I wrote:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="blue"&gt;CREATE FUNCTION &lt;/font&gt;&lt;font color="black"&gt;GetDateRange &lt;br /&gt;
(&lt;br /&gt;
    @StartDate &lt;/font&gt;&lt;font color="blue"&gt;DateTime&lt;/font&gt;&lt;font color="black"&gt;, &lt;br /&gt;
    @EndDate &lt;/font&gt;&lt;font color="blue"&gt;DateTime&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;)&lt;br /&gt;
RETURNS @DateRangeList &lt;/font&gt;&lt;font color="blue"&gt;TABLE &lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;(&lt;br /&gt;
    Date &lt;/font&gt;&lt;font color="blue"&gt;DateTime NOT NULL&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;)&lt;br /&gt;
&lt;/font&gt;&lt;font color="blue"&gt;AS &lt;br /&gt;
BEGIN&lt;br /&gt;
    IF &lt;/font&gt;&lt;font color="black"&gt;@StartDate &amp;gt; @EndDate&lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;BEGIN&lt;br /&gt;
        &lt;/font&gt;&lt;font color="darkgreen"&gt;--Unfortunately you cannot raise an error in a UDF so simply return no rows&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;RETURN&lt;br /&gt;
    END;&lt;br /&gt;
&lt;br /&gt;
    WITH &lt;/font&gt;&lt;font color="black"&gt;DateRange(Date) &lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br /&gt;
    &lt;/font&gt;&lt;font color="black"&gt;(&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;SELECT&lt;br /&gt;
            &lt;/font&gt;&lt;font color="black"&gt;@StartDate Date&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;UNION ALL&lt;br /&gt;
        SELECT&lt;br /&gt;
            DATEADD&lt;/font&gt;&lt;font color="black"&gt;(day, &lt;/font&gt;&lt;font color="maroon"&gt;1&lt;/font&gt;&lt;font color="black"&gt;, Date) Date&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;FROM&lt;br /&gt;
            &lt;/font&gt;&lt;font color="black"&gt;DateRange&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;WHERE&lt;br /&gt;
            &lt;/font&gt;&lt;font color="black"&gt;Date &amp;lt; @EndDate&lt;br /&gt;
    )&lt;br /&gt;
&lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;INSERT &lt;/font&gt;&lt;font color="black"&gt;@DateRangeList&lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;Date &lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="black"&gt;DateRange&lt;br /&gt;
    &lt;/font&gt;&lt;font color="darkgreen"&gt;--You could remove Maximum Recursion level constraint by specifying a MaxRecusion of zero&lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;OPTION &lt;/font&gt;&lt;font color="black"&gt;(MaxRecursion &lt;/font&gt;&lt;font color="maroon"&gt;10000&lt;/font&gt;&lt;font color="black"&gt;)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
    RETURN&lt;br /&gt;
&lt;br /&gt;
END;&lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
The performance of the query is pretty good, but is almost identical to using a temp table/table variable and a loop to generate the same data. On my P4 2.8GHZ machine  at home both approaches generate a month's worth of days in 16ms and a year's worth in 30ms. I have to say I was somewhat surprised to find this out since I expected it to be faster but I suppose the inserts into the table variable negate the possible speed up. Regardless it is an interesting approach that I thought I'd share with you.&lt;img src="http://ridgway.co.za/aggbug/190.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Eden Ridgway</dc:creator>
            <guid>http://ridgway.co.za/archive/2007/11/23/using-a-common-table-expression-cte-to-generate-a-date.aspx</guid>
            <pubDate>Fri, 23 Nov 2007 06:51:14 GMT</pubDate>
            <comments>http://ridgway.co.za/archive/2007/11/23/using-a-common-table-expression-cte-to-generate-a-date.aspx#feedback</comments>
            <wfw:commentRss>http://ridgway.co.za/comments/commentRss/190.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Simple JavaScript Undo Manager for DTOs</title>
            <link>http://ridgway.co.za/archive/2007/11/07/simple-javascript-undo-manager-for-dtos.aspx</link>
            <description>When looking at implementing undo functionality, two common patterns that are used are the &lt;a href="http://www.dofactory.com/Patterns/PatternMemento.aspx"&gt;Memento&lt;/a&gt; or &lt;a href="http://www.dofactory.com/Patterns/PatternCommand.aspx"&gt;Command&lt;/a&gt; design patterns. For an example of using the Memento pattern on JavaScript objects take a look at Lawrence Carvalho's &lt;a href="http://www.nodetraveller.com/blog/javascript/actasundo/"&gt;ActAsUndoable post&lt;/a&gt;. This approach however did not suite the needs of the application I'm currently working on because the changes I'm making are on &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;Data Transfer Objects&lt;/a&gt; (DTOs) that have been serialized from the server using ASP.Net web services. As such I don't want to add any functionality to them and I don't really care about breaking encapsulation because all object values are public. I take these client side objects and "databind" (logically speaking) them to various UI elements, such as tree nodes and form fields. What I want to be able to offer however is the ability to cancel out changes without going back to the server to fetch the original data. I also want any undone changes to apply to the original objects and therefore simply cloning the objects by serializing and deserializing them using ASP.Net JSON serialization methods is not an option (it would make the object to UI element association management a pain). If however you don't care about preserving object references then this is a perfect solution for you, and can be done like this:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="blue"&gt;function &lt;/font&gt;&lt;font color="black"&gt;cloneObjectGraph(targetObject)&lt;br /&gt;
{&lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;jsonSerializedData &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;Sys.Serialization.JavaScriptSerializer.serialize(targetObject)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
    return &lt;/font&gt;&lt;font color="black"&gt;Sys.Serialization.JavaScriptSerializer.deserialize(jsonSerializedData)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;}&lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
So what I have created is a very simple pair of objects, UndoManager and UndoItem, that are ideally suited to taking a snapshot of state on simple JavaScript object graph, where all the values you care about are "public", and then being able to rollback the object graph to the snapshot point while preserving the original object references. If you want functionality such as the ability store state of more complex objects that have getters/setters and "private" variables (as is present with the &lt;a href="http://yuiblog.com/blog/2007/06/12/module-pattern/"&gt;Module pattern&lt;/a&gt; and others) then don't use these objects, rather take a look at the ActAsUndoable memento approach. Also if you want to implement an "action by action" undo/redo interface like word then rather look at using the command pattern.&lt;br /&gt;
&lt;br /&gt;
So getting on to UndoManager and UndoItem objects. As you can see from the diagram below, they are quite straightforward. The UndoManager exists to allow you to simply have a stack of changes that you can undo on a last in last out basis. The UndoItem object handles the storing of a single undo operation on an object graph.&lt;br /&gt;
&lt;div style="text-align: center;"&gt;&lt;a href="http://www.ridgway.co.za/images/ridgway_co_za/UndoManagerClassDiagram(1).png"&gt;&lt;img border="0" src="/images/ridgway_co_za/UndoManagerClassDiagram(1).png" alt="" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;
The way UndoItem takes a snapshot of an objects state is to "iterate" over all the object attributes using a for..in loop and copy any simple type to the _undoState variable. Any complex object it encounters, such as an object, date or array, it creates another UndoItem for that and adds it to _undoState in the attributes place. Hence it builds up a hierarchy of Undo Items it can call on when undo is called. When undoing the changes it uses the _objectReference it stored when constructing the UndoItem to copy the values back from the _undoState on to the original object.&lt;br /&gt;
&lt;br /&gt;
This gives one a really simple and unobtrusive way of capturing and restoring state. Say you have a person object that you want to save to save the state for, make changes and then undo them, you use an UndoItem to do it in the following way:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;person &lt;/font&gt;&lt;font color="blue"&gt;= &lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;{ &lt;br /&gt;
    IsActive: &lt;/font&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;font color="black"&gt;,&lt;br /&gt;
    Team: { Name: &lt;/font&gt;&lt;font color="#808080"&gt;'Admin' &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
}&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
var &lt;/font&gt;&lt;font color="black"&gt;undoItem &lt;/font&gt;&lt;font color="blue"&gt;= new &lt;/font&gt;&lt;font color="black"&gt;UndoItem(person)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;person.IsActive &lt;/font&gt;&lt;font color="blue"&gt;= false;&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;person.Team.Name &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="#808080"&gt;'General User'&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;undoItem.undo()&lt;/font&gt;&lt;font color="blue"&gt;;&lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
If you want to manage a stack of changes then you use the UndoManager like so:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;team &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;{ Name: &lt;/font&gt;&lt;font color="#808080"&gt;'Admin' &lt;/font&gt;&lt;font color="black"&gt;}&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
var &lt;/font&gt;&lt;font color="black"&gt;person &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;{ Name: &lt;/font&gt;&lt;font color="#808080"&gt;'Joe' &lt;/font&gt;&lt;font color="black"&gt;}&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
var &lt;/font&gt;&lt;font color="black"&gt;undoManager &lt;/font&gt;&lt;font color="blue"&gt;= new &lt;/font&gt;&lt;font color="black"&gt;UndoManager()&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;undoManager.saveUndoPoint(team)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;undoManager.saveUndoPoint(person)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;team.Name &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="#808080"&gt;'General User'&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;person.Name &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="#808080"&gt;'Bob'&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;/font&gt;&lt;font color="darkgreen"&gt;//Will undo the person name change&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;undoManager.undo()&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;/font&gt;&lt;font color="darkgreen"&gt;//Will undo the team name change&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;undoManager.undo()&lt;/font&gt;&lt;font color="blue"&gt;;&lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
If you are keen to use the objects  then you can &lt;a target="_blank" href="http://www.ridgway.co.za/demos/UndoManager.zip"&gt;download it here&lt;/a&gt; (the code is not minified). I have also created a set of Scriptaculous unit tests that you can &lt;a target="_blank" href="http://www.ridgway.co.za/demos/UndoManager/UndoManagerTests.htm"&gt;run here&lt;/a&gt;.&lt;img src="http://ridgway.co.za/aggbug/189.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Eden Ridgway</dc:creator>
            <guid>http://ridgway.co.za/archive/2007/11/07/simple-javascript-undo-manager-for-dtos.aspx</guid>
            <pubDate>Wed, 07 Nov 2007 06:47:10 GMT</pubDate>
            <comments>http://ridgway.co.za/archive/2007/11/07/simple-javascript-undo-manager-for-dtos.aspx#feedback</comments>
            <wfw:commentRss>http://ridgway.co.za/comments/commentRss/189.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Using Synchronous ASP.Net AJAX Web Service Calls and Scriptaculous to Test your JavaScript</title>
            <link>http://ridgway.co.za/archive/2007/10/30/using-synchronous-asp.net-ajax-web-service-calls-and-scriptaculous-to.aspx</link>
            <description>As our web applications become more JavaScript heavy it is becomes increasingly important that we have tests for this code. In the past I have managed to get away with it but in retrospect it was a risky approach to take. So in my latest project I started assessing the various JavaScript unit testing frameworks and decided &lt;a href="http://wiki.script.aculo.us/scriptaculous/show/UnitTesting" target="_blank"&gt;Scriptaculous&lt;/a&gt; was the way to go. I excluded &lt;a href="http://www.jsunit.net/" target="_blank"&gt;JsUnit&lt;/a&gt; as an option because it is not object oriented and didn't give me enough information about which tests had passed. The Scriptaculous unit testing framework also has some useful features like the ability to wait before completing the test and benchmarking of calls.&lt;br /&gt;
&lt;br /&gt;
The one big problem you have when testing an AJAX application however is that the out-of-band calls are made asynchronously. This means that if you are testing a method that does a load and want to ensure that certain values are set or calls made once the data has loaded you have to have a bit of a problem. The Scriptaculous framework's solution to this  is the ability to wait and execute a function that may then contain your asserts. Here is a basic example of what the test would look like:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="blue"&gt;new &lt;/font&gt;&lt;font color="black"&gt;Test.Unit.Runner(&lt;br /&gt;
{&lt;br /&gt;
    testShouldLoadDataOnInit: &lt;/font&gt;&lt;font color="blue"&gt;function&lt;/font&gt;&lt;font color="black"&gt;() &lt;br /&gt;
    {&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;manager &lt;/font&gt;&lt;font color="blue"&gt;= new &lt;/font&gt;&lt;font color="black"&gt;TestManager()&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
        &lt;/font&gt;&lt;font color="darkgreen"&gt;//This makes a web service call&lt;/font&gt;&lt;br /&gt;
&lt;font color="blue"&gt;         &lt;/font&gt;&lt;font color="black"&gt;manager.onInit()&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
        &lt;br /&gt;
        this&lt;/font&gt;&lt;font color="black"&gt;.wait(&lt;/font&gt;&lt;font color="maroon"&gt;500&lt;/font&gt;&lt;font color="black"&gt;, &lt;/font&gt;&lt;font color="blue"&gt;function&lt;/font&gt;&lt;font color="black"&gt;()&lt;br /&gt;
                       {&lt;br /&gt;
                          &lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;.assertNotEqual(manager._TestData, &lt;/font&gt;&lt;font color="blue"&gt;null&lt;/font&gt;&lt;font color="black"&gt;)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
                       &lt;/font&gt;&lt;font color="black"&gt;})&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
    &lt;/font&gt;&lt;font color="black"&gt;},&lt;br /&gt;
})&lt;/font&gt;&lt;font color="blue"&gt;;&lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
I found that this led to inconsistent test results because for various reasons the webservice request callbacks would take a varying amount of time. Of course you could try to cover yourself by making the wait time larger but then your tests take too long to run. Both of these problems will discourage others from using and extending your tests.&lt;br /&gt;
&lt;br /&gt;
Having hand coded XMLHTTP calls in the days before the approach was known as AJAX I knew that it was possible to make the calls synchronously, so all I needed to do was get the generated ASP.Net AJAX webservice  proxies to use a new synchronous  executor. I came across &lt;a href="http://geekswithblogs.net/rashid/archive/2007/07/04/SJAX-Call.aspx" target="_blank"&gt;Amit's SJAX post&lt;/a&gt; that demonstrated how to created a synchronous executor for a Sys.Net.WebRequest object which was very useful. I discovered that one could change the executor for generated webservice proxy calls by changing the default executor type for the Sys.Net.WebRequestManager, like so:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="black"&gt;Sys.Net.WebRequestManager.set_defaultExecutorType(&lt;/font&gt;&lt;font color="#808080"&gt;"Example.Executor"&lt;/font&gt;&lt;font color="black"&gt;)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
So I took Amit's example, changed it somewhat and got it to work work as a synchronous request handler (using the debug version of the ASP.Net AJAX framework JavaScript as a guide). This resulted in a handler that looked like this (note I have removed code and replaced them with comments for brevity) [&lt;a href="http://www.ridgway.co.za/demos/XMLHttpSyncExecutor.zip"&gt;download full file here&lt;/a&gt;]:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="black"&gt;Type.registerNamespace(&lt;/font&gt;&lt;font color="#808080"&gt;'Sjax'&lt;/font&gt;&lt;font color="black"&gt;)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;Sjax.XMLHttpSyncExecutor &lt;/font&gt;&lt;font color="blue"&gt;= function&lt;/font&gt;&lt;font color="black"&gt;()&lt;br /&gt;
{&lt;br /&gt;
    Sjax.XMLHttpSyncExecutor.initializeBase(&lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
    this&lt;/font&gt;&lt;font color="black"&gt;._started &lt;/font&gt;&lt;font color="blue"&gt;= false;&lt;br /&gt;
    this&lt;/font&gt;&lt;font color="black"&gt;._responseAvailable &lt;/font&gt;&lt;font color="blue"&gt;= false;&lt;br /&gt;
    this&lt;/font&gt;&lt;font color="black"&gt;._onReceiveHandler &lt;/font&gt;&lt;font color="blue"&gt;= null;&lt;br /&gt;
    this&lt;/font&gt;&lt;font color="black"&gt;._xmlHttpRequest &lt;/font&gt;&lt;font color="blue"&gt;= null;&lt;br /&gt;
    &lt;br /&gt;
    this&lt;/font&gt;&lt;font color="black"&gt;.get_aborted &lt;/font&gt;&lt;font color="blue"&gt;= function&lt;/font&gt;&lt;font color="black"&gt;()&lt;br /&gt;
    {&lt;br /&gt;
        &lt;/font&gt;&lt;font color="darkgreen"&gt;//Parameter validation code removed here...&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;return false;&lt;br /&gt;
    &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
&lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;.get_responseAvailable &lt;/font&gt;&lt;font color="blue"&gt;= function&lt;/font&gt;&lt;font color="black"&gt;()&lt;br /&gt;
    {&lt;br /&gt;
        &lt;/font&gt;&lt;font color="darkgreen"&gt;//Parameter validation code removed here...&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;return this&lt;/font&gt;&lt;font color="black"&gt;._responseAvailable&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
    &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
&lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;.get_responseData &lt;/font&gt;&lt;font color="blue"&gt;= function&lt;/font&gt;&lt;font color="black"&gt;()&lt;br /&gt;
    {&lt;br /&gt;
        &lt;/font&gt;&lt;font color="darkgreen"&gt;//Parameter validation code removed here...&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;return this&lt;/font&gt;&lt;font color="black"&gt;._xmlHttpRequest.responseText&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
    &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
&lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;.get_started &lt;/font&gt;&lt;font color="blue"&gt;= function&lt;/font&gt;&lt;font color="black"&gt;()&lt;br /&gt;
    {&lt;br /&gt;
        &lt;/font&gt;&lt;font color="darkgreen"&gt;//Parameter validation code removed here...&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;return this&lt;/font&gt;&lt;font color="black"&gt;._started&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
    &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
&lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;.get_statusCode &lt;/font&gt;&lt;font color="blue"&gt;= function&lt;/font&gt;&lt;font color="black"&gt;()&lt;br /&gt;
    {&lt;br /&gt;
        &lt;/font&gt;&lt;font color="darkgreen"&gt;//Parameter validation code removed here...&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;return this&lt;/font&gt;&lt;font color="black"&gt;._xmlHttpRequest.status&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
    &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
&lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;.get_statusText &lt;/font&gt;&lt;font color="blue"&gt;= function&lt;/font&gt;&lt;font color="black"&gt;()&lt;br /&gt;
    {&lt;br /&gt;
        &lt;/font&gt;&lt;font color="darkgreen"&gt;//Parameter validation code removed here...&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;return this&lt;/font&gt;&lt;font color="black"&gt;._xmlHttpRequest.statusText&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
    &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
&lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;.get_xml &lt;/font&gt;&lt;font color="blue"&gt;= function&lt;/font&gt;&lt;font color="black"&gt;()&lt;br /&gt;
    {&lt;br /&gt;
        &lt;/font&gt;&lt;font color="darkgreen"&gt;//Code removed&lt;br /&gt;
    &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
&lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;.executeRequest &lt;/font&gt;&lt;font color="blue"&gt;= function&lt;/font&gt;&lt;font color="black"&gt;()&lt;br /&gt;
    {&lt;br /&gt;
        &lt;/font&gt;&lt;font color="darkgreen"&gt;//Parameter validation code removed here...&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;webRequest &lt;/font&gt;&lt;font color="blue"&gt;= this&lt;/font&gt;&lt;font color="black"&gt;.get_webRequest()&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
        if &lt;/font&gt;&lt;font color="black"&gt;(webRequest &lt;/font&gt;&lt;font color="blue"&gt;=== null&lt;/font&gt;&lt;font color="black"&gt;)&lt;br /&gt;
        {&lt;br /&gt;
            &lt;/font&gt;&lt;font color="blue"&gt;throw &lt;/font&gt;&lt;font color="black"&gt;Error.invalidOperation(Sys.Res.nullWebRequest)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
        &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;body &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;webRequest.get_body()&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
        var &lt;/font&gt;&lt;font color="black"&gt;headers &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;webRequest.get_headers()&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
        var &lt;/font&gt;&lt;font color="black"&gt;verb &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;webRequest.get_httpVerb()&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
        var &lt;/font&gt;&lt;font color="black"&gt;xmlHttpRequest &lt;/font&gt;&lt;font color="blue"&gt;= new &lt;/font&gt;&lt;font color="black"&gt;XMLHttpRequest()&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
        this&lt;/font&gt;&lt;font color="black"&gt;._onReceiveHandler &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;Function.createCallback(&lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;._onReadyStateChange, { sender:&lt;/font&gt;&lt;font color="blue"&gt;this &lt;/font&gt;&lt;font color="black"&gt;})&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
        this&lt;/font&gt;&lt;font color="black"&gt;._started &lt;/font&gt;&lt;font color="blue"&gt;= true;&lt;br /&gt;
        &lt;/font&gt;&lt;font color="black"&gt;xmlHttpRequest.onreadystatechange &lt;/font&gt;&lt;font color="blue"&gt;= this&lt;/font&gt;&lt;font color="black"&gt;._onReceiveHandler&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
        &lt;/font&gt;&lt;font color="black"&gt;xmlHttpRequest.open(verb, webRequest.getResolvedUrl(), &lt;/font&gt;&lt;font color="blue"&gt;false&lt;/font&gt;&lt;font color="black"&gt;)&lt;/font&gt;&lt;font color="blue"&gt;; &lt;/font&gt;&lt;font color="darkgreen"&gt;// False to call Synchronously&lt;br /&gt;
&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;if &lt;/font&gt;&lt;font color="black"&gt;(headers)&lt;br /&gt;
        {&lt;br /&gt;
            &lt;/font&gt;&lt;font color="blue"&gt;for &lt;/font&gt;&lt;font color="black"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;header &lt;/font&gt;&lt;font color="blue"&gt;in &lt;/font&gt;&lt;font color="black"&gt;headers)&lt;br /&gt;
            {&lt;br /&gt;
                &lt;/font&gt;&lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;val &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;headers[header]&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
                if &lt;/font&gt;&lt;font color="black"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;typeof&lt;/font&gt;&lt;font color="black"&gt;(val) !&lt;/font&gt;&lt;font color="blue"&gt;== &lt;/font&gt;&lt;font color="#808080"&gt;"function"&lt;/font&gt;&lt;font color="black"&gt;)&lt;br /&gt;
                {&lt;br /&gt;
                    xmlHttpRequest.setRequestHeader(header, val)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
                &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;if &lt;/font&gt;&lt;font color="black"&gt;(verb.toLowerCase() &lt;/font&gt;&lt;font color="blue"&gt;=== &lt;/font&gt;&lt;font color="#808080"&gt;"post"&lt;/font&gt;&lt;font color="black"&gt;)&lt;br /&gt;
        {&lt;br /&gt;
            &lt;/font&gt;&lt;font color="blue"&gt;if &lt;/font&gt;&lt;font color="black"&gt;((headers &lt;/font&gt;&lt;font color="blue"&gt;=== null&lt;/font&gt;&lt;font color="black"&gt;) || !headers[&lt;/font&gt;&lt;font color="#808080"&gt;'Content-Type'&lt;/font&gt;&lt;font color="black"&gt;])&lt;br /&gt;
            {&lt;br /&gt;
                xmlHttpRequest.setRequestHeader(&lt;/font&gt;&lt;font color="#808080"&gt;'Content-Type'&lt;/font&gt;&lt;font color="black"&gt;, &lt;/font&gt;&lt;font color="#808080"&gt;'application/x-www-form-urlencoded'&lt;/font&gt;&lt;font color="black"&gt;)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
            &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
&lt;br /&gt;
            &lt;/font&gt;&lt;font color="blue"&gt;if &lt;/font&gt;&lt;font color="black"&gt;(!body)&lt;br /&gt;
            {&lt;br /&gt;
                body &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="#808080"&gt;''&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
            &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;._started &lt;/font&gt;&lt;font color="blue"&gt;= true;&lt;br /&gt;
        this&lt;/font&gt;&lt;font color="black"&gt;._xmlHttpRequest &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;xmlHttpRequest&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
        &lt;/font&gt;&lt;font color="black"&gt;xmlHttpRequest.send(body)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
    &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
&lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;.getAllResponseHeaders &lt;/font&gt;&lt;font color="blue"&gt;= function&lt;/font&gt;&lt;font color="black"&gt;()&lt;br /&gt;
    {&lt;br /&gt;
        &lt;/font&gt;&lt;font color="darkgreen"&gt;//Parameter validation code removed here...&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;return this&lt;/font&gt;&lt;font color="black"&gt;._xmlHttpRequest.getAllResponseHeaders()&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
    &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
    &lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;.getResponseHeader &lt;/font&gt;&lt;font color="blue"&gt;= function&lt;/font&gt;&lt;font color="black"&gt;(header)&lt;br /&gt;
    {&lt;br /&gt;
        &lt;/font&gt;&lt;font color="darkgreen"&gt;//Parameter validation code removed here...&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;return this&lt;/font&gt;&lt;font color="black"&gt;._xmlHttpRequest.getResponseHeader(header)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
    &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
    &lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;._onReadyStateChange &lt;/font&gt;&lt;font color="blue"&gt;= function&lt;/font&gt;&lt;font color="black"&gt;(e)&lt;br /&gt;
    {  &lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;executor &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;e.sender&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
            &lt;br /&gt;
        if &lt;/font&gt;&lt;font color="black"&gt;(executor._xmlHttpRequest.readyState &lt;/font&gt;&lt;font color="blue"&gt;=== &lt;/font&gt;&lt;font color="maroon"&gt;4&lt;/font&gt;&lt;font color="black"&gt;)&lt;br /&gt;
        {&lt;br /&gt;
            &lt;/font&gt;&lt;font color="darkgreen"&gt;//Validation code removed here...&lt;br /&gt;
&lt;br /&gt;
            &lt;/font&gt;&lt;font color="black"&gt;executor._responseAvailable &lt;/font&gt;&lt;font color="blue"&gt;= true;&lt;br /&gt;
&lt;br /&gt;
            &lt;/font&gt;&lt;font color="black"&gt;executor._xmlHttpRequest.onreadystatechange &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;Function.emptyMethod&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
            &lt;/font&gt;&lt;font color="black"&gt;executor._onReceiveHandler &lt;/font&gt;&lt;font color="blue"&gt;= null;&lt;br /&gt;
&lt;br /&gt;
            &lt;/font&gt;&lt;font color="black"&gt;executor._started &lt;/font&gt;&lt;font color="blue"&gt;= false;&lt;br /&gt;
            &lt;br /&gt;
            var &lt;/font&gt;&lt;font color="black"&gt;webRequest &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;executor.get_webRequest()&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
            &lt;/font&gt;&lt;font color="black"&gt;webRequest.completed(Sys.EventArgs.Empty)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
            &lt;br /&gt;
            &lt;/font&gt;&lt;font color="darkgreen"&gt;//Once the completed callback handler has processed the data it needs from the XML HTTP request we can clean up&lt;br /&gt;
            &lt;/font&gt;&lt;font color="black"&gt;executor._xmlHttpRequest &lt;/font&gt;&lt;font color="blue"&gt;= null;&lt;br /&gt;
        &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Sjax.XMLHttpSyncExecutor.registerClass(&lt;/font&gt;&lt;font color="#808080"&gt;'Sjax.XMLHttpSyncExecutor'&lt;/font&gt;&lt;font color="black"&gt;, Sys.Net.WebRequestExecutor)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
So now we can create tests that test objects that make synchronous webservice calls by changing the default executor in the setup of the unit test like this:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="blue"&gt;new &lt;/font&gt;&lt;font color="black"&gt;Test.Unit.Runner(&lt;br /&gt;
{&lt;br /&gt;
    setup: &lt;/font&gt;&lt;font color="blue"&gt;function&lt;/font&gt;&lt;font color="black"&gt;() &lt;br /&gt;
    { &lt;br /&gt;
        Sys.Net.WebRequestManager.set_defaultExecutorType(&lt;/font&gt;&lt;font color="#808080"&gt;"Sjax.XMLHttpSyncExecutor"&lt;/font&gt;&lt;font color="black"&gt;)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
    &lt;/font&gt;&lt;font color="black"&gt;},&lt;br /&gt;
&lt;br /&gt;
    testShouldLoadDataOnInit: &lt;/font&gt;&lt;font color="blue"&gt;function&lt;/font&gt;&lt;font color="black"&gt;() &lt;br /&gt;
    {&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;manager &lt;/font&gt;&lt;font color="blue"&gt;= new &lt;/font&gt;&lt;font color="black"&gt;TestManager()&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
        &lt;/font&gt;&lt;font color="black"&gt;manager.onInit()&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
        &lt;br /&gt;
        this&lt;/font&gt;&lt;font color="black"&gt;.assertNotEqual(manager._TestData, &lt;/font&gt;&lt;font color="blue"&gt;null&lt;/font&gt;&lt;font color="black"&gt;)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
    &lt;/font&gt;&lt;font color="black"&gt;},&lt;br /&gt;
})&lt;/font&gt;&lt;font color="blue"&gt;;&lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
I think you'll agree that with the extensibility they have provided in the ASP.Net AJAX framework, what we have now is quite a neat way of ensuring that our tests run consistently and as fast as they can. My thanks go out to Microsoft and the Scriptaculous team! :)&lt;img src="http://ridgway.co.za/aggbug/188.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Eden Ridgway</dc:creator>
            <guid>http://ridgway.co.za/archive/2007/10/30/using-synchronous-asp.net-ajax-web-service-calls-and-scriptaculous-to.aspx</guid>
            <pubDate>Tue, 30 Oct 2007 06:17:07 GMT</pubDate>
            <comments>http://ridgway.co.za/archive/2007/10/30/using-synchronous-asp.net-ajax-web-service-calls-and-scriptaculous-to.aspx#feedback</comments>
            <wfw:commentRss>http://ridgway.co.za/comments/commentRss/188.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Using ASP.Net AJAX WebServices (ScriptServices) in ExtJS</title>
            <link>http://ridgway.co.za/archive/2007/10/09/using-asp.net-ajax-webservices-scriptservices-in-extjs.aspx</link>
            <description>I've only just started investigating &lt;a href="http://extjs.com/"&gt;ExtJS&lt;/a&gt; and what it can possibly provide over and above the ASP.Net AJAX framework. The first thing I wanted to do was use the ASP.Net AJAX JavaScript webservice proxies instead of the expected REST style services. Unfortunately I ran into several problems and ended up using a slightly different approach to what I found on the &lt;a href="http://extjs.com/forum" target="_blank"&gt;ExtJS forums&lt;/a&gt;. Let me quickly outline the problem. In ExtJS they use a store wrapper for their data which is assigned to a grid panel. This store object may also know how to fetch external data that it needs via a proxy, which is defined like so:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;ds &lt;/font&gt;&lt;font color="blue"&gt;= new &lt;/font&gt;&lt;font color="black"&gt;Ext.data.Store({&lt;br /&gt;
    proxy: &lt;/font&gt;&lt;font color="blue"&gt;new &lt;/font&gt;&lt;font color="black"&gt;Ext.data.HttpProxy(&lt;br /&gt;
         {&lt;br /&gt;
          url: &lt;/font&gt;&lt;font color="#808080"&gt;'/WebServices/OrderService.asmx/GetOrders'&lt;/font&gt;&lt;font color="black"&gt;,&lt;br /&gt;
          params: { userId: getUserId(), day: &lt;/font&gt;&lt;font color="blue"&gt;new Date&lt;/font&gt;&lt;font color="black"&gt;() }&lt;br /&gt;
         }),&lt;br /&gt;
    reader: &lt;/font&gt;&lt;font color="blue"&gt;new &lt;/font&gt;&lt;font color="black"&gt;Ext.data.JsonReader(&lt;br /&gt;
        {&lt;br /&gt;
           id: &lt;/font&gt;&lt;font color="#808080"&gt;'WorkDoneId'&lt;br /&gt;
        &lt;/font&gt;&lt;font color="black"&gt;},&lt;br /&gt;
    ...&lt;br /&gt;
})&lt;/font&gt;&lt;font color="blue"&gt;;&lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
Unfortunately, try as I might to get this to call my web service (and I tried quite a few different approaches), I would get errors returned by the service. It may have been that unlike all the examples I had seen on the web, like &lt;a target="_blank" href="http://daniellarson.spaces.live.com/blog/cns!D3543C5837291E93!966.entry"&gt;Daniel Larson's&lt;/a&gt; my service calls actually needed to send parameters through to the service. One was to add additional properties to the ScriptMethod attribute on the web service like so:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="black"&gt;[ScriptMethod(ResponseFormat &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;ResponseFormat.Json, UseHttpGet &lt;/font&gt;&lt;font color="blue"&gt;= true&lt;/font&gt;&lt;font color="black"&gt;, XmlSerializeString &lt;/font&gt;&lt;font color="blue"&gt;= false&lt;/font&gt;&lt;font color="black"&gt;)]&lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
I also tried using the ASPProxy class found on &lt;a href="http://extjs.com/forum/showthread.php?t=8587&amp;amp;highlight=asp+webservice+ajax"&gt;this forum post&lt;/a&gt;. This also didn't work properly and there were a few minor irritations with the code. It all seemed pretty silly since with the ScriptManager service reference I had a client side proxy that I knew would work properly. So I created the AspWebServiceProxy object that would allow you to simply pass in a reference to the client side web service proxy object and method and use that:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="black"&gt;AspWebServiceProxy &lt;/font&gt;&lt;font color="blue"&gt;= function &lt;/font&gt;&lt;font color="black"&gt;(conn)&lt;br /&gt;
           {&lt;br /&gt;
              AspWebServiceProxy.superclass.constructor.call(&lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
              &lt;/font&gt;&lt;font color="black"&gt;Ext.apply(&lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;, conn)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
           &lt;/font&gt;&lt;font color="black"&gt;}&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;/font&gt;&lt;font color="black"&gt;Ext.extend(AspWebServiceProxy, Ext.data.DataProxy, &lt;br /&gt;
{&lt;br /&gt;
     load : &lt;/font&gt;&lt;font color="blue"&gt;function &lt;/font&gt;&lt;font color="black"&gt;(params, reader, callback, scope, arg)&lt;br /&gt;
            {&lt;br /&gt;
               &lt;/font&gt;&lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;userContext &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;{&lt;br /&gt;
                                    callback: callback, &lt;br /&gt;
                                    reader: reader, &lt;br /&gt;
                                    arg: arg, &lt;br /&gt;
                                    scope: scope&lt;br /&gt;
                                 }&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
               &lt;br /&gt;
               var &lt;/font&gt;&lt;font color="black"&gt;proxyWrapper &lt;/font&gt;&lt;font color="blue"&gt;= this;&lt;br /&gt;
               &lt;br /&gt;
               &lt;/font&gt;&lt;font color="darkgreen"&gt;//Handles the response we get back from the web service call&lt;br /&gt;
               &lt;/font&gt;&lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;webServiceCallback &lt;/font&gt;&lt;font color="blue"&gt;= function&lt;/font&gt;&lt;font color="black"&gt;(response) &lt;br /&gt;
                                        { &lt;br /&gt;
                                            proxyWrapper.loadResponse(response, userContext)&lt;/font&gt;&lt;font color="blue"&gt;; &lt;br /&gt;
                                        &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
               &lt;br /&gt;
               &lt;/font&gt;&lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;serviceParams &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;[]&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
               &lt;br /&gt;
               &lt;/font&gt;&lt;font color="darkgreen"&gt;//Convert the params into an array of values so that they can be used in the call (note assumes that the properties on the object are in the correct order)&lt;br /&gt;
               &lt;/font&gt;&lt;font color="blue"&gt;for &lt;/font&gt;&lt;font color="black"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;property &lt;/font&gt;&lt;font color="blue"&gt;in &lt;/font&gt;&lt;font color="black"&gt;params)&lt;br /&gt;
               {&lt;br /&gt;
                  serviceParams.push(&lt;/font&gt;p&lt;font color="black"&gt;arams[property])&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
               &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
               &lt;br /&gt;
               &lt;/font&gt;&lt;font color="darkgreen"&gt;//Add the webservice callback handlers&lt;br /&gt;
               &lt;/font&gt;&lt;font color="black"&gt;serviceParams.push(webServiceCallback)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
               &lt;/font&gt;&lt;font color="black"&gt;serviceParams.push(&lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;.handleErrorResponse)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
               &lt;br /&gt;
               &lt;/font&gt;&lt;font color="darkgreen"&gt;//Make the actual ASP.Net web service call&lt;br /&gt;
               &lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;.webServiceProxyMethod.apply(&lt;/font&gt;&lt;font color="blue"&gt;this&lt;/font&gt;&lt;font color="black"&gt;.webServiceProxy, serviceParams)&lt;/font&gt;&lt;font color="blue"&gt;; &lt;br /&gt;
            &lt;/font&gt;&lt;font color="black"&gt;},&lt;br /&gt;
            &lt;br /&gt;
     handleErrorResponse : &lt;/font&gt;&lt;font color="blue"&gt;function&lt;/font&gt;&lt;font color="black"&gt;(response, userContext, &lt;/font&gt;&lt;font color="black"&gt;methodName&lt;/font&gt;&lt;font color="black"&gt;)&lt;br /&gt;
                           {&lt;br /&gt;
                              &lt;/font&gt;&lt;font color="blue"&gt;alert&lt;/font&gt;&lt;font color="black"&gt;(&lt;/font&gt;&lt;font color="#808080"&gt;"Error while calling web service method:&lt;/font&gt;&lt;font color="#808080"&gt;" + &lt;/font&gt;&lt;font color="black"&gt;methodName +&lt;/font&gt;&lt;font color="#808080"&gt; "\n" &lt;/font&gt;&lt;font color="black"&gt;+ &lt;/font&gt;&lt;font color="black"&gt;response&lt;/font&gt;&lt;font color="black"&gt;.get_message())&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
                           &lt;/font&gt;&lt;font color="black"&gt;},&lt;br /&gt;
 &lt;br /&gt;
     loadResponse : &lt;/font&gt;&lt;font color="blue"&gt;function &lt;/font&gt;&lt;font color="black"&gt;(response, userContext, methodName)&lt;br /&gt;
                    {&lt;br /&gt;
                        &lt;/font&gt;&lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;result &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;userContext.reader.readRecords(response)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
                        &lt;/font&gt;&lt;font color="black"&gt;userContext.callback.call(userContext.scope, result, userContext.arg, &lt;/font&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;font color="black"&gt;)&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;
                    &lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;
        &lt;br /&gt;
})&lt;/font&gt;&lt;font color="blue"&gt;;&lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
So if you had an ASP.Net web service script reference on your page, like this:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt; &lt;font color="blue"&gt;&amp;lt;&lt;/font&gt;&lt;font color="maroon"&gt;asp:ScriptManager&lt;/font&gt;&lt;font color="red"&gt; ID&lt;/font&gt;&lt;font color="blue"&gt;="PageScriptManager"&lt;/font&gt;&lt;font color="red"&gt; runat&lt;/font&gt;&lt;font color="blue"&gt;="server"&amp;gt;&lt;/font&gt;&lt;font color="black"&gt;&lt;br /&gt;
    &lt;/font&gt;&lt;font color="blue"&gt;&amp;lt;&lt;/font&gt;&lt;font color="maroon"&gt;Services&lt;/font&gt;&lt;font color="blue"&gt;&amp;gt;&lt;/font&gt;&lt;font color="black"&gt;&lt;br /&gt;
        &lt;/font&gt;&lt;font color="blue"&gt;&amp;lt;&lt;/font&gt;&lt;font color="maroon"&gt;asp:ServiceReference&lt;/font&gt;&lt;font color="red"&gt; Path&lt;/font&gt;&lt;font color="blue"&gt;="/WebServices/OrderService.asmx"&lt;/font&gt;&lt;font color="red"&gt; InlineScript&lt;/font&gt;&lt;font color="blue"&gt;="false"&lt;/font&gt;&lt;font color="red"&gt; &lt;/font&gt;&lt;font color="blue"&gt;/&amp;gt;&lt;br /&gt;
    &amp;lt;/&lt;/font&gt;&lt;font color="maroon"&gt;Services&lt;/font&gt;&lt;font color="blue"&gt;&amp;gt;&lt;/font&gt;&lt;font color="black"&gt;&lt;br /&gt;
&lt;/font&gt;&lt;font color="blue"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="maroon"&gt;asp:ScriptManager&lt;/font&gt;&lt;font color="blue"&gt;&amp;gt;&lt;/font&gt;&lt;font color="black"&gt;&lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
to use the proxy class one would change the code at the start of the article to look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt;  &lt;font color="blue"&gt;var &lt;/font&gt;&lt;font color="black"&gt;ds &lt;/font&gt;&lt;font color="blue"&gt;= new &lt;/font&gt;&lt;font color="black"&gt;Ext.data.Store({&lt;br /&gt;
    proxy: &lt;/font&gt;&lt;font color="blue"&gt;new &lt;/font&gt;&lt;font color="black"&gt;AspWebServiceProxy(&lt;br /&gt;
         {&lt;br /&gt;
          webServiceProxy: Example.OrderService,&lt;br /&gt;
          webServiceProxyMethod: Example.OrderService.GetOrders,&lt;br /&gt;
          params: {userId: getUserId(), day: &lt;/font&gt;&lt;font color="blue"&gt;new Date&lt;/font&gt;&lt;font color="black"&gt;()}&lt;br /&gt;
         }),&lt;br /&gt;
    reader: &lt;/font&gt;&lt;font color="blue"&gt;new &lt;/font&gt;&lt;font color="black"&gt;Ext.data.JsonReader(&lt;br /&gt;
        {&lt;br /&gt;
           id: &lt;/font&gt;&lt;font color="#808080"&gt;'WorkDoneId'&lt;br /&gt;
        &lt;/font&gt;&lt;font color="black"&gt;},&lt;br /&gt;
    ...&lt;br /&gt;
})&lt;/font&gt;&lt;font color="blue"&gt;; &lt;/font&gt; 	&lt;/div&gt;
&lt;br /&gt;
I'm sure that I'll be tweaking the AspWebServiceProxy object over time as I discover its short comings, but at least it is a decent start and is hopefully useful to others as well. One of my concerns are the manner in which the attributes on the extraParams object must be specified in the same order as the web service method parameters. I did it this way to keep it consistent with all the other examples I had seen where they used an object as opposed to an array. I may change this, but I like the fact that with the current approach the parameter value pairs are obvious.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(255, 0, 0);"&gt;Update - 2 Nov 2007: Changed the service options of extraParams to params. So now one can use dataStore.load({params: {userId: 4, day: new Date()} }) to load data after the creation of the data source.&lt;/span&gt;&lt;img src="http://ridgway.co.za/aggbug/186.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Eden Ridgway</dc:creator>
            <guid>http://ridgway.co.za/archive/2007/10/09/using-asp.net-ajax-webservices-scriptservices-in-extjs.aspx</guid>
            <pubDate>Tue, 09 Oct 2007 05:19:34 GMT</pubDate>
            <comments>http://ridgway.co.za/archive/2007/10/09/using-asp.net-ajax-webservices-scriptservices-in-extjs.aspx#feedback</comments>
            <slash:comments>20</slash:comments>
            <wfw:commentRss>http://ridgway.co.za/comments/commentRss/186.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>