Feel like a geek and get yourself Ema Personal Wiki for Android and Windows

29 September 2009

Inheritance and NHibernate.Search

I recently ran into a problem using NHibernate.Search. It is not possible to query properties of a derived class if NHibernate.Search only has access to it through a base class.
I used to have:
  [IndexedEmbedded]
  public virtual FieldType FieldType
  {
      get;
      set;
  }
The FieldType class is an abstract class from which concrete implementations derive. I wanted to index the properties of several derived classes, for example the OtherFieldType class:
public class OtherFieldType : FieldType {
  [Field]
  public virtual string Name {
      get;
      set;
  }
}
In this example, querying NHibernate.Search with "FieldType.Name:something" won't return any results. Apparently NHibernate.Search does not know it should query the concrete class implementation, OtherFieldType, for this query.

The workaround for this is to remove the IndexedEmbedded attribute from the base property and include a private field dedicated for NHibernate.Search to index and query. The private field does hold the concrete implementation:
  public virtual FieldType FieldType
  {
      get;
      set;
  }

  [IndexedEmbedded]
  private OtherFieldType OtherFieldType
  {
      get
      {
          return FieldType as OtherFieldType;
      }
  }
In this way, NHibernate.Search will know how to index and search the embedded properties. The query "OtherFieldType.Name:something" will now return the correct results.

26 September 2009

Google Chrome plugin for IE - yet another browser platform

The newly released Google Chrome plugin for IE introduces yet another browser platform to be aware of as web developer. We test our websites on IE, FF, Chrome and maybe Safari. Now a new platform is added to the list: IE with a bit of Chrome.

The Google Chrome Frame developers did their best to make it as unobtrusive as possible. The plugin will only kick in if the Google Chrome Frame tag is present on a webpage. But the tag does not guarantee anything. Maybe the website visitor refuses to install the plugin. Maybe the website visitor uses the opt-in list to force your website to use the plugin, although there is no tag present.

So note to self: don't forget to test the website without the plugin if the Google Chrome Frame tag is used. And don't forget to test the website with the plugin enabled although the website does not include the tag.

25 September 2009

Html Agility Pack to the rescue

One of our products is a messaging processor which uses XMl internally. Somehow someone messed up and managed to insert characters into the XML which are not valid, making the message "invalid XML". By the way "Invalid XML" is a contradictio in terminis. I would rather refer to "invalid XML file" as A Text File That Looks A Lot Like XML But Isn't.

Solving the issue would require updating the shared core component which is used by many applications. Updating the core component was not an option as a bugfix.

We decided to fix the bug in the following major release, but still needed a workaround for the problems in the field.

Enter Html Agility Pack. It is a tolerant library that can read HTML files (text files looking a lot like SGML or like XML) and convert them to XHTML. We inserted a processor into the processing chain that XMLlifies the message as it passes the processor, et voilĂ !

24 September 2009

Another client wish

For an internal project (C# / NHibernate / ASP.NET MVC / JQuery) there was a request that users could be able to mark parts of the data with colors to indicate parts of the data have changed.

If I had to incorporate this into my domain model, it would be quite complex. I would have to keep track of statuses of every property of every object, and every action should know which status data is relevant to that particular action.

I decided that this would be a simple solution: the coloring will be purely a user-interface feature. There will be a table in the database with the columns "URL", "ElementId", "Color" to store the coloring data. The userinterface will be querying this data after the page has been loaded and store the data using AJAX calls.

I am not 100% sure about this. It is clearly the simplest solution. But the colors are really statusinfo about the data in the application, while the statusinfo will never be associated with the data, only with user interface elements. But I decided in favor of the UI solution taking into account that
- the coloring data is cursory
- the request is purely a visual one
- the ASP.NET MVC application will be the only user of the data

See if I will regret this later.

23 September 2009

Client wishes

In an application I am working on different clients want different views, depending on the context. For example: client A is a sonographer and wants all ultrasound data on top, client B is an obstetrician and wants all obstetric data on top.

I first thought of a per-user preference which is stored in the database. Unfortunately, I did not have a per-user store mechanism yet, so I would have to develop it. Because I am lazy, this triggered a though: this isn't actually a per-user setting, but a per-role setting. There are clients that are both obstetricians and sonographers. They would want the data ordered differently depending on the role they have at that time.

So I decided to solve this in a very simple way, which the user is going to like. I created a button in the view that only switches view properties when clicked. No server-side code involved. It sets a persistent cookie on the client with the last state. The next time the user visits the particular part of the application, the last state is restored.