UI elements of import. Gets called from TeImport.
This class needs to deal with multi threading issues since it gets called from TeImport (which runs in the background), but every UI element it creates needs to run on the main thread.
Наследование: IFWDisposable
Пример #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Imports using the specified import settings.
        /// </summary>
        /// <param name="progressDlg">The progress dialog.</param>
        /// <param name="parameters">The paramaters: import settings, undo action, and book
        /// merger, TeImportUi.</param>
        /// <returns>The Scripture reference of the first thing imported</returns>
        /// <remarks>This method runs on the background thread!</remarks>
        /// ------------------------------------------------------------------------------------
        protected virtual object ImportSf(IAdvInd4 progressDlg, object[] parameters)
        {
            Debug.Assert(parameters.Length == 3);
            IScrImportSet     importSettings = (IScrImportSet)parameters[0];
            UndoImportManager undoManager    = (UndoImportManager)parameters[1];
            TeImportUi        importUi       = (TeImportUi)parameters[2];

            return(TeSfmImporter.Import(importSettings, m_cache, m_styleSheet,
                                        undoManager, importUi));
        }
Пример #2
0
        /// <summary>
        /// Calls the importer.
        /// </summary>
        /// <param name="importSettings">The import settings.</param>
        /// <param name="undoManager">The undo manager.</param>
        /// <param name="importUi">The import UI.</param>
        /// <returns></returns>
        protected virtual ScrReference Import(IScrImportSet importSettings, UndoImportManager undoManager,
                                              TeImportUi importUi)
        {
            if (importSettings != null)
            {
                return(TeSfmImporter.Import(importSettings, m_cache, m_styleSheet,
                                            undoManager, importUi, m_fParatextStreamlinedImport));
            }

            return((ScrReference)TeXmlImporter.Import(m_cache, m_styleSheet, m_sOXESFile,
                                                      undoManager, importUi));
        }
Пример #3
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);
        }
Пример #4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the TeSfmImporter class
		/// </summary>
		/// <param name="settings">Import settings object (filled in by wizard)</param>
		/// <param name="cache">The cache used to import to and get misc. info. from.</param>
		/// <param name="styleSheet">Stylesheet from which to get scripture styles.</param>
		/// <param name="undoManager">The undo import manager(which is responsible for creating
		/// and maintainging the archive of original books being overwritten).</param>
		/// <param name="importCallbacks">UI callbacks</param>
		/// ------------------------------------------------------------------------------------
		protected TeSfmImporter(IScrImportSet settings, FdoCache cache,
			FwStyleSheet styleSheet, UndoImportManager undoManager, TeImportUi importCallbacks)
		{
			Debug.Assert(cache != null);
			Debug.Assert(styleSheet != null);

			m_settings = settings;
			m_cache = cache;
			m_styleSheet = styleSheet;
			m_undoManager = undoManager;
			m_importCallbacks = importCallbacks;
			m_importCallbacks.Importer = this;

			Debug.Assert(m_settings.BasicSettingsExist);
			// ENHANCE (TomB): Make it possible to start importing in the middle
			// of a book.
			(m_settings as ScrImportSet).StartRef =
				new BCVRef((m_settings as ScrImportSet).StartRef.Book, 1, 0);
		}
Пример #5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Call this static method to Import Scripture
		/// </summary>
		/// <param name="settings">Import settings object (filled in by wizard)</param>
		/// <param name="cache">The cache used to import to and get misc. info. from.</param>
		/// <param name="styleSheet">Stylesheet from which to get scripture styles.</param>
		/// <param name="undoManager">The undo import manager (which is responsible for creating
		/// and maintaining the archive of original books being overwritten and maintaining
		/// the book filter).</param>
		/// <param name="importCallbacks">UI callbacks</param>
		/// <returns>
		/// The Scripture reference of the first thing that was imported
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public static ScrReference Import(IScrImportSet settings, FdoCache cache,
			FwStyleSheet styleSheet, UndoImportManager undoManager, TeImportUi importCallbacks)
		{
			using (TeSfmImporter importer = new TeSfmImporter(settings, cache, styleSheet, undoManager,
				importCallbacks))
			{
				importer.Import();
				return importer.m_firstImportedRef;
			}	// Dispose() releases any hold on ICU character properties.
		}
