<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>Vorleak Chy's Blog</title>
	
	<link>http://vorleakchy.com</link>
	<description>I have passion for technologies</description>
	<lastBuildDate>Thu, 03 Jun 2010 10:38:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/vorleakchy" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="vorleakchy" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>VirtualBox: No IP Address After Copying VDI</title>
		<link>http://vorleakchy.com/2010/05/virtualbox-no-ip-address-after-copying-vdi/</link>
		<comments>http://vorleakchy.com/2010/05/virtualbox-no-ip-address-after-copying-vdi/#comments</comments>
		<pubDate>Tue, 18 May 2010 10:18:18 +0000</pubDate>
		<dc:creator>Vorleak Chy</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[VirtualBox]]></category>

		<guid isPermaLink="false">http://vorleakchy.com/?p=119</guid>
		<description><![CDATA[After copying the virtual disk (.vdi file) from one machine to another, create a new virtual machine using the copied .vdi as a virtual disk and boot up then suddenly you don&#8217;t get an IP from DHCP.
What you can do to solve this problem now just:

Open the file /etc/udev/rules.d/70-persistent-net.rules
Delete all the contents and save it
Reboot [...]]]></description>
			<content:encoded><![CDATA[<p>After copying the virtual disk (.vdi file) from one machine to another, create a new virtual machine using the copied .vdi as a virtual disk and boot up then suddenly you don&#8217;t get an IP from DHCP.</p>
<p>What you can do to solve this problem now just:</p>
<ul>
<li>Open the file /etc/udev/rules.d/70-persistent-net.rules</li>
<li>Delete all the contents and save it</li>
<li>Reboot the virtual machine</li>
<li>If you still have this problem then try to change eth&#8230; to eth0 in the file /etc/network/interfaces</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://vorleakchy.com/2010/05/virtualbox-no-ip-address-after-copying-vdi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VirtualBox: Change UUID of VDI</title>
		<link>http://vorleakchy.com/2010/05/virtualbox-change-uuid-of-vdi/</link>
		<comments>http://vorleakchy.com/2010/05/virtualbox-change-uuid-of-vdi/#comments</comments>
		<pubDate>Mon, 17 May 2010 12:31:30 +0000</pubDate>
		<dc:creator>Vorleak Chy</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[VirtualBox]]></category>

		<guid isPermaLink="false">http://vorleakchy.com/?p=113</guid>
		<description><![CDATA[I use VirtualBox regularly. Recently I copy the image of Virtual Disk (.vdi file) is a convenient way of duplicate the disk, in case I want to avoid reinstalling an operating system from scratch.
By adding the copy in the Virtual Media Manager, I get an error like this screenshot below because of UUID already exists.

In this case, I [...]]]></description>
			<content:encoded><![CDATA[<p>I use VirtualBox regularly. Recently I copy the image of Virtual Disk (.vdi file) is a convenient way of duplicate the disk, in case I want to avoid reinstalling an operating system from scratch.</p>
<p>By adding the copy in the Virtual Media Manager, I get an error like this screenshot below because of UUID already exists.</p>
<p><img class="alignnone size-full wp-image-114" title="VirtualBox - Error" src="http://vorleakchy.com/wp-content/uploads/2010/05/VirtualBox-Error.png" alt="VirtualBox - Error" width="542" height="266" /></p>
<p>In this case, I have to do the following</p>
<pre class="brush: bash;">
VBoxManage internalcommands setvdiuuid disk2.vdi
</pre>
<p>Since the old UUID is replaced with a new one, I can now add and use the virtual disk.</p>
]]></content:encoded>
			<wfw:commentRss>http://vorleakchy.com/2010/05/virtualbox-change-uuid-of-vdi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Polymorphic Associations in Ruby on Rails</title>
		<link>http://vorleakchy.com/2009/10/polymorphic-associations-in-ruby-on-rails/</link>
		<comments>http://vorleakchy.com/2009/10/polymorphic-associations-in-ruby-on-rails/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 09:53:12 +0000</pubDate>
		<dc:creator>Vorleak Chy</dc:creator>
				<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://vorleakchy.com/?p=102</guid>
		<description><![CDATA[You might have instances where the associations could be with multiple models. For example, if you have a Picture model that can be associated with either a Student model or an Employee model. In this case, you really want to be able to call @picture.imageable to get the image. This is where polymorphic associations come [...]]]></description>
			<content:encoded><![CDATA[<p>You might have instances where the associations could be with multiple models. For example, if you have a Picture model that can be associated with either a Student model or an Employee model. In this case, you really want to be able to call @picture.imageable to get the image. This is where polymorphic associations come in.</p>
<pre class="brush: ruby;">
class Picture &lt; ActiveRecord::Base
  belongs_to :imageable, :polymorphic =&gt; true
end

class Student &lt; ActiveRecord::Base
  has_many :pictures, :as =&gt; :imageable
end

class Employee &lt; ActiveRecord::Base
  has_many :pictures, :as =&gt; :imageable
end
</pre>
<p>You can think of a polymorphic belongs_to declaration as setting up an interface that any other model can use.<br />
You can also retrieve a collection of pictures: @student.pictures or @employee.pictures from instances of Student or Employee model.</p>
<p>To make this work, you need to declare both a foreign key column and a type column in the model that declares the polymorphic interface:</p>
<pre class="brush: ruby;">
class CreatePictures &lt; ActiveRecord::Migration
  def self.up
    create_table :pictures do |t|
      t.string  :name
      t.integer :imageable_id
      t.string  :imageable_type
      t.timestamps
    end
  end

  def self.down
    drop_table :pictures
  end
end
</pre>
<p>Finally, you can read more on the <a href="http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html">documentation</a> written by Rails team.</p>
]]></content:encoded>
			<wfw:commentRss>http://vorleakchy.com/2009/10/polymorphic-associations-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using UUID as Primary Key in Ruby on Rails</title>
		<link>http://vorleakchy.com/2009/10/using-uuid-as-primary-key-in-ruby-on-rails/</link>
		<comments>http://vorleakchy.com/2009/10/using-uuid-as-primary-key-in-ruby-on-rails/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 10:25:37 +0000</pubDate>
		<dc:creator>Vorleak Chy</dc:creator>
				<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://vorleakchy.com/?p=93</guid>
		<description><![CDATA[You may be working on multi-master database model which required to use UUID and sometime because of using auto incrementing integer primary key just is not good enough.
So, you want to replace the default integer-based primary keys in your model with a UUID.
Now you need to disable the default id column by setting :id =&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>You may be working on multi-master database model which required to use <a href="http://en.wikipedia.org/wiki/UUID">UUID</a> and sometime because of using auto incrementing integer primary key just is not good enough.</p>
<p>So, you want to replace the default integer-based primary keys in your model with a UUID.</p>
<p>Now you need to disable the default id column by setting :id =&gt; false and create a primary key named uuid instead</p>
<pre class="brush: ruby;">
create_table :products, :id =&gt; false do |t|
  t.string :uuid, :limit =&gt; 36, :primary =&gt; true
end
</pre>
<p>In the Product model you need to set the name of this primary key column</p>
<pre class="brush: ruby;">
class Product &lt; ActiveRecord::Base
  set_primary_key &quot;uuid&quot;
end
</pre>
<p>You need to create UUID itself for the next step. Because of most databases do not support UUID out of the box so you have to do in rails application.</p>
<p>Install the <a href="http://github.com/sporkmonger/uuidtools/">uuidtools</a> gem</p>
<pre class="brush: bash;">
sudo gem install uuidtools
</pre>
<p>Then go into your rails application and create uuid_helper.rb in your lib directory</p>
<pre class="brush: ruby;">
require 'rubygems'
require 'uuidtools'

module UUIDHelper
  def before_create()
    self.uuid = UUIDTools::UUID.timestamp_create().to_s
  end
end
</pre>
<p>Include this module in all UUID-enabled models, like Product in this example</p>
<pre class="brush: ruby;">
class Product &lt; ActiveRecord::Base
  set_primary_key &quot;uuid&quot;
  include UUIDHelper
end
</pre>
<p>Now, you have the uuid field is automatically filled with a Universally Unique Identifier whenever you save a new Product object.</p>
]]></content:encoded>
			<wfw:commentRss>http://vorleakchy.com/2009/10/using-uuid-as-primary-key-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introduction to Refactoring</title>
		<link>http://vorleakchy.com/2009/10/introduction-to-refactoring/</link>
		<comments>http://vorleakchy.com/2009/10/introduction-to-refactoring/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 01:36:52 +0000</pubDate>
		<dc:creator>Vorleak Chy</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[BarCampPP]]></category>
		<category><![CDATA[Refactoring]]></category>

		<guid isPermaLink="false">http://vorleakchy.com/?p=88</guid>
		<description><![CDATA[I have presented about &#8220;Introduction to Refactoring&#8221; with Mr. Dane at BarCamp PP2. What interesting for me was &#8220;Coder Camp&#8221; which got more helps from Mr. Sokun to make it up without preparation, especially the room was full.
You can get more presentations from Share Vision Team. Thanks to the team that spent almost two days to [...]]]></description>
			<content:encoded><![CDATA[<p>I have presented about &#8220;Introduction to Refactoring&#8221; with <a href="http://savotdane.blogspot.com/">Mr. Dane</a> at <a href="http://barcampphnompenh.org/">BarCamp PP2</a>. What interesting for me was &#8220;Coder Camp&#8221; which got more helps from <a href="http://chornsokun.wordpress.com/">Mr. Sokun</a> to make it up without preparation, especially the room was full.</p>
<p>You can get more presentations from <a href="http://forum.sharevisionteam.org/index.php?topic=3.0">Share Vision Team</a>. Thanks to the team that spent almost two days to help with presentations and introduced many people to know about Share Vision Team at booth.</p>
<div style="width: 425px; text-align: left;"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" title="Introduction to Refactoring" href="http://www.slideshare.net/vorleak.chy/introduction-to-refactoring">Introduction to Refactoring</a><object style="margin:0px" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=introductiontorefactoring-091004215346-phpapp01&amp;stripped_title=introduction-to-refactoring" /><param name="allowfullscreen" value="true" /><embed style="margin:0px" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=introductiontorefactoring-091004215346-phpapp01&amp;stripped_title=introduction-to-refactoring" allowscriptaccess="always" allowfullscreen="true"></embed></object></div>
<div id="__ss_2124666" style="width: 425px; text-align: left;">
<div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/vorleak.chy">vorleak.chy</a>.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://vorleakchy.com/2009/10/introduction-to-refactoring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing GeoServer on Ubuntu</title>
		<link>http://vorleakchy.com/2009/08/installing-geoserver-on-ubuntu/</link>
		<comments>http://vorleakchy.com/2009/08/installing-geoserver-on-ubuntu/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 12:12:24 +0000</pubDate>
		<dc:creator>Vorleak Chy</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[GeoServer]]></category>
		<category><![CDATA[Map]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://vorleakchy.com/2009/08/installing-geoserver-on-ubuntu/</guid>
		<description><![CDATA[Recently, I install GeoServer 1.7.6 on Ubuntu 9.04. I would like to share some information with everybody what I have configured on my local PC.
As far as I follow the installation instruction of GeoServer documentation for Linux I get the error message “The JAVA_HOME environment variable is not defined
This environment variable is needed to run [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I install <a href="http://geoserver.org/">GeoServer</a> 1.7.6 on Ubuntu 9.04. I would like to share some information with everybody what I have configured on my local PC.</p>
<p>As far as I follow the installation instruction of <a href="http://docs.geoserver.org/1.7.x/en/user/installation/geoserver-install.html">GeoServer documentation</a> for Linux I get the error message “The JAVA_HOME environment variable is not defined<br />
This environment variable is needed to run this program” when I try to startup server by typing “sudo sh startup.sh”. It means that it doesn’t find the default path for JAVA_HOME so you need to setup.</p>
<p>Setting up JAVA_HOME you need to lookup the Java program path in your PC. In my local PC is “/usr/lib/jvm/java-6-sun”.</p>
<p>Finally you also setup GEOSERVER_HOME is where GeoServer folder stores on your local PC.</p>
<p>Anyway you can copy the codes below to startup.sh, shutdown.sh files in /geoserver/bin folder, put on the top and replace the path.</p>
<pre class="brush: bash;">
JAVA_HOME=&quot;/usr/lib/jvm/java-6-sun&quot;;
GEOSERVER_HOME=&quot;/home/administrator/software/geoserver&quot;;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://vorleakchy.com/2009/08/installing-geoserver-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Strategy Design Pattern</title>
		<link>http://vorleakchy.com/2008/11/strategy-design-pattern/</link>
		<comments>http://vorleakchy.com/2008/11/strategy-design-pattern/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 12:09:32 +0000</pubDate>
		<dc:creator>Vorleak Chy</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://vorleakchy.com/?p=33</guid>
		<description><![CDATA[If you have the algorithms with conditional statements in the client code it will be messy. The Strategy pattern moves an algorithm from the client code to a separate class. A program that requires a particular service or function and that has several ways of carrying out that function is a candidate for the Strategy [...]]]></description>
			<content:encoded><![CDATA[<p>If you have the algorithms with conditional statements in the client code it will be messy. The <a href="http://sourcemaking.com/design_patterns/strategy">Strategy pattern</a> moves an algorithm from the client code to a separate class. A program that requires a particular service or function and that has several ways of carrying out that function is a candidate for the Strategy pattern. Programs choose between these algorithms based on computational efficiency or user choice. There can be any number of strategies, more can be added, and any of them can be changed at any time. One of the dominant strategies of object-oriented design is the &#8220;open-closed principle&#8221;.</p>
<p>There are a number of cases in programs where we would like to do the same thing in several different ways. Here is a list that can be strategy:</p>
<ul>
<li>Compress files using different algorithms</li>
<li>Save files in different formats</li>
<li>Use different link-breaking strategies to display text data</li>
<li>Capture video data using different compression schemes</li>
<li>Plot the same data in different formats: line, graph, bar chart, or pie chart</li>
</ul>
<p>Let&#8217;s consider a simplified sorting an array using quick sort or bubble sort which a client will choose as an algorithm to sort elements in array. Here is an example below I have to do now in both C# and JavaScript:</p>
<h3>Code in C#</h3>
<p>There are QucikSort and BubbleSort as concrete classes will implement an interface because they have the same method, the only different is an algorithm.</p>
<pre class="brush: csharp;">
using System;

namespace Patterns.Strategy
{
    public interface ISortStrategy
    {
        void Sort(string[] arr);
    }

    public class QuickSort : ISortStrategy
    {
        public void Sort(string[] arr)
        {
            Console.Write(string.Format(&quot;QuickSort array contains {0} elements&quot;, arr.Length));
        }
    }

    public class BubleSort : ISortStrategy
    {
        public void Sort(string[] arr)
        {
            Console.Write(string.Format(&quot;BubleSort array contains {0} elements&quot;, arr.Length));
        }
    }

    public class SortableArray
    {
        private readonly ISortStrategy sortStrategy;

        public SortableArray(ISortStrategy sortStrategy)
        {
            this.sortStrategy = sortStrategy;
        }

        public void SortArray(string[] arr)
        {
            sortStrategy.Sort(arr);
        }
    }
}
</pre>
<p>Here is a client code will choose which algorithm is needed to sort an array.</p>
<pre class="brush: csharp;">
using System;

namespace Patterns.Strategy
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var array = new[] {&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;};

            var sortableArray = new SortableArray(new QuickSort());
            sortableArray.SortArray(array);
            Console.Read();
        }
    }
}
</pre>
<h3>Code in JavaScript</h3>
<pre class="brush: csharp;">
var Patterns = {};
Patterns.Strategy = {};

Patterns.Strategy.SortableArray = function(sortStrategy) {
    this.sort = function(arr) {
        sortStrategy(arr);
    };
};

Patterns.Strategy.SortStrategy = {
  quickSort : function(arr){
    console.log('QuickSort array contains ' + arr.length + ' elements');
  },

  bubbleSort : function(arr){
    console.log('BubbleSort array contains ' + arr.length + ' elements');
  }
};

var array = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;];
var sortableArray = new Patterns.Strategy.SortableArray(Patterns.Strategy.SortStrategy.quickSort);
sortableArray.sort(array);
</pre>
<p>If you meet this problem and need to solve it please go to your application and do the code refactorings which is now the <a href="http://www.jetbrains.com/resharper/">ReSharper</a> tool add-in to Visual Studio is very powerful to do this and much more. Doesn&#8217;t it?</p>
]]></content:encoded>
			<wfw:commentRss>http://vorleakchy.com/2008/11/strategy-design-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NAnt task with Red-Gate SQL Compare</title>
		<link>http://vorleakchy.com/2008/11/nant-task-with-red-gate-sql-compare/</link>
		<comments>http://vorleakchy.com/2008/11/nant-task-with-red-gate-sql-compare/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 12:05:46 +0000</pubDate>
		<dc:creator>Vorleak Chy</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[NAnt]]></category>

		<guid isPermaLink="false">http://vorleakchy.com/?p=30</guid>
		<description><![CDATA[It can be an easy way to do if you have a database with schema changes. You have to convert a database to scripts so that you can commit to source control by comparing script files. Or you get update from source control as scripts and synchronize to your local database.
Most code development these days [...]]]></description>
			<content:encoded><![CDATA[<p>It can be an easy way to do if you have a database with schema changes. You have to convert a database to scripts so that you can commit to source control by comparing script files. Or you get update from source control as scripts and synchronize to your local database.</p>
<p>Most code development these days involves using a “local development” model. In other words, the code is created on the developers’ local machines, and the shared source control database is the integration point and provides the mechanism for sharing new code. The automated delivery processes then provide the isolated continuous integration process as already specified. Database development is not necessarily handled in the same way, but it can be. The actual model used affects the requirements for handling database integration.</p>
<p><img class="alignnone size-full wp-image-31" title="Local Development" src="http://vorleakchy.com/wp-content/uploads/2009/09/local_development.gif" alt="Local Development" width="484" height="258" /></p>
<p><a href="http://www.red-gate.com/">Red-Gate</a> have a very good product called <a href="http://www.red-gate.com/products/SQL_Compare/">SQL Compare</a> which can compare two database versions and produce a script to convert one version to the other and a <a href="http://www.red-gate.com/products/SQL_Comparison_SDK/">SQL Toolkit</a> that allows you to automate the process.</p>
<p><a href="http://nant.sourceforge.net/">NAnt</a> task help you a lot of saving time instead of doing manual work everyday by creating custom task for your own which I include in here.</p>
<p>Here is an example of the configuration:</p>
<p>This is a build file which will load SyncNAntTask.dll as a custom task and have two databases need to synchronize with script files.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; ?&gt;
&lt;project name=&quot;SyncDatabase&quot;&gt;
  &lt;property name=&quot;schemaRoot.dir&quot; value=&quot;..\database\schema\&quot; /&gt;
  &lt;property name=&quot;dbServer&quot; value=&quot;localhost&quot; /&gt;
  &lt;property name=&quot;dbUserId&quot; value=&quot;sa&quot; /&gt;
  &lt;property name=&quot;dbPassword&quot; value=&quot;123&quot; /&gt;
  &lt;loadtasks assembly=&quot;..\src\SyncNAntTask\bin\Debug\SyncNAntTask.dll&quot;/&gt;
  &lt;syncDatabase&gt;
    &lt;databases&gt;
      &lt;database folder=&quot;${schemaRoot.dir}db1&quot; server=&quot;${dbServer}&quot; name=&quot;db1&quot; userId=&quot;${dbUserId}&quot; password=&quot;${dbPassword}&quot; /&gt;
      &lt;database folder=&quot;${schemaRoot.dir}db2&quot; server=&quot;${dbServer}&quot; name=&quot;db2&quot; userId=&quot;${dbUserId}&quot; password=&quot;${dbPassword}&quot; /&gt;
     &lt;/databases&gt;
   &lt;/syncDatabase&gt;
&lt;/project&gt;
</pre>
<p>There are three .cs files for the SyncNAntTask.dll which I have to separate.</p>
<p>It&#8217;s quite simple for database element with five attributes.</p>
<pre class="brush: csharp;">
using NAnt.Core;
using NAnt.Core.Attributes;

namespace SyncNAntTask
{
    [ElementName(&quot;database&quot;)]
    public class DatabaseInfo : Element
    {
        [TaskAttribute(&quot;folder&quot;, Required = true)]
        public string Folder { get; set; }

        [TaskAttribute(&quot;server&quot;, Required = true)]
        public string Server { get; set; }

        [TaskAttribute(&quot;name&quot;, Required = true)]
        public new string Name { get; set; }

        [TaskAttribute(&quot;userId&quot;, Required = true)]
        public string UserId { get; set; }

        [TaskAttribute(&quot;password&quot;, Required = true)]
        public string Password { get; set; }
    }
}
</pre>
<p>It&#8217;s for syncDatabase task which contains collection of database elements.</p>
<pre class="brush: csharp;">
using NAnt.Core;
using NAnt.Core.Attributes;
using RedGate.SQLCompare.Engine;
using SyncNAntTask;

namespace SyncNAntTask
{
    [TaskName(&quot;syncDatabase&quot;)]
    public class SynchronizeDatabaseTask : Task
    {
        private DatabaseInfo[] databaseInfos;

        [BuildElementCollection(&quot;databases&quot;, &quot;database&quot;)]
        public DatabaseInfo[] DbInfos
        {
            get { return databaseInfos; }
            set { databaseInfos = value; }
        }

        protected override void ExecuteTask()
        {
            foreach (DatabaseInfo dbInfo in databaseInfos)
            {
                SynchronizeScripts.Synchronize(dbInfo.Folder,
                                               new ConnectionProperties(dbInfo.Server, dbInfo.Name, dbInfo.UserId,
                                                                        dbInfo.Password));
            }
        }
    }
}
</pre>
<p>It is static class to run a task to do synchronizing between script files and database.</p>
<pre class="brush: csharp;">
using System;
using RedGate.SQL.Shared;
using RedGate.SQLCompare.Engine;

namespace SyncNAntTask
{
    public static class SynchronizeScripts
    {
        public static void Synchronize(string scriptFolder, ConnectionProperties targetConnectionProperties)
        {
            using (Database sourceDatabaseScripts = new Database(), targetDatabase = new Database())
            {
                // Establish the schema from the scripts stored in the sourceDatabaseScripts scripts folder
                // Passing in null for the database information parameter causes SQL Compare to read the
                // XML file supplied in the folder.
                sourceDatabaseScripts.Register(scriptFolder, null, Options.Default);

                // Read the schema for the targetDatabase database
                targetDatabase.Register(targetConnectionProperties, Options.Default);

                // Compare the database against the scripts.
                // Comparing in this order makes the targetDatabase the second database
                Differences sourceDatabaseScriptsVStargetDatabase =
                    sourceDatabaseScripts.CompareWith(targetDatabase, Options.Default);

                // Select all of the differences for synchronization
                foreach (Difference difference in sourceDatabaseScriptsVStargetDatabase)
                {
                    difference.Selected = IsIncludeObject(difference);
                }

                // Calculate the work to do using sensible default options
                // The targetDatabase is to be updated, so the runOnTwo parameter is true
                var work = new Work();
                work.BuildFromDifferences(sourceDatabaseScriptsVStargetDatabase, Options.Default, true);

                // We can now access the messages and warnings
                Console.WriteLine(&quot;Messages:&quot;);

                foreach (Message message in work.Messages)
                {
                    Console.WriteLine(message.Text);
                }

                Console.WriteLine(&quot;Warnings:&quot;);

                foreach (Message message in work.Warnings)
                {
                    Console.WriteLine(message.Text);
                }

                // Disposing the execution block when it's not needed any more is important to ensure
                // that all the temporary files are cleaned up
                using (ExecutionBlock block = work.ExecutionBlock)
                {
                    // Display the SQL used to synchronize
                    Console.WriteLine(&quot;SQL to synchronize:&quot;);
                    Console.WriteLine(block.GetString());

                    // Finally, use a BlockExecutor to run the SQL against the WidgetProduction database
                    var executor = new BlockExecutor();
                    executor.ExecuteBlock(block, targetConnectionProperties.ServerName,
                                          targetConnectionProperties.DatabaseName, false,
                                          targetConnectionProperties.UserName, targetConnectionProperties.Password);
                }
            }
        }

        private static bool IsIncludeObject(Difference difference)
        {
            if (difference.DatabaseObjectType != ObjectType.User &amp;&amp;
                difference.DatabaseObjectType != ObjectType.Role &amp;&amp;
                difference.DatabaseObjectType != ObjectType.Queue &amp;&amp;
                difference.DatabaseObjectType != ObjectType.Service &amp;&amp;
                MeetExcludeSpecialCase(difference) == false)
            {
                return true;
            }

            return false;
        }

        private static bool MeetExcludeSpecialCase(Difference difference)
        {
            if ((difference.DatabaseObjectType == ObjectType.Table &amp;&amp;
                 difference.Name.ToLower().StartsWith(&quot;[dbo].[aspnet_sql&quot;)) ||
                (difference.DatabaseObjectType == ObjectType.StoredProcedure &amp;&amp;
                 difference.Name.ToLower().StartsWith(&quot;[dbo].[aspnet_sql&quot;)) ||
                (difference.DatabaseObjectType == ObjectType.StoredProcedure &amp;&amp;
                 difference.Name.ToLower().StartsWith(&quot;[dbo].[sqlquery&quot;)))
            {
                return true;
            }

            return false;
        }
    }
}
</pre>
<p>That&#8217;s all for this, do you have another way? please let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://vorleakchy.com/2008/11/nant-task-with-red-gate-sql-compare/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Factory Method Pattern in JavaScript</title>
		<link>http://vorleakchy.com/2008/11/factory-method-pattern-in-javascript/</link>
		<comments>http://vorleakchy.com/2008/11/factory-method-pattern-in-javascript/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 12:03:02 +0000</pubDate>
		<dc:creator>Vorleak Chy</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://vorleakchy.com/?p=27</guid>
		<description><![CDATA[Last two months I posted about Factory Method Design Pattern in C#. Now I do the same thing in JavaScript.
This is a simple example of the factory method pattern in JavaScript, The factory method getPhone() will generate Phone object. I just keep as organizing with namespace &#8220;Patterns&#8221; as in C#.

var Patterns = {};

Patterns.Nokia = function(){
 [...]]]></description>
			<content:encoded><![CDATA[<p>Last two months I posted about <a href="http://vorleakchy.com/2008/09/factory-method-design-pattern/">Factory Method Design Pattern</a> in C#. Now I do the same thing in JavaScript.</p>
<p>This is a simple example of the factory method pattern in JavaScript, The factory method getPhone() will generate Phone object. I just keep as organizing with namespace &#8220;Patterns&#8221; as in C#.</p>
<pre class="brush: jscript;">
var Patterns = {};

Patterns.Nokia = function(){
    this.getPrice = function(){
        return 200;
    };
};

Patterns.Motorola = function(){
    this.getPrice = function(){
        return 100;
    };
};

Patterns.PhoneFactory = {
    getPhone : function(type){
        switch(type){
            case &quot;Motorola&quot;:
                return new Patterns.Motorola();
            case &quot;Nokia&quot;:
            default:
                return new Patterns.Nokia();
        }
    }
};

var phone = Patterns.PhoneFactory.getPhone(&quot;Nokia&quot;);
console.log(phone.getPrice());
</pre>
]]></content:encoded>
			<wfw:commentRss>http://vorleakchy.com/2008/11/factory-method-pattern-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Art Of Test WebAii Tests Web UI</title>
		<link>http://vorleakchy.com/2008/10/art-of-test-webaii-tests-web-ui/</link>
		<comments>http://vorleakchy.com/2008/10/art-of-test-webaii-tests-web-ui/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 11:56:52 +0000</pubDate>
		<dc:creator>Vorleak Chy</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[Web Testing]]></category>

		<guid isPermaLink="false">http://vorleakchy.com/?p=23</guid>
		<description><![CDATA[My colleague have some problems using Selenium to test the website specifically issues with JavaScript and Ajax. Also we would like to include testing nicely and easily integrated into our build process with continuous integration.
So we did together a bit of searching and found the free .Net automation framework for web testing produced by Art [...]]]></description>
			<content:encoded><![CDATA[<p>My colleague have some problems using <a href="http://www.openqa.org/selenium/">Selenium</a> to test the website specifically issues with JavaScript and Ajax. Also we would like to include testing nicely and easily integrated into our build process with continuous integration.</p>
<p>So we did together a bit of searching and found the free .Net automation framework for web testing produced by <a href="http://www.artoftest.com/">Art Of Test Inc</a> called <a href="http://www.artoftest.com/products/webaii.aspx">WebAii</a>. Just see from the demo it seems to do everything we want.</p>
<p>I would think this is more useful framework rather than the others for now even I’ve just started to use it and there are just a small sample codes of its features. I guess it can be a killer web testing application. I tried it with my colleague and how about you?</p>
<p>Here is an example for you to try it:</p>
<p>Configuration file App.config</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;configuration&gt;
  &lt;configSections&gt;
    &lt;section name=&quot;WebAii.Settings&quot; type=&quot;ArtOfTest.WebAii.Core.SettingsConfigSectionHandler,ArtOfTest.WebAii, Version=1.1.900.0, Culture=neutral, PublicKeyToken=4FD5F65BE123776C&quot;/&gt;
  &lt;/configSections&gt;
  &lt;WebAii.Settings
    annotateExecution=&quot;false&quot;
    baseUrl=&quot;http://www.google.com/&quot;
    clientReadyTimeout=&quot;50000&quot;
    defaultBrowser=&quot;InternetExplorer&quot;
    enableScriptLogging=&quot;false&quot;
    enableUILessRequestViewing=&quot;false&quot;
    executionDelay=&quot;0&quot;
    executionTimeout=&quot;60000&quot;
    localWebServer=&quot;None&quot;
    logLocation=&quot;C:\WebAiiLog\&quot;
    queryEventLogErrorsOnExit=&quot;false&quot;
    simulatedMouseMoveSpeed=&quot;0.3&quot;
    webAppPhysicalPath=&quot;&quot;/&gt;
&lt;/configuration&gt;
</pre>
<p>Abstract class PageBase.cs</p>
<pre class="brush: csharp;">
using ArtOfTest.WebAii.Core;
using NUnit.Framework;

namespace WebAiiUITest
{
    public abstract class PageBase
    {
        public readonly Manager manager = new Manager(true);
        protected Browser browser;
        protected Find find;

        [SetUp]
        public void SetUp()
        {
            manager.Start();
            manager.LaunchNewBrowser();

            browser = manager.ActiveBrowser;
            find = browser.Find;
            browser.NavigateTo(&quot;http://www.google.com/&quot;);
        }

        [TearDown]
        public void TearDown()
        {
            browser.Close();
        }
    }
}
</pre>
<p>Testing class KeywordSearch.cs</p>
<pre class="brush: csharp;">
using ArtOfTest.WebAii.Controls.HtmlControls;
using NUnit.Framework;

namespace WebAiiUITest
{
    [TestFixture]
    public class KeywordSearch : PageBase
    {
        [Test]
        public void Should_keyword_search_found()
        {
            var searchText = &quot;WowKhmer Tech&quot;;

            find.ById&lt;htmlinputtext&gt;(&quot;q&quot;).Value = searchText;
            find.ById&lt;htmlinputsubmit&gt;(&quot;btnG&quot;).Click();

            Assert.IsNotNull(find.ById&lt;htmlanchor&gt;(searchText));
        }
    }
}
</pre>
<p>This example will run with Internet Explorer browser. You can run with Firefox just change defaultBrowser=”Firefox” in App.config you can either write one line of code but I would like keep it easily in configuration file. It still doesn’t work if it opens with a new tab, from my experience unless you need to have a setting in browser. Click Tools -> Options -> Tabs -> select “a new window” option.</p>
]]></content:encoded>
			<wfw:commentRss>http://vorleakchy.com/2008/10/art-of-test-webaii-tests-web-ui/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
