TFS 11 2012 API Questions : query capacity and days off

前端 未结 3 1621
梦如初夏
梦如初夏 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.

提交回复
热议问题