private static void UpdateAttachment(WacRequest wacRequest, RequestDetailsLogger logger) { string mailboxSmtpAddress = wacRequest.MailboxSmtpAddress.ToString(); string ewsAttachmentId = wacRequest.EwsAttachmentId; CobaltStoreSaver cobaltStoreSaver; if (WacUtilities.ShouldUpdateAttachment(mailboxSmtpAddress, ewsAttachmentId, out cobaltStoreSaver)) { logger.Set(WacRequestHandlerMetadata.Updated, true); cobaltStoreSaver.SaveAndLogExceptions(logger); return; } logger.Set(WacRequestHandlerMetadata.Updated, false); }
protected override Stream InternalExecute() { UserContext userContext = UserContextManager.GetUserContext(HttpContext.Current, CallContext.Current.EffectiveCaller, true); ConfigurationContext configurationContext = new ConfigurationContext(userContext); string mailboxSmtpAddress = userContext.MailboxIdentity.PrimarySmtpAddress.ToString(); CobaltStoreSaver cobaltStoreSaver; if (WacUtilities.ShouldUpdateAttachment(mailboxSmtpAddress, this.id, out cobaltStoreSaver)) { base.CallContext.ProtocolLog.Set(GetAttachmentMetadata.Updated, true); cobaltStoreSaver.SaveAndLogExceptions(base.CallContext.ProtocolLog); } else { base.CallContext.ProtocolLog.Set(GetAttachmentMetadata.Updated, false); } AttachmentHandler attachmentHandler = new AttachmentHandler(this.id, this.webOperationContext, base.CallContext, configurationContext); attachmentHandler.IsImagePreview = this.isImagePreview; Stream result; try { using (AttachmentHandler.IAttachmentRetriever attachmentRetriever = AttachmentRetriever.CreateInstance(this.id, base.CallContext)) { AttachmentHandler.IAttachmentPolicyChecker policyChecker = AttachmentPolicyChecker.CreateInstance(configurationContext.AttachmentPolicy); Stream attachmentStream = attachmentHandler.GetAttachmentStream(attachmentRetriever, policyChecker, this.asDataUri); GetAttachment.EliminateGzFileDoubleCompression(attachmentRetriever); base.CallContext.OnDisposed += delegate(object sender, EventArgs args) { if (attachmentStream != null) { attachmentStream.Dispose(); } }; if (attachmentRetriever.Attachment != null) { base.CallContext.ProtocolLog.Set(GetAttachmentMetadata.Extension, attachmentRetriever.Attachment.FileExtension); base.CallContext.ProtocolLog.Set(GetAttachmentMetadata.Length, attachmentRetriever.Attachment.Size); } result = attachmentStream; } } catch (InvalidStoreIdException innerException) { throw new OwaInvalidRequestException("Invalid ID, " + this.GetParametersForLogging(), innerException); } catch (InvalidIdMalformedException innerException2) { throw new OwaInvalidRequestException("Malformed ID, " + this.GetParametersForLogging(), innerException2); } catch (CannotOpenFileAttachmentException) { this.webOperationContext.StatusCode = HttpStatusCode.NotFound; result = null; } catch (ObjectNotFoundException) { this.webOperationContext.StatusCode = HttpStatusCode.NotFound; result = null; } return(result); }