Ejemplo n.º 1
0
            /// ------------------------------------------------------------------------------------
            /// <summary>
            /// Load the mappings for a Paratext 6/7 project into the specified list.
            /// </summary>
            /// <returns><c>true</c> if the Paratext mappings were loaded successfully; <c>false</c>
            /// otherwise</returns>
            /// ------------------------------------------------------------------------------------
            public void LoadProjectMappings(IScrImportSet importSettings)
            {
                RefreshProjects();
                if (!m_IsParatextInitialized)
                {
                    ClearImportSettings(importSettings);
                    return;
                }

                var mainMappings      = importSettings.GetMappingListForDomain(ImportDomain.Main);
                var backTransMappings = importSettings.GetMappingListForDomain(ImportDomain.BackTrans);
                var notesMappings     = importSettings.GetMappingListForDomain(ImportDomain.Annotations);

                if (mainMappings == null || backTransMappings == null || notesMappings == null)
                {
                    ClearImportSettings(importSettings);
                    return;
                }

                if (!LoadProjectMappings(importSettings.ParatextScrProj, mainMappings, ImportDomain.Main))
                {
                    importSettings.ParatextScrProj = null;
                }

                if (!LoadProjectMappings(importSettings.ParatextBTProj, backTransMappings, ImportDomain.BackTrans))
                {
                    importSettings.ParatextBTProj = null;
                }

                if (!LoadProjectMappings(importSettings.ParatextNotesProj, notesMappings, ImportDomain.Annotations))
                {
                    importSettings.ParatextNotesProj = null;
                }
            }
Ejemplo n.º 2
0
            /// ------------------------------------------------------------------------------------
            /// <summary>
            /// Load the mappings for a Paratext 6/7 project into the specified list.
            /// </summary>
            /// <returns><c>true</c> if the Paratext mappings were loaded successfully; <c>false</c>
            /// otherwise</returns>
            /// ------------------------------------------------------------------------------------
            public void LoadProjectMappings(IScrImportSet importSettings)
            {
                RefreshProjects();
                if (!m_IsParatextInitialized)
                {
                    importSettings.ParatextScrProj   = null;
                    importSettings.ParatextBTProj    = null;
                    importSettings.ParatextNotesProj = null;
                    return;
                }

                if (!LoadProjectMappings(importSettings.ParatextScrProj, importSettings.GetMappingListForDomain(ImportDomain.Main), ImportDomain.Main))
                {
                    importSettings.ParatextScrProj = null;
                }

                if (!LoadProjectMappings(importSettings.ParatextBTProj, importSettings.GetMappingListForDomain(ImportDomain.BackTrans), ImportDomain.BackTrans))
                {
                    importSettings.ParatextBTProj = null;
                }

                if (!LoadProjectMappings(importSettings.ParatextNotesProj, importSettings.GetMappingListForDomain(ImportDomain.Annotations), ImportDomain.Annotations))
                {
                    importSettings.ParatextNotesProj = null;
                }
            }
Ejemplo n.º 3
0
        public void LoadParatextMappings_MarkMappingsInUse()
        {
            var stylesheet = new FwStyleSheet();

            stylesheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles);
            IScrImportSet importSettings = Cache.ServiceLocator.GetInstance <IScrImportSetFactory>().Create();

            importSettings.ParatextScrProj = "TEV";
            ScrMappingList mappingList = importSettings.GetMappingListForDomain(ImportDomain.Main);

            mappingList.Add(new ImportMappingInfo(@"\hahaha", @"\*hahaha", false,
                                                  MappingTargetType.TEStyle, MarkerDomain.Default, "laughing",
                                                  null, null, true, ImportDomain.Main));
            mappingList.Add(new ImportMappingInfo(@"\bthahaha", @"\*bthahaha", false,
                                                  MappingTargetType.TEStyle, MarkerDomain.Default, "laughing",
                                                  "en", null, true, ImportDomain.Main));

            Unpacker.UnPackParatextTestProjects();

            ParatextHelper.LoadProjectMappings(importSettings);

            Assert.IsTrue(mappingList[@"\c"].IsInUse);
            Assert.IsTrue(mappingList[@"\p"].IsInUse);
            Assert.IsFalse(mappingList[@"\ipi"].IsInUse);
            Assert.IsFalse(mappingList[@"\hahaha"].IsInUse,
                           "In-use flag should have been cleared before re-scanning when the P6 project changed.");
            Assert.IsTrue(mappingList[@"\bthahaha"].IsInUse,
                          "In-use flag should not have been cleared before re-scanning when the P6 project changed because it was in use by the BT.");
        }
