Sunday, July 31, 2011

Creating a composite key in your container

If you need to create a composite key (for a dictionary for example) where the natural key could come from multiple sources a standard technique is to prepend the source to the natural key to ensure that it is unique. However, this can still cause duplicate keys so to solve this problem you should always add a delimiter between any concatenations that you do.

The problem is easily illustrated by looking at how files are managed in folders. Typically the composite key is the fully directory path and file name which identifies the file you are looking for. The delimiter is the backslash.

Say you had 2 files: bat.txt and mybat.txt

Let's say that they were in 2 directories:
c:\temp\somy and c:\temp\so

Without those backslashes we would have:
giving us the same key.

So in code you may have:

public void AddItem(string source, string itemName,
  object data, Dictionary<string, object> myDictionary)
     string compositeKey = source + "+" + itemName;
     myDictionary.Add(compositeKey, data);

Tuesday, July 26, 2011

Disable thumbs.db in Win7

Notes for self on how to do this.

  1. Start Local Group Policy Editor.
    1. From start menu type gpedit.msc and hit enter.
  2. Navigate the left pane:
    1. User Configuration
    2. Administrative Templates
    3. Windows Components
    4. Windows Explorer
  3. On right hand side find:
    1. Turn off the caching of thumbnails in hidden thumbs.dg files
    2. Double click this item.
    3. Change value to Enabled

Other notes:

Might need to log off and log on again.

Will not delete existing thumbs.db file.