예제 #1
0
        // Token: 0x06001999 RID: 6553 RVA: 0x0005A2D8 File Offset: 0x000584D8
        internal static CreateAttachmentResponse CreateAttachment(CallContext callContext, CreateAttachmentRequest translatedRequest)
        {
            CreateAttachmentHelper.UpdateContentType(callContext);
            CreateAttachmentResponse result;

            using (CreateAttachment createAttachment = new CreateAttachment(callContext, translatedRequest))
            {
                if (!createAttachment.PreExecute())
                {
                    result = null;
                }
                else
                {
                    ServiceResult <AttachmentType> currentStepResult;
                    try
                    {
                        currentStepResult = createAttachment.Execute();
                    }
                    catch (LocalizedException exception)
                    {
                        currentStepResult = ExceptionHandler <AttachmentType> .GetServiceResult <AttachmentType>(exception, null);
                    }
                    createAttachment.SetCurrentStepResult(currentStepResult);
                    result = (CreateAttachmentResponse)createAttachment.PostExecute();
                }
            }
            return(result);
        }
        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);
        }
        public CreateAttachmentFromForm(CallContext callContext, HttpRequest request) : base(callContext)
        {
            HttpPostedFile httpPostedFile = request.Files[0];
            string         fileName       = Path.GetFileName(httpPostedFile.FileName);

            this.translatedRequest = CreateAttachmentHelper.CreateAttachmentRequest(new ItemId(request.Form["parentItemId"], request.Form["parentChangeKey"]), fileName, httpPostedFile.ContentLength, httpPostedFile.ContentType, CreateAttachmentHelper.GetContentBytes(httpPostedFile.InputStream), bool.Parse(request.Form["isInline"]), request.Form["cancellationId"]);
            this.fileSize          = httpPostedFile.ContentLength;
            this.contentType       = httpPostedFile.ContentType;
        }
        // Token: 0x060019CD RID: 6605 RVA: 0x0005C2F0 File Offset: 0x0005A4F0
        internal static CreateAttachmentResponse AttachReferenceAttachment(AttachmentDataProvider attachmentDataProvider, UserContext userContext, string location, string dataProviderItemId, string parentItemId, IdConverter idConverter, string dataProviderParentItemId = null, string providerEndpointUrl = null)
        {
            CreateAttachmentResponse result = null;

            if (!userContext.IsDisposed)
            {
                if (string.IsNullOrEmpty(providerEndpointUrl))
                {
                    providerEndpointUrl = attachmentDataProvider.GetEndpointUrlFromItemLocation(location);
                }
                string linkingUrl = attachmentDataProvider.GetLinkingUrl(userContext, location, providerEndpointUrl, dataProviderItemId, dataProviderParentItemId);
                string text       = Path.GetFileName(HttpUtility.UrlDecode(linkingUrl));
                if (OneDriveProUtilities.IsDurableUrlFormat(text))
                {
                    text = text.Substring(0, text.LastIndexOf("?", StringComparison.InvariantCulture));
                }
                try
                {
                    userContext.LockAndReconnectMailboxSession();
                    IdAndSession            idAndSession            = new IdAndSession(StoreId.EwsIdToStoreObjectId(parentItemId), userContext.MailboxSession);
                    ReferenceAttachmentType referenceAttachmentType = new ReferenceAttachmentType
                    {
                        Name = text,
                        AttachLongPathName  = linkingUrl,
                        ProviderEndpointUrl = providerEndpointUrl,
                        ProviderType        = attachmentDataProvider.Type.ToString()
                    };
                    if (!userContext.IsGroupUserContext)
                    {
                        referenceAttachmentType.ContentId   = Guid.NewGuid().ToString();
                        referenceAttachmentType.ContentType = "image/png";
                    }
                    AttachmentHierarchy attachmentHierarchy = new AttachmentHierarchy(idAndSession, true, true);
                    using (AttachmentBuilder attachmentBuilder = new AttachmentBuilder(attachmentHierarchy, new AttachmentType[]
                    {
                        referenceAttachmentType
                    }, idConverter, true))
                    {
                        ServiceError serviceError;
                        Attachment   attachment = attachmentBuilder.CreateAttachment(referenceAttachmentType, out serviceError);
                        if (serviceError == null)
                        {
                            attachmentHierarchy.SaveAll();
                        }
                        result = CreateAttachmentHelper.CreateAttachmentResponse(attachmentHierarchy, attachment, referenceAttachmentType, idAndSession, serviceError);
                    }
                }
                finally
                {
                    userContext.UnlockAndDisconnectMailboxSession();
                }
            }
            return(result);
        }