Ejemplo n.º 4
0
        public void LoadParatextMappings_MarkMappingsInUse()
        {
            if (ScriptureProvider.VersionInUse >= new Version(8, 0))
            {
                Assert.Ignore("This test uses data that is only valid for Paratext7. The test fails with Paratext8 installed.");
            }
            var stylesheet = new LcmStyleSheet();

            stylesheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles);
            IScrImportSet importSettings = Cache.ServiceLocator.GetInstance <IScrImportSetFactory>().Create();

            Cache.LangProject.TranslatedScriptureOA.ImportSettingsOC.Add(importSettings);
            importSettings.ParatextScrProj = "TEV";
            ScrMappingList mappingList = importSettings.GetMappingListForDomain(ImportDomain.Main);

            Assert.NotNull(mappingList, "Setup Failure, no mapping list returned for the domain.");
            mappingList.Add(new ImportMappingInfo(@"\hahaha", @"\*hahaha", false,
                                                  MappingTargetType.TEStyle, MarkerDomain.Default, "laughing",
                                                  null, null, true, ImportDomain.Main));
            mappingList.Add(new ImportMappingInfo(@"\bthahaha", @"\*bthahaha", false,
                                                  MappingTargetType.TEStyle, MarkerDomain.Default, "laughing",
                                                  "en", null, true, ImportDomain.Main));

            Unpacker.UnPackParatextTestProjects();

            ParatextHelper.LoadProjectMappings(importSettings);

            Assert.IsTrue(mappingList[@"\c"].IsInUse);
            Assert.IsTrue(mappingList[@"\p"].IsInUse);
            Assert.IsFalse(mappingList[@"\ipi"].IsInUse);
            Assert.IsFalse(mappingList[@"\hahaha"].IsInUse,
                           "In-use flag should have been cleared before re-scanning when the P6 project changed.");
            Assert.IsTrue(mappingList[@"\bthahaha"].IsInUse,
                          "In-use flag should not have been cleared before re-scanning when the P6 project changed because it was in use by the BT.");
        }
Ejemplo n.º 5
0
        public void LoadParatextMappings_Normal()
        {
            if (ScriptureProvider.VersionInUse >= new Version(8, 0))
            {
                Assert.Ignore("This test uses data that is only valid for Paratext7. The test fails with Paratext8 installed.");
            }
            Unpacker.UnPackParatextTestProjects();

            var stylesheet = new LcmStyleSheet();

            stylesheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles);
            IScrImportSet importSettings = Cache.ServiceLocator.GetInstance <IScrImportSetFactory>().Create();

            Cache.LangProject.TranslatedScriptureOA.ImportSettingsOC.Add(importSettings);
            importSettings.ParatextScrProj = "KAM";
            ParatextHelper.LoadProjectMappings(importSettings);

            ScrMappingList mappingList = importSettings.GetMappingListForDomain(ImportDomain.Main);

            // Test to see that the projects are set correctly
            Assert.AreEqual(44, mappingList.Count);

            Assert.AreEqual(MarkerDomain.Default, mappingList[@"\c"].Domain);
            Assert.AreEqual(MarkerDomain.Default, mappingList[@"\v"].Domain);
            Assert.AreEqual(@"\f*", mappingList[@"\f"].EndMarker);
            Assert.IsTrue(mappingList[@"\p"].IsInUse);
            Assert.IsFalse(mappingList[@"\tb2"].IsInUse);
        }
