comments edit

What a weekend in L.A! Beautiful sunny weather hovering in the mid seventies all weekend. I played soccer on both Saturday and Sunday. Watched Spiderman II (loved it). Had some of the best Chinese food I’ve had in a long while. Found time to work on RSS Bandit. Went bodysurfing at the beach. What more can I say? I’m a happy camper.

comments edit

​10. That actor who played the President was totally unconvincing\

  1. It oversimplified the way I stole the election\
  2. Too many of them fancy college-boy words\
  3. If Michael Moore had waited a few months, he could have included the part where I get him deported\
  4. Didn’t have one of them hilarious monkeys who smoke cigarettes and gives people the finger\
  5. Of all Michael Moore’s accusations, only 97% are true\
  6. Not sure - - I passed out after a piece of popcorn lodged in my windpipe\
  7. Where the hell was Spider-man?\
  8. Couldn’t hear most of the movie over Cheney’s foul mouth\
  9. I thought this was supposed to be about dodgeball\

comments edit

SpamA little while back, I had a few ideas about how to combat comment spam. My ideas were more geared towards a trust-based approach to stopping comment graffiti than spam, but they were a bit naive in some ways.

Lately, I’ve been following some conversations on various blogs attempting to address this problem. Dave Winer suggest that comments expire unless the owner does something about it.

Phil Ringnalda responds that he doesn’t want the comments to ever get indexed. This problem seems likely solved by this suggestion in From The Orient that notes that simply stripping the links out of the text themselves will make sure Google doesn’t index it.

As Derek Powazek points out, it is Google’s voracious appetite for indexing pages that is the root motivation for people to comment spam a blog. One question I have about all this is doesn’t Google honor the the robots.txt file or the META tag standard for excluding robots? Adding the following tag:


tells Google not to index the links on the given page. Another option is to add a Robots.txt file and tell Google not to index your archives. Personally, I think this second option is too draconian. I think it’s great that people find my blog when they search on how to select random records from SQL Server.

Perhaps what is needed is for us to get together and extend the Robots.txt standard and then push for Google to honor it. Now, I don’t know exactly how Google indexes a website. I don’t know if it parses it as an HTML tree, but supposing it does. It’d be great to have this ability.

<DIV noindex="false" nofollow="true">
Welcome to the comments section of this page.The content here will be indexed, but the links will not.Your spam's no good here. 

Another option is to just have a comment that indicates everything AFTER the comment should not be indexed:

This is easier for an web crawler to parse.

Combining this with an image verification system (like the one that comes with the ASP.NET resource kit from SAX), hopefully lowers the real motivation to comment spam a site. If it doesn’t increase their page rank AND they can’t automate posting it, why bother?

Another crazy idea I’ll mention (and I know this will bog down the server a bit) is to use a component that converts text to an image. That way by default, the entire comment will not be indexed. Just thought I’d throw that out there.

comments edit

I need to see if my brother-in-law can hook me up with one of these.

LONDON/TOKYO (Reuters) - Sony Corp. said on Thursday it is launching a Walkman digital music player capable of storing far more songs than Apple Computer Inc.’s market-leading iPod, while also undercutting iPod’s price. \ \ The Japanese consumer electronics maker said the 20-gigabyte device, which is its second hard-disk drive gadget aimed at unseating Apple and can store 13,000 songs, will be launched on July 10 in Japan, by mid-August in the United States and in September in Europe. \ \ Dubbed the Network Walkman NW-HD1, it marks a major upgrade to the legendary Walkman brand and the announcement comes on the 25th anniversary of the introduction of Sony’s groundbreaking portable music player – July 1, 1979.

[via Reuters]

comments edit

iTunes Art ImporterFound this on Scott Hanselman’s blog. The iTunes Art Importer.

It uses the Web Service to find Album Covers for my iTunes collection - and it just works.

That is very cool, though there may be a licensing issue with Amazon as Joshua Flanagan notes:

