GeekSpeak comments edit

I noticed, about a month ago, that whenever I would log in to Windows Live Messenger, I’d get a little toast popup telling me to verify my email address:

You need to verify your e-mail address with Windows Live Messenger.

I clicked, I followed the verification process, and I thought everything was cool.  Not so.  The prompt kept coming up.  On subsequent times I tried to verify my address, though, it would tell me that I didn’t need to verify.  What gives?

I had recently taken advantage of the “linked ID” feature of Windows Live IDs.  The misleading thing here: I did need to verify an email address, just not the one I was signing in with.  Curiously, signing in with the other IDs didn’t prompt me to verify… but that’s neither here nor there.  After fighting my way through support for a month on this (and specifically asking them if it had to do with my linked IDs), it came back that, yes, it was something to do with one of the other accounts.

Anyway, if you’re getting prompted and you recently linked your IDs, it’s probably a problem with one of the linked accounts.  Make sure they’re allverified.

General Ramblings comments edit

Dad's Car Accident
Dad’s Car Accident

My dad was headed to work yesterday and hit an icy patch in the road.  His car spun 180 degrees, went into the ditch, and hit a tree.

He’s okay, albeit on some serious pain killers and with some chipped vertebrae.  No one else was involved or injured and after some physical therapy and some time to rest up, he should be good as new.

Here are some pictures of what was left of his car.  Absolutely totaled.  He had to climb out the passenger window because the frame was so bent up neither door would open.

Of course, the thing he seems to be most concerned with is that, somewhere in the chaos, he lost his glasses.  Heh.

gists, aspnet, net comments edit

Let’s say you have some text on your web site that has an image inline.  Something like this:

Fields with a ! icon indicate failed validation.

You’ve seen that before.  You’ve probably done that before.  Now let’s say you’re using ASP.NET themes and skins to control your look and feel, and that icon is different based on your theme.  It might change to be:

Fields with a ! icon indicate failed validation.

You could have some ASPX code that handles that with the SkinID of the image, right?

Fields with a <asp:Image ID="icon" runat="server" SkinID="validationIcon" /> icon indicate failed validation.

Okay, that works acceptably, provided your skin defines an Image that has a SkinID “validationIcon.”  But you’re a savvy ASP.NET developer and you know better than to put literal strings like that right in your web application - you put your strings in resx files and look them up at runtime so your app can be localized.  Now what?

There are a few ideas you could try, but they don’t work (or not well):

  • String.Format - You could leave a {0} in the page text and try to String.Format the image into place.  That might work if you weren’t skinning, but you need to take advantage of ASP.NET skins… so that won’t work.
  • Client-side script - You could try some client-side script to render the image to a hidden place on the page and then place it into a <span /> or something in in the instructions, but that’s kind of painful.
  • Break the text up into separate controls - You could make the text three controls: the text before the image, the image, and the text after the image.  This could become hard to manage from a localization perspective (what if there isn’t any text after the image?) and it’s not terribly flexible.

The answer: ParseControl.

The System.Web.UI.Page class has a ParseControl method on it that it inherits from TemplateControl.  You can use this to your advantage - just put the markup inline into your resource string and use ParseControl method to create a control hierarchy on the fly.  Then just swap the parsed control hierarchy into your page where you want the text to display.  Put a Literal in your ASPX and do your string lookup…

<asp:Literal ID="pageText" runat="server" Text="<%$Resources: MyResources, PageText %>"/>

And in your resx file, put the entire text, including the image markup:

<data name="PageText" xml:space="preserve">
  <value>Fields with a &lt;asp:Image ID="icon" runat="server" SkinID="validationIcon" /&gt; indicate failed validation.</value>

See how that looks just like ASPX page markup?  Perfect.  Now in the codebehind of your page class, replace the Literal with the control hierarchy that gets parsed from the text in that very Literal:

public partial class MyPage : System.Web.UI.Page
  protected void Page_Load(object sender, EventArgs e)
    Control parsed = this.ParseControl(this.pageText.Text);
    Control parent = this.pageText.Parent;
    int index = parent.Controls.IndexOf(this.pageText);
    parent.Controls.AddAt(index, parsed);