Ejemplo n.º 6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Imports the specified book.
        /// </summary>
        /// <param name="owningForm">Form that can be used as the owner of progress dialogs and
        /// message boxes.</param>
        /// <param name="bookNum">The canonical book number.</param>
        /// <returns>
        /// The ScrBook created to hold the imported data
        /// </returns>
        /// ------------------------------------------------------------------------------------
        private IScrBook ImportBook(Form owningForm, int bookNum)
        {
            IScrImportSet importSettings        = null;
            var           haveSomethingToImport = NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
            {
                importSettings = m_scr.FindOrCreateDefaultImportSettings(TypeOfImport.Paratext6, m_scriptureStylesheet, FwDirectoryFinder.FlexStylesPath);
                importSettings.RevertToSaved();
                importSettings.ParatextScrProj = m_associatedPtText.Name;
                importSettings.StartRef        = new BCVRef(bookNum, 0, 0);
                var chapter                          = m_associatedPtText.Versification.LastChapter(bookNum);
                importSettings.EndRef                = new BCVRef(bookNum, chapter, m_associatedPtText.Versification.LastVerse(bookNum, chapter));
                importSettings.ImportTranslation     = true;
                importSettings.ImportBackTranslation = false;
                ParatextHelper.LoadProjectMappings(importSettings);
                var importMap  = importSettings.GetMappingListForDomain(ImportDomain.Main);
                var figureInfo = importMap[@"\fig"];
                if (figureInfo != null)
                {
                    figureInfo.IsExcluded = true;
                }
                importSettings.SaveSettings();
                return(true);
            });

            if (haveSomethingToImport && ReflectionHelper.GetBoolResult(ReflectionHelper.GetType("ParatextImport.dll", "ParatextImport.ParatextImportManager"), "ImportParatext", owningForm, m_cache, importSettings, m_scriptureStylesheet, App))
            {
                return(m_scr.FindBook(bookNum));
            }
            return(null);
        }
        /// <summary>
        /// This class creates text, it must delete it here when UNDO is commanded
        /// so it can update InterestingTexts.
        /// </summary>

/*		public override void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel)
 *              {
 *                      if (cvDel != 1)
 *                              return;
 *                      SaveOnChangeRecord();
 *                      SuppressSaveOnChangeRecord = true;
 *                      try
 *                      {
 *                              m_list.DeleteCurrentObject();
 *                      }
 *                      finally
 *                      {
 *                              SuppressSaveOnChangeRecord = false;
 *                      }
 *                      GetInterestingTextList().UpdateInterestingTexts();
 *              } */

        #region IBookImporter Members
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Imports the specified book.
        /// </summary>
        /// <param name="bookNum">The canonical book number.</param>
        /// <param name="owningForm">Form that can be used as the owner of progress dialogs and
        /// message boxes.</param>
        /// <param name="importBt">True to import only the back translation, false to import
        /// only the main translation</param>
        /// <returns>
        /// The ScrBook created to hold the imported data
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public IScrBook Import(int bookNum, Form owningForm, bool importBt)
        {
            IScripture scr = Cache.LangProject.TranslatedScriptureOA;
            bool       haveSomethingToImport = NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
            {
                IScrImportSet importSettings   = scr.FindOrCreateDefaultImportSettings(TypeOfImport.Paratext6);
                importSettings.StyleSheet      = ScriptureStylesheet;
                IScrText paratextProj          = ParatextHelper.GetAssociatedProject(Cache.ProjectId);
                importSettings.ParatextScrProj = paratextProj.Name;
                importSettings.StartRef        = new BCVRef(bookNum, 0, 0);
                int chapter           = paratextProj.Versification.LastChapter(bookNum);
                importSettings.EndRef = new BCVRef(bookNum, chapter, paratextProj.Versification.LastVerse(bookNum, chapter));
                if (!importBt)
                {
                    importSettings.ImportTranslation     = true;
                    importSettings.ImportBackTranslation = false;
                }
                else
                {
                    List <IScrText> btProjects = ParatextHelper.GetBtsForProject(paratextProj).ToList();
                    if (btProjects.Count > 0 && (string.IsNullOrEmpty(importSettings.ParatextBTProj) ||
                                                 !btProjects.Any(st => st.Name == importSettings.ParatextBTProj)))
                    {
                        importSettings.ParatextBTProj = btProjects[0].Name;
                    }
                    if (string.IsNullOrEmpty(importSettings.ParatextBTProj))
                    {
                        return(false);
                    }
                    importSettings.ImportTranslation     = false;
                    importSettings.ImportBackTranslation = true;
                }
                ParatextHelper.LoadProjectMappings(importSettings);
                ScrMappingList importMap     = importSettings.GetMappingListForDomain(ImportDomain.Main);
                ImportMappingInfo figureInfo = importMap[@"\fig"];
                if (figureInfo != null)
                {
                    figureInfo.IsExcluded = true;
                }
                importSettings.SaveSettings();
                return(true);
            });

            if (haveSomethingToImport && ReflectionHelper.GetBoolResult(ReflectionHelper.GetType("TeImportExport.dll",
                                                                                                 "SIL.FieldWorks.TE.TeImportManager"), "ImportParatext", owningForm, ScriptureStylesheet,
                                                                        (FwApp)m_mediator.PropertyTable.GetValue("App")))
            {
                return(scr.FindBook(bookNum));
            }
            return(null);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Imports the specified book's back translation.
        /// </summary>
        /// <param name="owningForm">Form that can be used as the owner of progress dialogs and
        /// message boxes.</param>
        /// <param name="bookNum">The canonical book number.</param>
        /// <param name="btProject">The BT project to import</param>
        private void ImportBackTranslation(Form owningForm, int bookNum, IScrText btProject)
        {
            if (string.IsNullOrEmpty(btProject.Name))
            {
                return;
            }
            IScrImportSet importSettings = null;

            NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
            {
                importSettings = m_scr.FindOrCreateDefaultImportSettings(TypeOfImport.Paratext6, m_scriptureStylesheet, FwDirectoryFinder.FlexStylesPath);
                importSettings.ParatextScrProj       = m_associatedPtText.Name;
                importSettings.StartRef              = new BCVRef(bookNum, 0, 0);
                importSettings.EndRef                = new BCVRef(bookNum, 0, 0);
                importSettings.ParatextBTProj        = btProject.Name;
                importSettings.ImportTranslation     = false;
                importSettings.ImportBackTranslation = true;

                ParatextHelper.LoadProjectMappings(importSettings);
                var importMap = importSettings.GetMappingListForDomain(ImportDomain.Main);
                // Check for corrupted import settings, clear them out if they are bad.
                if (importMap == null)
                {
                    m_scr.DefaultImportSettings = null;
                    m_scr.ImportSettingsOC.Clear();
                    importSettings = null;
                }
                else
                {
                    var figureInfo = importMap[@"\fig"];
                    if (figureInfo != null)
                    {
                        figureInfo.IsExcluded = true;
                    }
                    importSettings.SaveSettings();
                }
            });

            if (importSettings != null)
            {
                ReflectionHelper.GetBoolResult(ReflectionHelper.GetType("ParatextImport.dll", "ParatextImport.ParatextImportManager"), "ImportParatext", owningForm, m_cache, importSettings, m_scriptureStylesheet, App);
            }
        }
