Chorn Sokun’s Weblog

try { divide and conquer; } catch { keep it simple!; } finally { nothing is impossible; }

I lost the title

with one comment

Recently, I start listen to old Khmer song then I like this song

but damn I don’t remember what the title of this song, and as you know title of oldies song is tricky to guess. So I needed your help do you know what’s the title of the song?

Written by Chorn Sokun

January 17, 2010 at 4:49 pm

Posted in Entertainment

Tagged with

Build mono on Ubuntu Karmic 9.10 x64

with 8 comments

As always I would start off with CRY ME A RIVER :L, lol I told myself that I will never ever build mono from release source or /trunk again. I am lying myself :( ok here I go again this time I load Ubuntu Karmic x64 on my Toshiba M100 ~2 years old the original purpose is to just load it with multimedia app so that my wife could enjoy watching DVD, play MP3, browse the Inernet and blah blah blah … all just for entertainment :) It turn out !

Ok, here is the main story it turn out that I caught an e-mail from mono mailing list Mono 2.6 for Ubuntu its haunting me. Why don’t I just spend sometime with that instead of wasting time playing JX2 :D yeah let try.

  1. Download Mono 2.6.1 stable source
  2. Read instruction Parallel Mono Environment; ** people keep telling me to reference this instruction although I did follow the exact step, perhaps someone better shot a webcast instead of writing unworkable instruction.

Build Source

First thing first extract the source code from .tar.bz2 since I not a command savvy *yet* I use nautilus context menu to extract the source file; when all source code extracted let get into command line:

// create mono-dev-env using script written in http://www.mono-project.com/Parallel_Mono_Environments
> ./mono-dev-env
// your command prompt now shall look like this where ~src is the location that I stored source code
[mono] ~src @

libgdiplus-2.6

// just in case execute
[mono] ~src @ sudo apt-get build-dep libgdiplus
// ... now you are ready to build libgdiplus-2.6
[mono] ~src @ cd libgdiplus-2.6
[mono] ~src/libgdiplus-2.6 @ ./configure --prefix=/opt/mono
[mono] ~src/libgdiplus-2.6 @ make; sudo make install

mono-2.6.1

[mono] ~src @ cd mono-2.6.1
[mono] ~src/mono-2.6.1  @ ./configure --prefix=/opt/mono
[mono] ~src/mono-2.6.1  @ make; sudo make install

gtk-sharp-2.12.9

Here come the pain :D as gtk-sharp depend on a lot of library we need to make sure those library are installed first before compile gtk-sharp-2.12.9 as of Ubuntu Karmic I need to install the following packages:

> sudo apt-get intall libpango1.0-dev libatk1.0-dev libgtk2.0-dev
// after that I can just do
[mono] ~src/gtk-sharp-2.12.9 @ ./configure  --prefix=/opt/mono
[mono] ~src/gtk-sharp-2.12.9 @ make; sudo make install

gnome-sharp-2.24.1

// dependency library just in case
> sudo apt-get install libgnomecanvas2-dev libgnome2-dev
// resume build task
[mono] ~/src/gnome-sharp-2.24.1 @ ./configure --prefix=/opt/mono
[mono] ~/src/gnome-sharp-2.24.1 @ make; sudo make install

gnome-desktop-sharp-2.24.0

[mono] ~/src/gnome-desktop-sharp-2.24.0 @ ./configure --prefix=/opt/mono
[mono] ~/src/gnome-desktop-sharp-2.24.0 @ make; sudo make install

The rest of the library seem to go just fine, I learn that execute sudo ./configure cause me a lot of troubles thanks @alex for pointing this out.

mono-tools-2.6.1

description on what this library give coming up next …

mono-addins-0.4

description on what this library give coming up next …

mono-debugger-2.6

As I reached to this point ./configure started to complain me like this > configure: error: Cannot find termcap library to solve the problem I need to install

// ref: http://ubuntuforums.org/showpost.php?p=2929293&postcount=3
$ sudo apt-get install libncurses5-dev

Side Note

Petit Eric <surfzoid[at]gmail[dot]com> wrote:

