HackCamp @ Google London

A couple of weekends ago, I was lucky enough to be able to go along to HackCamp at the Google offices in London together with the mflow team. It’s the first ‘hack’ day/camp I’ve been to – and although I didn’t stay for the whole weekend nor did I actively participate in the hacking, I got to see what a hack camp is all about. For those of you who have never heard of this term before, a hack day/camp is basically a congregation of hackers, developers, designers (geeks in other words) who get together and spend 24~48 hours building an application using whatever tools they have at their disposal, in small groups or alone.

HackCamp @ Google London

There were about 10 or so different speakers presenting their APIs at HackCamp, and although you didn’t have to use those APIs in particular, it was certainly very interesting hearing about what others have to offer. One of the APIs that I thought was a great idea was this one – 0870.me. 0870.me is an API that allows you to plug in a standard 08* number (which mobile networks charge a fortune for here in the UK) and it will return to you a matching non-08* number if it can find one in it’s database. How neat is that??

There were speakers from Twitter, Google AppEngine and Buzz to name a few big ones, but also lots of smaller companies. Tum and Demis from mflow gave a talk about the mflow API.

Once all the hacked-up apps had been submitted, I had a quick look and found this little gem: tron. It is very cool to see that someone has used the mflow API in their app!

Anyway, having had a small taste of these ‘hack’ camps, I may just have to keep my eyes out for another that I can go to coz they sure do look like they could be lots of geeky-fun :)

Read More

.NET ObjectDataSource ignores culture information when inserting and updating

It’s been ages since I last updated my blog and I’m feeling super guilty.

So I thought I’d get stuck into it again and start with a whinge – a whinge about something that had me stumped for way too long this morning.

I have to say that I hardly ever use the out-of-the-box ASP.NET server controls (like asp:DropDownList, asp:TextBox, asp:DataGrid, etc etc) because I prefer to use standard HTML controls, stick runat=”server” tags on them and handle them manually. Call me old-fashioned, tell me I’m doing it the “hard” way… I don’t care. It works and I know how to do it quickly. I always find that when I use the more complete and complex server controls, I get 95% of the work done quickly and then spend hours trying to get the last 5% to work. I don’t like that very much.

Anyway, sometimes I end up having to use a variety of these server controls and today was one such day. Everything was going swimmingly until I tried to insert / update a DateTime property on the type that I had bound my ListView control to, using an ObjectDataSource. I’m in the UK and here, we do not use US-formatted dates. For some reason, no matter where I put localization code to set the locale to “en-GB”, when I hit my “Save” button, my code would throw an exception because it could not convert the string representation of the date into a DateTime object. That’s because it was trying to convert it to an American date. Grr!!!

After a lot of Googling, I came across this article. And there was the answer I was looking for.

Turns out that this is a known bug since ASP.NET 2.0 that Microsoft have decided they “won’t fix”. WTF. They’ve decided not to fix it because ”... the potential fix is relatively dangerous and the workaround is relatively simple…”.

The bug occurs because behind the scenes, .NET is calling ConvertFromInvariantString on all the new values – which is the “en-US” culture. This is clearly a massive assumption on their part but alas, it seems it is “too risky” to fix this.

The “simple workaround” they suggest is to handle the OnItemInserting and OnItemUpdating or OnRowUpdating events and in those handlers, extract the date values from the EventArgs, parse them from strings into DateTime objects and save them back. The following is an example of how one might do this:

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
private static void MyList_ItemInserting(object sender, ListViewInsertEventArgs e)
{
	var myDate = e.Values["MyDate"].ToString();
	e.Values["MyDate"] = DateTime.Parse(myDate);
}
 
private static void MyList_ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
	var myDate = e.Values["MyDate"].ToString();
	e.Values["MyDate"] = DateTime.Parse(myDate);
}

I realize this is not a hard fix – but the annoying part was figuring out why it was happening in the first place!!

Anyway, I hope this whinge helps someone else solve this problem… :)

Read More