【发布时间】:2018-05-18 23:18:17
【问题描述】:
我们在一台 TFS 服务器下有多个集合,每个集合都有多个项目。我希望能够检查输入的用户名是否是 TFS 服务器上任何项目级别组的一部分。 到目前为止,我能够连接到 TFS,并获取集合下的所有项目名称。我需要帮助来查找组名,然后查询这些组以检查用户是否属于该组。
这是我尝试过的代码 -
static void Main(string[] args)
{
NetworkCredential netCred = new NetworkCredential(@"username", @"pwd");
TfsConfigurationServer configServ = new TfsConfigurationServer(new Uri("https://my-tfs.schwab.com/tfs"), netCred);
var tfsAllCols = new List<KeyValuePair<Guid, string>>();
try
{
configServ.Authenticate();
Console.WriteLine("Autheticated in server with ad creds...");
ReadOnlyCollection<CatalogNode> colNodes = configServ.CatalogNode.QueryChildren(
new[] { CatalogResourceTypes.ProjectCollection },
false,
CatalogQueryOptions.None);
foreach (CatalogNode node in colNodes)
{
var colId = new Guid(node.Resource.Properties["InstanceId"]);
TfsTeamProjectCollection teamProjectCollection =
configServ.GetTeamProjectCollection(colId);
tfsAllCols.Add(new KeyValuePair<Guid, string>(colId, teamProjectCollection.Name));
}
//hardcoding the colname for testing
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("https://ruby-tfs.schwab.com/tfs/colname/"), netCred);
tpc.EnsureAuthenticated();
// Get the catalog of team project collections
ReadOnlyCollection<CatalogNode> projNodes = tpc.CatalogNode.QueryChildren(
new[] { CatalogResourceTypes.TeamProject },
false, CatalogQueryOptions.None);
}
catch (Exception ex)
{
throw ex;
}
Console.ReadLine();
}
【问题讨论】:
-
提示:Best practices for catching and re-throwing .NET exceptions。此外,您是否遇到错误?