protected override IConfigurable ConvertDataObjectToPresentationObject(IConfigurable dataObject) { if (dataObject == null) { return(null); } ADUser aduser = (ADUser)dataObject; UserPhotoConfiguration userPhotoConfiguration = new UserPhotoConfiguration(dataObject.Identity, Stream.Null, null); if (CmdletProxy.TryToProxyOutputObject(userPhotoConfiguration, base.CurrentTaskContext, aduser, this.Identity == null, this.ConfirmationMessage, CmdletProxy.AppendIdentityToProxyCmdlet(aduser))) { return(userPhotoConfiguration); } IConfigurable result; try { ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromADUser(aduser, null); using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(exchangePrincipal, CultureInfo.InvariantCulture, "Client=Management;Action=Get-UserPhoto")) { using (MemoryStream memoryStream = new MemoryStream()) { PhotoManagementRetrievalPipeline photoManagementRetrievalPipeline = new PhotoManagementRetrievalPipeline(GetUserPhoto.PhotosConfiguration, mailboxSession, (IRecipientSession)base.DataSession, this.tracer); PhotoResponse photoResponse = photoManagementRetrievalPipeline.Retrieve(this.CreateRetrievePhotoRequest(exchangePrincipal), memoryStream); HttpStatusCode status = photoResponse.Status; if (status != HttpStatusCode.OK && status == HttpStatusCode.NotFound) { this.WriteError(new UserPhotoNotFoundException(this.Preview), ExchangeErrorCategory.Client, this.Identity, true); throw new InvalidOperationException(); } memoryStream.Seek(0L, SeekOrigin.Begin); result = new UserPhotoConfiguration(dataObject.Identity, memoryStream, photoResponse.Thumbprint); } } } catch (UserPhotoNotFoundException) { throw; } catch (Exception ex) { ExManagementApplicationLogger.LogEvent(ManagementEventLogConstants.Tuple_FailedToRetrievePhoto, new string[] { dataObject.ToString(), ((ADUser)dataObject).UserPrincipalName, ex.ToString() }); throw; } finally { this.tracer.Dump(new PhotoRequestLogWriter(GetUserPhoto.RequestLog, GetUserPhoto.GenerateRequestId())); } return(result); }
protected override void WriteResult(IConfigurable dataObject) { if (!base.ParameterSetName.Equals("Identity")) { base.WriteResult(dataObject); return; } ADUser aduser = (ADUser)dataObject; if (aduser.MailboxMoveStatus != RequestStatus.None) { base.WriteResult(dataObject); return; } this.WriteError(new ManagementObjectNotFoundException(Strings.ErrorUserNotBeingMoved(dataObject.ToString())), ErrorCategory.InvalidArgument, this.Identity, false); }