/// ------------------------------------------------------------------------------------ /// <summary> /// Completes the import. /// </summary> /// <param name="firstImported">The reference of the first thing that was imported</param> /// ------------------------------------------------------------------------------------ protected ScrReference CompleteImport(ScrReference firstImported) { if (firstImported == null) { return(ScrReference.Empty); } // An empty first imported reference can happen if we imported just the BT. //Debug.Assert(!firstImported.IsEmpty, "We should have a useful reference if we imported something!"); // Display the ImportedBooks dialog if we imported any vernacular Scripture. if (m_undoImportManager.ImportedBooks.Any(x => x.Value)) { DisplayImportedBooksDlg(m_undoImportManager.BackupVersion); } m_undoImportManager.RemoveEmptyBackupSavedVersion(); m_undoImportManager.CollapseAllUndoActions(); // sync stuff if (m_app != null) { using (new WaitCursor(m_mainWnd)) { // Refresh all the views of all applications connected to the same DB. This // will cause any needed Scripture data to be reloaded lazily. m_app.Synchronize(SyncMsg.ksyncStyle); } } return(firstImported); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Completes the import. /// </summary> /// <param name="firstImported">The reference of the first thing that was imported</param> /// ------------------------------------------------------------------------------------ protected ScrReference CompleteImport(ScrReference firstImported) { if (firstImported == null) { return(ScrReference.Empty); } // An empty first imported reference can happen if we imported just the BT. //Debug.Assert(!firstImported.IsEmpty, "We should have a useful reference if we imported something!"); // Display the ImportedBooks dialog if we imported any vernacular Scripture. if (m_undoImportManager.ImportedBooks.Any(x => x.Value)) { DisplayImportedBooksDlg(m_undoImportManager.BackupVersion); } m_undoImportManager.RemoveEmptyBackupSavedVersion(); // Keeping versions we made just for PT imports (which always entirely replace the current non-archived ones) // just clutters things up and makes S/R more expensive. if (m_fParatextStreamlinedImport) { m_undoImportManager.RemoveImportedVersion(); } m_undoImportManager.CollapseAllUndoActions(); // sync stuff if (m_app != null) { using (new WaitCursor(m_mainWnd)) { // Refresh all the views of all applications connected to the same DB. This // will cause any needed Scripture data to be reloaded lazily. m_app.Synchronize(SyncMsg.ksyncStyle); } } return(firstImported); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Actually does the import, really. /// </summary> /// <param name="importSettings">The import settings.</param> /// <param name="fDisplayUi">if set to <c>true</c> shows the UI.</param> /// <returns>The first reference that was imported</returns> /// ------------------------------------------------------------------------------------ private ScrReference InternalImport(IScrImportSet importSettings, bool fDisplayUi) { ScrReference firstImported = ScrReference.Empty; using (new IgnorePropChanged(m_cache)) { bool fRollbackPartialBook = false; bool fPartialBtImported = false; try { Logger.WriteEvent("Starting import"); using (ProgressDialogWithTask progressDlg = new ProgressDialogWithTask(m_mainWnd)) { progressDlg.CancelButtonText = TeResourceHelper.GetResourceString("kstidStopImporting"); progressDlg.Title = TeResourceHelper.GetResourceString("kstidImportProgressCaption"); progressDlg.StatusMessage = TeResourceHelper.GetResourceString("kstidImportInitializing"); if (importSettings == null) // XML (OXES) import { progressDlg.ProgressBarStyle = ProgressBarStyle.Continuous; } TeImportUi importUi = CreateTeImportUi(progressDlg); #if DEBUG_SINGLE_THREADED if (importSettings != null) { firstImported = (ScrReference)progressDlg.RunTask_DebuggingOnly(fDisplayUi, new BackgroundTaskInvoker(Import), importSettings, undoImportManager, importUi); } else { firstImported = (ScrReference)progressDlg.RunTask_DebuggingOnly(fDisplayUi, new BackgroundTaskInvoker(ImportXml), undoImportManager, importUi); } #else if (importSettings != null) { firstImported = (ScrReference)progressDlg.RunTask(fDisplayUi, new BackgroundTaskInvoker(ImportSf), importSettings, m_undoImportManager, importUi); } else { firstImported = (ScrReference)progressDlg.RunTask(fDisplayUi, new BackgroundTaskInvoker(ImportXml), m_undoImportManager, importUi); } #endif } } catch (WorkerThreadException e) { if (e.InnerException is ScriptureUtilsException) { ScriptureUtilsException se = e.InnerException as ScriptureUtilsException; if (FwApp.App != null) { string sCaption = ScriptureUtilsException.GetResourceString( se.IsBackTransError ? "kstidBTImportErrorCaption" : "kstidImportErrorCaption"); MessageBox.Show(m_mainWnd, se.Message, sCaption, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, FwApp.App.HelpFile, HelpNavigator.Topic, se.HelpTopic); } if (se.IsBackTransError && !se.InterleavedImport) { fPartialBtImported = true; } else { fRollbackPartialBook = true; } } else if (e.InnerException is ParatextLoadException) { if (FwApp.App != null) { string sCaption = ScriptureUtilsException.GetResourceString("kstidImportErrorCaption"); Exception innerE = e.InnerException; StringBuilder sbMsg = new StringBuilder(innerE.Message); while (innerE.InnerException != null) { innerE = innerE.InnerException; sbMsg.Append("\r"); sbMsg.Append(innerE.Message); } MessageBox.Show(m_mainWnd, sbMsg.ToString(), sCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); } fRollbackPartialBook = true; } else if (e.InnerException is CancelException) { // User cancelled import in the middle of a book fRollbackPartialBook = true; } else { m_undoImportManager.DoneImportingFiles(true); m_undoImportManager.CollapseAllUndoActions(); throw; } } finally { m_importedSavedVersion = m_undoImportManager.ImportedSavedVersion; Logger.WriteEvent("Finished importing"); } m_undoImportManager.DoneImportingFiles(fRollbackPartialBook); if (m_importedSavedVersion != null && m_importedSavedVersion.BooksOS.Count == 0 && !fPartialBtImported) { // Either there was nothing in the file, or the user canceled during the first book. // In any case, we didn't get any books, so whatever has been done should be undone. m_undoImportManager.UndoEntireImport(); m_importedSavedVersion = null; return(null); } } return(firstImported); }