Search This Blog

Loading...

Sunday, November 12, 2006

How to Get a List of Build Statuses

I have a TFS build installer utility that uses the BuildStore interface to get list of available fields to install. I wanted to filter the list with the build status field but did not find a function that returns the list so using Reflector I found out the the statuses are inside a class named BuildStatus. This class contains a list of public, static, string properties that each one of them represents a build status. The real string value of the build status property is stored in a resource named BuildTypeResource.

So in order to get the list of build statuses I wrote this method:

public static string[] GetBuildStatuses()
{
Type t = typeof(Microsoft.TeamFoundation.Build.Common.BuildConstants.BuildStatus);
ArrayList constants = new ArrayList();
PropertyInfo[] propertyInfos = t.GetProperties(BindingFlags.Public | BindingFlags.Static |
BindingFlags.FlattenHierarchy);
List<string> buildStatuses = new List<string>();
foreach (PropertyInfo propertyInfo in propertyInfos)
{
if (propertyInfo.PropertyType == typeof(string))
{
buildStatuses.Add(propertyInfo.GetValue(null, new object[] { }).ToString());
}
}
return buildStatuses.ToArray();
}

The method uses reflection in order to go through all the properties of the class and retrive their values. The result list will return:

"Build Initializing", "Getting Sources", "Sync Completed", "Compilation Started", "Compilation Completed", "Testing Started", "Testing Completed", "Successfully Completed", "Failed", "Stopped".

No comments: