private static CobaltStore CreateCobaltStore(IExchangePrincipal exchangePrincipal, Attachment attachment, WacRequest wacRequest, CachedAttachmentInfo attachmentInfo) { if (exchangePrincipal == null) { throw new ArgumentException("exchangePrincipal"); } if (exchangePrincipal.MailboxInfo.IsRemote) { throw new OwaInvalidRequestException("Remote mailboxes are not supported."); } Guid objectGuid = exchangePrincipal.MailboxInfo.MailboxDatabase.ObjectGuid; bool diagnosticsEnabled = WacConfiguration.Instance.DiagnosticsEnabled; MdbCache instance = MdbCache.GetInstance(); string path = instance.GetPath(objectGuid); string correlationId = HttpContext.Current.Request.Headers["X-WOPI-CorrelationID"]; CobaltStore store = new CobaltStore(path, objectGuid.ToString(), correlationId, diagnosticsEnabled, WacConfiguration.Instance.BlobStoreMemoryBudget); using (Stream contentStream = ((StreamAttachment)attachment).GetContentStream(PropertyOpenMode.ReadOnly)) { store.Save(contentStream); } store.Saver.Initialize((string)wacRequest.MailboxSmtpAddress, wacRequest.ExchangeSessionId, WacConfiguration.Instance.AutoSaveInterval, delegate { using (Stream documentStream = store.GetDocumentStream()) { WacRequestHandler.ReplaceAttachmentContent(documentStream, wacRequest); } return(true); }, delegate(Exception exception) { store.SaveFailed(exception); }); return(store); }
void IHttpHandler.ProcessRequest(HttpContext context) { RequestDetailsLogger logger = OwaApplication.GetRequestDetailsLogger; string text = context.Request.QueryString["UserEmail"]; logger.ActivityScope.SetProperty(OwaServerLogger.LoggerData.PrimarySmtpAddress, text); WacUtilities.SetEventId(logger, "WAC.BadRequest"); context.Response.TrySkipIisCustomErrors = true; try { if (WacActiveMonitoringHandler.IsWacActiveMonitoringRequest(context.Request, context.Response)) { WacUtilities.SetEventId(logger, "WAC.ActiveMonitoring"); } else { WacRequest wacRequest = WacRequest.ParseWacRequest(text, context.Request); WacRequestHandler.SetCommonResponseHeaders(wacRequest, context.Response); string text2 = wacRequest.GetElapsedTime().TotalHours.ToString("0.00"); logger.ActivityScope.SetProperty(WacRequestHandlerMetadata.SessionElapsedTime, text2); if (wacRequest.IsExpired()) { throw new OwaInvalidRequestException(string.Concat(new object[] { "Can't process ", wacRequest.RequestType, " request because the Url has expired. Hours since start: ", text2 })); } logger.Set(WacRequestHandlerMetadata.ExchangeSessionId, wacRequest.ExchangeSessionId); switch (wacRequest.RequestType) { case WacRequestType.CheckFile: WacUtilities.SetEventId(logger, "WAC.CheckFile"); WacRequestHandler.ProcessCheckFileRequest(context, wacRequest, logger); goto IL_28B; case WacRequestType.GetFile: WacUtilities.SetEventId(logger, "WAC.GetFile"); WacRequestHandler.ProcessGetFileRequest(context, wacRequest, logger); goto IL_28B; case WacRequestType.Lock: WacUtilities.SetEventId(logger, "WAC.Lock"); WacRequestHandler.IncrementLockCount(wacRequest); goto IL_28B; case WacRequestType.UnLock: WacUtilities.SetEventId(logger, "WAC.Unlock"); WacRequestHandler.DecrementLockCount(wacRequest); goto IL_28B; case WacRequestType.RefreshLock: WacUtilities.SetEventId(logger, "WAC.RefreshLock"); goto IL_28B; case WacRequestType.PutFile: WacUtilities.SetEventId(logger, "WAC.PutFile"); WacRequestHandler.ReplaceAttachmentContent(context.Request.InputStream, wacRequest); goto IL_28B; case WacRequestType.Cobalt: WacUtilities.SetEventId(logger, "WAC.Cobalt"); WacRequestHandler.ProcessCobaltRequest(context, wacRequest, delegate(Enum key, string value) { logger.ActivityScope.SetProperty(key, value); }); goto IL_28B; case WacRequestType.DeleteFile: WacUtilities.SetEventId(logger, "WAC.DeleteFile"); throw new OwaInvalidRequestException("Exchange does not support WAC's DeleteFile operation."); } WacUtilities.SetEventId(logger, "WAC.Unknown"); throw new OwaInvalidRequestException("Invalid request type"); IL_28B :; } } catch (Exception ex) { logger.ActivityScope.SetProperty(ServiceCommonMetadata.GenericErrors, ex.ToString()); logger.ActivityScope.SetProperty(WacRequestHandlerMetadata.RequestUrl, context.Request.Url.ToString()); logger.ActivityScope.SetProperty(WacRequestHandlerMetadata.UserAgent, context.Request.UserAgent); context.Response.Headers["X-WOPI-ServerError"] = ex.ToString(); if (ex is OwaInvalidRequestException || ex is OwaOperationNotSupportedException || ex is OverBudgetException) { context.Response.StatusCode = 404; } else { context.Response.StatusCode = 500; } } finally { logger.ActivityScope.SetProperty(WacRequestHandlerMetadata.WopiServerName, context.Request.Headers["X-WOPI-ServerVersion"]); logger.ActivityScope.SetProperty(WacRequestHandlerMetadata.WopiClientVersion, context.Request.Headers["X-WOPI-InterfaceVersion"]); logger.ActivityScope.SetProperty(WacRequestHandlerMetadata.WopiCorrelationId, context.Request.Headers["X-WOPI-CorrelationID"]); } }