コード例 #1
0
        private void DisplayImportError(SUE_ErrorCode errorCode, string sParam1, string sParam2,
                                        string msgDetails)
        {
            string msgTemplate;
            string topic;
            bool   includeDetails;

            ScriptureUtilsException.GetErrorMsgAndHelpTopic(errorCode,
                                                            out msgTemplate, out topic, out includeDetails);
            string message;

            if (!string.IsNullOrEmpty(sParam1) && !string.IsNullOrEmpty(sParam2))
            {
                message = string.Format(msgTemplate, sParam1, sParam2, msgDetails);
            }
            else if (!string.IsNullOrEmpty(sParam1))
            {
                message = string.Format(msgTemplate, sParam1, msgDetails);
            }
            else
            {
                message = string.Format(msgTemplate, msgDetails);
            }

            // TODO-Linux: Help is not implemented in Mono
            MessageBox.Show(this, message,
                            ScriptureUtilsException.GetResourceString("kstidXmlImportErrorCaption"),
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, m_helpTopicProvider.HelpFile,
                            HelpNavigator.Topic, topic);
        }
コード例 #2
0
        public void BackTranslation_ReportBTTextNotPartOfPara()
        {
            CheckDisposed();

            m_importer.Settings.ImportBackTranslation = true;
            m_importer.TextSegment.FirstReference     = new BCVRef(2, 0, 0);
            m_importer.TextSegment.LastReference      = new BCVRef(2, 0, 0);
            m_importer.ProcessSegment("", @"\id");

            ReflectionHelper.SetField(m_importer, "m_importDomain", ImportDomain.BackTrans);

            ITsStrBldr bldr = TsStrBldrClass.Create();

            bldr.ReplaceRgch(0, 0, "Exodus", 6, null);
            Dictionary <int, ITsStrBldr> bldrs = ReflectionHelper.GetField(m_importer, "m_BTStrBldrs") as Dictionary <int, ITsStrBldr>;

            bldrs[1] = bldr;

            try
            {
                ReflectionHelper.CallMethod(m_importer, "ReportBTTextNotPartOfPara");
            }
            catch (Exception e)
            {
                ScriptureUtilsException sue = e.InnerException as ScriptureUtilsException;
                Assert.IsFalse(sue.InterleavedImport);
            }
        }
コード例 #3
0
ファイル: TeImportUi.cs プロジェクト: vkarthim/FieldWorks
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Displays an import error message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// ------------------------------------------------------------------------------------
        public virtual void ErrorMessage(string message)
        {
            CheckDisposed();

            if (m_ctrl.InvokeRequired)
            {
                m_ctrl.Invoke(new StringErrorMessageInvoker(ErrorMessage), message);
            }
            else
            {
                MessageBox.Show(message,
                                ScriptureUtilsException.GetResourceString("kstidImportErrorCaption"));
            }
        }
コード例 #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the caption for the Unable to Import message box.
        /// </summary>
        /// <param name="codeType">Type of the code.</param>
        /// <returns>string for the message box caption</returns>
        /// ------------------------------------------------------------------------------------
        private string GetDialogCaption(ErrorCodeType codeType)
        {
            switch (codeType)
            {
            case ErrorCodeType.BackTransErrorCode:
                return(ScriptureUtilsException.GetResourceString("kstidBTImportErrorCaption"));

            case ErrorCodeType.XmlErrorCode:
                return(ScriptureUtilsException.GetResourceString("kstidXmlImportErrorCaption"));

            default:
                return(ScriptureUtilsException.GetResourceString("kstidImportErrorCaption"));
            }
        }
コード例 #5
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Displays the "Unable to Import" message box.
        /// </summary>
        /// -----------------------------------------------------------------------------------
        private void DisplayImportError(SUE_ErrorCode errorCode, string msgDetails)
        {
            string msgTemplate;
            string topic;
            bool   includeDetails;

            ScriptureUtilsException.GetErrorMsgAndHelpTopic(errorCode,
                                                            out msgTemplate, out topic, out includeDetails);
            MessageBox.Show(this, string.Format(msgTemplate, msgDetails),
                            ScriptureUtilsException.GetResourceString("kstidImportErrorCaption"),
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, FwApp.App.HelpFile,
                            HelpNavigator.Topic, topic);
        }