Пример #6
0
		/// <summary>
		/// Executes in two distinct scenarios.
		///
		/// 1. If disposing is true, the method has been called directly
		/// or indirectly by a user's code via the Dispose method.
		/// Both managed and unmanaged resources can be disposed.
		///
		/// 2. If disposing is false, the method has been called by the
		/// runtime from inside the finalizer and you should not reference (access)
		/// other managed objects, as they already have been garbage collected.
		/// Only unmanaged resources can be disposed.
		/// </summary>
		/// <param name="disposing"></param>
		/// <remarks>
		/// If any exceptions are thrown, that is fine.
		/// If the method is being done in a finalizer, it will be ignored.
		/// If it is thrown by client code calling Dispose,
		/// it needs to be handled by fixing the bug.
		///
		/// If subclasses override this method, they should call the base implementation.
		/// </remarks>
		protected virtual void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (m_isDisposed)
				return;

			if (disposing)
			{
				// Dispose managed resources here.
				if (m_ParaBldr != null)
					m_ParaBldr.Dispose();
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_ParaBldr = null;
			m_cache = null;
			m_styleSheet = null;
			m_scr = null;
			m_undoManager = null;
			m_importCallbacks = null;
			m_ScrSectionHeadParaProxy = null;
			m_DefaultIntroSectionHeadParaProxy = null;
			m_DefaultScrParaProxy = null;
			m_DefaultIntroParaProxy = null;
			m_BTStrBldrs = null;
			m_SavedParaBldr = null;
			m_CurrFootnote = null;
			m_ttpChapterNumber = null;
			m_sPrevBook = null;
			m_scrBook = null;
			m_currSection = null;

			m_isDisposed = true;
		}
Пример #7
0
		/// <summary>
		/// Calls the importer.
		/// </summary>
		/// <param name="importSettings">The import settings.</param>
		/// <param name="undoManager">The undo manager.</param>
		/// <param name="importUi">The import UI.</param>
		/// <returns></returns>
		protected virtual ScrReference Import(IScrImportSet importSettings, UndoImportManager undoManager,
			TeImportUi importUi)
		{
			if (importSettings != null)
			{
				return TeSfmImporter.Import(importSettings, m_cache, m_styleSheet,
					undoManager, importUi, m_fParatextStreamlinedImport);
			}

			return (ScrReference) TeXmlImporter.Import(m_cache, m_styleSheet, m_sOXESFile,
				undoManager, importUi);
		}
Пример #8
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Call this static method to Import Scripture
		/// </summary>
		/// <param name="settings">Import settings object (filled in by wizard)</param>
		/// <param name="cache">The cache used to import to and get misc. info. from.</param>
		/// <param name="styleSheet">Stylesheet from which to get scripture styles.</param>
		/// <param name="undoManager">The undo import manager (which is responsible for creating
		/// and maintaining the archive of original books being overwritten and maintaining
		/// the book filter).</param>
		/// <param name="importCallbacks">UI callbacks</param>
		/// <param name="streamLinedImport">flag indicated if import id done through FLEx.</param>
		/// <returns>
		/// The Scripture reference of the first thing that was imported
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public static ScrReference Import(IScrImportSet settings, FdoCache cache,
			FwStyleSheet styleSheet, UndoImportManager undoManager, TeImportUi importCallbacks,
			bool streamLinedImport = false)
		{
			using (TeSfmImporter importer = new TeSfmImporter(settings, cache, styleSheet, undoManager,
				importCallbacks, streamLinedImport))
			{
				importer.Import();
				importCallbacks.AllowCancel = false; // LT-16647: Disallow canceling import after it is complete (before disposing importer).
				return importer.m_firstImportedRef;
			}	// Dispose() releases any hold on ICU character properties.
		}
Пример #9
0
        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);
        }
