kam*_*cus 26 .net testing tfs tfs2008 tfs2010
我有一些答案!随意贡献自己的发现.
据我所知,有三种主要方法可以从TFS中检索一个简单的团队项目列表:
我在进行的简单测试中比较了计算返回项目总数时的三种方法.
方法1:目录服务(仅限TFS 2010)
public IEnumerable<string> GetTeamProjectNamesUsingCatalog()
{
ReadOnlyCollection<CatalogNode> projectNodes = new TfsTeamProjectCollection(collectionUri).CatalogNode.QueryChildren(
new[] { CatalogResourceTypes.TeamProject },
false, CatalogQueryOptions.None);
foreach (var tp in projectNodes)
yield return tp.Resource.DisplayName;
}
Run Code Online (Sandbox Code Playgroud)
方法2:VersionControlServer
public IEnumerable<string> GetTeamProjectNamesUsingVCS()
{
TfsTeamProjectCollection tp = new TfsTeamProjectCollection(collectionUri);
foreach (var p in tp.GetService<VersionControlServer>().GetAllTeamProjects(false))
yield return p.Name;
}
Run Code Online (Sandbox Code Playgroud)
方法3:ICommonStructureService
public IEnumerable<string> GetTeamProjectNamesUsingStructureService()
{
var structService = new TfsTeamProjectCollection(collectionUri).GetService<ICommonStructureService>();
foreach (var p in structService.ListAllProjects())
yield return p.Name;
}
Run Code Online (Sandbox Code Playgroud)
我跑的单元测试非常简单.我使用.Count()方法来确保我们迭代所有团队项目(.Any()更快,因为它将在返回第一个名称后停止).
结果
对于TFS 2010,连续5次运行3次测试:


对于TFS 2008,连续5次运行2次测试(无目录服务):


偏见
TfsTeamProjectCollections; 你还需要迭代这些.在这个测试中,我只使用了一个集合.TfsTeamProjectCollection; 我切换到使用该TfsTeamProjectCollectionFactory.GetTeamProjectCollection()方法,每次测试运行实际上都比较慢.如果您为每个请求拨打多个电话,可能会更快.发现
正如您所看到的,在第一次执行后ICommonStructureService发现所有团队项目似乎相当快.注意:我使用(TFS 2010 API中的新增功能)进行了早期测试,并且相同的代码比其他两种方法慢.ICommonStructureService3
如果一致的表现是关键,我想我建议VersionControlServer这样做.
但请记住,您希望对团队项目执行什么操作.如果仅仅列出它们就是您所需要的,那么ICSS可能就是您的选择.如果要使用列表进行导航,还需要路径($/TeamProject)或Uri.在这种情况下,VCS可能是最好的方法,因为您可以使用ServerItem属性,该属性保存项目的路径.您也可以使用ICSS("$/" + p.Name)来避免使用简单的字符串连接.
希望这有助于其他一些TFS API开发人员.
| 归档时间: |
|
| 查看次数: |
7968 次 |
| 最近记录: |