protected override List <ExportError> ExportConversationAttachments(IConversation conversation, string exportFilename, out IAttachmentExportLocator exportLocator)
        {
            List <ExportError>      exportErrors            = new List <ExportError>();
            string                  exportBasePath          = Path.GetDirectoryName(exportFilename);
            AttachmentExportLocator attachmentExportLocator = new AttachmentExportLocator(exportBasePath);
            string                  attachmentDirectoryPath = null;
            bool exportedVideoAttachment = false;
            bool exportedAudioAttachment = false;

            foreach (IConversationMessage message in conversation)
            {
                if (!message.HasAttachments())
                {
                    continue;
                }

                if (attachmentDirectoryPath == null)
                {
                    string attachmentDirectoryName = GenerateAttachmentExportDirectoryName(exportFilename);
                    attachmentDirectoryPath = Path.Combine(exportBasePath, attachmentDirectoryName);
                    attachmentDirectoryPath = FileCreator.CreateNewDirectoryWithRenameAttempts(attachmentDirectoryPath, _exportFileSystem, MaxRenameAttempts);
                }

                foreach (IMessageAttachment attachment in message.Attachments)
                {
                    try
                    {
                        string exportedPath = ExportMessageAttachment(attachment, attachmentDirectoryPath);
                        attachmentExportLocator.AddAttachmentExportLocation(attachment, exportedPath);

                        if (attachment.Type == AttachmentType.Video)
                        {
                            exportedVideoAttachment = true;
                        }
                        else if (attachment.Type == AttachmentType.Audio)
                        {
                            exportedAudioAttachment = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        exportErrors.Add(new ExportError(conversation, ex));
                    }
                }
            }

            if (exportedVideoAttachment)
            {
                string videoIconPath = PlaceVideoIconFile(attachmentDirectoryPath);
                attachmentExportLocator.AddFileExportLocation(VideoIconOutputFilename, videoIconPath);
            }
            if (exportedAudioAttachment)
            {
                string audioIconPath = PlaceAudioIconFile(attachmentDirectoryPath);
                attachmentExportLocator.AddFileExportLocation(AudioIconOutputFilename, audioIconPath);
            }

            exportLocator = attachmentExportLocator;
            return(exportErrors);
        }
Example #2
0
        public void CreateNewDirectoryWithRenameAttemptsExcessiveRenamesTest()
        {
            MockFileSystem mockFileSystem = new MockFileSystem();

            FileCreator.CreateNewDirectoryWithRenameAttempts("D:\\fakepath\\namecollision", mockFileSystem, 1);
            FileCreator.CreateNewDirectoryWithRenameAttempts("D:\\fakepath\\namecollision", mockFileSystem, 1);
        }
Example #3
0
        public void CreateNewDirectoryWithRenameAttemptsDateTest()
        {
            MockFileSystem mockFileSystem = new MockFileSystem();

            FileCreator.CreateNewDirectoryWithRenameAttempts("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012", mockFileSystem, 10);
            Assert.AreEqual(1, mockFileSystem.DirectoryCount);
            Assert.IsTrue(mockFileSystem.DirectoryExists("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012"));
            FileCreator.CreateNewDirectoryWithRenameAttempts("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012", mockFileSystem, 10);
            Assert.AreEqual(2, mockFileSystem.DirectoryCount);
            Assert.IsTrue(mockFileSystem.DirectoryExists("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012 (2)"));
        }
Example #4
0
        public void CreateNewDirectoryWithRenameAttemptsTest()
        {
            MockFileSystem mockFileSystem = new MockFileSystem();

            FileCreator.CreateNewDirectoryWithRenameAttempts("x:\\abc\\def\\", mockFileSystem, 10);
            Assert.AreEqual(1, mockFileSystem.DirectoryCount);
            Assert.IsTrue(mockFileSystem.DirectoryExists("x:\\abc\\def\\"));
            FileCreator.CreateNewDirectoryWithRenameAttempts("x:\\abc\\def\\", mockFileSystem, 10);
            Assert.AreEqual(2, mockFileSystem.DirectoryCount);
            Assert.IsTrue(mockFileSystem.DirectoryExists("x:\\abc\\def (2)"));
            FileCreator.CreateNewDirectoryWithRenameAttempts("x:\\abc\\def\\", mockFileSystem, 10);
            Assert.AreEqual(3, mockFileSystem.DirectoryCount);
            Assert.IsTrue(mockFileSystem.DirectoryExists("x:\\abc\\def (3)"));
        }
        public List <ExportError> ExportMultipleConversations(IEnumerable <IConversation> conversations, IDisplayOptionsReadOnly displayOptions, string exportPath, IProgressCallback progressCallback)
        {
            List <ExportError> exportErrors      = new List <ExportError>();
            string             createdFolderPath = FileCreator.CreateNewDirectoryWithRenameAttempts(exportPath, _exportFileSystem, MaxRenameAttempts);

            ExportedFilenameGenerator filenameGenerator = new ExportedFilenameGenerator();

            foreach (IConversation conversation in conversations)
            {
                CheckForCancel(progressCallback);

                //
                // Don't export empty conversations
                //

                if (conversation.MessageCount == 0)
                {
                    IncrementProgress(progressCallback);
                    continue;
                }

                try
                {
                    string filename       = filenameGenerator.CreateExportFilenameSuggestion(conversation) + "." + GetExportFileExtension();
                    string exportFilename = Path.Combine(createdFolderPath, filename);

                    List <ExportError> currentErrors = Export(conversation, displayOptions, exportFilename);
                    exportErrors.AddRange(currentErrors);
                }
                catch (Exception ex)
                {
                    exportErrors.Add(new ExportError(conversation, ex));
                }

                IncrementProgress(progressCallback);
            }

            return(exportErrors);
        }