1

我的目标是在 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);
                   }
                }
            }

        }
4

1 回答 1

2

我使用以下代码获取 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);
 }
}

因此,首先我使用 recursive flag 获取 Valid Users 组(包括组)的所有用户QueryMembership.Expanded。然后将成员的 SID 列表转换为用户身份列表,其中所有信息都以可读的方式保存。

于 2013-08-26T07:20:40.997 回答