NHibernate + Mono + MySQL Fly by
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)

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
Storm the Castle in Action
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
Gdo, Gazetteer Database Online
There 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 ;)
Use jQuery to catch and display MR AJAX errors
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.
MonoRail, IRescueController Handle Unexpected Exception
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 !");
}
}
Khmer Localization with .NET
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)

by faking treat fr-FR == km-KH and that work !
Never die with your tool, exercise your brain ;)
Rediscover WinForm, landing Alien base?
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;
}
jQuery.selectboxes removeOption()
Base on the doc page located here http://www.texotela.co.uk/code/jquery/select/ if I wanted to remove (clear) items from a select box all I need to do is call:
$('#select_box').removeOption(/./);
But in my case I had a select box like this:
<select name="select_box" id="select_box">
<option value="">N/A</option>
<option value="1">Low</option>
<option value="2">Meduim</option>
<option value="3">High</option>
</select>
and of cause the syntax specified above doesn’t do the trick; this is how I fix it:
$('#select_box').removeOption(/(.?)/);
Was that how it should be done? oh ! by the way the shorter way
$('#select_box').empty();
Weekend => app.goLive ;)
Early this month I got into a busy schedule in order to release my new database application. I needed to run & check a final test, wrote up manual and do some paper work to invite my colleague across the country (2 staffs from each province X 24) to attend a 3 days training workshop in total we get approximately 48 staffs which is too much for an IT training so we split it into 2 batches 12 provinces each.
In term of the actual database I allocated 2 days and for the first day of the training I leave it for general IT update lesson which include Khmer Unicode orientation half morning, and for that session alone I am very lucky to have Mr. CHEA Sok Huor a Country Project Leader from PAN and his colleague came in for help. Without them I wouldn’t know where to get such precise Khmer Unicode Orientation somewhere else, so thank you from the deepest of my heart.
Oh! Talking about helping there is another gentle who I owe him as well, that gentle is Mr. Tuy Pheap my long colleague. We share room in the last 3 years before he moved on to his current job and come back to seat behind my back :) “Again :D”. I disturb him from time to time :D policing what my system do against his employer needs (the World Bank) not only that he also help me correct my Khmer Translation + Spelling :) and this phrase “ខ្ញុំយល់ហើយ!!!” for a button which in English say “I Understand” was his innovation :) let me tell you about this joke
In our new application if there are any problems or errors detected a list of detail explanation will show up ( jQuery modal ) what I originally did was to have user click on “Ok” button to close the message. But without anything special user might just click “Ok” and go on … that not fun. So we came up with an idea instead of naming the button “Ok” we called it “I Understand” :))
And as a side effect during the training we forget to translate a few messages so default message showed. Since the user do not read English and he dare not click on the button to close the message :(
I am glad with the result as it turn out and thanks to all the backend libraries that I used without them I wouldn’t know how much I would need to damage my brain cells to get this job done :)
What I used?
- NHibernate
- Castle (MonoRail, ActiveRecord)
- Rhino-Tool (Rhino.Security, Rhino.Common)
- Oh ! ASP.NET for sure :) but I a brail devil don’t blame me for not using webform
- Log4net
- jQuery & it plug-in(s)
Challenges:
- For the past 5 years most of them get use to do data entry in desktop mode (VB6)
- Some of them using the Internet for the first time; right this is (1==1).
- The amount of data that we collect had increase 1.5X
- More restriction in term of data modification – they used to have full control over there data and that cause me alot of headache over the past years.
At the end of training session I got a request to setup a demo URL (http://db.ncdd.gov.kh/pid-train) so that when participant get back to their duty province they can teach their colleague, by doing this I get a few additional feedback on how to improve the process of data entry as well as knowing how user interact with the application.
For sure: “No one is perfect” and “No software ever release bug free” as long as it could do it main job properly I would call it V1.
Now the weekend is coming I had to switch on actual URL and for that mean I had to copy a folder change connection string to get another URL up and running KOOL stuff ;)
PHP date diff
I call out for an excuse for not practicing PHP enough recent year; with just a simple date_diff could knock me out :) not to open my complain of having different version of PHP to check before using a function(s) I got a request from a friend to help workout how many days from two given date.
Now if I have two date string (it is what we get from form post right?)
// fixed format as I don't want to deal with complicate of different world format :(
$day1 = "26/03/2009";
$day2 = "28/03/2009";
// now I need to know how many days does it take from day1 to day2
// PHP 4.x; ignore my out of date PHP skill this is how I did it
$break_day1_apart = explode('/', $day1);
$break_day2_apart = explode('/', $day2);
$day1_number_form = $break_day1_apart[2].$break_day1_apart[1].$break_day1_apart[0];
$day2_number_form = $break_day2_apart[2].$break_day2_apart[1].$break_day2_apart[0];
$day_diff = abs((int)$day2_number_form - (int)$day1_number_form);
// and it should work by theory
echo $day_diff;
Suck ! what would you do instead?