Ejemplo n.º 9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="SCTextEnum"/> class.
        /// </summary>
        /// <param name="settings">The import settings</param>
        /// <param name="domain">The source domain</param>
        /// <param name="startRef">first reference to retrieve</param>
        /// <param name="endRef">last reference to retrieve</param>
        /// <param name="encConverters">The encoding converters repository</param>
        /// ------------------------------------------------------------------------------------
        public SCTextEnum(IScrImportSet settings, ImportDomain domain,
                          BCVRef startRef, BCVRef endRef, IEncConverters encConverters)
        {
            m_settings   = settings;
            m_domain     = domain;
            m_startRef   = new BCVRef(startRef);
            m_endRef     = new BCVRef(endRef);
            m_mappingSet = m_settings.GetMappingSetForDomain(domain);

            // Gets the set of encoding converters
            m_encConverters = encConverters;

            // make a list of all of the begin and end markers for inline markers
            // Also build the map of encoding converters
            m_InlineBeginAndEndMarkers = new List <string>();
            foreach (ImportMappingInfo mapping in m_settings.GetMappingListForDomain(domain))
            {
                if (mapping.IsInline || m_settings.ImportTypeEnum == TypeOfImport.Paratext5)
                {
                    m_InlineBeginAndEndMarkers.Add(mapping.BeginMarker);
                    if (mapping.IsInline)
                    {
                        m_InlineBeginAndEndMarkers.Add(mapping.EndMarker);
                    }
                }
            }

            m_InlineBeginAndEndMarkers.Sort(new StrLengthComparer(false));

            // Build a list of all of the characters that inline markers start with
            Set <char> tempCharList = new Set <char>();

            foreach (string marker in m_InlineBeginAndEndMarkers)
            {
                tempCharList.Add(marker[0]);                 // Set ignores duplicates.
            }
            m_InlineMarkerStartChars = tempCharList.ToArray();
            // Get the import file source that will provide the files to import.
            m_importSource     = settings.GetImportFiles(domain);
            m_importSourceEnum = m_importSource.GetEnumerator();
        }
