// Token: 0x0600150A RID: 5386 RVA: 0x0004ABF4 File Offset: 0x00048DF4
        private static AttachmentIdType[] ConvertAttachmentIdsToAttachmentIdTypes(string[] attachmentIds, Item item, PolicyTipRequestLogger policyTipRequestLogger)
        {
            if (attachmentIds == null || attachmentIds.Length == 0)
            {
                return(null);
            }
            List <AttachmentIdType> list = new List <AttachmentIdType>();

            foreach (string text in attachmentIds)
            {
                AttachmentId item2 = null;
                try
                {
                    item2 = AttachmentId.Deserialize(text);
                }
                catch (CorruptDataException)
                {
                    policyTipRequestLogger.AppendData("InvalidAttachment", text);
                }
                AttachmentIdType item3 = new AttachmentIdType(new IdAndSession(item.Id, item.Session, new List <AttachmentId>
                {
                    item2
                }).GetConcatenatedId().Id);
                list.Add(item3);
            }
            return(list.ToArray());
        }
        protected override CreateAttachmentResponse InternalExecute()
        {
            UserContext userContext = UserContextManager.GetUserContext(base.CallContext.HttpContext, base.CallContext.EffectiveCaller, true);
            CreateAttachmentResponse createAttachmentResponse;

            if (this.translatedRequest.CancellationId != null && userContext.CancelAttachmentManager.OnCreateAttachment(this.translatedRequest.CancellationId, null))
            {
                createAttachmentResponse = CreateAttachmentHelper.BuildCreateAttachmentResponseForCancelled();
            }
            else
            {
                createAttachmentResponse = CreateAttachmentHelper.CreateAttachment(base.CallContext, this.translatedRequest);
                if (createAttachmentResponse != null && createAttachmentResponse.ResponseMessages != null && createAttachmentResponse.ResponseMessages.Items != null && createAttachmentResponse.ResponseMessages.Items.Length == 1 && createAttachmentResponse.ResponseMessages.Items[0].ResponseCode == ResponseCodeType.NoError)
                {
                    ((AttachmentInfoResponseMessage)createAttachmentResponse.ResponseMessages.Items[0]).Attachments[0].Size        = this.fileSize;
                    ((AttachmentInfoResponseMessage)createAttachmentResponse.ResponseMessages.Items[0]).Attachments[0].ContentType = this.contentType;
                }
                if (this.translatedRequest.CancellationId != null)
                {
                    AttachmentIdType attachmentIdFromCreateAttachmentResponse = CreateAttachmentHelper.GetAttachmentIdFromCreateAttachmentResponse(createAttachmentResponse);
                    userContext.CancelAttachmentManager.CreateAttachmentCompleted(this.translatedRequest.CancellationId, attachmentIdFromCreateAttachmentResponse);
                }
            }
            return(createAttachmentResponse);
        }
        // Token: 0x060019CC RID: 6604 RVA: 0x0005C200 File Offset: 0x0005A400
        protected override CreateAttachmentResponse InternalExecute()
        {
            UserContext             userContext             = UserContextManager.GetUserContext(base.CallContext.HttpContext, base.CallContext.EffectiveCaller, true);
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            CancellationToken       token = cancellationTokenSource.Token;

            if (this.cancellationId != null && userContext.CancelAttachmentManager.OnCreateAttachment(this.cancellationId, cancellationTokenSource))
            {
                return(null);
            }
            CreateAttachmentResponse createAttachmentResponse = null;

            try
            {
                AttachmentDataProvider provider = userContext.AttachmentDataProviderManager.GetProvider(base.CallContext, this.attachmentDataProviderId);
                createAttachmentResponse = CreateReferenceAttachmentFromAttachmentDataProvider.AttachReferenceAttachment(provider, userContext, this.location, this.dataProviderItemId, this.itemId.Id, base.IdConverter, this.dataProviderParentItemId, this.providerEndpointUrl);
            }
            finally
            {
                if (this.cancellationId != null)
                {
                    AttachmentIdType attachmentIdFromCreateAttachmentResponse = CreateAttachmentHelper.GetAttachmentIdFromCreateAttachmentResponse(createAttachmentResponse);
                    if (attachmentIdFromCreateAttachmentResponse != null)
                    {
                        userContext.CancelAttachmentManager.CreateAttachmentCompleted(this.cancellationId, attachmentIdFromCreateAttachmentResponse);
                    }
                    else
                    {
                        userContext.CancelAttachmentManager.CreateAttachmentCancelled(this.cancellationId);
                    }
                }
            }
            return(createAttachmentResponse);
        }
 // Token: 0x0600016C RID: 364 RVA: 0x00005B88 File Offset: 0x00003D88
 public void CreateAttachmentCompleted(string cancellationId, AttachmentIdType attachmentId)
 {
     OwaServerTraceLogger.AppendToLog(new TraceLogEvent("CancelAttachmentManager.CreateAttachmentCompleted", this.userContext, "CreateAttachmentCompleted", string.Format("CreateAttachment completed for AttachmentId: {0}, CancellationId: {1}.", (attachmentId == null) ? "Null" : attachmentId.Id, string.IsNullOrEmpty(cancellationId) ? "Null" : cancellationId)));
     if (cancellationId == null)
     {
         return;
     }
     this.CancellationItems[cancellationId].AttachmentId = attachmentId;
     this.CancellationItems[cancellationId].AttachmentCompletedEvent.Set();
 }
