我的目标是在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);
}
}
}
}
答案 0 :(得分: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);
}
}
首先,我使用递归标记QueryMembership.Expanded
获取Valid Users组的所有用户(包括组)。将会员的SID列表转换为用户身份列表,其中包含所有信息的可读方式。