/// ------------------------------------------------------------------------------------ /// <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); }
private ScrReference InternalImport(IScrImportSet importSettings, bool fDisplayUi) { ScrReference firstImported = ScrReference.Empty; bool fPartialBtImported = false; try { Logger.WriteEvent("Starting import"); using (var progressDlg = new ProgressDialogWithTask(m_mainWnd)) { progressDlg.CancelButtonText = TeResourceHelper.GetResourceString("kstidStopImporting"); progressDlg.Title = TeResourceHelper.GetResourceString("kstidImportProgressCaption"); progressDlg.Message = TeResourceHelper.GetResourceString("kstidImportInitializing"); using (TeImportUi importUi = CreateTeImportUi(progressDlg)) { firstImported = (ScrReference)progressDlg.RunTask(fDisplayUi, ImportTask, importSettings, m_undoImportManager, importUi); } } } catch (WorkerThreadException e) { if (e.InnerException is ScriptureUtilsException) { var se = (ScriptureUtilsException)e.InnerException; if (m_helpTopicProvider != null) { string sCaption = GetDialogCaption(se.ImportErrorCodeType); // TODO-Linux: Help is not implemented in Mono MessageBox.Show(m_mainWnd, se.Message, sCaption, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, m_helpTopicProvider.HelpFile, HelpNavigator.Topic, se.HelpTopic); } if (se.ImportErrorCodeType == ErrorCodeType.BackTransErrorCode && !se.InterleavedImport) { fPartialBtImported = true; } } else if (e.InnerException is ParatextLoadException) { if (!MiscUtils.RunningTests) { Logger.WriteError(e); string sCaption = ScriptureUtilsException.GetResourceString("kstidImportErrorCaption"); Exception innerE = e.InnerException; var sbMsg = new StringBuilder(innerE.Message); while (innerE.InnerException != null) { innerE = innerE.InnerException; sbMsg.AppendLine(); sbMsg.Append(innerE.Message); } MessageBoxUtils.Show(m_mainWnd, sbMsg.ToString(), sCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (!(e.InnerException is CancelException)) { // User didn't just cancel import in the middle of a book -- let's die. throw e; } } if (m_undoImportManager.ImportedBooks.Count == 0 && !fPartialBtImported) { Logger.WriteEvent("Nothing imported. Undoing Import."); // 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(); return(null); } return(firstImported); }