Ejemplo n.º 10
0
        public void LoadParatextMappings_Normal()
        {
            Unpacker.UnPackParatextTestProjects();

            var stylesheet = new FwStyleSheet();

            stylesheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles);
            IScrImportSet importSettings = Cache.ServiceLocator.GetInstance <IScrImportSetFactory>().Create();

            importSettings.ParatextScrProj = "KAM";
            ParatextHelper.LoadProjectMappings(importSettings);

            ScrMappingList mappingList = importSettings.GetMappingListForDomain(ImportDomain.Main);

            // Test to see that the projects are set correctly
            Assert.AreEqual(44, mappingList.Count);

            Assert.AreEqual(MarkerDomain.Default, mappingList[@"\c"].Domain);
            Assert.AreEqual(MarkerDomain.Default, mappingList[@"\v"].Domain);
            Assert.AreEqual(@"\f*", mappingList[@"\f"].EndMarker);
            Assert.IsTrue(mappingList[@"\p"].IsInUse);
            Assert.IsFalse(mappingList[@"\tb2"].IsInUse);
        }
Ejemplo n.º 11
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="SCTextEnum"/> class.
		/// </summary>
		/// <param name="settings">The import settings</param>
		/// <param name="domain">The source domain</param>
		/// <param name="startRef">first reference to retrieve</param>
		/// <param name="endRef">last reference to retrieve</param>
		/// <param name="encConverters">The encoding converters repository</param>
		/// ------------------------------------------------------------------------------------
		public SCTextEnum(IScrImportSet settings, ImportDomain domain,
			BCVRef startRef, BCVRef endRef, IEncConverters encConverters)
		{
			m_settings = settings;
			m_domain = domain;
			m_startRef = new BCVRef(startRef);
			m_endRef = new BCVRef(endRef);
			m_mappingSet = m_settings.GetMappingSetForDomain(domain);

			// Gets the set of encoding converters
			m_encConverters = encConverters;

			// make a list of all of the begin and end markers for inline markers
			// Also build the map of encoding converters
			m_InlineBeginAndEndMarkers = new List<string>();
			foreach (ImportMappingInfo mapping in m_settings.GetMappingListForDomain(domain))
			{
				if (mapping.IsInline || m_settings.ImportTypeEnum == TypeOfImport.Paratext5)
				{
					m_InlineBeginAndEndMarkers.Add(mapping.BeginMarker);
					if (mapping.IsInline)
						m_InlineBeginAndEndMarkers.Add(mapping.EndMarker);
				}
			}

			m_InlineBeginAndEndMarkers.Sort(new StrLengthComparer(false));

			// Build a list of all of the characters that inline markers start with
			Set<char> tempCharList = new Set<char>();
			foreach (string marker in m_InlineBeginAndEndMarkers)
				tempCharList.Add(marker[0]); // Set ignores duplicates.

			m_InlineMarkerStartChars = tempCharList.ToArray();
			// Get the import file source that will provide the files to import.
			m_importSource = settings.GetImportFiles(domain);
			m_importSourceEnum = m_importSource.GetEnumerator();
		}
Ejemplo n.º 12
0
			/// ------------------------------------------------------------------------------------
			/// <summary>
			/// Load the mappings for a Paratext 6/7 project into the specified list.
			/// </summary>
			/// <returns><c>true</c> if the Paratext mappings were loaded successfully; <c>false</c>
			/// otherwise</returns>
			/// ------------------------------------------------------------------------------------
			public void LoadProjectMappings(IScrImportSet importSettings)
			{
				RefreshProjects();
				if (!m_IsParatextInitialized)
				{
					importSettings.ParatextScrProj = null;
					importSettings.ParatextBTProj = null;
					importSettings.ParatextNotesProj = null;
					return;
				}

				if (!LoadProjectMappings(importSettings.ParatextScrProj, importSettings.GetMappingListForDomain(ImportDomain.Main), ImportDomain.Main))
					importSettings.ParatextScrProj = null;

				if (!LoadProjectMappings(importSettings.ParatextBTProj, importSettings.GetMappingListForDomain(ImportDomain.BackTrans), ImportDomain.BackTrans))
					importSettings.ParatextBTProj = null;

				if (!LoadProjectMappings(importSettings.ParatextNotesProj, importSettings.GetMappingListForDomain(ImportDomain.Annotations), ImportDomain.Annotations))
					importSettings.ParatextNotesProj = null;
			}