Sasha Sydoruk

Building a better mousetrap with XHTML, AJAX and RSS

TFS - HowTo - Get a list of users and pending changes

using System;
using System.Collections.Generic;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace SashaSydoruk
{
    internal class Example
    {
        private static Dictionary<string, List<string>> pendingChanges = new Dictionary<string, List<string>>();

        public static void Main()
        {
            TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(“tfsserver”);
            VersionControlServer vcs = (VersionControlServer) tfs.GetService(typeof(VersionControlServer));

            PendingSet[] sets = vcs.GetPendingSets(new String[] {“$/”}, RecursionType.Full);

            foreach(PendingSet set in sets)
            {
                foreach(PendingChange pc in set.PendingChanges)
                {
                    AddPendingChange(set.OwnerName, pc.LocalItem);
                }
            }

            List<string> userNames = new List<string>(pendingChanges.Keys);
            userNames.Sort();
            foreach(string userName in userNames)
            {
                pendingChanges[userName].Sort();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(userName);
                Console.ResetColor();

                foreach(string fileName in pendingChanges[userName])
                {
                    Console.WriteLine(fileName);
                }
                Console.WriteLine();
                Console.WriteLine();
            }

            Console.ReadKey();
        }

        private static void AddPendingChange(string username, string filename)
        {
            if(!pendingChanges.ContainsKey(username))
            {
                pendingChanges[username] = new List<string>();
            }

            pendingChanges[username].Add(filename);
        }
    }
}

No comments yet. Be the first.

Leave a reply