Team Foundation Server Does Not Like Encryption

Illustration

I got my laptop from repairs and I got puzzled with Team Foundation Server not working. At once I saw one reason - SQL Server would not read from database files. Tracing back my steps before repair, I just decrypted files and everything was fine once more.

However, although I could see my collection in Team Foundation Server Administration Console I could not connect to it neither through Visual Studio 2008 neither through Visual Studio 2010. I just received message “Unable to connect to remote server”.

After confirming that indeed my server was down, I tried to start it back up from IIS Management Console. That failed with message that two additional services are stopped too - Windows Process Activation Service (incorrectly refereed to as Windows Activation Service) and World Wide Web Publishing Service.

Working on a hunch, I decrypted inetpub directory. After that was done, both services could be started once more. With that my Team Foundation Server went back among living.

Lesson of a day: be careful what you encrypt.

Core Configurator 2.0

Illustration

For those that use Windows Server Core installations there is new candy in store - Core Configurator 2.0.

Not only that this collection of scripts will help with quite a few of administration tasks, but it will do it with basic graphical interface.

Lovers of GUI, rejoice.

Google Public DNS

Illustration

Few days ago Google announced new project. This time, DNS is thing they wish to change.

What they decided to offer is public DNS service for anybody willing to re-configure his IP settings. Since having DNS at 8.8.8.8 and 8.8.4.4 is quite easy to remember, there is no problem to change it at all computers that you use.

What Google gives here is promise of speed and I must say that they deliver. Their DNS is quite speedy and stable. While I cannot say that I would miss it much if they decide to pull a plug, I must say that I had no issues with it. And little bit of speed is not a bad thing.

How to Make Sausage

Illustration

Here is recipe that I use for making sausages. These sausages can be made with pure pork, but I like to also add some beef meat.

First step is to grind meat in meat grinder. Pieces should be small, but not in paste-like form. If you don’t have meat grinder just ask your butcher to grind meat for you. Or buy minced meat. Just don’t use food processor because it will completely destroy meat texture.

Spread salt, pepper and paprika (both sweet and hot) over minced meat. In another bowl add garlic into boiling hot water and leave it to rest for fifteen minutes. Filter garlic out and pour hot water over minced meat with spices. Mix thoroughly.

After all spices are distributed evenly take a taste of meat. This step is quite necessary since hot paprika can vary from batch to batch. If it is not hot enough, just add hot paprika. During smoking sausage will loose quite a lot of water and hot paprika will surface so don’t go too wild.

Once you are satisfied with taste, fill casings (I usually use salted pig casings). You will need sausage stuffer for this step since consistency needs to be quite dense.

This sausage mix is intended for smoking and I would not recommend frying it. However, if you wish instant results, you can cook it with water on medium fire for fifteen minutes.

Ingredients:

  • 7.5 kg Minced pork
  • 2.5 kg Minced beef
  • 200 g Salt
  • 20 g Black pepper
  • 25 g Hot paprika (ground)
  • 250 g Sweet paprika (ground)
  • 250 g Garlic

Structure Alignment

Let’s begin with example:

struct Test {
    Int16 A;
    Int32 B;
}

Since Int16 has length of two bytes and Int32 has length of 4 bytes one would expect total length of 6 bytes. However, upon check (with Marshal.SizeOf) we will discover that total length is 8 bytes. This difference is expected and allocated length is due to alignment of data structures.

When 32-bit processor reads data, it will do that in chunks of 4 bytes. If we want whole value to be read in one pass, it needs to be placed on alignment boundaries. If we want to read 4 bytes, we need those bytes to be at offset 0, 4, 8… or any other multiple of 4. This also explains length of first structure. First two bytes belong to variable A, then there are two padding bytes and final four bytes are variable B. Only function of those two bytes of padding is to ensure proper offset for variable B. Exact values of padding bytes are not of interest to us.

Alignment is almost always done on natural boundary of data type. 8-bit data types (e.g. Byte) will be aligned on 1-byte boundary, 16-bit data types (e.g. Int16) will be aligned on 2-byte boundary, 32-bit data types (e.g. Int32, Single, Boolean) will be aligned on 4-byte boundary and 64-bit data (e.g. Int64, Double) will be aligned on 8-byte boundary. All data types larger than that will be also aligned on 8-byte boundary.

To show it with example:

struct Test {
    Int16 A;
    Int16 B;
    Int16 C;
}

Length of this structure will be 6. This is because every variable is on natural boundary and there is no padding needed. If we decide that B needs to be Int32, length will jump to 12. This is because byte boundary needs to be aligned on 4-byte values and we will have padding after both A and C. This also shows how important careful ordering can be. If we make C Int32, total length will be 8 - no padding.

Calculating everything by hand can be sometimes quite annoying. This is why I made this function:

using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
static void DebugStructureAlignment(object structure) {
    var t = structure.GetType();
    if (t.IsValueType) {
        Debug.WriteLine("Offset  Length  Field");
        int realTotal = 0;
        foreach (var iField in t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) {
            Debug.Write(Marshal.OffsetOf(t, iField.Name).ToString().PadLeft(6));
            Debug.Write("  ");
            int size = Marshal.SizeOf(iField.GetValue(structure));
            realTotal += size;
            Debug.Write(size.ToString().PadLeft(6));
            Debug.Write("  ");
            Debug.WriteLine(iField.Name);
        }
        Debug.WriteLine("        " + Marshal.SizeOf(structure).ToString().PadLeft(6) + " bytes total");
        Debug.WriteLine("        " + realTotal.ToString().PadLeft(6) + " bytes total (data without padding)");
    }
}

Just give it instance of structure as parameter and you will get offsets and lengths of all fields inside of it. While this function is not perfect and I would not be surprised that there are some errors inside, mostly it will just work. In case you are playing with Windows API a lot, chances are that you have something like this already written.