Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
581 views
in Technique[技术] by (71.8m points)

tfs 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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]='CodeCurrent401-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]='CodeCurrent401-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]='CodeCurrent401-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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...