Example #5
0
        // Token: 0x0600199D RID: 6557 RVA: 0x0005A534 File Offset: 0x00058734
        internal static AttachmentIdType CreateAttachmentAndSendPendingGetNotification(UserContext userContext, string itemId, byte[] bytes, string name, CreateAttachmentNotificationPayload result, IdConverter idConverter, string channelId)
        {
            AttachmentIdType result2 = null;

            if (!userContext.IsDisposed)
            {
                AttachmentBuilder attachmentBuilder = null;
                try
                {
                    userContext.LockAndReconnectMailboxSession();
                    if (result.ResultCode == AttachmentResultCode.Success)
                    {
                        IdAndSession       idAndSession       = new IdAndSession(StoreId.EwsIdToStoreObjectId(itemId), userContext.MailboxSession);
                        FileAttachmentType fileAttachmentType = new FileAttachmentType
                        {
                            Content  = bytes,
                            IsInline = false,
                            Name     = name,
                            Size     = bytes.Length
                        };
                        AttachmentHierarchy attachmentHierarchy = new AttachmentHierarchy(idAndSession, true, true);
                        attachmentBuilder = new AttachmentBuilder(attachmentHierarchy, new AttachmentType[]
                        {
                            fileAttachmentType
                        }, idConverter, true);
                        ServiceError serviceError;
                        using (Attachment attachment = attachmentBuilder.CreateAttachment(fileAttachmentType, out serviceError))
                        {
                            if (serviceError == null)
                            {
                                attachmentHierarchy.SaveAll();
                            }
                            result.Response = CreateAttachmentHelper.CreateAttachmentResponse(attachmentHierarchy, attachment, fileAttachmentType, idAndSession, serviceError);
                        }
                        if (result.Response.ResponseMessages.Items != null && result.Response.ResponseMessages.Items.Length > 0 && result.Response.ResponseMessages.Items[0].ResponseCode == ResponseCodeType.NoError)
                        {
                            ((AttachmentInfoResponseMessage)result.Response.ResponseMessages.Items[0]).Attachments[0].Size = fileAttachmentType.Size;
                            result2 = CreateAttachmentHelper.GetAttachmentIdFromCreateAttachmentResponse(result.Response);
                        }
                    }
                    CreateAttachmentHelper.SendPendingGetNotification(userContext, result, channelId);
                }
                finally
                {
                    userContext.UnlockAndDisconnectMailboxSession();
                    if (attachmentBuilder != null)
                    {
                        attachmentBuilder.Dispose();
                    }
                }
            }
            return(result2);
        }
