Archive for December, 2006

Took the Which-Superhero-are-you test

December 30, 2006 3:01 pm

Saw this on TechCrunch and thought I’d play along. Looks like I’m Spiderman:

Your results:
You are Spider-Man

Spider-Man
60%
Hulk
50%
Robin
47%
Superman
45%
Supergirl
45%
Catwoman
40%
Iron Man
40%
Batman
35%
Green Lantern
35%
The Flash
30%
Wonder Woman
25%
You are intelligent, witty,
a bit geeky and have great
power and responsibility.


Click here to take the “Which Superhero am I?” quiz…

Finally added some links – are you surprised at what I picked?

December 28, 2006 10:59 pm

Today I got around to adding some links to my blog. If you look at the initial set you may be wondering why I mostly have the categories “Simplifying Life” and “Sensible Money Management” populated for now. What I’ve written about so far has been related to software and technology. So what gives?

Well, I since I work as a software developer, I’m somewhat naturally drawn towards high tech toys and software development topics. I’m a nut for tech toys, though I’m usually too cheap to buy them – working for a high tech company has its fringe benefits in that department. It’s easier for me to write about things from that sphere, since I know at least a little about it. So that’s where I started.

But one of my other big interests in life is limiting my impact on the environment and help make sure that our planet remains a viable habitat for my kids, their kids and so forth. I believe in picking up my own trash and making sure it goes into the proper waste stream. I believe in trying to limit the amount of trash I generate, so the waste stream becomes as small as possible. I believe that keeping my business as local as possible is important for reducing my impact on the environment. I believe that the only way to make a difference in the world is through personal action, meaning I have to do something. If I don’t do it, who will? And if I don’t do it, how can I get other people to join me?

I’m sure you can see that these things don’t mesh very well: a fascination with software, computers and high tech toys paired with an interest in reducing my impact on the planet. Let me just say that I struggle with this paradox a lot. I’m going to explore the notions of “voluntary simplicity” in addition to my ramblings about software and tech toys. Maybe you’ll enjoy it, maybe you won’t. Whichever way, I’ve now enabled “unregistered” commenting. So please comment away. I invite you to a conversation.

iRobot Roomba improvements I’d like to see

December 26, 2006 6:45 pm

I splurged on an iRobot Roomba robotic vacuum cleaner this Christmas. It’s quite a neat thing to watch working. But I’d like some improvements made to it:

  • A light that shows when the Roomba hits a virtual wall, so I can place the wall in just the right spot and at just the right angle to block the robot’s path. My house is full of door-less openings that would make the machine run out of juice if not stopped by virtual walls.
  • A “wall following first” mode, so I could be sure it has done the edges of the room before embarking on it’s normal “random” cleaning pattern.
  • Detection of area rugs. So far the Roomba gets stuck on our rag rugs and the Christmas tree skirt. Putting up virtual walls for these would be almost impossible.
  • Seeing the model of the room that the robot builds up somehow. Also, how much of that model it thinks it has covered and how often.

Other than that I’m pretty happy with this high tech “toy” worker so far.

Localizing an XBAP application without using LocBaml

December 12, 2006 4:23 pm

Using the LocBaml sample application that Microsoft provides with the Windows SDK for Windows Presentation Foundation can be very frustrating. By default it seems to pick up a lot of things that clutter the resulting CSV file. If your application contains a lot of image resources, those will get duplicated in the localized resource dlls as well, increasing the space that your application occupies on the hard drive. And finally, getting an XBAP application to be deployable after localization with LocBaml requires opening up the application manifest and adding all the localized resource files to it. Otherwise a deployment error will bite you.

So with all those problems, we decided to take a different approach for our WPF XBAP applications. We put all our strings into a standalone XAML file, producing a ResourceDictionary. This way our application can pick up strings using Text=”{StaticResource strXYZ}” for XAML markup and/or use Application.Current.FindResource(“strXYZ”) for codebehind. We name the file “Strings_en-US.xaml”. We can localize this file nicely, and name the resulting set appropriately: “Strings_de-DE.xaml”, “Strings_fr-FR.xaml” and so on. These files can then be included as resources in the application. They can also be added as “loose” XAML files, so we can add languages or make corrections after compilation.

The string resource file looks something like this:



<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:sys="clr-namespace:System;assembly=mscorlib" 
>
  <sys:String x:Key="strButtonOK">OK</sys>
  <sys:String x:Key="strButtonCancel">Cancel</sys>
</ResourceDictionary>


At application load time, we look at the CurrentCulture and attempt to load the ResourceDictionary object like this:


ResourceDictionary rd = null;
System.Globalization.CultureInfo ci = 
     System.Globalization.CultureInfo.CurrentCulture;
string langCountry = ci.Name;
string languageFile = 
     string.Format("/Resources/Strings/Strings_{0}.xaml", langCountry);
try 
{ 
  rd = (ResourceDictionary)Application.LoadComponent(
                              new Uri(languageFile, UriKind.RelativeOrAbsolute)
                                  );
}


You can imagine this with some catch {} fallbacks for when a specific language-country combination doesn’t exist. We’ll fall back to a file that’s only language specific, and if that doesn’t work out, we’ll fall back to en-US.

We’re not using CurrentUICulture, since that seems to be tied to the UI language of Vista, and we want our apps to follow what the user sets in Control Panel. CurrentCulture seems to work for that.

To load the strings into the global resource dictionary, we just do


Application.Current.Resources.MergedDictionaries.Add(rd);

To load loose XAML files that are not part of the application’s resources, we do something like this:


ResourceDictionary rd1 = null;
string languageFileLoose = string.Format(
         "pack://siteoforigin:,,,/Resources/Strings/Strings_{0}.xaml",
         langCountry
      );
Uri uri = new Uri(languageFileLoose, UriKind.Absolute);
System.Windows.Resources.StreamResourceInfo info;
System.Windows.Markup.XamlReader reader;
try {
  info = Application.GetRemoteStream(uri); 
  reader = new System.Windows.Markup.XamlReader(); 
  rd1 = (ResourceDictionary)reader.LoadAsync(info.Stream); 
}

Again, we extend this with catch {} blocks to fall back to a file that’s only language specific. We do the loose XAML loading after we’ve loaded embedded resources, so we can rely on a basic set of languages and strings, but can add languages, fix string translation errors or make improvements in the loose XAML after compiling things.

It may work for you as well, but ymmv.

Update: Changed the first Uri to UriKind.RelativeOrAbsolute