I’ve thought about using the Amazon Web Services for similar purposes, but I believe it is a violation of their licensing agreement to store their images locally for more than 24 hours. So, in order for the Album Art feature to work, you would always need to be connected to the internet, so the image can be retrieved each day it is used. Check out the License Agreement link on and see if you have a different interpretation.

Well, I’m always connected. Lawyer friends, any thoughts?

comments edit

collisionKoba asks:

If Michael Moore and George W. Bush collide, will they annihilate in a flash of light and energy?)

Perhaps if we did that, the energy output could fuel the country for centuries and we wouldn’t need any of Iraq’s oil.

comments edit

Sweet! This is extremely exciting. Now developing for the Linux platform is becoming a viable option. Perhaps I can start putting penguins in my office, post on Slashdot more often, and join the 1337. ;). Miguel notes:

We vastly underestimated the Slashdot effect. There were 85k hits in the first hour since we went live, and then the machine collapsed under the weight and has remained in that state despite repeated attempts to get some data out of it.

[Via Miguel de Icaza]

comments edit

ThermometerDave Winer the founder of RSS and a popular member of the so-called blogosphere writes:

Yesterday on NPR they played an excerpt where he confronts members of Congress and asks if they would send their children to fight in Iraq. What a ridiculous question. No parent will say yes to that question. You could have asked that question on the Capitol steps during World War II and they still wouldn’t say yes. See how this cheapens the question of whether we should be in Iraq? In a smart world, we wouldn’t be there, but it isn’t because Congress people won’t say yes when confronted by a camera crew. \ \ Moore is the worst of American politics, an opportunist, an anti-intellectual. \ \ Vote no on Moore.

With all due respect, I think Dave misses the point of Moore’s questioning. Of course it’s a ridiculous question and no parent would say yes. That’s the whole point. We’re sending children (primarily of the poorer sections of society) to fight and die based on conspicuously absent evidence. Where are the WMDs? Where is the tie to Al Queda? Yet our Congress and the President so cavalierly send these troops to Iraq. Would they be so cavalier if their own children were in any danger of being sent to Iraq? The point of the question is to emphasize that these aren’t faceless people we’re sending. We’re sending the sons of daughters of fellow Americans. The point is to get these Congress members to consider the pain they would feel if their own sons and daughters were sent.

As for WWII, I don’t believe comparing the Iraq conflict to World War II is a useful comparison. First of all, we were attacked by the enemy we engaged. Iraq did not attack us, Al Queda did. In that effort, kids under 18 faked documents in order to join the effort. People were proud to serve or have their kids serve. It was widely seen as a just and necessary war.

comments edit

IraqMy response to Dave Winer’s post about Michael Moore’s new movie has generated a lot (for me) comments. I appreciate the comments whether you’re in agreement with me or not. I’d like to address them for a moment with this post. Dave Winer, in his response to my post, asks:

Who was it who said that “I disagree with everything he says but I’ll fight to the death for his right to say it.”

The answer, at least according to a letter printed in this article, is Rush Limbaugh (though he was probably quoting someone else). I feel the same way about Rush, but if he were to make a movie, I’d at least see it before speaking out against it. ;) And, I’d also like to point out that I am NOT making the claim (and I said this before) that Fahrenheit 9/11 is unbiased journalism. I don’t think even Mr. Moore himself is that audacious. So with that, let me jump in.

Did I Miss the Point?\ Randy says I miss the point because one of the senators has a nephew on the way to Afghanistan. However, for the record, the reason we went to Afghanistan is NOT the same reason we went to Iraq. Even the administration (when they try to get their story straight) will admit to that somewhat. Secondly, Moore does mention in the movie that one congress person has a son or relative in Iraq. I wish he had interviewed that person, but the fact that he didn’t interview this one person out of the 433 (active) members of the House and 100 senators does not make the scene pointless.

