User Image Update APIs - Extended Identity Properties Not Saved

I am trying to write a small script to install all user images on their AD image, I jumped a bit in ILSpy and found out what to install using the TFS Server API, however the code should be bit because I use the client API instead.

The code that I have below can successfully iterate over all users in tfs, view them in AD, capture a thumbnail, set the property on the TFS identifier. But for my life, I cannot get an extended property for me to save it back to TFS.

The code is no exception, but the property is not set to the value that I set for it when I launch the application.

Does anyone know a way to save advanced properties through the api client?

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);
}
+5
1

, .

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); 
}
+7

All Articles