Ejemplo n.º 1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// If all of the books are "new" or auto-merged, then don't actually show the dialog.
		/// See TE-7072 and TE-2126. Otherwise, show the dialog and process normally.
		/// </summary>
		/// <param name="wnd"></param>
		/// ------------------------------------------------------------------------------------
		public void ShowOrSave(IWin32Window wnd)
		{
			int cNewOrAutoMerged = 0;
			m_owningForm = wnd as Form;

			foreach (ListViewItem item in lstImportedBooks.Items)
			{
				BookMerger bookMerger = item.Tag as BookMerger;
				if (bookMerger == null)
				{
					++cNewOrAutoMerged;
					continue;
				}

				using (ProgressDialogWithTask progressDlg = new ProgressDialogWithTask(m_owningForm))
				{
					bookMerger.AttemptAutoMerge = true;
					bookMerger.BookVersionAgent = this;
					bookMerger.UseFilteredDiffList();
					progressDlg.Title = DlgResources.ResourceString("kstidCompareCaption");
					Debug.Assert(bookMerger.BookRev != null);
					progressDlg.Message = string.Format(
						DlgResources.ResourceString("kstidMergeProgress"), bookMerger.BookRev.BestUIName);
#if DEBUG_SINGLE_THREADED
					progressDlg.RunTask_DebuggingOnly(true, new BackgroundTaskInvoker(
						bookMerger.DetectDifferences));
#else
					progressDlg.RunTask(true, new BackgroundTaskInvoker(bookMerger.DetectDifferences));
#endif
				}
				if (bookMerger.AutoMerged)
				{
					SetItemStatus(item, ImportedBookStatus.AutoMerged);
					cNewOrAutoMerged++;
				}
			}

			if (cNewOrAutoMerged < lstImportedBooks.Items.Count)
				ShowDialog(wnd);
			else
				OnClosed(null);
		}
Ejemplo n.º 2
0
		/// ------------------------------------------------------------------------------------
		/// <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;
		}