Filed Under (Blog) by fakhrul on 25-03-2009

Yesterday, my friend had ask me how to “print screen” the web page. He want to put the print screen image into his report. The problem is, he cannot simply push the print screen button on the keyboard to get all the content. Some web page had a long content, so that we need to scroll down and up to look all the content. If we press the print screen button, it will capture only the screen that we see.
Fortunately we have a cool firefox extension to print screen the web page. It is ScreenGrab. You can download it here.
Thanks to mkhairul that told me about this long long time ago.
Filed Under (Development) by fakhrul on 23-03-2009
For our new system, we are planning to use the XmlSerializer Class to serialize our object into the database. So what is XmlSerializer can do?
Definition
Serializes and deserializes objects into and from XML documents. The XmlSerializer enables you to control how objects are encoded into XML.
This is a very useful class if you want to persist your object. You can store your object either in the text file or maybe in database. Later, if you want to get your object back, you can deserialize it. In our case, we prefer to put in the database.
How to use it?
I had made some simple program to show how to use the XmlSerializer Class. This will serialize to the xml file. You can also refer to the MSDN to know more. Here is the code snippets:
using System;
using System.Xml.Serialization;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press any key to start serialize...");
Console.ReadKey();
DoSerializeToFile();
Console.WriteLine("Press any key to start deserialize...");
Console.ReadKey();
DoDeserializeFromFile();
Console.ReadKey();
}
private static void DoDeserializeFromFile()
{
try
{
Console.WriteLine("Start deserialize process");
// Initialize the XmlSerializer
XmlSerializer serializer = new XmlSerializer(typeof(Student));
//Initialize the text reader. This will read the student.xml file in your BIN folder
TextReader reader = new StreamReader("student.xml");
//Start the deserialize
Student student = (Student)serializer.Deserialize(reader);
//display the result
Console.WriteLine("Date\t" + student.DateJoin.ToShortDateString());
Console.WriteLine("Current Term\t" + student.CurrentTerm);
for (int i = 0; i < student.ResultByTerm.Length; i++)
{
Console.WriteLine("Current Term\t" + student.ResultByTerm[i]);
}
Console.WriteLine("Deserialize completed");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private static void DoSerializeToFile()
{
try
{
Console.WriteLine("Start serialize process");
// Initialize the XmlSerializer
XmlSerializer serializer = new XmlSerializer(typeof(Student));
//Initialize the writer. This will create the student.xml file in your BIN folder
TextWriter writer = new StreamWriter("student.xml");
//Create a Student object
Student student = new Student();
student.DateJoin = DateTime.Now;
student.CurrentTerm = 2;
student.ResultByTerm = new int[2];
student.ResultByTerm[0] = 4;
student.ResultByTerm[1] = 5;
//Serialize to writer (write to xml)
serializer.Serialize(writer, student);
//clise writer
writer.Close();
Console.WriteLine("Serialize completed");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
[XmlRootAttribute]
public class Student
{
[XmlAttribute]
public DateTime DateJoin { get; set; }
[XmlAttribute]
public int CurrentTerm { get; set; }
[XmlArrayAttribute]
public int[] ResultByTerm { get; set; }
}
}
Filed Under (Development, ORM) by fakhrul on 21-03-2009
Definition
By refering to the wikipedia, the Object Relational Mapping (ORM) is defined as
A programming technique for converting data between incompatible type systems in relational databases and object-oriented programming languages. This creates, in effect, a “virtual object database” that can be used from within the programming language. There are both free and commercial packages available that perform object-relational mapping, although some programmers opt to create their own ORM tools.
ORM is place between the database and the .NET object. For example, we have a class name as Student and the table name as TBL_STUDENT. The ORM are used to map the class Student and the TBL_STUDENT. There are 2 way to map the object and the table, one way is using the xml file, and other is using the .NET atrribute. In Nhibernate, I am using the attribute mapping because it is much easier.
Why you use it?
- You can apply the Domain Driven Design (DDD) easily.
- ORM generate the sql statement for you.
- It is price less. Free. There are a lot of open source for ORM.
- Support for multiple database. It’s flexible to change which DBMS you want to use. All setting is in the config files.
- Good performance. As you know, the ORM frameworks are develop from the expert all over the world. So you don’t worry about it. The only thing you need to worry is, how to use it. (Fortunately, almost all of the API was documented well.)
- The source code are provided (for open source ORM). You have the code and you can change it if you are need to do.
- Support are available. You can ask a question and discuss anything regarding to the ORM in the forum.
- Faster development process. Forget the learning curve because I think you only need not more than a week to know how to use it. Once you now, you will be suprise how fast it can be.
Last word
There are a lot of ORM framework for .NET. For example Spring.Net, NHibernate and Castle ActiveRecord. I had experience in using NHibernate and Castle ActiveRecord. Castle ActiveRecord is actually sit on top of NHibernate. It was build by a group of geek to simplify the use of NHibernate.
There are also a lot of tutorial and reference you can get from the internet. You can google it, the keyword is “ORM”, “NHibernate”, “Castle active record”.
Hope this post had give you an idea about the ORM. Thanks.
Other links
http://aspalliance.com/1069_Introducing_Object_Relational_Mapper.1
http://en.wikipedia.org/wiki/Object-relational_mapping
http://www.hibernate.org/343.html
http://www.castleproject.org/ActiveRecord/
Filed Under (Blog) by fakhrul on 21-03-2009
Semalam hari terakhir aku kat bangkok. On the way nak balik tu, sempat la singgah site sekejap. Seperti apa yang aku expect, kerja-kerja pemasangan toll masih sedang dijalankan lagi. ETC software untuk toll sudah di installkan di sini. Kawan aku pon dah buat simple test untuk software dia tu. Tapi, tak banyak yang boleh di test sebab equipment pon belum 100% siap. Dia test apa yang mampu saja.
Sambil menunggu diorang buat keje pemasangan tu, aku pon sempat la posing sikit kat depan toll. Hehe.

Kitorang tak stay lama kat toll ni, sebab nak kejar flight kol 8.20 waktu Bangkok.
Wassalam.
Filed Under (Blog) by fakhrul on 20-03-2009
Baru sampai kat hotel ni. Hari ni full day aku dan kawan aku kat office Smart Traffic. Penat cocentrate buat kerja kat ofis (ahaks) sampai tak sempat nak belajar bahasa Thailand. Yang aku tahu sebut “Kop-khun” je. Terima kasih maknanya. Berbudi bahasa betul aku ni.
Bawah ni aku letak map office ngan hotel. Mana la tahu geng-geng lain nak datang jugak kan. Hehe.
Hotel yang aku stay ni tak jauh sangat dengan office. Dalam 10 minit (tumpang kereta orang). So, kira ok la kan.
View Larger Map
Keesokan hari nya, aku akan pergi ke site (Highway). Tak tahu la apa yang akan jadi esok. Harap-harap semua berjalan dengan lancar (walaupun aku tahu memang tak akan berjalan lancar). Haha.
Filed Under (Blog) by fakhrul on 18-03-2009
Aku kat Bangkok sekarang ni. Sambil menunggu kawan aku tengah mandi tu, sempat jugak la aku menyempatkan diri untuk memblog. :). Bukan nye apa, just nak kongsi serba sedikit pengalaman aku di Bangkok ni. So nanti kalau office mate or kawan-kawan lain nak datang sini. Ada lah guide sikit.
Aku bertolak dari LCCT (naik Air Asia aje) dalam kol 6.45 pm waktu Malaysia. Pukul 4.45 pm aku dah sampai kat LCCT tu. Memang kena sampai dalam 2 jam sebelum waktu departure. Perjalanan dari KLIA ke Bangkok lebih kurang 1 jam 45 minit. So sampai di airport Bangkok dalam kol 7.30 pm waktu Bangkok (waktu kat Bangkok ni lewat 1 jam daripada waktu Malaysia).
Sampai je ke Bangkok, ada staff daripada Smart Traffic datang jemput. Alhamdulillah. Tak perlu la aku menggunakan skill bahasa isyarat aku untuk naik teksi. Diorang ni bukan tahu sangat speaking. At least aku ni, tahu la sket2 walaupon grammar hancur. Haha.
Lepas tu, diorang hantar pergi ke hotel. Sebenarnya, perbalanjaan untuk trip ni, diorang yang sponsor. So tak banyak pilihan sangat la. Diorang yg bayar kan. Office diorang kat Jalan Ramkamheang.
Aku stay kat Regent Hotel, kat Ramkamheang jugak. Aku memang recommend korang stay kat hotel ni sebab dia bercirikan Islam. Masuk-masuk hotel je, baru la nampak orang yang bertudung. Sejuk sikit hati bila tengok orang pakai tudung ni. Hehe.
Makan kat hotel ni pon ok, Tak la mahal sgt, dalam 80 Bath untuk 1 set nasi dan 40 Bath untuk teh ais. Kalau nak makan kat tempat lain pon boleh. FYI, kat sini susah sikit nak cari makanan yang halal. Tapi kalau korang ternampak ada perkataan Bismillah, Allah, Muhammad, kira ok la tu. Yakin je. Insyallah.
Ok la, kawan aku ni dah abis membersihkan diri pon. Time to have a breakfast. Lepas tu teruskan misi aku di sini. Diorang datang amikkitorang dalam pukul 9.00 am waktu Bangkok ke ofis diorang. Dalam 10 minit, sampai la office. Ok la. Wassalam.
Filed Under (Blog) by fakhrul on 15-03-2009
Sedih juga tinggalkan kekawan sekerja kat MEDIU ni. Banyak memori-memori indah kan. Tetapi apa kan daya. Jasa aku kat MEDIU ni sampai minggu lepas je. Kjap, jap !, ada ke jasa aku kat MEDIU ni?. Haha. Apa aku dah buat kat MEDIU selama setahun ni? Hehe, ada la sikit, ICMS (dashboard), CMS, FIleStore, Library application sket, web service utk CBE yang tak pakai tu. Then, pegi Bangkok install CBE (yang ni paling best sebab boleh pegi jalan-jalan free) . Itu saja la yang penting, yang gosip-gosip tu, mengeTEH kat Pelita tu tak payah cerita ek. Haha.
Apa pun, aku ucapkan terima kasih pada semua staff MEDIU. Especially pada DEV TEAM. Tanpa diorang, siapa la aku ni. Eceh.. Banyak aku belajar daripada sifu2 MEDIU ni. Especialy in Web Development.
Inilah teammate aku kat MEDIU, semua nye muka kekenyangan tu. Baru lepas balun Nasi Beriani King. Huhu. Thanks semua, sebab belanja ye. Susah-susah je korang ni.
Next day, aku dapat hadiah la pulak. Terharu rasanye. Eceh, dalam hati tertunggu-tunggu, mana la hadiah aku ni. Hehe. Walaupun tak dapat LCD TV yang diminta, tapi kira ok la ni. At least ada kenangan.

Ini kata-kata semangat daripada kekawan MEDIU.

Di persembahkan, hadiah nya ialah (lihat di bawah). Boleh la pasang kat LCD TV nnt ni. Syukran Jazilan.

Akhir kata kepada MEDIU staff, kalau ada program baik punya. Jangan lupa ajak ye. Kalau tak busy, boleh la aku join.
Wassalam
Filed Under (Development, ORM) by fakhrul on 07-03-2009
I had started a development of my project using the Asp.Net (Code behind), Castle ActiveRecord and MySql. Here are some of the important points for configuration to make sure it will runs smoothly.
Firstly you need to have all the necessary library:
- Castle Active Record
- My Sql Connector for .NET
Note: You can put all the assemblies either in the GAC directory or you can create a new folder in your solution folder and puts in there. You can name it as “Libraries”. I suggest you to create a new folder in your solution directory and put every dependency library there. By doing this, you can minimize the chances of missing library.
Secondly, you need to add the reference of
1. Castle Active Record
- Castle.ActiveRecord.dll
- Castle.Core.dll
- Castle.Components.Validator.dll
- Castle.DynamicProxy.dll
- NHibernate.dll
- Iesi.Collections.dll
- log4net.dll
2. MySql Connector
Then, add the web.config as below
<configuration>
<configsections>
<section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord"/>
</configsections>
<activerecord isWeb="true">
<config>
<add key="hibernate.connection.driver_class" value="NHibernate.Driver.MySqlDataDriver"/>
<add key="hibernate.dialect" value="NHibernate.Dialect.MySQLDialect"/>
<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<add key="hibernate.connection.connection_string" value="Database=DB_NAME;Data Source=DB_IP;User Id=DB_LOGIN;Password=DB_PASSWORD"/>
</config>
</activerecord>
</configuration>
Lastly, add the ActiveRecord initialization inside your Global.asax
protected void Application_Start(object sender, EventArgs e)
{
Castle.ActiveRecord.Framework.IConfigurationSource cfgSource = Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler.Instance;
Castle.ActiveRecord.ActiveRecordStarter.Initialize(new[] { System.Reflection.Assembly.Load("Sample.Domain") }, cfgSource);
}
Filed Under (Blog) by fakhrul on 01-03-2009
|
|