Example #6
0
        internal static void DownloadAndAttachFile(Guid operationId, AttachmentDataProvider attachmentDataProvider, UserContext userContext, string location, string dataProviderItemId, string parentItemId, string subscriptionId, IdConverter idConverter, string channelId, string dataProviderParentItemId, string providerEndpointUrl, CancellationToken cancellationToken, string cancellationId)
        {
            AttachmentResultCode errorCode    = AttachmentResultCode.GenericFailure;
            Exception            exception    = null;
            AttachmentIdType     attachmentId = null;

            try
            {
                OwaDiagnostics.SendWatsonReportsForGrayExceptions(async delegate()
                {
                    try
                    {
                        DownloadItemAsyncResult downloadItemResult = await attachmentDataProvider.DownloadItemAsync(location, dataProviderItemId, dataProviderParentItemId, providerEndpointUrl, cancellationToken).ConfigureAwait(false);
                        CreateAttachmentNotificationPayload result = new CreateAttachmentNotificationPayload
                        {
                            SubscriptionId = subscriptionId,
                            Id             = operationId.ToString(),
                            Bytes          = downloadItemResult.Bytes,
                            Item           = downloadItemResult.Item,
                            ResultCode     = downloadItemResult.ResultCode
                        };
                        attachmentId = CreateAttachmentHelper.CreateAttachmentAndSendPendingGetNotification(userContext, parentItemId, result.Bytes, result.Item.Name, result, idConverter, channelId);
                    }
                    catch (OperationCanceledException exception)
                    {
                        errorCode = AttachmentResultCode.Cancelled;
                        exception = exception;
                        if (cancellationId != null)
                        {
                            userContext.CancelAttachmentManager.CreateAttachmentCancelled(cancellationId);
                        }
                    }
                });
            }
            catch (GrayException ex)
            {
                ExTraceGlobals.AttachmentHandlingTracer.TraceError <string>(0L, "CreateAttachmentFromAttachmentDataProvider.DownloadAndAttachFile Exception while trying to download and attach file async : {0}", ex.StackTrace);
                exception = ex;
            }
            finally
            {
                if (cancellationId != null)
                {
                    userContext.CancelAttachmentManager.CreateAttachmentCompleted(cancellationId, attachmentId);
                }
                if (exception != null)
                {
                    CreateAttachmentHelper.SendFailureNotification(userContext, subscriptionId, operationId.ToString(), errorCode, channelId, exception);
                }
            }
        }
Example #7
0
        // Token: 0x060019A1 RID: 6561 RVA: 0x0005A864 File Offset: 0x00058A64
        internal static AttachmentIdType GetAttachmentIdFromCreateAttachmentResponse(CreateAttachmentResponse response)
        {
            AttachmentIdType result = null;

            if (response != null && response.ResponseMessages != null && response.ResponseMessages.Items != null && response.ResponseMessages.Items.Length > 0)
            {
                AttachmentInfoResponseMessage attachmentInfoResponseMessage = (AttachmentInfoResponseMessage)response.ResponseMessages.Items[0];
                if (attachmentInfoResponseMessage.ResponseCode == ResponseCodeType.NoError && attachmentInfoResponseMessage.Attachments != null && attachmentInfoResponseMessage.Attachments.Length > 0)
                {
                    result = attachmentInfoResponseMessage.Attachments[0].AttachmentId;
                }
            }
            return(result);
        }
        // Token: 0x06001AD5 RID: 6869 RVA: 0x00065E80 File Offset: 0x00064080
        private static WacAttachmentType GetResultForReferenceAttachment(CallContext callContext, UserContext userContext, GetWacAttachmentInfo.Implementation implementation, AttachmentDataProvider provider, string mailboxAddress, BaseItemId referenceItemId, string fileName, bool isEdit, string userDisplayName, string sessionId, RequestDetailsLogger logger)
        {
            GetWacAttachmentInfo.LogReferenceAttachmentProperties(logger, implementation.ResultAttachmentWebServiceUrl, GetWacAttachmentInfoMetadata.ResultReferenceAttachmentServiceUrl, implementation.ResultAttachmentContentUrl, GetWacAttachmentInfoMetadata.ResultReferenceAttachmentUrl);
            AttachmentIdType  ewsAttachmentIdType = GetWacAttachmentInfo.GetEwsAttachmentIdType(callContext, implementation.ResultItemId, implementation.ResultAttachmentId);
            WacAttachmentType result = GetWacAttachmentInfo.CreateWacAttachmentType(userContext.LogonIdentity, ewsAttachmentIdType, implementation.ResultAttachmentWebServiceUrl, implementation.ResultAttachmentContentUrl, isEdit, implementation.ResultIsInDraft);

            if (implementation.ResultAttachmentCreation == WacAttachmentCreationType.Upload)
            {
                try
                {
                    GetWacAttachmentInfo.PostUploadMessage(mailboxAddress, userContext.LogonIdentity.PrimarySmtpAddress.ToString(), userDisplayName, referenceItemId, fileName, implementation.ResultAttachmentContentUrl, implementation.ResultAttachmentProviderType, implementation.ResultAttachmentWebServiceUrl, sessionId);
                }
                catch (Exception value)
                {
                    logger.Set(GetWacAttachmentInfoMetadata.HandledException, value);
                }
            }
            return(result);
        }