コード例 #6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Displays an import error message.
        /// </summary>
        /// <param name="e">The exception.</param>
        /// ------------------------------------------------------------------------------------
        public virtual void ErrorMessage(EncodingConverterException e)
        {
            CheckDisposed();

            if (m_ctrl.InvokeRequired)
            {
                m_ctrl.Invoke(new ExceptionErrorMessageInvoker(ErrorMessage), e);
            }
            else
            {
                MessageBox.Show(m_progressDialog.OwnerForm, e.Message,
                                ScriptureUtilsException.GetResourceString("kstidImportErrorCaption"),
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, FwApp.App.HelpFile,
                                HelpNavigator.Topic, e.HelpTopic);
            }
        }
コード例 #7
0
ファイル: TeImportUi.cs プロジェクト: vkarthim/FieldWorks
        public virtual void ErrorMessage(EncodingConverterException e)
        {
            CheckDisposed();

            if (m_ctrl.InvokeRequired)
            {
                m_ctrl.Invoke(new ExceptionErrorMessageInvoker(ErrorMessage), e);
            }
            else
            {
                // TODO-Linux: Help is not implemented in Mono
                MessageBox.Show(e.Message,
                                ScriptureUtilsException.GetResourceString("kstidImportErrorCaption"),
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0,
                                m_helpTopicProvider.HelpFile, HelpNavigator.Topic, e.HelpTopic);
            }
        }
コード例 #8
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create a text segment enumerator for importing a project
		/// </summary>
		/// <param name="firstRef">start reference for importing</param>
		/// <param name="lastRef">end reference for importing</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public ISCTextEnum TextEnum(BCVRef firstRef, BCVRef lastRef)
		{
			try
			{
				if (m_encConverters == null)
					m_encConverters = new EncConverters();
			}
			catch (DirectoryNotFoundException ex)
			{
				string message = string.Format(ScriptureUtilsException.GetResourceString(
						"kstidEncConverterInitError"), ex.Message);
				throw new EncodingConverterException(message,
					"/Beginning_Tasks/Import_Standard_Format/Unable_to_Import/Encoding_converter_not_found.htm");
			}

			// get the enumerator that will return text segments
			return new SCTextEnum(m_settings, m_domain, firstRef, lastRef, m_encConverters);
		}
コード例 #9
0
ファイル: SCTextEnum.cs プロジェクト: sillsdev/WorldPad
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get an encoding converter for a mapping
        /// </summary>
        /// <param name="icuLocale">An ICU Locale</param>
        /// <param name="marker">The marker whose data is to be converted (used only for
        /// error reporting)</param>
        /// <returns>the encoding converter for the writing system of the mapping's ICU locale
        /// </returns>
        /// ------------------------------------------------------------------------------------
        private IEncConverter GetEncodingConverterForLocale(string icuLocale, string marker)
        {
            // If an entry already exists, then just look it up and return it
            if (m_icuLocaleToConverterMap.ContainsKey(icuLocale))
            {
                return(m_icuLocaleToConverterMap[icuLocale]);
            }

            // If there is no entry, then find the writing system with the ICU locale, get its
            // converter name and get a converter for that name.
            ILgWritingSystem ws = new LgWritingSystem(Cache,
                                                      Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr(icuLocale));
            IEncConverter converter = null;

            if (ws.LegacyMapping != null)
            {
                try
                {
                    converter = (IEncConverter)m_encConverters[ws.LegacyMapping];
                }
                catch
                {
                    // Something bad happened... Try to carry on.
                    // This is a workaround until TE-5068 is fixed.
                    converter = null;
                }
                if (converter == null)
                {
                    throw new EncodingConverterException(string.Format(ScriptureUtilsException.GetResourceString(
                                                                           "kstidEncConvMissingConverter"), m_lineNumber, m_currentFile.FileName,
                                                                       ws.LegacyMapping, marker),
                                                         "/Beginning_Tasks/Import_Standard_Format/Unable_to_Import/Encoding_converter_not_found.htm");
                }
            }
            m_icuLocaleToConverterMap[icuLocale] = converter;
            return(converter);
        }