In that example code, we:

  • Parse the text that got looked up from resources into a control hierarchy.  This lets us account for localization while still providing the inline themed icon we’re looking for.
  • Grab the parent of the original control.  This is important because you need to insert the parsed control hierarchy into the proper spot in the control tree.
  • Find the exact location of the original control in the parent’s control structure.  This tells us where to put the parsed control hierarchy.
  • Insert the parsed control hierarchy into the proper spot.
  • Remove the original control from the hierarchy - we’ve replaced it, so it’s no longer needed.

Pretty nifty, eh?  There are lots of other things you might want to consider if you do this, but I’ll leave them as “an exercise for the reader,” so to speak:

  • The example replaces the control with the parsed hierarchy; you might instead wish to add the parsed hierarchy as a child of the control you’re “replacing.”
  • If you use the same text twice in the same page, you may end up with control naming clashes; you might want to wrap the parsed control hierarchy in a naming container to avoid that.
  • You probably don’t want to repeat this code over and over in every page; you’d want to have a single service class that does this for you.

A tiny word of warning:  you probably don’t want to do this on every single string you localize. It’s not super expensive, but it isn’t necessarily “free,” either.  Here’s the timing from trace output - you can see the obvious difference in the amount of time the page Load event (where I’m doing this) takes vs. the other events.

Timings for parsing inline

It’s only ~0.01 seconds, but you wouldn’t want to, say, put this in the middle of a big databinding block.

General Ramblings comments edit

Woke up last night at 2:45a to the neighbors out in their yard arguing.  No physical violence, and it was mostly the guy yelling, but super loud.  I don’t even think I’d heard them before, except for their dog barking incessantly a year or so back.  Sigh.

Jenn ended up calling the cops who couldn’t actually find our house on a map.  She kept having to give a bunch of nearby cross-streets and directions.  That makes me feel really safe.  I imagine a time where there’s a psycho killer in my house trying to stab me and the 911 conversation goes like this:

Travis: Oh my God, help, there’s someone in my house trying to stab me!  Here’s my address - get here as soon as possible! Dispatcher: Hmmm… you don’t seem to be on the map. What’s your nearest cross-street? Travis: I think he’s coming up the stairs! Wait - cross-street? Uh… Foo Ave. Dispatcher: Yeeeaaaah, um, is that north or south of Bar St.? Travis: South.  Hurry! Dispatcher: Are you sure? Where are you in relation to Baz Pl.? Travis: -stabbed to death-

That’s the first time I’ve called the cops on someone.  When they finally arrived, it was in total force - like, two cars and another cop running up a side street.  I’m surprised the SWAT team wasn’t there.

Had a hell of a time getting back to sleep, though.  It took me forever to get to sleep the first time, then this.  I’m dead tired today.  Damn, anyway.

gaming, xbox comments edit

Okay, so for a while I thought it might be that I got a bum set of drums with my copy of Rock Band because I’m only able to get like 98% on Easy level.  I mean, I swear I’m hitting them right, but it’s just not registering.

To test, I went into practice mode and played a song segment that basically has no drums at all - so I wouldn’t get confused by notes being hit or missed.  I did a roll on each drum to see how it went and all of the hits were registered.  I also hit various combinations of two pads simultaneously and all of those hits were registered.  So I was/am encountering a combination of issues, all adding up to Bad News for Me:

  1. The timing on the drums is utterly unforgiving.  If you’re playing guitar, you get a little plus/minus room for strumming and hitting a note.  Sort of a “close enough” buffer.  With drums, you’re either ON or you’re NOT.  No fudge room.  A millisecond or two off, and it won’t count.
  2. The USB hub that comes with the game is pretty bad and seems to introduce a little latency.  Not a lot, but with timing having to be pretty precise, I notice a little better response when I plug the drums into the Xbox directly and everything else goes in the hub.
  3. Calibrating the game is hugely important.  Sometimes the presets work; I manually calibrated mine and things seemed to be a little better.
  4. I may just be a sucky drummer.  After checking out the responsiveness of the drums, calibrating everything, and plugging the drums right into the Xbox, I’m doing a little better but am still missing a couple of notes per song on Easy mode.  It’s usually during a spot where I have to hit two pads simultaneously and I think it’s that I’m hitting them close to correctly but actually hitting one pad slightly earlier than the other, so it doesn’t count.

I’m pretty good at Donkey Konga bongos.  I think playing drums with your hands and playing them with sticks might be two different beasts.  I’m OK with that - knowing that it means practice is one thing; doubting yourself without knowing if it’s the equipment or not is a whole other set of insecurities.