Пример #10
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Call this static method to import Scripture from an OXES (XML) file.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="styleSheet"></param>
		/// <param name="sOXESFile"></param>
		/// <param name="undoManager"></param>
		/// <param name="importUi"></param>
		/// <returns></returns>
		/// -----------------------------------------------------------------------------------
		public static object Import(FdoCache cache, FwStyleSheet styleSheet, string sOXESFile,
			UndoImportManager undoManager, TeImportUi importUi)
		{
#if DEBUG
			DateTime start = DateTime.Now;
#endif
			using (TeXmlImporter importer = new TeXmlImporter(cache, styleSheet, sOXESFile, undoManager,
				importUi))
			{
				importer.ImportXml();
#if DEBUG
				TimeSpan span = new TimeSpan(DateTime.Now.Ticks - start.Ticks);
				string msg = String.Format("Time to import {0}: {1} hours, {2} minutes, {3} seconds, {4} millseconds ({5} ticks).",
					sOXESFile, span.Hours, span.Minutes, span.Seconds, span.Milliseconds, span.Ticks);
				Debug.WriteLine(msg);
#endif
				return importer.m_firstImportedRef;
			}
		}
Пример #11
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Constructor used with XML (OXES) based import.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="styleSheet"></param>
		/// <param name="sOXESFile">name of the XML (OXES) file</param>
		/// <param name="undoManager"></param>
		/// <param name="importCallbacks"></param>
		/// -----------------------------------------------------------------------------------
		private TeXmlImporter(FdoCache cache, FwStyleSheet styleSheet, string sOXESFile,
			UndoImportManager undoManager, TeImportUi importCallbacks)
		{
			Debug.Assert(cache != null);
			Debug.Assert(styleSheet != null);
			Debug.Assert(sOXESFile != null && sOXESFile.Length > 0);

			m_cache = cache;
			m_styleSheet = styleSheet;
			m_sOXESFile = sOXESFile;

			// Allow tests to pass in a bogus filename.
			m_sOXESDir = (m_sOXESFile.Trim().Length > 0 ? Path.GetDirectoryName(m_sOXESFile) : null);
			m_undoManager = undoManager;
			m_importCallbacks = importCallbacks;
			m_importCallbacks.Importer = this;
			int cChapters = CountChapters();
			if (cChapters > 0)
				m_importCallbacks.Maximum = cChapters;
			m_rfcWs = new RfcWritingSystem(cache, false);
		}
Пример #12
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Constructor used with XML (OXES) based import.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="styleSheet"></param>
		/// <param name="sOXESFile">name of the XML (OXES) file</param>
		/// <param name="undoManager"></param>
		/// <param name="importCallbacks"></param>
		/// -----------------------------------------------------------------------------------
		protected TeXmlImporter(FdoCache cache, FwStyleSheet styleSheet, string sOXESFile,
			UndoImportManager undoManager, TeImportUi importCallbacks)
		{
			Debug.Assert(cache != null);
			Debug.Assert(styleSheet != null);
			Debug.Assert(sOXESFile != null && sOXESFile.Length > 0);

			m_cache = cache;
			m_styleSheet = styleSheet;
			m_sOXESFile = sOXESFile;

			// Allow tests to pass in a bogus filename.
			m_sOXESDir = (m_sOXESFile.Trim().Length > 0 ? Path.GetDirectoryName(m_sOXESFile) : null);
			m_undoManager = undoManager;
			m_importCallbacks = importCallbacks;
			m_importCallbacks.Importer = this;
			int cChapters = CountChapters();
			if (cChapters > 0)
				m_importCallbacks.Maximum = cChapters;

			m_tssChapterStartKey = TsStringUtils.MakeTss("chapterStart", m_cache.DefaultUserWs);
			m_tssVerseStartKey = TsStringUtils.MakeTss("verseStart", m_cache.DefaultUserWs);
			m_tssLabelTrKey = TsStringUtils.MakeTss("labelTr", m_cache.DefaultUserWs);
			m_tssNoteKey = TsStringUtils.MakeTss("note", m_cache.DefaultUserWs);
			m_tssFigureKey = TsStringUtils.MakeTss("figure", m_cache.DefaultUserWs);
		}