Who Said Germany Attacked The US?\ Several commenters questioned my grasp of history. Kris asks “Germany attacked the UNited States in WW2?. says, “We were attacked by Germany prior to entering world war II? Really?… *snip* Seems like your grasp of history is pretty selective…”. Why is everyone talking about Germany? I never said Germany. I’m referring to a little event called Pearl Harbor on December 7, 1941 in which the Japanese attacked the United States on U.S. soil. Though we supported the war effort prior to this event, we didn’t enter the war until this event.

Is It Primarily The Poor In The Military\ Kris says, “‘primarily of the poorer sections of society’ … spoken like a true college graduate. What about the pro football player Pat Tillman?”.\ Are you implying that the army is primarily made up of NFL football players? No offense intended, but I assume you’re not a statitician nor a demographer. My college education taught me not to look at anecdotal evidence as fact. I didn’t claim everyone in the military is poor. My dad was in the military, he didn’t come from that poor a family. However, the military attracts many more people from the less affluent than the more affluent. The rich don’t need the GI bill to send their kid to college.

What About Putin?\ Richard points out that Putin warned the U.S. about possible Iraqi terror attacks. That’s actually an interesting point, but it’s too early to say much about it, since that just came out recently and I don’t know enough about it as it relates to timing and specificity. Richard’s point leads into a whole ‘nother discussion about the doctrine of preemption etc, of which I think is a mistake.

Conclusion\ Whatever his goals, Michael Moore succeeding in generating a lot of discussion, even from those who haven’t seen the movie. I agree that asking congress people to send their kids to Iraq is a ridiculous proposition, especially since you can’t compell another person to join. It’s a personal decision. But I still contend that Moore makes a good point with that stunt. Basically, its the point of the movie:

They serve so that we don’t have to. They offer to give up their lives so that we can be free. It is, remarkably, their gift to us. And all they ask for in return is that we never send them into harm’s way unless it is absolutely necessary. Will they ever trust us again?

Like I said, I appreciate the comments.

comments edit

At least it wasn’t what I expected.  By default, the current directory for your Windows service is the System32 folder.  I keep forgetting that which causes me problems when I try to access a file or folder using a relative path.


Use the above line of code to set the current directory to the same directory as your windows service. Don’t say I didn’t warn you. I shall never forget again.

comments edit

Surprisingly, most of my good friends who read this blog don’t care much about software development or .NET. They’re not riveted by gripping stories of flexible configuration section handlers, or the heart palpitating episodes of my titanic battle with the StringDictionary’s handling of string casing. Nor do they spend their leisure moments contemplating new and exciting IBlogExtension plugins.

What, pray tell, do these people do for fun, you ask? It’s still a mystery to me.

Last night my friend Walter told me that his interest wanes when I post a long ode to code. He’s one of those guys who like to read the “Human Interest” stories in the paper (and my blog).

Many blogs (mine included) have post categories to group entries. I could suggest that he subscribe to every category except for the Software Dev & .NET, but as he uses to subscribe, that would really clutter his main page. It’d be great if Yahoo provided the ability to subscribe to multiple categories of a single blog and present that as one blog. At the very least they could display the category for blog items.

However, if you don’t mind the clutter, here are links to the RSS feeds for each of my categories (thus far).

[Listening to: Star 69 - Fatboy Slim - Halfway Between The Gutter And The Stars (5:43)]

comments edit

And I expect my arms to be tired (ba-dump pshhh).

We’re heading over there on July 28 to see my wife’s best friend (from back when they lived in Japan) and her husband.  She’s working on her residency at some hospital somewhere over there (I know so much). How’s the weather been up there? Being a transplanted Alaskan, I’m a big fan of the Northwest. I expect that the days will be nice and long. 

It’s been a long time since I’ve been up to Seattle. Any recommendations?

comments edit

