Search This Blog

Tuesday, April 17, 2007

How to Get Build Result Details using TFS API - Part 3

The previous post in this series was about the build steps section of the build report. In this post we will see how to retrieve the associated changesets section details.

Using the BuildStore object we have created in this post we can get a list of ChangeSetData objects that contain the needed information (an example on how to get the buildUri parameter value available in this post also):

ChangeSetData[] changesets = buildStore.GetChangeSetsForBuild(buildUri);


foreach (ChangeSetData changeset in buildReport.Changesets)

{

MessageBox.Show(changeset.ChangeSetId.ToString());

MessageBox.Show(changeset.ChangeSetUri);

MessageBox.Show(changeset.CheckedInBy);

MessageBox.Show(changeset.Comment);

}


Thursday, April 12, 2007

Extracting Images from Work Items Attachments

In this example I will show how to use the WorkItemStore interface. This example will execute a stored query on the work items database and will extract the attachments from the work items returned from the query. This is a good training for working with the WorkItemStore interface.

private void ExtractWorkItemsAttachments(string teamFoundationServer, string teamProject, string storedQuery,

string saveTo)

{
//Logon to the server and create the needed objects
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(teamFoundationServer);
tfs.EnsureAuthenticated();
WorkItemStore store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
Project tfsProject = store.Projects[teamProject];
StoredQueryCollection sqc = tfsProject.StoredQueries;
string querystring;
//Search for the query
foreach (StoredQuery query in sqc)
{
if (query.Name == storedQuery)
{
//Execute the query
querystring = query.QueryText;
querystring = querystring.Replace("@project", "'" + tfsProject.Name + "'");
WorkItemCollection workItems = store.Query(querystring);
//Extract the attachments
foreach (WorkItem workItem in workItems)
{
if (workItem.Attachments.Count > 0)
{
foreach (Attachment attachment in workItem.Attachments)
{
//Using WebClient to download the attachment
WebClient webClient = new WebClient();
webClient.Credentials = CredentialCache.DefaultCredentials;
string fileName = Path.Combine(saveTo, attachment.Name);
webClient.DownloadFile(attachment.Uri.AbsoluteUri, fileName);
}
}
}
}
}
}

Tuesday, April 10, 2007

How to Get Build Result Details using TFS API - Part 2

The previous post in this series was about the summary section of the build report. In this post we will see how to retrieve the build steps section details.
Using the BuildStore object we have created in the previous post we can get a list of BuildStepData objects that contain the needed information (an example on how to get the buildUri parameter value available in the previous post also):

BuildStepData[] buildSteps = buildStore.GetBuildSteps(buildUri);

Now we can go through all the objects in the collection and retrieve details for each one of them.

foreach (BuildStepData in buildSteps)
{
MessageBox.Show(buildStep.BuildStepMessage);
MessageBox.Show(buildStep.BuildStepName);
MessageBox.Show(buildStep.FinishTime.ToString());
MessageBox.Show(buildStep.Status.ToString());
}