【问题标题】:Retrieving user email & display name from Team Foundation Server从 Team Foundation Server 检索用户电子邮件和显示名称
【发布时间】:2013-08-26 15:20:40
【问题描述】:

我的目标是在 TFS 中检索整个用户的所有电子邮件地址。 我终于成功地获得了用户的 SID 列表,但我认为它不行,因为我检索 SID 的组中有组,我不知道如何访问它。 这是我代码中的重要部分,希望在这里得到答案。

  TeamFoundationIdentity[] projectGroups = _ims.ListApplicationGroups(projectUri, ReadIdentityOptions.None);

            Dictionary<IdentityDescriptor, object> descSet = new Dictionary<IdentityDescriptor, object>(IdentityDescriptorComparer.Instance);

            foreach (TeamFoundationIdentity projectGroup in projectGroups)
            {
                descSet[projectGroup.Descriptor] = projectGroup.Descriptor;
            }

            // Expanded membership of project groups
            projectGroups = _ims.ReadIdentities(descSet.Keys.ToArray(), MembershipQuery.Expanded, ReadIdentityOptions.None);

            // Collect all descriptors
            foreach (TeamFoundationIdentity projectGroup in projectGroups)
            {
                foreach (IdentityDescriptor mem in projectGroup.Members)
                {
                    TeamFoundationIdentity[] _identities = _ims.ReadIdentities(new IdentityDescriptor[] {mem}, MembershipQuery.Expanded, ReadIdentityOptions.None);
                   foreach(TeamFoundationIdentity id in _identities)
                   {
                      //the sid
                      Console.WriteLine(id.Descriptor.Identifier);
                   }
                }
            }

        }

【问题讨论】:

    标签: c# tfs


    【解决方案1】:

    我使用以下代码获取 TeamProjectCollection 的所有用户:

    IGroupSecurityService gss = (IGroupSecurityService)tfsConnection.GetService(typeof(IGroupSecurityService));
    Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Users", QueryMembership.Expanded);
    Identity[] UserId = gss.ReadIdentities(SearchFactor.Sid, SIDS.Members, QueryMembership.None);
    
    foreach (Identity user in UserId)
    {    
     // check if group or user
     if (!user.SecurityGroup)
     {
      Console.Writeln(user.DisplayName +" -> "+ user.Domain + "\" + user.AccountName + "-" + user.MailAddress);
     }
    }
    

    首先我使用递归标志QueryMembership.Expanded 获取有效用户组(包括组)的所有用户。而不是将成员的 SID 列表转换为用户身份列表,其中包含所有信息以可读的方式。

    【讨论】:

    • 它可以工作,但 IGroupSecurityService 现在已经过时了。
    猜你喜欢
    • 1970-01-01
    • 2011-01-12
    • 1970-01-01
    • 1970-01-01
    • 2020-06-22
    • 1970-01-01
    • 1970-01-01
    • 2017-02-23
    • 1970-01-01
    相关资源
    最近更新 更多