예제 #6
0
        // Token: 0x060019A3 RID: 6563 RVA: 0x0005A918 File Offset: 0x00058B18
        internal static CreateReferenceAttachmentFromLocalFileRequest CreateReferenceAttachmentRequest(HttpRequest request)
        {
            HttpPostedFile httpPostedFile = request.Files[0];

            return(new CreateReferenceAttachmentFromLocalFileRequest
            {
                FileContentToUpload = Convert.ToBase64String(CreateAttachmentHelper.GetContentBytes(httpPostedFile.InputStream)),
                FileName = httpPostedFile.FileName,
                ParentItemId = new ItemId(request.Form["parentItemId"], request.Form["parentChangeKey"]),
                SubscriptionId = request.Form["subscriptionId"]
            });
        }
예제 #7
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);
        }
예제 #8
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);
                }
            }
        }
예제 #9
0
        private CreateAttachmentRequest CreateImageAttachmentRequest(byte[] attachmentData)
        {
            CreateAttachmentRequest createAttachmentRequest = null;

            if (attachmentData != null)
            {
                string fileName    = "BingMap";
                string contentType = "image/jpeg";
                createAttachmentRequest = CreateAttachmentHelper.CreateAttachmentRequest(this.request.ParentItemId, fileName, attachmentData.Length, contentType, attachmentData, true, null);
            }
            if (createAttachmentRequest == null)
            {
                throw new OwaException("CreateAttachmentRequestError");
            }
            return(createAttachmentRequest);
        }
예제 #10
0
        // Token: 0x060019A0 RID: 6560 RVA: 0x0005A7F8 File Offset: 0x000589F8
        internal static void SendFailureNotification(UserContext userContext, string subscriptionId, string operationId, AttachmentResultCode code, string channelId, Exception ex)
        {
            if (ex != null)
            {
                OwaServerTraceLogger.AppendToLog(new TraceLogEvent("CreateAttachmentExceptionTrace", userContext, "SendFailureNotification", "Attachment operation failed. Stack Trace:\n" + ex.ToString()));
            }
            CreateAttachmentNotificationPayload result = new CreateAttachmentNotificationPayload
            {
                SubscriptionId = subscriptionId,
                Id             = operationId,
                Bytes          = null,
                Item           = null,
                ResultCode     = code
            };

            CreateAttachmentHelper.SendPendingGetNotification(userContext, result, channelId);
        }
예제 #11
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);
        }
예제 #12
0
        protected override string InternalExecute()
        {
            if (!this.isHtml5)
            {
                CreateAttachmentHelper.UpdateContentType(base.CallContext);
            }
            UserContext             userContext             = UserContextManager.GetUserContext(base.CallContext.HttpContext, base.CallContext.EffectiveCaller, true);
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            CancellationToken       token = cancellationTokenSource.Token;

            if (this.cancellationId != null)
            {
                bool flag = userContext.CancelAttachmentManager.OnCreateAttachment(this.cancellationId, cancellationTokenSource);
                if (flag)
                {
                    CreateAttachmentHelper.SendFailureNotification(userContext, this.subscriptionId, null, AttachmentResultCode.Cancelled, this.channelId, null);
                    return(null);
                }
            }
            Guid operationId = Guid.NewGuid();

            CreateReferenceAttachmentFromLocalFile.UploadAndAttachReferenceAttachment(operationId, userContext, base.CallContext, this.itemId, this.fileName, this.fileContent, base.IdConverter, this.subscriptionId, this.channelId, token, this.cancellationId);
            return(operationId.ToString());
        }
