コード例 #1
0
        public void AttachmentProviderGetsUploader(
            string expectedKey,
            IAttachmentUploader expectedUploader)
        {
            // Arrange
            var provider = AttachmentUploaderProvider.Instance;

            // Act
            IAttachmentUploader actualUploader = provider.Get(expectedKey);

            // Assert
            Assert.IsType(expectedUploader.GetType(), actualUploader);
        }
コード例 #2
0
        private static async Task <UploadResult> TryUploadAttachmentAsync(
            Attachment attachment,
            DeliverMessageEnvelope deliverMessage,
            IAttachmentUploader uploader)
        {
            try
            {
                Logger.Trace($"Start Uploading Attachment {attachment.Id}...");
                Task <UploadResult> uploadAsync = uploader.UploadAsync(attachment, deliverMessage.Message.MessageInfo);
                if (uploadAsync == null)
                {
                    throw new ArgumentNullException(
                              nameof(uploadAsync),
                              $@"{uploader.GetType().Name} returns 'null' for Attachment {attachment.Id}");
                }

                UploadResult attachmentResult = await uploadAsync.ConfigureAwait(false);

                attachment.ResetContentPosition();

                Payload referencedPayload =
                    deliverMessage.Message.Payloads.FirstOrDefault(attachment.Matches);

                if (referencedPayload == null)
                {
                    throw new InvalidOperationException(
                              $"No referenced <Payload/> element found in DeliverMessage to assign the upload location to with attachment Id = {attachment.Id}");
                }

                referencedPayload.Location = attachmentResult.DownloadUrl;

                Logger.Trace($"Attachment {attachment.Id} uploaded succesfully");
                return(attachmentResult);
            }
            catch (Exception exception)
            {
                Logger.Error($"Attachment {attachment.Id} cannot be uploaded because of an exception: {Environment.NewLine}" + exception);
                return(UploadResult.FatalFail);
            }
        }