コード例 #1
0
        protected override void AddAttachment(IMessageAttachment messageAttachment)
        {
            UIElement       attachmentElement;
            AttachmentModel attachmentModel = new AttachmentModel(_fileSystem, messageAttachment);

            switch (messageAttachment.Type)
            {
            case AttachmentType.Image:
                attachmentElement = new AttachmentImage(attachmentModel);
                break;

            case AttachmentType.Video:
                attachmentElement = new AttachmentVideo(attachmentModel);
                break;

            case AttachmentType.Audio:
                attachmentElement = new AttachmentAudio(attachmentModel);
                break;

            default:
                throw new ArgumentException("Unrecognized attachment type: " + messageAttachment.Type.ToString());
            }

            _currentParagraph.Inlines.Add(attachmentElement);
        }
コード例 #2
0
        public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IPipelineInformation pipelineInformation, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage
        {
            IMessageAttachment attachment = null;
            var queueName = AutoMessageMapper.GetQueueName <T>();

            try
            {
                string attachmentId = null;
                if (typeof(ICommandWithAttachment).IsAssignableFrom(typeof(T)))
                {
                    attachmentId = AttachmentUtility.GetAttachmentIds(messageStateHandler.MessageProperties).FirstOrDefault();
                    if (!string.IsNullOrEmpty(attachmentId))
                    {
                        attachment = await _attachmentProvider.GetAttachmentAsync(queueName, attachmentId, cancellationToken).ConfigureAwait(false);

                        var message = (ICommandWithAttachment)await messageStateHandler.GetMessageAsync().ConfigureAwait(false);

                        message.Attachment = attachment;
                    }
                }

                await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false);

                if (attachment != null)
                {
                    attachment.Stream?.Dispose();
                    await _attachmentProvider.DeleteAttachmentAsync(queueName, attachmentId, cancellationToken).ConfigureAwait(false);
                }
            }
            finally
            {
                attachment?.Stream?.Dispose();
            }
        }
コード例 #3
0
        private void AddVideoAttachment(IMessageAttachment videoAttachment)
        {
            string attachmentRelativeFilename = GetRelativeFilenameForAttachment(videoAttachment);
            string videoIconRelativeFilename  = GetRelativeFilenameForFile(ConversationExporterHtml.VideoIconOutputFilename);

            _htmlBuffer.AppendFormat("<a href=\"{0}\" target=\"_blank\"><img class=\"attachmentVideo\" src=\"{1}\" /></a>\r\n", attachmentRelativeFilename, videoIconRelativeFilename);
        }
コード例 #4
0
 public async Task UploadAttachmentAsync(string queueName, string id, IMessageAttachment attachment, CancellationToken cancellationToken = default(CancellationToken))
 {
     var blob = new BlobClient(_connectionString, queueName, id);
     await blob.UploadAsync(attachment.Stream, new BlobHttpHeaders { ContentType = attachment.ContentType }, new Dictionary <string, string> {
         { "Filename", attachment.Filename }
     }, cancellationToken : cancellationToken)
     .ConfigureAwait(false);
 }
コード例 #5
0
        public async Task UploadAttachmentAsync(string queueName, string id, IMessageAttachment attachment, CancellationToken cancellationToken = default(CancellationToken))
        {
            var container = _blobClient.GetContainerReference(queueName);
            var blob      = container.GetBlockBlobReference(id);

            blob.Properties.ContentType = attachment.ContentType;
            blob.Metadata.Add("Filename", attachment.Filename);
            await blob.UploadFromStreamAsync(attachment.Stream, null, null, null, cancellationToken).ConfigureAwait(false);
        }
コード例 #6
0
        private string ExportMessageAttachment(IMessageAttachment attachment, string attachmentExportDirectory)
        {
            string attachmentExportPath = Path.Combine(attachmentExportDirectory, attachment.OriginalFilename);
            string createdAttachmentExportPath;

            using (Stream attachmentOutputStream = FileCreator.CreateNewFileWithRenameAttempts(attachmentExportPath, _exportFileSystem, MaxRenameAttempts, out createdAttachmentExportPath))
            {
                _exportFileSystem.CopyFile(attachment.Path, attachmentOutputStream);
            }
            return(createdAttachmentExportPath);
        }
コード例 #7
0
        protected void AddMessage(bool isOutgoing, double messageIntervalSeconds, string senderPhoneNumber, string messageContents, string chatId, IMessageAttachment attachment)
        {
            _LastMessageId++;

            DateTime timestamp = _LastTimestamp.AddSeconds(messageIntervalSeconds);

            TextMessage textMessage = new TextMessage(_LastMessageId, isOutgoing, timestamp, messageContents, senderPhoneNumber, chatId, null, attachment);
            _TextMessages.Add(textMessage);

            _LastTimestamp = timestamp;
        }
コード例 #8
0
 protected override void AddAttachment(IMessageAttachment messageAttachment)
 {
     if (messageAttachment.Type == AttachmentType.Image)
     {
         AddImageAttachment(messageAttachment);
     }
     else if (messageAttachment.Type == AttachmentType.Video)
     {
         AddVideoAttachment(messageAttachment);
     }
 }
