Search code examples
tfstfs-sdk

TFS 11 2012 API Questions : query capacity and days off


I need to get several things done with the TFS API. Among those, I have to read the Resource planning information for the sprints of each Project to display in a WPF UI.

Tagging along this guide, I now have the following method:

    private TfsTeamService _teamService;
    private ICommonStructureService4 _structureService;
    TeamSettingsConfigurationService _teamSettingsConfigurationService;

    public void GetUserIterationAssignments(IList<ProjectInfo> projects)
    {
        foreach (ProjectInfo project in projects)
        {
            Console.WriteLine(project.Name);

            TeamFoundationTeam team = _teamService.QueryTeams(project.Uri).First();
            IList<Guid> teamGuids = new List<Guid>() { team.Identity.TeamFoundationId };
            TeamConfiguration config = _teamSettingsConfigurationService.GetTeamConfigurations(teamGuids).FirstOrDefault();
            if (config != null)
            {
                foreach (string nodePath in config.TeamSettings.IterationPaths)
                {
                    var projectNameIndex = nodePath.IndexOf("\\", 2);
                    var fullPath = nodePath.Insert(projectNameIndex, "\\Iteration");
                    var nodeInfo = _structureService.GetNodeFromPath(fullPath);
                    if (nodeInfo.StartDate != null &&
                       nodeInfo.FinishDate != null)
                    {
                        foreach (TeamFoundationIdentity member in team.GetMembers(_collection, MembershipQuery.Direct))
                        {
                            Console.WriteLine("{0} is in assigned to {1} from {2}", 
                                                    member.DisplayName, 
                                                    nodeInfo.Name,
                                                    nodeInfo.StartDate,
                                                    nodeInfo.FinishDate);
                        }
                    }
                }
            }
        }
    }

What I need to print to Console (just for this example of course) is most of the information shown in the Capacity view:

enter image description here

To be more precise, I need to access

  • daily capacity
  • days off (member)
  • days off (team)

Any ideas on how to do this?


Solution

  • These values are only available from the Server Object Model (there is no Client Object Model equivalent at the moment). The interfaces and objects are all made Internal so even on the server you can't access these values.

    internal TeamCapacity GetTeamIterationCapacity(Guid teamId, Guid iterationId);

    Declaring Type: Microsoft.TeamFoundation.Server.WebAccess.WorkItemTracking.Common.DataAccess.TeamConfigurationComponent

    Assembly: Microsoft.TeamFoundation.Server.WebAccess.WorkItemTracking.Common, Version=12.0.0.0

    At the moment the only way to get to the data is through the json service (/tfs/{ProjectCollection}/{Team Project}/_api/_teamcapacity/updateteamcapacity/{Team}/{Iteration/Path}?__v=4) the Team Capacity page uses or directly from the ProjectCollection database from the tables mentioned by James Tupper.

    It looks like the json service is using Request Verification which makes it hard to use from any external system.

    Required Disclaimer:

    The server databases of TFS are not meant for extensibility, any direct queries against them are not supported and the model can change without notice, even between service packs. Querying the TFS databases directly is not supported. Changing the values in the TFS databases through any other means than the official API's will essentially put your TFS server in an unsupported state and can cause major issues when upgrading to a newer version later on.