在通过API创建新的工作项时,无法获取TFS for AssignedTo字段中的有效用户列表(Cannot get a list of valid users in TFS for Assigned

编程入门 行业动态 更新时间:2024-10-22 08:20:49
在通过API创建新的工作项时,无法获取TFS for AssignedTo字段中的有效用户列表(Cannot get a list of valid users in TFS for AssignedTo field while creating new Workitems via API)

您好我正在尝试通过TFS API创建新的工作项,这是我在下面使用的方法,以获取可以分配工作项的有效用户列表。 不知何故,它在validUserSids行上给了我一个空引用异常。 谁知道这里有什么问题?

private string[] TFSUsers(string server) { // Get a Reference to Team Foundation Server. TeamFoundationServer tfs = tfsdata.GetTFS(server); // Get a reference to Group Security Service. IGroupSecurityService gss = (IGroupSecurityService)tfs.GetService(typeof(IGroupSecurityService)); // Resolve to SIDs Identity validUserSids = gss.ReadIdentity(SearchFactor.AccountName, "TFS Valid Users", QueryMembership.Expanded); // Resolve to actual users Identity[] validUsers = gss.ReadIdentities(SearchFactor.Sid, validUserSids.Members, QueryMembership.None); List<string> Users = new List<string>(); foreach (Identity user in validUsers) { Users.Add(user.DisplayName); } return Users.ToArray(); }

Hi I am trying to create new workitems via the TFS API and this is the method I have used below to get a list of valid users who can be assigned workitems. Somehow, it gives me a null reference exception on validUserSids line. Anyone know what's wrong here?

private string[] TFSUsers(string server) { // Get a Reference to Team Foundation Server. TeamFoundationServer tfs = tfsdata.GetTFS(server); // Get a reference to Group Security Service. IGroupSecurityService gss = (IGroupSecurityService)tfs.GetService(typeof(IGroupSecurityService)); // Resolve to SIDs Identity validUserSids = gss.ReadIdentity(SearchFactor.AccountName, "TFS Valid Users", QueryMembership.Expanded); // Resolve to actual users Identity[] validUsers = gss.ReadIdentities(SearchFactor.Sid, validUserSids.Members, QueryMembership.None); List<string> Users = new List<string>(); foreach (Identity user in validUsers) { Users.Add(user.DisplayName); } return Users.ToArray(); }

最满意答案

以下是如何获取TFS中的用户列表:

var tfs = TeamFoundationServerFactory.GetServer("http://vstspioneer:8080/tfs/VSTSDF"); var workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore)); var allowedValues = workItemStore.FieldDefinitions[CoreField.AssignedTo].AllowedValues; foreach (String value in allowedValues) { Console.WriteLine(value); }

Here's how you would get the list of users in TFS:

var tfs = TeamFoundationServerFactory.GetServer("http://vstspioneer:8080/tfs/VSTSDF"); var workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore)); var allowedValues = workItemStore.FieldDefinitions[CoreField.AssignedTo].AllowedValues; foreach (String value in allowedValues) { Console.WriteLine(value); }

更多推荐

本文发布于:2023-08-06 18:52:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1454588.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   用户列表   工作   TFS   AssignedTo

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!