// 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);
        }
Exemplo n.º 2
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);
                }
            }
        }