Finally I’ve gotten around to contributing an article to the Code Project community. Writing articles and whatnot has always been on my //TODO: list, but until now, I’ve only had articles published on my blog (not counting the RSS Bandit user documentation)

Surprise of surprises, the article I submitted is about a configuration section handler. Basically the same thing I posted here. Code Project is fine with that as long as I’m the copyright holder of the article.

Ok, so that’s two technical posts in a row, time to write something non-geek… Think! Think!

comments edit

Ian Griffiths points out why he doesn’t like configuration section handlers much, and one of the primary reasons is how they require extra “cruft” in order to tell .NET about the handler. I have to agree for the most part. I’ve always wanted a #region tag for the App.config file just to hide that junk away, but that’s pretty much a cop out. Cyrus points out how the C# team was ambivalent about even having a region tag in the IDE.

One good point Ian and Craig (via email) brought up is that configuration sections are often misused. I should have stated this in my article, but I’ll state it here for the record. Perhaps I’ll even use an H2 tag and all caps. Here goes.


That’s not what it’s there for. Remember, the application configuration file is stored in your application’s directory of the Program Files directory (by default). If you’re a proper windows logo programmer, you’ll know that the typical user should not have write access there. Otherwise you don’t deserve that shiny “Designed forWindows XP” icon.

I tend to write a lot of Windows Services. I try to build an installer for each one that provides a GUI for the user to enter in some configuration data which gets written to the config file upon installation. That’s pretty much the only time my config files get modified unless we need to adminstratively change something or other. Note the use of an administrator and not a user.

For more information about persisting user settings, check out:

comments edit

Today I ran into an annoying nuance of the StringDictionary class (located in the System.Collections.Specialized namespace so as not to be confused with the other imposter string dictionaries). It’s not a bug, but I feel the API for it could have been slightly better on this minor point.

Right there in the documentation for the class it points out that:

The key is handled in a case-insensitive manner; it is translated to lower case before it is used with the string dictionary.

Thus it takes the key you give it, and changes it to a lower case value before storing it. I verified this with Reflector.


public virtual void Add(string key, string value)
      this.contents.Add(key.ToLower(CultureInfo.InvariantCulture), value);

Whoa there! Stop the presses! Call Michael Moore! Ok, ok. So in the grand scheme of things, it’s a minor issue. It’s not a huge deal. However, API usability (and language design) focuses on keeping the minor annoyances to a minimum. Otherwise they’ll add up and form a major disturbance and soon you’ll have an angry developer standing on his/her soap box whining and ranting about it on a blog.

The issue for me is that this wasn’t the behavior I expected. If an API is going to change data you give it, I wish it would indicate that somehow. Perhaps the method could be AddKeyAndValueButLowerCaseTheKey() ;). All joking aside, it isn’t necessary to lower-case the key before storing it in order to provide case-insensitive storage. Internally, StringDictionary uses a HashTable to store its keys and values. The dictionary could have made the HashTable use a CaseInsensitiveHashCodeProvider when storing keys. That way the key doesn’t have to change, but you get case insensitivity.

In any case, like I said, it’s normally not a big deal except for the fact that I am building a Setup and Deployment project within Visual Studio.NET for a Windows service. When building a project installer, the Installer (in the namespace System.Configuration.Install) class provides a property called Context of type InstallContext. This class gives you a property called Parameters which is a StringDictionary containing values you may have pulled from the user interface.

I’m trying to look up nodes within an XML file that correspond to the keys of the Parameters dictionary using XPath, hoping to update the node values with the values from the dictionary. However, XPath is case sensitive so I can’t match these things up. Unfortunately I can’t change the XML to be all lower case, and I can’t change the Installer class to not use a StringDictionary (or better yet, correct the dictionary’s behavior), so I’m stuck with resorting to a hack until something better comes along.

comments edit

UPDATE: In ASP.NET 2.0, there’s an even easier approach that supercedes this one. I wrote about it here.