コード例 #9
0
 protected override void AddAttachment(IMessageAttachment messageAttachment)
 {
     if (messageAttachment.Type == AttachmentType.Image)
     {
         AddImageAttachment(messageAttachment);
     }
     else if (messageAttachment.Type == AttachmentType.Video)
     {
         AddVideoAttachment(messageAttachment);
     }
 }
コード例 #10
0
        public AttachmentModel(IFileSystem fileSytem, IMessageAttachment attachment)
        {
            _fileSystem = fileSytem;

            BackupPath = attachment.Path;

            if (string.IsNullOrEmpty(BackupPath) || !_fileSystem.FileExists(BackupPath))
            {
                throw new AttachmentOpenException("Can't find expected attachment file: " + BackupPath);
            }

            OrignalFilename = attachment.OriginalFilename;

            _tempCopyPath = null;
        }
コード例 #11
0
        public AttachmentModel(IFileSystem fileSytem, IMessageAttachment attachment)
        {
            _fileSystem = fileSytem;

            BackupPath = attachment.Path;

            if (string.IsNullOrEmpty(BackupPath) || !_fileSystem.FileExists(BackupPath))
            {
                throw new AttachmentOpenException("Can't find expected attachment file: " + BackupPath);
            }

            OrignalFilename = attachment.OriginalFilename;

            _tempCopyPath = null;
        }
コード例 #12
0
ファイル: TextMessage.cs プロジェクト: jzajac2/AllYourTexts
        public TextMessage(long messageId, bool isOutgoing, DateTime timestamp, string messageContents, string address, string chatId, string country, IMessageAttachment messageAttachment)
        {
            MessageId = messageId;
            IsOutgoing = isOutgoing;
            Timestamp = timestamp;
            Attachments = new List<IMessageAttachment>();
            if (messageAttachment != null)
            {
                AddAttachment(messageAttachment);
            }

            MessageContents = ConvertEmptyToNull(messageContents);
            Address = ConvertEmptyToNull(address);
            ChatId = ConvertEmptyToNull(chatId);
            Country = ConvertEmptyToNull(country);
        }
コード例 #13
0
        protected override void AddAttachment(IMessageAttachment messageAttachment)
        {
            UIElement attachmentElement;
            AttachmentModel attachmentModel = new AttachmentModel(_fileSystem, messageAttachment);
            switch (messageAttachment.Type)
            {
                case AttachmentType.Image:
                    attachmentElement = new AttachmentImage(attachmentModel);
                    break;
                case AttachmentType.Video:
                    attachmentElement = new AttachmentVideo(attachmentModel);
                    break;
                case AttachmentType.Audio:
                    attachmentElement = new AttachmentAudio(attachmentModel);
                    break;
                default:
                    throw new ArgumentException("Unrecognized attachment type: " + messageAttachment.Type.ToString());
            }

            _currentParagraph.Inlines.Add(attachmentElement);
        }
コード例 #14
0
        public async Task UploadAttachmentAsync(string queueName, string id, IMessageAttachment attachment, CancellationToken cancellationToken = default(CancellationToken))
        {
            var db = _multiplexer.GetDatabase(_configuration.DatabaseId);

            var hash = new HashEntry[]
            {
                new HashEntry(FileName, attachment.Filename),
                new HashEntry(ContentType, attachment.ContentType),
            };



            using (var memoryStream = new MemoryStream())
            {
                await attachment.Stream.CopyToAsync(memoryStream).ConfigureAwait(false);

                await Task.WhenAll(
                    db.HashSetAsync(RedisQueueConventions.GetAttachmentMetadataKey(queueName, id), hash),
                    db.StringSetAsync(RedisQueueConventions.GetAttachmentBinaryKey(queueName, id), memoryStream.ToArray()))
                .ConfigureAwait(false);
            }
        }
コード例 #15
0
ファイル: TextMessage.cs プロジェクト: cheunjq/AllYourTexts
 public void AddAttachment(IMessageAttachment attachment)
 {
     Attachments.Add(attachment);
 }
コード例 #16
0
ファイル: TextMessage.cs プロジェクト: jzajac2/AllYourTexts
 public void AddAttachment(IMessageAttachment attachment)
 {
     Attachments.Add(attachment);
 }
コード例 #17
0
 private string GetRelativeFilenameForAttachment(IMessageAttachment attachment)
 {
     return _attachmentExportLocator.GetAttachmentExportRelativePath(attachment);
 }
コード例 #18
0
        protected void AddMessage(bool isOutgoing, double messageIntervalSeconds, string senderPhoneNumber, string messageContents, string chatId, IMessageAttachment attachment)
        {
            _LastMessageId++;

            DateTime timestamp = _LastTimestamp.AddSeconds(messageIntervalSeconds);

            TextMessage textMessage = new TextMessage(_LastMessageId, isOutgoing, timestamp, messageContents, senderPhoneNumber, chatId, null, attachment);

            _TextMessages.Add(textMessage);

            _LastTimestamp = timestamp;
        }
