【发布时间】:2014-10-12 20:30:55
【问题描述】:
这里我使用 IIdentityManagementService 按名称检索指定用户。现在我只想检索他们所属的团队项目,并且可以在 TFS 中为其创建任务/工作项。我的程序允许用户在 TFS 中创建任务,我只希望他们能够看到他们有权访问以创建任务/工作项的项目列表。
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();
【问题讨论】:
-
您是否查看过 GetEffectivePermissions:msdn.microsoft.com/en-us/library/… 通常源代码管理根目录是 $/TeamProjectName。您可能只检查那个的权限。虽然我还没有尝试过,但如果我这样做了,我会尝试。
-
我找不到对 VersionControl 的引用。根据 Visual Studio 2013,Microsoft.TeamFoundation.VersionControl.Client 不存在。没关系,我找到了。
-
听起来您缺少参考资料?
-
你也可以看看这个:codeproject.com/Articles/262673/…
-
由于某种原因,在我的添加参考搜索中没有返回任何搜索结果。我手动找到的。