public void CreateExportFolderNameSuggestionTest()
        {
            var mockDescriptionHelper = new Mock<IConversationDescriptionHelper>();
            mockDescriptionHelper.Setup(x => x.GetDescription(It.IsAny<IConversation>()))
                .Returns("<some conversation>");

            var mockClock = new Mock<IClock>();
            mockClock.Setup(x => x.CurrentTime())
                .Returns(new DateTime(2012, 10, 27));

            ExportedFilenameGenerator filenameGenerator = new ExportedFilenameGenerator(mockDescriptionHelper.Object, mockClock.Object);
            Assert.AreEqual("iPhone Text History Backup - 2012-10-27", filenameGenerator.CreateExportFolderNameSuggestion());
        }
        private void VerifyConversationFilenameStartsWith(IConversation conversation, string conversationDescription, string filenamePrefixExpected)
        {
            var mockDescriptionHelper = new Mock<IConversationDescriptionHelper>();
            mockDescriptionHelper.Setup(x => x.GetDescription(It.IsAny<IConversation>()))
                .Returns(conversationDescription);

            var mockClock = new Mock<IClock>();
            mockClock.Setup(x => x.CurrentTime())
                .Returns(new DateTime(2012, 10, 27));

            ExportedFilenameGenerator filenameGenerator = new ExportedFilenameGenerator(mockDescriptionHelper.Object, mockClock.Object);
            string filenameSuggestionActual = filenameGenerator.CreateExportFilenameSuggestion(conversation);
            Assert.AreEqual(filenamePrefixExpected, filenameSuggestionActual);
        }
        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;
        }
Exemplo n.º 4
0
        private void ExportCurrentConversation()
        {
            ExportedFilenameGenerator filenameGenerator = new ExportedFilenameGenerator();
            SaveFileDialog saveDialog = new SaveFileDialog();
            const int FilterIndexHtml = 1;
            const int FilterIndexPlaintext = 2;
            saveDialog.Filter = "Web Page|*.html|Text File|*.txt";
            saveDialog.Title = "Save Conversation History As";
            saveDialog.AddExtension = true;
            saveDialog.FileName = filenameGenerator.CreateExportFilenameSuggestion(_mainWindowModel.SelectedConversation);
            saveDialog.ShowDialog();

            if (string.IsNullOrEmpty(saveDialog.FileName))
            {
                return;
            }

            IFileSystem exportFileSystem = new OsFileSystem();
            IConversationExporter conversationExporter;

            switch (saveDialog.FilterIndex)
            {
                case FilterIndexHtml:
                    conversationExporter  = new ConversationExporterHtml(exportFileSystem);
                    break;
                case FilterIndexPlaintext:
                    conversationExporter = new ConversationExporterPlaintext(exportFileSystem);
                    break;
                default:
                    throw new ArgumentException("Invalid file save type.");
            }
            conversationExporter.Export(_mainWindowModel.SelectedConversation, _displayOptions, saveDialog.FileName);
        }
        private void ExportConversationsAsync()
        {
            ExportedFilenameGenerator filenameGenerator = new ExportedFilenameGenerator();
            string folderName = filenameGenerator.CreateExportFolderNameSuggestion();

            string outputPath = System.IO.Path.Combine(folderPathTextBox.Text, folderName);

            BackgroundWorker backgroundWorker = new BackgroundWorker();
            _progressCallback = new ProgressCallback(backgroundWorker);

            backgroundWorker.WorkerReportsProgress = true;
            backgroundWorker.WorkerSupportsCancellation = true;
            backgroundWorker.DoWork += OnDoWork;
            backgroundWorker.ProgressChanged += OnProgressChanged;
            backgroundWorker.RunWorkerCompleted += OnWorkerCompleted;

            ExportMultipleDialogModel.ExportFormat exportFormat = GetExportFormat();

            AsyncExportingProgressParams exportingParams = new AsyncExportingProgressParams(_progressCallback, _model, exportFormat, outputPath);

            SetUiToExportInProgress();

            backgroundWorker.RunWorkerAsync(exportingParams);
        }