2012-09-28 17 views
5

Sto provando a scrivere un piccolo script per impostare tutte le immagini degli utenti sulla loro immagine AD, ho fatto qualche salto in ILSpy e ho scoperto cosa impostare usando il server TFS API, tuttavia il codice deve essere un po 'diverso perché sto usando l'API del client.API per aggiornare l'immagine degli utenti - Proprietà estese identità non salvando

Il codice che ho di seguito può scorrere ripetutamente tutti gli utenti in tfs, cercarli in AD, prendere la miniatura, impostare la proprietà sull'identità TFS. Ma non posso per la vita di me ottenere la proprietà estesa per salvare di nuovo in TFS.

Il codice non fa eccezione, ma la proprietà non è impostata sul valore che ho impostato su quando eseguirò l'applicazione.

Qualcuno conosce il modo di salvare le proprietà estese tramite l'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); 
} 

risposta

7

Calcolato, necessario per impostare alcune proprietà aggiuntive.

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); 
} 
Problemi correlati