6

我正在尝试编写一个小脚本来将所有用户图像设置为他们的 AD 图像,我在 ILSpy 中进行了一些跳跃,并找到了使用 TFS 服务器 API 设置的内容,但是代码需要有点不同,因为我' m 改用客户端 API。

我下面的代码可以成功遍历 tfs 中的所有用户,在 AD 中查找它们,获取缩略图,在 TFS 标识上设置属性。但我无法终生将扩展属性保存回 TFS。

代码也不例外,但该属性未设置为我下次运行应用程序时设置的值。

有谁知道通过客户端 api 保存扩展属性的方法?

Microsoft.TeamFoundation.Client.TeamFoundationServer teamFoundationServer = new Microsoft.TeamFoundation.Client.TeamFoundationServer("{URL TO TFS}");

FilteredIdentityService service = teamFoundationServer.GetService<FilteredIdentityService>(); ;
IIdentityManagementService2 service2 = teamFoundationServer.GetService<IIdentityManagementService2>();

foreach (var identity in service.SearchForUsers(""))
{
    var user = UserPrincipal.FindByIdentity(new PrincipalContext(ContextType.Domain), identity.UniqueName);
    if (user == null) continue;
    var de = new System.DirectoryServices.DirectoryEntry("LDAP://" + user.DistinguishedName);
    var thumbNail = de.Properties["thumbnailPhoto"].Value as byte[];

    identity.SetProperty("Microsoft.TeamFoundation.Identity.CandidateImage.Data", thumbNail);
    identity.SetProperty("Microsoft.TeamFoundation.Identity.CandidateImage.UploadDate", DateTime.UtcNow);

    service2.UpdateExtendedProperties(identity);
}
4

1 回答 1

7

想通了,需要设置一些额外的属性。

Microsoft.TeamFoundation.Client.TeamFoundationServer teamFoundationServer = new Microsoft.TeamFoundation.Client.TeamFoundationServer("http://urltotfs");

FilteredIdentityService service = teamFoundationServer.GetService<FilteredIdentityService>(); ;
IIdentityManagementService2 service2 = teamFoundationServer.GetService<IIdentityManagementService2>();

foreach (var identity in service.SearchForUsers(""))
{
    var user = UserPrincipal.FindByIdentity(new PrincipalContext(ContextType.Domain), identity.UniqueName);
    if (user == null) continue;
    var de = new System.DirectoryServices.DirectoryEntry("LDAP://" + user.DistinguishedName);
    var thumbNail = de.Properties["thumbnailPhoto"].Value as byte[];

    identity.SetProperty("Microsoft.TeamFoundation.Identity.Image.Data", thumbNail);
    identity.SetProperty("Microsoft.TeamFoundation.Identity.Image.Type", "image/png");
    identity.SetProperty("Microsoft.TeamFoundation.Identity.Image.Id", Guid.NewGuid().ToByteArray());
    identity.SetProperty("Microsoft.TeamFoundation.Identity.CandidateImage.Data", null);
    identity.SetProperty("Microsoft.TeamFoundation.Identity.CandidateImage.UploadDate", null);

    service2.UpdateExtendedProperties(identity); 
}
于 2012-09-28T20:19:55.860 回答