/// ------------------------------------------------------------------------------------ /// <summary> /// Load the scripture project and enumerator, preparing us to read the data files. /// </summary> /// <param name="settings">Import settings object (filled in by wizard)</param> /// ------------------------------------------------------------------------------------ public void LoadScriptureProject(IScrImportSet settings) { m_settings = settings; m_ImportType = settings.ImportTypeEnum; // Load ScriptureText object switch (TypeOfImport) { case TypeOfImport.Paratext6: if ((!settings.ImportTranslation && !settings.ImportAnnotations) || !LoadParatextVernacularProject()) if (!LoadParatextBackTranslationProject()) if (!LoadParatextNotesProject()) throw new InvalidOperationException("There was nothing worth loading."); break; case TypeOfImport.Other: case TypeOfImport.Paratext5: ScrVers versification = m_settings.Cache.LangProject.TranslatedScriptureOA.Versification; m_settings.CheckForOverlappingFilesInRange( new ScrReference(m_settings.StartRef, versification), new ScrReference(m_settings.EndRef, versification)); m_scSfmText = new SCScriptureText(settings, ImportDomain.Main); // Now initialize the TextEnum with the range of scripture text we want m_scTextEnum = m_scSfmText.TextEnum(m_settings.StartRef, m_settings.EndRef); break; default: Debug.Assert(false, "bogus TypeOfImport"); break; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load the scripture project and enumerator, preparing us to read the data files. /// </summary> /// <param name="settings">Import settings object (filled in by wizard)</param> /// ------------------------------------------------------------------------------------ public void LoadScriptureProject(IScrImportSet settings) { m_settings = settings as ScrImportSet; m_ImportType = settings.ImportTypeEnum; // Load ScriptureText object switch (TypeOfImport) { case TypeOfImport.Paratext6: if (!LoadParatextVernacularProject()) { if (!LoadParatextBackTranslationProject()) { if (!LoadParatextNotesProject()) { throw new InvalidOperationException("There was nothing worth loading."); } } } break; case TypeOfImport.Other: case TypeOfImport.Paratext5: Paratext.ScrVers versification = m_settings.Cache.LangProject.TranslatedScriptureOA.Versification; m_settings.CheckForOverlappingFilesInRange( new ScrReference(m_settings.StartRef, versification), new ScrReference(m_settings.EndRef, versification)); m_scSfmText = new SCScriptureText(settings, ImportDomain.Main); // Now initialize the TextEnum with the range of scripture text we want m_scTextEnum = m_scSfmText.TextEnum(m_settings.StartRef, m_settings.EndRef); break; default: Debug.Assert(false, "bogus TypeOfImport"); break; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Defines the import settings given a type of import (Paratext5, Paratext6 or Other). /// Either we find import settings in the database or create a new set. /// </summary> /// <param name="importType">Type of the import.</param> /// ------------------------------------------------------------------------------------ private void DefineImportSettings(TypeOfImport importType) { NonUndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(m_cache.ActionHandlerAccessor, () => { m_settings = m_scr.FindOrCreateDefaultImportSettings(importType); }); InitializeScrImportSettings(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Finds the import settings of the specified type. If the requested type is not found /// but import settings of unknown type are found, the unknown settings will be returned. /// </summary> /// <param name="importType">Type of the import.</param> /// <returns> /// The import set of the specified type, or an unknown type as a fallback; /// otherwise <c>null</c> will be returned. /// </returns> /// ------------------------------------------------------------------------------------ public IScrImportSet FindImportSettings(TypeOfImport importType) { IScrImportSet unknownSet = null; foreach (IScrImportSet importSet in ImportSettingsOC) { if (importSet.ImportTypeEnum == importType) return importSet; else if (importSet.ImportTypeEnum == TypeOfImport.Unknown) unknownSet = importSet; } // If we didn't find an import set of the type we were looking for but we found // unknown import settings... if (unknownSet != null) { // then the unknown settings have not been completely defined. They may be used // as the requested importType. unknownSet.ImportTypeEnum = importType; return unknownSet; } return null; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the import settings named Default, if any, or the first available /// one (which is probably the only one), or creates new settings if none exist. /// </summary> /// <param name="importType">type of import type to find</param> /// ------------------------------------------------------------------------------------ public IScrImportSet FindOrCreateDefaultImportSettings(TypeOfImport importType) { IScrImportSet settings = DefaultImportSettings_internal; // First, attempt to find the default import settings if (settings != null && (settings.ImportType == (int)importType || importType == TypeOfImport.Unknown)) return settings; if (ImportSettingsOC.Count > 0) { // If the specified type is unknown, just return the first set. if (importType == TypeOfImport.Unknown) return ImportSettingsOC.ToArray()[0]; else { // Attempt to find the specified import type. foreach (IScrImportSet importSettings in ImportSettingsOC) { if (importSettings.ImportType == (int)importType) return importSettings; } } } // Didn't find the specified type of settings, so create a new set. IScrImportSet newSettings = m_cache.ServiceLocator.GetInstance<IScrImportSetFactory>().Create(); ImportSettingsOC.Add(newSettings); newSettings.ImportType = (int)importType; return newSettings; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Defines the import settings given a type of import (Paratext5, Paratext6 or Other). /// Either we find import settings in the database or create a new set. /// </summary> /// <param name="importType">Type of the import.</param> /// ------------------------------------------------------------------------------------ private void DefineImportSettings(TypeOfImport importType) { IScrImportSet settings = ((Scripture)m_scr).FindImportSettings(importType); if (settings == null) { m_settings = new ScrImportSet(); m_scr.ImportSettingsOC.Add(m_settings); m_settings.ImportTypeEnum = importType; } else m_settings = (ScrImportSet)settings; InitializeScrImportSettings(); }