コード例 #19
0
 protected override void AddAttachment(IMessageAttachment messageAttachment)
 {
     //
     // Plaintext renderer ignores message attachments.
     //
 }
コード例 #20
0
 private void AddVideoAttachment(IMessageAttachment videoAttachment)
 {
     string attachmentRelativeFilename = GetRelativeFilenameForAttachment(videoAttachment);
     string videoIconRelativeFilename = GetRelativeFilenameForFile(ConversationExporterHtml.VideoIconOutputFilename);
     _htmlBuffer.AppendFormat("<a href=\"{0}\" target=\"_blank\"><img class=\"attachmentVideo\" src=\"{1}\" /></a>\r\n", attachmentRelativeFilename, videoIconRelativeFilename);
 }
コード例 #21
0
 private string ExportMessageAttachment(IMessageAttachment attachment, string attachmentExportDirectory)
 {
     string attachmentExportPath = Path.Combine(attachmentExportDirectory, attachment.OriginalFilename);
     string createdAttachmentExportPath;
     using (Stream attachmentOutputStream = FileCreator.CreateNewFileWithRenameAttempts(attachmentExportPath, _exportFileSystem, MaxRenameAttempts, out createdAttachmentExportPath))
     {
         _exportFileSystem.CopyFile(attachment.Path, attachmentOutputStream);
     }
     return createdAttachmentExportPath;
 }
コード例 #22
0
 public void AddOutgoingMessageWithAttachment(double messageIntervalSeconds, string messageContents, IMessageAttachment attachment)
 {
     AddMessage(true, messageIntervalSeconds, _RemotePhoneNumber, messageContents, null, attachment);
 }
コード例 #23
0
 public string GetAttachmentExportRelativePath(IMessageAttachment attachment)
 {
     return(_exportMappings[attachment.Path]);
 }
コード例 #24
0
 public async Task SendMessage(IMessageAttachment file)
 {
     await SendMessage(null, attachments : new[] { file });
 }
コード例 #25
0
 protected abstract void AddAttachment(IMessageAttachment messageAttachment);
コード例 #26
0
 public string GetAttachmentExportRelativePath(IMessageAttachment attachment)
 {
     return _exportMappings[attachment.Path];
 }
コード例 #27
0
        private void AddImageAttachment(IMessageAttachment imageAttachment)
        {
            string relativeFilename = GetRelativeFilenameForAttachment(imageAttachment);

            _htmlBuffer.AppendFormat("<a href=\"{0}\" target=\"_blank\"><img class=\"attachmentImage\" src=\"{0}\" /></a>", relativeFilename);
        }
コード例 #28
0
ファイル: TextMessage.cs プロジェクト: cheunjq/AllYourTexts
        public TextMessage(long messageId, bool isOutgoing, DateTime timestamp, string messageContents, string address, string chatId, string country, IMessageAttachment messageAttachment)
        {
            MessageId   = messageId;
            IsOutgoing  = isOutgoing;
            Timestamp   = timestamp;
            Attachments = new List <IMessageAttachment>();
            if (messageAttachment != null)
            {
                AddAttachment(messageAttachment);
            }

            MessageContents = ConvertEmptyToNull(messageContents);
            Address         = ConvertEmptyToNull(address);
            ChatId          = ConvertEmptyToNull(chatId);
            Country         = ConvertEmptyToNull(country);
        }
コード例 #29
0
 private void AddImageAttachment(IMessageAttachment imageAttachment)
 {
     string relativeFilename = GetRelativeFilenameForAttachment(imageAttachment);
     _htmlBuffer.AppendFormat("<a href=\"{0}\" target=\"_blank\"><img class=\"attachmentImage\" src=\"{0}\" /></a>", relativeFilename);
 }
コード例 #30
0
 public void AddOutgoingMessageWithAttachment(double messageIntervalSeconds, string messageContents, IMessageAttachment attachment)
 {
     AddMessage(true, messageIntervalSeconds, _RemotePhoneNumber, messageContents, null, attachment);
 }
コード例 #31
0
 protected abstract void AddAttachment(IMessageAttachment messageAttachment);
コード例 #32
0
 public void AddAttachmentExportLocation(IMessageAttachment attachment, string exportLocation)
 {
     string relativePath = FullPathToRelativePath(exportLocation);
     AddFileExportRelativeLocation(attachment.Path, relativePath);
 }
コード例 #33
0
        public void AddAttachmentExportLocation(IMessageAttachment attachment, string exportLocation)
        {
            string relativePath = FullPathToRelativePath(exportLocation);

            AddFileExportRelativeLocation(attachment.Path, relativePath);
        }
コード例 #34
0
 protected override void AddAttachment(IMessageAttachment messageAttachment)
 {
     //
     // Plaintext renderer ignores message attachments.
     //
 }
コード例 #35
0
 private string GetRelativeFilenameForAttachment(IMessageAttachment attachment)
 {
     return(_attachmentExportLocator.GetAttachmentExportRelativePath(attachment));
 }