For those who want 2.6.1 deb, there is OBS repository for i586 http://bit.ly/MonoDebOBS, the X86_64 are available here http://surfzoid.free.fr/Mono/ubuntu9.10/ or http://dl.free.fr/c1roVOfLL
in sources directory you will find  libgdiplus sources and all files need to build deb from them (.dsc, …) here http://dl.free.fr/iHFHXaIuj you will find mono2.6 idem

Written by Chorn Sokun

January 15, 2010 at 9:30 pm

Posted in Mono 2.6, OSS, Ubuntu

MR, Ambiguous controller names

leave a comment »

Reading through Phil Haack’s post implication in supporting area in ASP.NET MVC 2 remind me the time I faced the same problem using MonoRail, I believe I had post my solution in the passed but I can’t dig inside my blog entry to get it back.

So here it goes again the trick I used in to fix the problem let assume I had Admin Area & User Area and each has a HomeController I then would create controller file like this:

  • Admin [ Folder ]
    • AdminHomeController.cs
  • User [ Folder ]
    • UserHomeController.cs

Then I need to use ControllerDetails attribute to give these two controller a prefer url

// access with /admin/home/index.castle
[ControllerDetails("home", Area="admin")]
public class AdminHomeController: SmartDispatcherController { ... }

// access with /user/home/index.castle
[ControllerDetails("home", Area="user")]
public class UserHomeController: SmartDispatcherController { ... }

That work for me !

Written by Chorn Sokun

January 13, 2010 at 9:38 pm

Posted in MonoRail, Tips & Tricks

NHibernate + Mono + MySQL Fly by

with 5 comments

I thought about it and I want to see it works for me and there it goes ;)

  • Ubuntu Karmic
  • Mono 2.4.3
  • NHibernate (trunk)
  • MySql connector-net (trunk)
NH1

rebuild the stack for new home ;)

Sweet :) next rediscover Castle stack on Mono that should be fun let see how much I stress MonoDevelop 2.2

Written by Chorn Sokun

November 5, 2009 at 5:11 pm

Posted in Brainstorm, OSS, Ubuntu

Tagged with , ,

Storm the Castle in Action

with 2 comments

felt bore today and decided to tune into studio and record some stuff :D hope you enjoy it.

I know, I know the quality is bad but I don’t know I am not do much with youtube so it the luck I get :) BUT as always orginal video can be download here.

Source code: http://storm-the-castle.googlecode.com/svn/tags/barcamppp

Written by Chorn Sokun

October 23, 2009 at 5:50 pm

Gdo, Gazetteer Database Online

with 2 comments

Gazetteer Database OnlineThere are 3/4 variants of the Cambodia Gazetteer after UNTAC created the list; now it time to put this mess to rest one and for all.

Ministry of Interior, Department of Local Administration currently setup a task force to reconsolidates the master list and make it an only office Gazetteer.

Now my colleague expected to write up a forward document about this project; which I’m not going to discuss here.

What you should know in the near future there is only one set of Cambodia Gazetteer and you can access it online absolutely free, so stay tune …

And you don’t have to guess how I built or when it goes live since I had 3 projects developed & maintenance in parallel no doubt I no longer had time to enjoy playing JXII :(

Feature Highlight:

- Online browsing Province, District, Commune, Village meta data

- Province, District, Commune Map (produced by external consultant)

- Download Gazetteer data in Excel format for offline use.

I love this job ;)

Written by Chorn Sokun

October 2, 2009 at 1:18 am

Posted in Community, OSS, Rumor

Tagged with ,

Use jQuery to catch and display MR AJAX errors

leave a comment »

This post influenced Dave Ward’s post to replicate the behavior that he discussed within MonoRail application.  To mimic this behavior I created a method call RenderJsonError(Exception ex) inside my base controller (I want to reuse this method)

public abstract class AbstractBaseController: ARSmartDispatcherController{
   private void RenderJsonError(Exception ex){
      CancelLayout();
      Response.StatusCode = 500;
      Response.ContentType = "application/json; charset=utf-8";

      // I love this Framework :)
      var json = Context.Services.JSONSerializer.Serialize(
         new ErrorObject(){
            Message = e.Message,
            StackTrace = e.StackTrace
         });

      RenderText(json);
   }
}

