Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

Archive for November 2007

Time to play the Game in the Castle

leave a comment »

Life is learning, after getting myself familiar with the Castle stack I started to look at another abstraction stack known as ‘Rhino-Tools’ as it advertises to ease my development life so why not give it a shot ;) then the story go:

Well, I did get the information from somewhere else about all these stack but let for complete reference check this out Building the Castle Stack (ish) TM – from Trunk

The point is now I have to deal with test unit to be sure everything work as advertised so I grab additional tool:

  • MbUnit – A Generative Unit Test Framework
  • NUnit – Also a Unit testing framework initially ported from JUnit

Once these tools get installed I fire up my vs.net command line:
..\castle-trunk>nant >buildLog.txt

well it still complaint me that MbUnit or NUnit can not find … WhAT?
BCurse I did not add MbUnit or NUnit path to the execute path environment :( anyway my path string is already too long I decided to set the path of these two framework directly in the ..\castle-trunk\common.xml

….more script …
<!– Where is MbUnit.Cons.exe ? –>
<property name=”mbunit-console” value=”C:\Program Files\MbUnit\MbUnit.Cons.exe” overwrite=”false”>

<!– Where is nunit-console executable(win/mono) ? –>
<property name=”nunit-console2″ value=”nunit-console2″ overwrite=”false”>
<property name=”nunit-console” value=”C:\Program Files\NUnit-Net-2.0 2.2.10\bin\nunit-console.exe” overwrite=”false”>
….more script …

Okay let do it again:
..\castle-trunk>nant >buildLog.txt
BUILD FAILED !? what?
Review buildLog.txt I learn that I did not enable SqlServer DTS ha sorry.
>Enable SqlServer DTS Agent
..\castle-trunk>nant >buildLog.txt
Voilá: BUILD SUCCEEDED – 1 non-fatal error(s), 0 warning(s)

Now I am ready to roll next step let u know later ;)

Advertisements

Written by Chorn Sokun

November 16, 2007 at 9:47 am

Once upon a time there was a ^GENERIC^

leave a comment »

Man ! how many times did you hear me say “I’m love the Generic so MUCH”. Not only it elegant but it really got it gold purpose of code reduction. Let look back at my previous solution on ActiveRecord Type Hierarchy and see how generic could help me:

[ActiveRecord("List_Lookups", DiscriminatorColumn = "Type", 
  DiscriminatorType = "String", DiscriminatorValue = "NA")]
public class Lookup: ActiveRecordBase where T: class{.... some code ...}

and now for derived class DeleteAll(), FindAll() etc are just ready to be use isn’t that cool?

[ActiveRecord(DiscriminatorValue = "PTL")]
public class ProjectTypeList: Lookup{.. zero code ;)}

Now I am ready to focus on another matter ;)

By the way x1r0k3wl’s comment come to rescue.

Written by Chorn Sokun

November 2, 2007 at 10:45 am

Table Lookup & ActiveRecord Type Hierarchy

with 2 comments

In any database application I can say. We need to have a read-only list for user to pick instead of manually key in. I knew that this can be done easily using Castle.ActiveRecord so I started out like this:

Design a lookup table

“Lookup” Table Schema:

  • ID – int primary key
  • Name – varchar(50)
  • Type – Discreminator Column

Very simple.

Generate ActiveRecord classes

[ActiveRecord("List_Lookups", DiscriminatorColumn = "Type",
  DiscriminatorType = "String", DiscriminatorValue = "NA")]
public class Lookup: ActiveRecordBase{.... some code ...}

sub-class code like this

[ActiveRecord(DiscriminatorValue = "PTL")]
public class ProjectTypeList: Lookup
{
}

Testing
Lucky that I start with this: ProjectTypeList.DeleteAll();
Which cause all the records in the Lookup table deleted. WEIRD !
It suppose to delete all records in Lookup table with column Type = “PTL”

Okay, I keep testing with FindAll() method and the result was not satisfied. I start lookup for the solution in the forum finally I got the answer from Hammett’s replied.

The answer is: “Implement our own DeleteAll(), FindAll() and other method by in the derived classes.”

using Castle.ActiveRecord;

namespace PID.Net.Models{
  [ActiveRecord(DiscriminatorValue = "PTL")]
  public class ProjectTypeList: Lookup
  {     

    public new static void DeleteAll()
    {
         DeleteAll( typeof(ProjectTypeList) );
    }     

    public new static ProjectTypeList[] FindAll()
    {
         return (ProjectTypeList[]) FindAll( typeof(ProjectTypeList) );
     }

 }
}

I hope I won’t waste my time next time I tried to deal with this scenario.

Written by Chorn Sokun

November 1, 2007 at 4:21 pm