コード例 #10
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get an encoding converter for a mapping
        /// </summary>
        /// <param name="wsId">The writing system ID</param>
        /// <param name="marker">The marker whose data is to be converted (used only for
        /// error reporting)</param>
        /// <returns>the encoding converter for the writing system of the mapping's ICU locale
        /// </returns>
        /// ------------------------------------------------------------------------------------
        private IEncConverter GetEncodingConverterForWs(string wsId, string marker)
        {
            // If an entry already exists, then just look it up and return it
            if (m_wsIdToConverterMap.ContainsKey(wsId))
            {
                return(m_wsIdToConverterMap[wsId]);
            }

            // If there is no entry, then find the writing system with the ICU locale, get its
            // converter name and get a converter for that name.
            CoreWritingSystemDefinition ws = Cache.ServiceLocator.WritingSystemManager.Get(wsId);
            IEncConverter converter        = null;

            if (!string.IsNullOrEmpty(ws.LegacyMapping))
            {
                try
                {
                    converter = m_encConverters[ws.LegacyMapping];
                }
                catch
                {
                    // Something bad happened... Try to carry on.
                    // This is a workaround until TE-5068 is fixed.
                    converter = null;
                }
                if (converter == null)
                {
                    throw new EncodingConverterException(string.Format(ScriptureUtilsException.GetResourceString(
                                                                           "kstidEncConvMissingConverter"), m_lineNumber, m_currentFile.FileName,
                                                                       ws.LegacyMapping, marker),
                                                         "/Beginning_Tasks/Import_Standard_Format/Unable_to_Import/Encoding_converter_not_found.htm");
                }
            }
            m_wsIdToConverterMap[wsId] = converter;
            return(converter);
        }
コード例 #11
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);
        }
コード例 #12
0
ファイル: SCTextEnum.cs プロジェクト: sillsdev/WorldPad
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Convert the source line into unicode if necessary
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private string ConvertSource(string source, ImportMappingInfo markerMapping)
        {
            // If the file is already Unicode then no need to convert it.
            if (m_currentFile.FileEncoding != Encoding.ASCII)
            {
                return(source);
            }

            IEncConverter dataEncoding;

            if (markerMapping == null)
            {
                // If the marker is not mapped, use the containing paragraph's encoding.
                dataEncoding = m_prevDataEncoding;
            }
            else
            {
                // book markers are a special case - do not convert them
                if (markerMapping.BeginMarker == ScrImportSet.s_markerBook)
                {
                    return(source);
                }

                if (markerMapping.IcuLocale != null)
                {
                    dataEncoding = GetEncodingConverterForLocale(markerMapping.IcuLocale,
                                                                 markerMapping.BeginMarker);
                }
                else
                {
                    // For paragraph styles or markers that do not map to existing styles,
                    // or verse or chapter numbers or any default para char style that is
                    // not inline get the encoder from the current domain. Otherwise use
                    // the containing paragraph's encoder
                    if (markerMapping.Style == null || markerMapping.IsParagraphStyle ||
                        markerMapping.StyleName == ScrStyleNames.VerseNumber ||
                        markerMapping.StyleName == ScrStyleNames.ChapterNumber ||
                        (!markerMapping.IsInline && markerMapping.StyleName ==
                         FdoResources.DefaultParaCharsStyleName))
                    {
                        dataEncoding = GetEncodingConverterForMarkerDomain(markerMapping);
                    }
                    else
                    {
                        dataEncoding = m_prevDataEncoding;
                    }
                }

                // If the marker maps to a paragraph style or pertains to a non-default domain,
                // then save the encoder as the current paragraph encoder
                if (m_domain == ImportDomain.Main &&
                    ((markerMapping.StyleName != FdoResources.DefaultParaCharsStyleName &&
                      (markerMapping.Style == null || markerMapping.IsParagraphStyle)) ||
                     (markerMapping.Domain & ~MarkerDomain.Footnote) != MarkerDomain.Default))
                {
                    m_prevDataEncoding = dataEncoding;
                }
            }

            // If an encoder was not found, then just return the text
            if (dataEncoding == null)
            {
                return(source);
            }

            // get a converter and convert the text
            dataEncoding.CodePageInput = kMagicCodePage;
            if (source != string.Empty)
            {
                try
                {
                    source = dataEncoding.Convert(source);
                }
                catch (Exception e)
                {
                    throw new EncodingConverterException(
                              string.Format(ScriptureUtilsException.GetResourceString(
                                                "kstidEncConverterError"), e.Message, dataEncoding.Name),
                              "/Beginning_Tasks/Import_Standard_Format/Unable_to_Import/Encoding_conversion_failed.htm");
                }
            }

            return(source);
        }
コード例 #13
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);
        }