public PhotoResponse Retrieve(PhotoRequest request, PhotoResponse response) { PhotoResponse result; using (new StopwatchPerformanceTracker("MailboxHandlerTotal", request.PerformanceLogger)) { using (new StorePerformanceTracker("MailboxHandlerTotal", request.PerformanceLogger)) { if (request.ShouldSkipHandlers(PhotoHandlers.Mailbox)) { this.tracer.TraceDebug((long)this.GetHashCode(), "MAILBOX HANDLER: skipped by request."); result = response; } else if (response.Served) { this.tracer.TraceDebug((long)this.GetHashCode(), "MAILBOX HANDLER: skipped because photo has already been served by an upstream handler."); result = response; } else { response.MailboxHandlerProcessed = true; request.PerformanceLogger.Log("MailboxHandlerProcessed", string.Empty, 1U); try { this.ComputeTargetPrincipalAndStampOntoRequest(request); if (request.TargetPrincipal == null) { this.tracer.TraceDebug((long)this.GetHashCode(), "MAILBOX HANDLER: skipped because target principal has not been initialized and could not be computed."); result = response; } else { this.tracer.TraceDebug <ExchangePrincipal, SmtpAddress>((long)this.GetHashCode(), "MAILBOX HANDLER: target principal: {0}; PRIMARY SMTP address: {1}", request.TargetPrincipal, request.TargetPrincipal.MailboxInfo.PrimarySmtpAddress); using (DisposeGuard disposeGuard = default(DisposeGuard)) { bool forceReloadThumbprint = true; IMailboxSession mailboxSession = request.HostOwnedTargetMailboxSessionGetter(request.TargetPrincipal); if (mailboxSession == null) { this.tracer.TraceDebug <ExchangePrincipal>((long)this.GetHashCode(), "MAILBOX HANDLER: opening session to mailbox of user {0}", request.TargetPrincipal); mailboxSession = this.CreateMailboxSession(request); disposeGuard.Add <IMailboxSession>(mailboxSession); forceReloadThumbprint = false; } int num = this.ReadThumbprintAndStampOntoResponse(request, response, mailboxSession, forceReloadThumbprint); this.tracer.TraceDebug <int>((long)this.GetHashCode(), "MAILBOX HANDLER: read photo thumbprint = {0:X8}", num); if (PhotoThumbprinter.Default.ThumbprintMatchesETag(num, request.ETag)) { result = this.ServePhotoNotModified(request, response); } else { result = this.ReadPhotoFromMailboxOntoResponse(request, response, mailboxSession); } } } } catch (ObjectNotFoundException ex) { request.PerformanceLogger.Log("MailboxHandlerPhotoAvailable", string.Empty, 0U); if (this.reader.HasPhotoBeenDeleted(ex)) { result = this.ServePhotoHasBeenDeleted(request, response); } else { this.tracer.TraceDebug <ObjectNotFoundException>((long)this.GetHashCode(), "MAILBOX HANDLER: photo not found. Exception: {0}", ex); result = response; } } catch (StorageTransientException arg) { this.tracer.TraceError <StorageTransientException>((long)this.GetHashCode(), "MAILBOX HANDLER: transient exception at reading photo. Exception: {0}", arg); request.PerformanceLogger.Log("MailboxHandlerError", string.Empty, 1U); throw; } catch (StoragePermanentException arg2) { this.tracer.TraceError <StoragePermanentException>((long)this.GetHashCode(), "MAILBOX HANDLER: permanent exception at reading photo. Exception: {0}", arg2); request.PerformanceLogger.Log("MailboxHandlerError", string.Empty, 1U); throw; } } } } return(result); }