How to get all collections from TFS

淺唱寂寞╮ 提交于 2019-11-29 07:46:39
private TfsConfigurationServer configurationServer;
configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(uri);



public IList<KeyValuePair<Guid, String>> GetCollections()
{
    //ApplicationLogger.Log("Entered into GetCollections() : ");
    var collectionList = new List<KeyValuePair<Guid, String>>();
    try
    {
        configurationServer.Authenticate();

        ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(
            new[] { CatalogResourceTypes.ProjectCollection },
            false,
            CatalogQueryOptions.None);
        foreach (CatalogNode collectionNode in collectionNodes)
        {
            var collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
            TfsTeamProjectCollection teamProjectCollection =
                configurationServer.GetTeamProjectCollection(collectionId);

            if (teamProjectCollection == null)
                continue;

            collectionList.Add(new KeyValuePair<Guid, String>(collectionId, teamProjectCollection.Name));
        }
    }
    catch (Exception e)
    {
        ApplicationLogger.Log(e);
    }

    return collectionList;
}

Each returned key value pair in the list contains the collection guid and collections name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!