public bool SetProfileImage(string identity, string imagePath, out string message) { bool ret = true; message = string.Empty; byte[] image = new byte[0]; TeamFoundationIdentity i = ims2.ReadIdentity(IdentitySearchFactor.AccountName, identity, MembershipQuery.Direct, ReadIdentityOptions.None); if (i == null) { message = "User/Group [" + identity + "] not found"; ret = false; } if (!File.Exists(imagePath)) { message = "File [" + imagePath + "] not found"; ret = false; } if (ret) { try { byte[] rawImage = File.ReadAllBytes(imagePath); image = ConvertAndResizeImage(rawImage); } catch (Exception ex) { message = "Could not read the profile image: " + ex.Message; ret = false; } } if (ret) { i.SetProperty("Microsoft.TeamFoundation.Identity.Image.Data", image); i.SetProperty("Microsoft.TeamFoundation.Identity.Image.Type", "image/png"); i.SetProperty("Microsoft.TeamFoundation.Identity.Image.Id", Guid.NewGuid().ToByteArray()); i.SetProperty("Microsoft.TeamFoundation.Identity.CandidateImage.Data", null); i.SetProperty("Microsoft.TeamFoundation.Identity.CandidateImage.UploadDate", null); try { ims2.UpdateExtendedProperties(i); } catch (PropertyServiceException) { // swallow; this exception happens each and every time, but the changes are applied :S. } message = "Profile image set"; } return(ret); }
public bool ClearProfileImage(string identity, out string message) { bool ret = true; message = string.Empty; TeamFoundationIdentity i = ims2.ReadIdentity(IdentitySearchFactor.AccountName, identity, MembershipQuery.Direct, ReadIdentityOptions.None); if (i == null) { message = "User/Group [" + identity + "] not found"; ret = false; } if (ret) { i.SetProperty("Microsoft.TeamFoundation.Identity.Image.Data", null); i.SetProperty("Microsoft.TeamFoundation.Identity.Image.Type", null); i.SetProperty("Microsoft.TeamFoundation.Identity.Image.Id", null); i.SetProperty("Microsoft.TeamFoundation.Identity.CandidateImage.Data", null); i.SetProperty("Microsoft.TeamFoundation.Identity.CandidateImage.UploadDate", null); try { ims2.UpdateExtendedProperties(i); } catch (PropertyServiceException) { // swallow; this exception happens each and every time, but the changes are applied :S. } message = "Profile image cleared"; } return(ret); }