public void UpdateUserProfilePhoto(O365Profile person, O365Service service, Stream photoStream) { switch (service) { case O365Service.Spo: var clientContext = GetSpoClientContextForSite(SpoSite.Admin); UpdateSpoPhoto(clientContext, person.Upn, photoStream); return; case O365Service.Exo: UpdateExoPhoto(person.Upn, photoStream); break; default: throw new ArgumentOutOfRangeException(nameof(service), service, null); } }
public MemoryStream DownloadProfilePhoto(O365Profile person, O365Service service) { switch (service) { case O365Service.Spo: var clientContext = GetSpoClientContextForSite(SpoSite.MySite); var uri = person.SpoProfilePictureUrlLarge; var serverrelativePath = uri.AbsolutePath; var memoryStream = new MemoryStream(); using (FileInformation f = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, serverrelativePath)) { f.Stream.CopyTo(memoryStream); } return(memoryStream); case O365Service.Exo: var exo = GetExoClientContext(); var results = exo.GetUserPhoto(person.Upn.Upn, "HR648x648", string.Empty); if (results.Status == GetUserPhotoStatus.PhotoReturned) { var picStream = new MemoryStream(results.Photo); return(picStream); } else { throw new FileNotFoundException($"Failed to get photo from Exo for {person.Upn.Upn}"); } default: throw new ArgumentOutOfRangeException(nameof(service), service, null); } }