Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS 11 2012 API Questions : query capacity and days off

Tags:

tfs

tfs-sdk

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?

like image 361
Sebastian Edelmeier Avatar asked Dec 21 '12 12:12

Sebastian Edelmeier


2 Answers

It's not a supported approach, and may break in the future if you upgrade to a newer version of TFS, but if you only want to read the data, you can go directly to the SQL database for your TFS server.

The specific values you need are in (assuming you're using DefaultCollection)

  • [Tfs_DefaultCollection].[dbo].[tbl_TeamConfigurationCapacity]
  • [Tfs_DefaultCollection].[dbo].[tbl_TeamConfigurationCapacityDaysOffRange]

These have references to iterations and users via GUIDs.

  • The iteration GUIDs can be found in [Tfs_Warehouse].[dbo].[DimIteration]
  • The User GUIDs can be found by searching on the user name/SSID in [Tfs_Configuration].[dbo].[tbl_Identity]

Here's a quick example that queries my capacity in hours-per-day for our January iteration:

select Capacity from [Tfs_DefaultCollection].[dbo].[tbl_TeamConfigurationCapacity] as _cap
inner join [Tfs_Configuration].[dbo].[tbl_Identity] as _user
    on _user.[Id] = _cap.[TeamMemberId]
inner join [Tfs_Warehouse].[dbo].[DimIteration] as _iter
    on _iter.[IterationGUID] = _cap.[IterationId]
        where _iter.[IterationPath]='\Code\Current\401-Jan'
        and _user.[DisplayName]='Williams, Jason'

You can use a similar approach to read the start/end date ranges for each holiday from the tbl_TeamConfigurationCapacityDaysOffRange. However, it is somewhat more complex as there are Team days off and Individual days off.

Here is the query I am using to achieve this. (It seems to work, although after 6 months of working for all our users, one of our users suddenly disappeared out of the query and I discovered that for no obvious reason I now needed to look his ID up in the IdentityMap table. The joys of reverse engineering stuff from undocumented sources :-(

select [StartTime],[EndTime] from [Tfs_DefaultCollection].[dbo].[tbl_TeamConfigurationCapacityDaysOffRange] as _cap1
    inner join [Tfs_Warehouse].[dbo].[DimIteration] as _iter1
      on _iter1.[IterationGUID] = _cap1.[IterationId]
          where _iter1.[IterationPath]='\Code\Current\401-Jan'
              and _cap1.[TeamMemberId]='00000000-0000-0000-0000-000000000000'
union
    select [StartTime],[EndTime] from [Tfs_DefaultCollection].[dbo].[tbl_TeamConfigurationCapacityDaysOffRange] as _cap2
        inner join [Tfs_DefaultCollection].[dbo].[tbl_IdentityMap] as _map
            on _map.[localId] = _cap2.[TeamMemberId]
        inner join [Tfs_Configuration].[dbo].[tbl_Identity] as _user2
            on _user2.[Id] = _map.[masterId]
        inner join [Tfs_Warehouse].[dbo].[DimIteration] as _iter2
            on _iter2.[IterationGUID] = _cap2.[IterationId]
                where _iter2.[IterationPath]='\Code\Current\401-Jan'
                    and (_user2.[DisplayName]='Williams, Jason')

You will just need to substitute appropriate values for the two places that mention the iteration path, and the Username to query.

like image 97
Jason Williams Avatar answered Oct 02 '22 09:10

Jason Williams


There is another unsupported possiblity. Have a look on website http://{tfs-server}:8080/tfs/DefaultCollection/{project}/_backlogs/Capacity/{iterationpath}. The data is behind contains the capacity information in JSON format (team-capacity-data).

https://onedrive.live.com/redir?resid=88F0C013A4398D9B%21129

like image 33
user3794016 Avatar answered Oct 02 '22 08:10

user3794016