为C#VS2012和VS2013获取TFS身份用户的mailaddress

时间:2013-10-25 15:37:46

标签: c# email visual-studio-2012 tfs visual-studio-2013

我在获取VS2013的TFS用户的MailAddress属性时遇到问题。以前,我使用IGroupSecurityServiceInterface来获取MailAddress,但是自VS2012以来,该方法现已过时。我可以成功获取SID,但是一旦我有了这个,我就会卡住那个特定用户的MailAddress。任何帮助将不胜感激。

这是我的代码:

//Establish Connection to TFS
Uri _tfsUri = new Uri("http://tfsurl:8080/tfs");
TfsConfigurationServer _tfsConfigServer = new TfsConfigurationServer(_tfsUri, new NetworkCredential("username", "password", "domain"));
_tfsConfigServer.EnsureAuthenticated();
if(!_tfsConfigServer.HasAuthenticated)
{
    Console.Out.WriteLine("Unable to authenticate");
}
IIdentityManagementService _ims = _tfsConfigServer.GetService<IIdentityManagementService>();

//Get Members of Group Interested in

IdentityDescriptor[] _membersGroup = _ims.ReadIdentity(IdentitySearchFactor.AccountName, "[DefaultCollection]\\MemberGroup", MembershipQuery.Expanded, ReadIdentityOptions.IncludeReadFromSource).Members;

//Obtain MailAddress
foreach (IdentityDescriptor _individualMember in _membersGroup)
{
     //Get SID for individual
     string _SID = _individualMember.Identifier.ToString();

     //Get MailAddress

}

//////////////// UPDATE ////////////////////////////// ///////

我实际上能够让电子邮件地址采用不同的方法:

TeamFoundationIdentity _usersGroup = _ims.ReadIdentity(IdentitySearchFactor.AccountName, "[DefaultCollection]\\MemberGroup", MembershipQuery.Expanded, ReadIdentityOptions.IncludeReadFromSource);
TeamFoundationIdentity[] _groupMembers = _ims.ReadIdentitites(_usersGroup.Members, MembershipQuery.None, ReadIdentityOptions.None);
foreach(TeamFoundationIdentity _member in _groupMembers)
{
    string _mailAddress = _member.GetAttribute("Mail", null);
}

0 个答案:

没有答案