TFS 11 2012 API Questions : query capacity and days off

前端 未结 3 1600
梦如初夏
梦如初夏 2020-12-19 13:57

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.

相关标签:
3条回答
  • 2020-12-19 14:00

    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.

    0 讨论(0)
  • 2020-12-19 14:03

    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.

    0 讨论(0)
  • 2020-12-19 14:11

    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

    0 讨论(0)
提交回复
热议问题