From the code above look like I need to create a dummy DTO class ErrorObject and hand it over to JSONSerializer service instead of doing string escape/string concat myself :) MR use Newtonsoft.Json.dll behind the scene.

public abstract class AbstractBaseController: ARSmartDispatcherController{
  ....
  internal class ErrorObject{
     public string Message { get; set; }
     public string StackTrace { get; set; }
  }
}

Now let through some booms back to client

public class HomeController: AbstractBaseController{
   public void Index(){
      try{
          throw new Exception("Boom ! boom !");
      }catch(Exception ex){
          RenderJsonError(ex);
      }
   }
}

That work ! however if you don’t want to deal with try{..} catch {..} then combine this technique with RescueAttribute describe in my previous post.

Written by Chorn Sokun

October 2, 2009 at 12:58 am

Posted in MonoRail

Tagged with ,

MonoRail, IRescueController Handle Unexpected Exception

with one comment

By default you can intercept unexpected exceptional error occur in MonoRail you can opt to render a specific view from Views/Rescues folder or let MR pick standard one such as 404 page not found …

How how about you want to log the exception then you need to build a custom controller class that implement IRescueController interface just like this:

public class RuntimeExceptionController : SmartDispatcherController, IRescueController
{
  public void Rescue(Exception exception, IController controller, IControllerContext controllerContext)
  {
    // ... log via log4net ...
    // ... render & send error back home :) whatever you find helpful
  }
}

// usage: simple
[Rescue(typeof(RuntimeExceptionController))]
public class HomeController: SmartDispatcherController{
  public void Index(){
     throw new Exception("Boom !");
  }
}

Written by Chorn Sokun

October 1, 2009 at 10:38 am

Khmer Localization with .NET

leave a comment »

Localization in .NET doesn’t seem to solve a lot of problem in theory but I get no luck to get it work, although I built a custom Culture and having the resource file embedded in the assembly it just WON’T WORK !

After look around for solution I decided to give up and cheat a bit building localization engine from scratch is not too difficult but I tend not to spend my time on this yet.

So here is my way to have bilingual UI (Khmer & English)
resource

by faking treat fr-FR == km-KH and that work !

Never die with your tool, exercise your brain ;)

Written by Chorn Sokun

October 1, 2009 at 9:10 am

Rediscover WinForm, landing Alien base?

leave a comment »

Simple scenario each time a province change, district, commune & village will reset, not a big deal for me now a day to have this scenario on the web application but hey look it WinForm :( let see

I started from Form Load event cbProvince combobox get binded then wire cbProvince with SelectedIndexChanged event handler to load list of district into cbDistrict combobox and so on the code look more or less like this


public void Form_Load(object sender, System.EventArgs e){
  // binding cbProvince
}

public void cbProvince_SelectedIndexChanged(object sender, EventArgs e){
  //... binding the cbDistrict ComboBox using current selected value from cbProvince
}

public void cbDistrict_SelectedIndexChanged(object sender, EventArgs e){
  //... binding the cbCommune ComboBox using current selected value from cbDistrict
}

Sound good all event wired hit F5 to try out. Guess what happen? it slow & AND finally throw an exception !!! but how? years passed and this behavior didn’t change a bit

// flag state
private bool formReady = false;
public void Form_Load(object sender, System.EventArgs e){
  // binding cbProvince
  formReady = true;
}

public void cbProvince_SelectedIndexChanged(object sender, EventArgs e){
  if(!formReady) return; // this is the trick don't fire the event
  formReady = false;
  //... binding the cbDistrict ComboBox using current selected value from cbProvince
  formReady = true;
}
public void cbDistrict_SelectedIndexChanged(object sender, EventArgs e){
  if(!formReady) return; // this is the trick don't fire the event
  formReady = false;
  //... binding the cbCommune ComboBox using current selected value from cbDistrict
  formReady = true;
}

Written by Chorn Sokun

September 29, 2009 at 10:50 pm