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); } } }
// 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); }
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); } }