Tuesday, January 19, 2010

“See, it’s not that the democrats are playing checkers and the republicans are playing chess. It’s that the republicans are playing chess, and the democrats are in the nurse’s office because once again they’ve glued their balls to their thighs.” - Jon Stewart @09:10/10:05

Tuesday, January 12, 2010

Just read a notice from BlackBerry that there is a software update for my phone. Not only did they completely gfail to sell me on the upgrade (what’s new?), they inject such a barrage of technical-ese that anyone’s eyes would glaze over.

Something tells me Apple would not have sent the same kind of email – see highlighted section below…

Find out when you update to the latest smartphone software! This free update is ready and waiting to help you do more with your BlackBerry smartphone. To update today visit http://www.blackberry.com/updates

New ways to work and play!

* As an aid to comprehension, this section provides a brief overview of the life-cycle of a device upgrade. * Each OTASL capable device will contain one or more OTASL Service Records(SR) each identifying a Device Manager (DM). The DM may be located at RIM, may be part of a BES or, in future, could be associated with a 3rd party application provider. Each SR will identify the applications which are of interest to the corresponding DM. SRs may be delivered by PRV, BES or in an upgrade application loaded OTA. … (it goes on, but there’s no point).

- "Yeah, a dogtornarian is a doctor for dogs. And he gives the dogs shots, and the dogs are really good, and they get a flu shot so they don't get sick! And when Riley grows up, she's gonna be a vegternarian, but she's only going to treat cats, and we're gonna treat both dogs AND cats! And we're gonna have a little baby, and the baby is going to to a school, and we're going to go to work! Just like Lottie and me go to school, and you and mommy go to work!"

Since this is an MVC app, our standard url format is of the usual http://albumcredits.com/{controller}/{action}/{index} kind, and forsomepages, I need to allow the url to simply specify the controller, defaulting the action to index – again, the usual ASP.NET MVC pattern.

I was familiar with the constraint parameter option for the AddRoute method, but had never studied it in much detail – we’d used it to limit certain indexes to be numeric, but that was all. For the root-level personalized urls we needed a more robust constraint – specifically we needed to exclude any controller from the list of valid personalized Urls.

I first spent more time than I cared to trying to come up with a regular expression pattern that would NOT match the list of controller names – it looked something like this: ^(?:(?!\b(foo|bar)\b).)*$ (thanks to Justin Poliey/stackoverflow.com) where foo and bar, etc were the controller names to NOT match.

Not until after I got that to work did I think to google “mvc custom route constraint”. Of course the MS MVC team was smarter than that – custom route constraints are really very straight forward…

For my purposes, I went with David Hayden’s approach – the code below is essentially the same as his, just with the logic reversed.