Tuesday, December 11, 2007

Camping trip to Doi Inthanon

I can't believe the extent of our travels in just four days. We went shopping in Bangkok on Friday afternoon, where I bought a new torchiere (floor lamp) for my home office. Much to our own surprise, we managed to make it to Chiang Mai by Saturday morning. We bought our new camping gear and then had an excellent camping trip with our friends, David and Jeab. We were back in Bangkok by Sunday night, and then on our home island by Monday evening. Whew.

When we departed our home Thursday evening, we had the intention of heading all the way to Chiang Mai. Even before reaching Bangkok, however, we decided it wasn't worth the additional eleven hour bus ride. We slept a night at my girlfriend's parent's house in Bangkok, and went shopping the next day. That evening, however, my girlfriend's mother phoned from work saying her niece (my girlfriend's cousin) will be driving with her boyfriend to Chiang Mai that very evening. We scrambled to hitch a ride, and arrived in Chiang Mai the next morning.

The highlight of the trip, without a doubt, was ascending to the peak of Doi Inthanon in Chiang Mai on Sunday morning at 6 a.m. Being the highest point in Thailand, it's a popular tourist destination among Thais. Now is the country's "cold" season, and that peak is the coolest place. Everyone goes there at 6 a.m. because it's the coldest time of day. It's for the thrill (?) of feeling freezing cold, as if in some foreign country.

Thursday, December 6, 2007

Collections for WPF and NHibernate

My current programming project is on the Microsoft .NET platform, and I'm writing code in the C# language. I'm using NHibernate — a popular object/relational mapping tool — in the data access layer, and Windows Presentation Foundation (WPF) for the user interface. One of the features making WPF so attractive is data binding. Although I was initially disappointed when I found out that NHibernate's collections don't work correctly out-of-the-box with WPF data binding, I soon found Gary DeReese's blog entry which provides a (partial) solution. Gary's "NotifyingCollectionDemo" shows how a custom collection type can be built to rectify NHibernate's shortcoming. After studying how his ObservableList (which is actually an observable bag) was created relative to the NHibernate API, I began work on my own "ObservableCollections" project which includes three custom collection types: observable bag, observable list, and observable set.

I've finished creating these custom collection types, so you can download the result now (updated 2008-Dec-10) to use in your own projects. The zip archive contains a Visual Studio 2005 solution that includes three projects. The "ObservableCollections" project is the library containing the custom collections. The "ObservableCollections Demo" project is a WPF program that you can run to play with the contents of a sample set and sample list collection. And the "CoreHelpers" project contains some miscellaneous helper classes that I use in various projects. Before running the demo project, however, you'll need to do the following:
  • Add references to the library and demo projects, pointing to the following NHibernate assemblies on your computer (unless already in the GAC): NHibernate, Castle.DynamicProxy, Iesi.Collections, and log4net.

  • Change the absolute path of the database in the hibernate.cfg.xml file to match its location on your computer.
The "CoreHelpers" project includes a OneToManyAssocSync helper class that makes it easy to maintain in-memory the semantics of a one-to-many bidirectional association. The demo project shows how to use it. There is also a ManyToManyAssocSync class for easily maintaining many-to-many bidirectional associations. (See this blog entry for a note about the renaming of these classes from their former names.)