Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

Archive for October 2009

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

Advertisements

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

with one 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

Posted in Programming, Tips & Tricks

Tagged with ,