C# 获取用户参与的特定项目
这里我使用IIdentialManagementService按名称检索指定的用户。现在,我只想检索那些团队项目,它们是TFS中的成员,并且可以为其创建任务/工作项。我的程序允许用户在TFS中创建任务,我只希望他们能够看到他们有权创建任务/工作项的项目列表C# 获取用户参与的特定项目,c#,tfs,C#,Tfs,这里我使用IIdentialManagementService按名称检索指定的用户。现在,我只想检索那些团队项目,它们是TFS中的成员,并且可以为其创建任务/工作项。我的程序允许用户在TFS中创建任务,我只希望他们能够看到他们有权创建任务/工作项的项目列表 var tfsTpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://dotnettfs:8080/tfs/")); identitySer
var tfsTpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://dotnettfs:8080/tfs/"));
identityService = tfsTpc.GetService<IIdentityManagementService>();
userId = identityService.ReadIdentity(
IdentitySearchFactor.DisplayName,
strOutlookUser,
MembershipQuery.Direct,
ReadIdentityOptions.None
);
userTpc = new TfsTeamProjectCollection(tfsTpc.Uri, userId.Descriptor);
cssService = (ICommonStructureService4)userTpc.GetService(typeof(ICommonStructureService4));
wis = userTpc.GetService<WorkItemStore>();
lstAllProjects.AddRange(cssService.ListAllProjects().ToList());
List<string> lstViewProjectNames = lstAllProjects.Select(a => a.Name).ToList();
我只想让他们能够看到他们正在进行的项目的列表
具有用于创建任务/工作项的访问权限
var tfsTpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://dotnettfs:8080/tfs/"));
identityService = tfsTpc.GetService<IIdentityManagementService>();
userId = identityService.ReadIdentity(
IdentitySearchFactor.DisplayName,
strOutlookUser,
MembershipQuery.Direct,
ReadIdentityOptions.None
);
userTpc = new TfsTeamProjectCollection(tfsTpc.Uri, userId.Descriptor);
cssService = (ICommonStructureService4)userTpc.GetService(typeof(ICommonStructureService4));
wis = userTpc.GetService<WorkItemStore>();
lstAllProjects.AddRange(cssService.ListAllProjects().ToList());
List<string> lstViewProjectNames = lstAllProjects.Select(a => a.Name).ToList();
工作项与区域关联,区域与团队项目关联
var store = wis.Projects[0]; //should be a specified project, not the first element.
WorkItem pbi = new WorkItem(store.WorkItemTypes["Product Backlog Item"]);
pbi.IterationPath = lstIterations.Where(a => a.Name == selectedIteration.ToString())
.Select(a => a.Path).First().ToString();
pbi.AreaPath = lstAreas.Where(a => a.Name == selectedArea.ToString())
.Select(a => a.Path).First().ToString();
基本步骤是:
1) 作为相关用户连接到TFS
2) 检索有问题的团队项目
3) 获取有问题的团队项目的区域
4) 检查每个节点是否具有创建工作项的能力(您可能只需要在根区域节点上执行递归检查即可)
您将需要的使用(可能不需要全部):
您看过GetEffectivePermissions了吗:通常源代码管理根目录是$/TeamProjectName。你可能只需要检查一下权限就可以了。虽然我没有尝试过,但如果我尝试过,我会尝试。我找不到对VersionControl的引用。根据visual studio 2013,Microsoft.TeamFoundation.VersionControl.Client不存在。没关系,我找到了。听起来你好像丢失了一个引用?你也可以看看这个:出于某种原因,它在我的添加引用搜索中没有返回任何搜索结果。我是手工找到的。
private TfsTeamProjectCollection GetTfsCollection()
{
return TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(this._tfsUri, this._tfsCollectionName));
}