Example #9
0
        protected override CreateAttachmentResponse InternalExecute()
        {
            UserContext userContext = UserContextManager.GetUserContext(base.CallContext.HttpContext, base.CallContext.EffectiveCaller, true);
            CreateAttachmentResponse createAttachmentResponse;

            if (this.request.CancellationId != null && userContext.CancelAttachmentManager.OnCreateAttachment(this.request.CancellationId, null))
            {
                createAttachmentResponse = CreateAttachmentHelper.BuildCreateAttachmentResponseForCancelled();
            }
            else
            {
                createAttachmentResponse = CreateAttachmentFromLocalFile.CreateAttachment(this.request);
                if (this.request.CancellationId != null)
                {
                    AttachmentIdType attachmentIdFromCreateAttachmentResponse = CreateAttachmentHelper.GetAttachmentIdFromCreateAttachmentResponse(createAttachmentResponse);
                    userContext.CancelAttachmentManager.CreateAttachmentCompleted(this.request.CancellationId, attachmentIdFromCreateAttachmentResponse);
                }
            }
            return(createAttachmentResponse);
        }
        // Token: 0x0600012E RID: 302 RVA: 0x0000514C File Offset: 0x0000334C
        public static bool DeleteAttachment(AttachmentIdType attachmentId)
        {
            bool result = false;

            if (attachmentId != null)
            {
                DeleteAttachmentJsonRequest deleteAttachmentJsonRequest = new DeleteAttachmentJsonRequest();
                DeleteAttachmentRequest     deleteAttachmentRequest     = new DeleteAttachmentRequest();
                deleteAttachmentRequest.AttachmentIds    = new AttachmentIdType[1];
                deleteAttachmentRequest.AttachmentIds[0] = attachmentId;
                deleteAttachmentJsonRequest.Body         = deleteAttachmentRequest;
                OWAService   owaservice  = new OWAService();
                IAsyncResult asyncResult = owaservice.BeginDeleteAttachment(deleteAttachmentJsonRequest, null, null);
                asyncResult.AsyncWaitHandle.WaitOne();
                DeleteAttachmentResponse body = owaservice.EndDeleteAttachment(asyncResult).Body;
                if (body != null && body.ResponseMessages != null && body.ResponseMessages.Items != null && body.ResponseMessages.Items[0] != null)
                {
                    result = (body.ResponseMessages.Items[0].ResponseCode == ResponseCodeType.NoError);
                }
            }
            return(result);
        }
        /// <summary>
        /// Saves all attachments belonging to a specific message. This method can only be called after the message
        /// has been saved in exchange.
        /// </summary>
        /// <param name="messageId"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public IEnumerable <ItemIdType> SaveAttachments(ItemIdType messageId, ChannelMessage message)
        {
            var binding = ChannelHelper.BuildChannel(hostname, username, password);

            // Create add attachment request.
            var attachementRequest = new CreateAttachmentType();

            attachementRequest.ParentItemId = messageId;
            attachementRequest.Attachments  = new AttachmentType[message.Attachments.Count];

            for (int i = 0; i < message.Attachments.Count; i++)
            {
                var channelAttachment = message.Attachments[i];
                var exchAttachment    = new FileAttachmentType();

                exchAttachment.Name        = channelAttachment.Filename;
                exchAttachment.ContentType = MimeHelper.GetMimeType(channelAttachment.Filename);
                exchAttachment.Content     = channelAttachment.ContentStream.GetBytes();

                attachementRequest.Attachments[i] = exchAttachment;

                var saveAttachmentResponse = binding.CreateAttachment(attachementRequest);

                // Determine whether the request was a success.
                if (saveAttachmentResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
                {
                    throw new Exception(saveAttachmentResponse.ResponseMessages.Items[0].MessageText);
                }

                AttachmentIdType attachmentId = ((AttachmentInfoResponseMessageType)saveAttachmentResponse.ResponseMessages.Items[0]).Attachments[0].AttachmentId;

                yield return(new ItemIdType {
                    ChangeKey = attachmentId.RootItemChangeKey, Id = attachmentId.RootItemId
                });
            }
        }
        // Token: 0x06001ACF RID: 6863 RVA: 0x0006569C File Offset: 0x0006389C
        public static WacAttachmentType Execute(CallContext callContext, IStoreSession originalAttachmentSession, IItem originalAttachmentItem, IAttachment originalAttachment, string draftId, string ewsAttachmentId, bool isEdit)
        {
            MdbCache.GetInstance().BeginAsyncUpdate();
            UserContext userContext = UserContextManager.GetUserContext(callContext.HttpContext, callContext.EffectiveCaller, true);

            if (userContext == null)
            {
                throw new OwaInvalidRequestException("Unable to determine user context.");
            }
            if (!userContext.IsWacEditingEnabled)
            {
                isEdit = false;
            }
            ConfigurationContext configurationContext = new ConfigurationContext(userContext);
            AttachmentPolicy     attachmentPolicy     = configurationContext.AttachmentPolicy;
            bool isPublicLogon = userContext.IsPublicLogon;

            if (!attachmentPolicy.GetWacViewingEnabled(isPublicLogon))
            {
                throw new OwaOperationNotSupportedException("WAC viewing not enabled for the current user");
            }
            MailboxSession mailboxSession = null;
            StoreObjectId  draftObjectId  = null;

            if (draftId != null)
            {
                IdAndSession idAndSession = GetWacAttachmentInfo.GetIdAndSession(callContext, draftId, false);
                mailboxSession = (idAndSession.Session as MailboxSession);
                draftObjectId  = StoreId.EwsIdToStoreObjectId(draftId);
                if (mailboxSession == null)
                {
                    throw new OwaOperationNotSupportedException("We need a MailboxSession to create the draft, but this a " + idAndSession.Session.GetType().Name);
                }
            }
            string text = originalAttachmentSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString();
            string primarySmtpAddress        = callContext.EffectiveCaller.PrimarySmtpAddress;
            RequestDetailsLogger protocolLog = callContext.ProtocolLog;

            protocolLog.Set(GetWacAttachmentInfoMetadata.LogonSmtpAddress, primarySmtpAddress);
            protocolLog.Set(GetWacAttachmentInfoMetadata.MailboxSmtpAddress, text);
            protocolLog.Set(GetWacAttachmentInfoMetadata.Edit, isEdit);
            protocolLog.Set(GetWacAttachmentInfoMetadata.Extension, originalAttachment.FileExtension);
            protocolLog.Set(GetWacAttachmentInfoMetadata.DraftProvided, draftId != null);
            string                 displayName = callContext.AccessingPrincipal.MailboxInfo.DisplayName;
            XSOFactory             factory     = new XSOFactory();
            AttachmentDataProvider defaultUploadDataProvider = new AttachmentDataProviderManager().GetDefaultUploadDataProvider(callContext);
            IReferenceAttachment   referenceAttachment       = originalAttachment as IReferenceAttachment;

            if (referenceAttachment != null)
            {
                GetWacAttachmentInfo.LogReferenceAttachmentProperties(protocolLog, referenceAttachment.ProviderEndpointUrl, GetWacAttachmentInfoMetadata.OriginalReferenceAttachmentServiceUrl, referenceAttachment.AttachLongPathName, GetWacAttachmentInfoMetadata.OriginalReferenceAttachmentUrl);
            }
            if (defaultUploadDataProvider != null)
            {
                protocolLog.Set(GetWacAttachmentInfoMetadata.AttachmentDataProvider, defaultUploadDataProvider.ToString());
            }
            WacAttachmentType wacAttachmentType;

            try
            {
                using (GetWacAttachmentInfo.Implementation implementation = new GetWacAttachmentInfo.Implementation(defaultUploadDataProvider, factory, originalAttachmentSession, originalAttachmentSession.MailboxOwner.ModernGroupType, originalAttachmentItem, originalAttachment, ewsAttachmentId, mailboxSession, draftObjectId, isEdit, displayName, (IStoreSession session, StoreId itemId, AttachmentId attachmentId) => new IdAndSession(itemId, (StoreSession)session)
                {
                    AttachmentIds =
                    {
                        attachmentId
                    }
                }.GetConcatenatedId().Id))
                {
                    implementation.Execute();
                    protocolLog.Set(GetWacAttachmentInfoMetadata.OriginalAttachmentType, implementation.OriginalAttachmentType);
                    protocolLog.Set(GetWacAttachmentInfoMetadata.ResultAttachmentType, implementation.ResultAttachmentType);
                    protocolLog.Set(GetWacAttachmentInfoMetadata.ResultAttachmentCreation, implementation.ResultAttachmentCreation);
                    if (implementation.ResultAttachmentType == AttachmentType.Reference)
                    {
                        IMailboxInfo mailboxInfo       = originalAttachmentSession.MailboxOwner.MailboxInfo;
                        string       mailboxAddress    = mailboxInfo.PrimarySmtpAddress.ToString();
                        StoreId      id                = originalAttachmentItem.Id;
                        BaseItemId   itemIdFromStoreId = IdConverter.GetItemIdFromStoreId(id, new MailboxId(mailboxInfo.MailboxGuid));
                        string       exchangeSessionId = WacUtilities.GetExchangeSessionId(default(Guid).ToString());
                        protocolLog.Set(GetWacAttachmentInfoMetadata.ExchangeSessionId, exchangeSessionId);
                        wacAttachmentType = GetWacAttachmentInfo.GetResultForReferenceAttachment(callContext, userContext, implementation, defaultUploadDataProvider, mailboxAddress, itemIdFromStoreId, originalAttachment.FileName, isEdit, displayName, exchangeSessionId, protocolLog);
                    }
                    else
                    {
                        if (implementation.ResultAttachmentType != AttachmentType.Stream)
                        {
                            throw new OwaNotSupportedException("Unsupported attachment type " + implementation.ResultAttachmentType);
                        }
                        AttachmentIdType ewsAttachmentIdType = GetWacAttachmentInfo.GetEwsAttachmentIdType(callContext, implementation.ResultItemId, implementation.ResultAttachmentId);
                        wacAttachmentType = GetWacAttachmentInfo.GetResultForStreamAttachment(callContext, userContext, configurationContext, attachmentPolicy, isPublicLogon, Thread.CurrentThread.CurrentCulture.Name, isEdit, (IStreamAttachment)implementation.ResultAttachment, implementation.ResultAttachmentExtension, ewsAttachmentIdType, implementation.ResultIsInDraft, implementation.ResultStoreSession, text, originalAttachmentSession.MailboxOwner.MailboxInfo.IsArchive);
                    }
                }
            }
            catch (ServerException exception)
            {
                wacAttachmentType = GetWacAttachmentInfo.HandleException(protocolLog, isEdit, exception, WacAttachmentStatus.UploadFailed);
            }
            catch (GetWacAttachmentInfo.AttachmentUploadException exception2)
            {
                wacAttachmentType = GetWacAttachmentInfo.HandleException(protocolLog, isEdit, exception2, WacAttachmentStatus.UploadFailed);
            }
            catch (RightsManagementPermanentException exception3)
            {
                wacAttachmentType = GetWacAttachmentInfo.HandleException(protocolLog, isEdit, exception3, WacAttachmentStatus.ProtectedByUnsupportedIrm);
            }
            catch (AttachmentProtectionException exception4)
            {
                wacAttachmentType = GetWacAttachmentInfo.HandleException(protocolLog, isEdit, exception4, WacAttachmentStatus.ProtectedByUnsupportedIrm);
            }
            catch (ObjectNotFoundException exception5)
            {
                wacAttachmentType = GetWacAttachmentInfo.HandleException(protocolLog, isEdit, exception5, WacAttachmentStatus.NotFound);
            }
            catch (OwaInvalidRequestException exception6)
            {
                wacAttachmentType = GetWacAttachmentInfo.HandleException(protocolLog, isEdit, exception6, WacAttachmentStatus.InvalidRequest);
            }
            catch (WacDiscoveryFailureException exception7)
            {
                wacAttachmentType = GetWacAttachmentInfo.HandleException(protocolLog, isEdit, exception7, WacAttachmentStatus.WacDiscoveryFailed);
            }
            catch (WebException exception8)
            {
                wacAttachmentType = GetWacAttachmentInfo.HandleException(protocolLog, isEdit, exception8, WacAttachmentStatus.AttachmentDataProviderError);
            }
            if (wacAttachmentType == null)
            {
                throw new OwaInvalidOperationException("There is no reason known for code to reach here without throwing an unhandled exception elsewhere");
            }
            protocolLog.Set(GetWacAttachmentInfoMetadata.Status, wacAttachmentType.Status.ToString());
            return(wacAttachmentType);
        }
        // Token: 0x06001AD7 RID: 6871 RVA: 0x00065FAC File Offset: 0x000641AC
        private static WacAttachmentType GetResultForStreamAttachment(CallContext callContext, UserContext userContext, ConfigurationContext configurationContext, AttachmentPolicy attachmentPolicy, bool isPublicLogon, string cultureName, bool isEdit, IStreamAttachment attachment, string attachmentExtension, AttachmentIdType attachmentIdType, bool isInDraft, IStoreSession storeSession, string mailboxSmtpAddress, bool isArchive)
        {
            WacFileRep  wacFileRep = GetWacAttachmentInfo.CreateWacFileRep(callContext, configurationContext, attachmentPolicy, isPublicLogon, isEdit, isArchive);
            HttpRequest request    = callContext.HttpContext.Request;
            string      text;
            string      arg;

            GetWacAttachmentInfo.GenerateWopiSrcUrl(request, wacFileRep, mailboxSmtpAddress, out text, out arg);
            if (text == null)
            {
                throw new OwaInvalidOperationException("WOPI URL is null.");
            }
            string      id                = attachmentIdType.Id;
            TokenResult oauthToken        = GetWacAttachmentInfo.GetOAuthToken(id, userContext, mailboxSmtpAddress, text);
            string      exchangeSessionId = WacUtilities.GetExchangeSessionId(oauthToken.TokenString);

            callContext.ProtocolLog.Set(GetWacAttachmentInfoMetadata.ExchangeSessionId, exchangeSessionId);
            SecurityIdentifier effectiveCallerSid = callContext.EffectiveCallerSid;

            CachedAttachmentInfo.GetInstance(mailboxSmtpAddress, id, exchangeSessionId, effectiveCallerSid, cultureName);
            string wacUrl = GetWacAttachmentInfo.GetWacUrl(isEdit, cultureName, attachmentExtension);

            if (string.IsNullOrEmpty(wacUrl))
            {
                throw new OwaInvalidRequestException(string.Format("Wac Base Url is null for this given extension {0} and culture {1}", attachmentExtension, cultureName));
            }
            new Uri(wacUrl);
            string format = "{0}WOPISrc={1}&access_token={2}";
            string arg2   = HttpUtility.UrlEncode(oauthToken.TokenString);
            string text2  = string.Format(format, wacUrl, HttpUtility.UrlEncode(text), arg2);
            string value  = string.Format(format, wacUrl, arg, arg2);

            callContext.ProtocolLog.Set(GetWacAttachmentInfoMetadata.WacUrl, value);
            if (!Uri.IsWellFormedUriString(text2, UriKind.Absolute))
            {
                throw new OwaInvalidOperationException("The WAC Iframe URL that was generated is not a well formed URI: " + text2);
            }
            return(new WacAttachmentType
            {
                AttachmentId = attachmentIdType,
                IsEdit = isEdit,
                IsInDraft = isInDraft,
                WacUrl = text2,
                Status = WacAttachmentStatus.Success
            });
        }
        // Token: 0x06001AD6 RID: 6870 RVA: 0x00065F4C File Offset: 0x0006414C
        private static WacAttachmentType CreateWacAttachmentType(OwaIdentity identity, AttachmentIdType attachmentIdType, string webServiceUrl, string contentUrl, bool isEdit, bool isInDraft)
        {
            string wacUrl;

            try
            {
                wacUrl = OneDriveProUtilities.GetWacUrl(identity, webServiceUrl, contentUrl, isEdit);
            }
            catch (Exception ex)
            {
                ex.ToString();
                throw;
            }
            return(new WacAttachmentType
            {
                AttachmentId = attachmentIdType,
                IsEdit = isEdit,
                IsInDraft = isInDraft,
                WacUrl = wacUrl,
                Status = WacAttachmentStatus.Success
            });
        }
Example #15
0
        internal static void UploadAndAttachReferenceAttachment(Guid operationId, UserContext userContext, CallContext callContext, ItemId itemId, string fileName, byte[] fileContent, IdConverter idConverter, string subscriptionId, string channelId, CancellationToken cancellationToken, string cancellationId)
        {
            AttachmentResultCode errorCode    = AttachmentResultCode.GenericFailure;
            AttachmentIdType     attachmentId = null;
            Exception            exception    = null;

            try
            {
                OwaDiagnostics.SendWatsonReportsForGrayExceptions(async delegate()
                {
                    try
                    {
                        AttachmentDataProvider attachmentDataProvider = userContext.AttachmentDataProviderManager.GetDefaultUploadDataProvider(callContext);
                        if (attachmentDataProvider == null)
                        {
                            throw new InvalidOperationException("The user has no default data provider");
                        }
                        UploadItemAsyncResult uploadResult = await attachmentDataProvider.UploadItemAsync(fileContent, fileName, cancellationToken, callContext).ConfigureAwait(false);
                        CreateAttachmentNotificationPayload notificationPayload = new CreateAttachmentNotificationPayload
                        {
                            SubscriptionId = subscriptionId,
                            Id             = operationId.ToString(),
                            Item           = uploadResult.Item,
                            ResultCode     = uploadResult.ResultCode
                        };
                        if (uploadResult.ResultCode == AttachmentResultCode.Success)
                        {
                            notificationPayload.Response = CreateReferenceAttachmentFromAttachmentDataProvider.AttachReferenceAttachment(attachmentDataProvider, userContext, uploadResult.Item.Location, string.Empty, itemId.Id, idConverter, null, uploadResult.Item.ProviderEndpointUrl);
                            attachmentId = CreateAttachmentHelper.GetAttachmentIdFromCreateAttachmentResponse(notificationPayload.Response);
                        }
                        if (!userContext.IsDisposed)
                        {
                            try
                            {
                                userContext.LockAndReconnectMailboxSession();
                                CreateAttachmentHelper.SendPendingGetNotification(userContext, notificationPayload, channelId);
                            }
                            finally
                            {
                                userContext.UnlockAndDisconnectMailboxSession();
                            }
                        }
                    }
                    catch (OperationCanceledException exception)
                    {
                        errorCode = AttachmentResultCode.Cancelled;
                        exception = exception;
                        if (cancellationId != null)
                        {
                            userContext.CancelAttachmentManager.CreateAttachmentCancelled(cancellationId);
                        }
                    }
                });
            }
            catch (GrayException ex)
            {
                ExTraceGlobals.AttachmentHandlingTracer.TraceError <string>(0L, "CreateReferenceAttachmentFromLocalFile.UploadAndAttachReferenceAttachment Exception while trying to upload and attach file async : {0}", ex.StackTrace);
                exception = ex;
            }
            finally
            {
                if (cancellationId != null)
                {
                    userContext.CancelAttachmentManager.CreateAttachmentCompleted(cancellationId, attachmentId);
                }
                if (exception != null)
                {
                    CreateAttachmentHelper.SendFailureNotification(userContext, subscriptionId, operationId.ToString(), errorCode, channelId, exception);
                }
            }
        }