예제 #13
0
 // Token: 0x0600199E RID: 6558 RVA: 0x0005A6C8 File Offset: 0x000588C8
 internal static void SendPendingGetNotification(UserContext userContext, CreateAttachmentNotificationPayload result)
 {
     CreateAttachmentHelper.SendPendingGetNotification(userContext, result, null);
 }
예제 #14
0
 // Token: 0x0600199C RID: 6556 RVA: 0x0005A520 File Offset: 0x00058720
 internal static void CreateAttachmentAndSendPendingGetNotification(UserContext userContext, string itemId, byte[] bytes, string name, CreateAttachmentNotificationPayload result, IdConverter idConverter)
 {
     CreateAttachmentHelper.CreateAttachmentAndSendPendingGetNotification(userContext, itemId, bytes, name, result, idConverter, null);
 }
예제 #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);
                }
            }
        }
예제 #16
0
        internal static void DownloadAndAttachFileFromUri(Uri uri, string name, string subscriptionId, Guid operationId, ItemId itemId, UserContext userContext, IdConverter idConverter)
        {
            try
            {
                OwaDiagnostics.SendWatsonReportsForGrayExceptions(async delegate()
                {
                    try
                    {
                        using (HttpClient client = new HttpClient())
                        {
                            using (HttpResponseMessage response = await client.GetAsync(uri))
                            {
                                HttpStatusCode statusCode = response.StatusCode;
                                AttachmentResultCode resultCode;
                                if (statusCode != HttpStatusCode.OK)
                                {
                                    switch (statusCode)
                                    {
                                    case HttpStatusCode.Forbidden:
                                        resultCode = AttachmentResultCode.AccessDenied;
                                        break;

                                    case HttpStatusCode.NotFound:
                                        resultCode = AttachmentResultCode.NotFound;
                                        break;

                                    default:
                                        if (statusCode != HttpStatusCode.RequestTimeout)
                                        {
                                            resultCode = AttachmentResultCode.GenericFailure;
                                        }
                                        else
                                        {
                                            resultCode = AttachmentResultCode.Timeout;
                                        }
                                        break;
                                    }
                                }
                                else
                                {
                                    resultCode = AttachmentResultCode.Success;
                                }
                                if (resultCode != AttachmentResultCode.Success)
                                {
                                    CreateAttachmentHelper.SendFailureNotification(userContext, subscriptionId, operationId.ToString(), resultCode, null, null);
                                }
                                byte[] buffer = await response.Content.ReadAsByteArrayAsync();
                                CreateAttachmentNotificationPayload result = new CreateAttachmentNotificationPayload
                                {
                                    SubscriptionId = subscriptionId,
                                    Id             = operationId.ToString(),
                                    Bytes          = buffer,
                                    Item           = null,
                                    ResultCode     = resultCode
                                };
                                CreateAttachmentHelper.CreateAttachmentAndSendPendingGetNotification(userContext, itemId.Id, buffer, name, result, idConverter);
                            }
                        }
                    }
                    catch (TaskCanceledException)
                    {
                    }
                });
            }
            catch (GrayException ex)
            {
                CreateAttachmentHelper.SendFailureNotification(userContext, subscriptionId, operationId.ToString(), AttachmentResultCode.GenericFailure, null, ex);
                ExTraceGlobals.AttachmentHandlingTracer.TraceError <string>(0L, "CreateAttachmentFromUri.DownloadAndAttachFileFromUri Exception while trying to download and attach file async : {0}", ex.StackTrace);
            }
        }