A while back Craig Andera wrote an excellent article entitled The Last Configuration Section Handler I’ll Ever Need which outlines a really nice and flexible configuration section handler. It is certainly a big time saver and was the leading contender as the last one I would ever need as well. That is until I realized it lacked one minor feature I need: the ability to reload itself when the config file changes.

Before continuing, please do go and read his article for background. It’s pretty short and well written. No really, go read it while I listen to

[American Dream (Joey Negro Club Mix) - Jakatta - Essential Mix - Mixed By Pete Tong (5:22)]

Having read his article, it should be apparent why reloading the settings when the file changes is a challenge. Mainly because you most likely will have a reference to your simple settings object (such as the MyStuff class in the article) which has to somehow be notified that a change has occurred. As you can see from the sample below, classes used to hold settings (such as the MyStuff class) are deliberately kept very simple in order to facilitate writing many of them. There’s no facility to watch for changes to the config file.

public class MyStuff {   private float foo ;   private string bar;   public float Foo   {     get { return foo ; }     set { foo = value ; }   }   public string Bar   {     get { return bar; }     set { bar = value ;   } } 

So after a bit of thought and a bit more beer, I came up with a solution that I believe still retains the simplicity of his approach, while adding the ability to have the settings dynamically get updated when the config file changes. My approach is also backwards compatible with existing setting objects created using his approach. Existing setting objects will not need any changes to work, though they won’t get the benefit of this new feature.

I’ve extended Craig’s solution with the addition of the XmlSectionSettingsBase abstract class. The purpose of this class is to act as the base class for your simple setting object. To add the ability to reload itself, just have your class inherit from XmlSectionSettingsBase and call the UpdateChanges() method before each property getter. As an example, I’ve modified the above settings object:

public class MyStuff : XmlSectionSettingsBase{   private float foo ;   private string bar;   public float Foo   {     get     {       UpdateChanges();      return foo ;     }     set { foo = value ; }   }   public string Bar   {     get     {       UpdateChanges();      return bar;     }     set { bar = value ;   } } 

That’s it! That is the total amount of changes to the settings class needed so that it will now track changes. I’ve also updated the XmlSerializerSectionHandler class as well. It’s now pretty small:

public class XmlSerializerSectionHandler : IConfigurationSectionHandler {   public object Create(object parent, object context, XmlNode section)  {    return XmlSectionSettingsBase.LoadSettings(section);  } }

Which leads us to the XmlSectionSettingsBase class which is the workhorse of my scheme. You’ll notice that I’ve removed all the logic from the section handler for loading the settings object from the config file. The reason for this is that the instance of the settings object has to know how to load itself from the config file if its going to watch it for changes. Since I didn’t want to duplicate logic, I moved that code to this class. I’ll outline the class with some broad strokes and let you download the source code for the complete picture.

First, let’s start with the static LoadSettings method.

public static object LoadSettings(XmlNode section){  object settings = DeserializeSection(section);  XmlSectionSettingsBase xmlSettings = settings        as XmlSectionSettingsBase;  if(xmlSettings != null)  {    xmlSettings._rootName = section.Name;    ((XmlSectionSettingsBase)settings).WatchForConfigChanges();  }   return settings;}

This method deserializes an instance of your settings object and checks to see if it inherits from XmlSectionSettingsBase. If not, it just returns, keeping this approach backwards compatible. Otherwise it calls WatchForConfigChanges which sets up a FileSystemWatcher to monitor for changes to the config file. Also notice that it stores the name of the config section node in a private member (_rootName) of the settings class. This becomes important later when we need to reload the settings.

void WatchForConfigChanges(){  FileInfo configFile = new FileInfo(    AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);  try   {     _watcher = new FileSystemWatcher(configFile.DirectoryName);    _watcher.Filter = configFile.Name;    _watcher.NotifyFilter = NotifyFilters.LastWrite;    _watcher.Changed +=       new FileSystemEventHandler(OnConfigChanged);    _watcher.EnableRaisingEvents = true;  }  catch(Exception ex)  {    Log.Error("Configuration problem.", ex);    throw new ConfigurationException("An       error occurred while attempting to watch for file       system changes.", ex);  }}

When a change occurs, the OnConfigChanged method is called. This method simply updates a boolean flag. This is the flag that the UpdateChanges method mentioned earlier checks before actually applying changes to the settings object.

void OnConfigChanged(object sender, FileSystemEventArgs e){  _isDataValid = false;}protected void UpdateChanges(){  if(!_isDataValid)    ReloadSettings();}

Now we hit upon the ReloadSettings method. This method uses the name of the node containing the config section we stored earlier (_rootName) in order to load an XmlDocument containing the new settings from the config file.

void ReloadSettings(){  XmlDocument doc = new XmlDocument();  doc.Load(    AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);  XmlNodeList nodes = doc.GetElementsByTagName(_rootName);  if(nodes.Count > 0)  {    //Note: newSettings should not watch for config changes.     XmlSectionSettingsBase newSettings =        DeserializeSection(nodes[0]) as XmlSectionSettingsBase;    newSettings._isDataValid = true;    CopySettings(newSettings);  }  else     throw       new System.Configuration.ConfigurationException(        "Configuration section " + _rootName + " not found.");}

The path to the config file is retrieved via a the AppDomain.CurrentDomain.SetupInformation.ConfigurationFile property. Once we have the section, we can call DeserializeSection to get an instance of our settings class with the new settings. This method is pretty is the same as the Create method in Craig’s version.

static object DeserializeSection(XmlNode section){  XPathNavigator navigator = section.CreateNavigator();   string typename =     (string)navigator.Evaluate("string(@type)");  Type type = Type.GetType(typename);  if(type == null)    throw new       ConfigurationException("The type ’" + typename       + "’ is not a valid type.       Double check the type parameter.");  XmlSerializer serializer = new XmlSerializer(type);   return serializer.Deserialize(new XmlNodeReader(section));}

After loading this new settings instance, I overwrite the current instance’s property values with the values from the new settings instance via a call to CopySettings.

void CopySettings(object newSettings){  if(newSettings.GetType() != this.GetType())    return;  PropertyInfo[] properties =     newSettings.GetType().GetProperties();  foreach(PropertyInfo property in properties)  {    if(property.CanWrite && property.CanRead)    {      property.SetValue(this,         property.GetValue(newSettings, null), null);    }  }}

Copy Settings uses reflection to iterate through all the public get properties of the new settings object and sets the corresponding property of the current instance if the current property can be written to.

And that’s the gist of it. So that you can try it out immediately, I zipped up a Visual Studio.NET 2003 solution (Haack.ConfigurationSolution.sln) that contains two Class Library projects: Haack.Configuration and UnitTests.Haack.Configuration. The first project contains the code outlined in this article including the modified MyStuff settings class. The second project contains a unit test (for NUnit) that demos the config section handler in action. This project also has couple of sample config files that use the section handler and reference the MyStuff class. The test runs through the following steps:

  • Creates a config file from an embedded resource (App.config).
  • Obtains an instance of MyStuff via the configuration section handler.
  • Verifies the original setting values.
  • Overwrites the config file using the NewApp.config embedded resource.
  • Verifies that properties of the MyStuff instance have been updated.

I made sure to package up NUnit as well so that you can run the test immediately. Also included with the zip file is some MSDN style documentation generated via NDoc.

[Download the Source]

Let me know if you find this useful, if you find any bugs, or if you have suggestions for improvement. Just drop me a line in the comments.

UPDATE: I updated the links to Craig’s articles and blogs so that they are no longer broken.

comments edit

For the uninitiated, a 404 message is a page that tells you that the file you requested cannot be found. Apparently, this site decided to have fun with it.