Get all iteration paths in TFS programtically

A common way to organize work items in TFS is to assign them to different iterations. I’m using this with the scum model where every sprint corresponds to one iteration. So how can we get all iteration paths in TFS to use them in our own implementation. The information is not saved on the work items, we will need to look directly at the project object and recursively iterate on the iteration object tree to get all iteration paths.

Example project
TFSIterationPath
In this example you will be able to connect to a TFS server and get all work items based on project and iteration path listed.
Read more

Open sourced some of my projects

I recently decided to open soruce some of my projects. You can find them under Projects on the blog.

DiveBuddy Planner
http://divebuddyplanner.codeplex.com
Is decompression planning application for windows phone 7. The algorithm used is based on Buhlmann ZHL16A, ZHL16B and ZH 17B with m-value gradient conservatism. Both air, nitrox and trimix diving is supported.

Scrumy
https://scrumy.codeplex.com
Scrumy is Visual Studio plugin. The current functionality cover printing TFS item to be used on a scrum progress board or kanban board.

Message box that can center on parent form

When using the built in MessageBox class to show message you are not able to center the dialog based on the parent form. This leads to that the dialog normaly popup in the center of the screen even if the application it’s executed only cover the upper right corner for example. The solution is simple to create our own MessageBox clone with this added functionality. I was also missing a possibility to show a self closing message. So I could for example give the user 10 seconds to respond to the message, after that I would simple close the message dialog and use the default response.


Read more

Using an enum type with WCF services

I recently started to work with Windows Communication Foundation and one of the first problems I did run into was how to use enum type in WCF.

This is a small example of a data contract and a service contract/interface that makes use of the enum type.

using System;
using System.ServiceModel;
using System.Runtime.Serialization;
 
namespace Test.DataContracts
{
    [DataContract(Namespace = "Testing", Name = "JobResult")]
    public enum JobResult
    {
        [EnumMember]
        Passed = 0,
        [EnumMember]
        Failed = 1,
        [EnumMember]
        Running = 2,
        [EnumMember]
        TestFailure = 3,
        [EnumMember]
        Queued = 4,
        [EnumMember]
        JobNotFound = 5
    }
}

Read more

UI automation with accessibility object and win 32 API

In my earlier blogs (Fun with UIAutomation and calc, Fun with UIAutomation and calc 2 (event handling)) I have been talking about how to user uiautomation in .NET. Now it time to dig down bellow uiautomation and go directly to the source WIN 32 API. I have tried to translate the first calculator project to use win 32 API and accessibility object instead. The first thing that we need to-do is to create DllImport statement for user32.dll used for handling more or less all windows UI and oleacc.dll used for accessing the accessibility object. You will find my complete solution in the end of the blog.

An example of DllImport is EnumChildWindows that gives use the possibility to get all child windows to a specific window.

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumChildWindows(IntPtr parentHandle, Win32Callback callback, IntPtr lParam);

Read more

Working with windows firewall from code

Quite recently I did some automation for an installation program that was changing the firewalls rules. So to be able to test that the installation was working as expected I need a way to access information about the firewall from code and also a way to change the information to verify that the installer was able to repair the rules. I found a lot of smaller code snippets mostly in VB on the net with random quality. Since I’m big fan of C# I did decide to create my one snippet’s in C#

The basic functionality is found in the COM object hnetcfg.dll. So the first thing to-do is to get a firewall manager.

private const string CLSIDFireWallManager = "{304CE942-6E39-40D8-943A-B913C40C9CD4}";
private static NetFwTypeLib.INetFwMgr GetFirewallManager()
{
    Type objectType = Type.GetTypeFromCLSID(new Guid(CLSIDFireWallManager));
    INetFwMgr manager = Activator.CreateInstance(objectType) as NetFwTypeLib.INetFwMgr;
    if (manager == null)
    {
        throw new NotSupportedException("Could not load firewall manager");
    }
 
    return manager;
}

Getting the current profile The profile is used for all firewall rules interactions.

private static INetFwProfile GetCurrentProfile()
{
    INetFwProfile profile;
    try
    {
        profile = GetFirewallManager().LocalPolicy.CurrentProfile;
    }
    catch (System.Runtime.InteropServices.COMException e)
    {
        throw new NotSupportedException("Could not get the current profile (COMException)", e);
    }
    catch (System.Runtime.InteropServices.InvalidComObjectException e)
    {
        throw new NotSupportedException("Could not get the current profile (InvalidComObjectException)", e);
    }
 
    return profile;
}

Is firewall on or of?

public static bool IsWindowsFirewallOn
{
    get
    {
        return GetCurrentProfile().FirewallEnabled;                
    }
 
    set
    {
        GetCurrentProfile().FirewallEnabled = value;
    }
}

Read more