/// ------------------------------------------------------------------------------------ /// <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); }
///------------------------------------------------------------------------------- /// <summary> /// If the user didn't choose cancel, save the controls' values. /// </summary> /// <param name="e"></param> ///------------------------------------------------------------------------------- protected override void OnClosing(CancelEventArgs e) { // If the scripture range is selected, then make sure both scripture references are // valid. Focus the incorrect one. if (this.DialogResult == DialogResult.OK && radImportRange.Checked) { if (!scrPsgFrom.Valid) { scrPsgFrom.Focus(); e.Cancel = true; return; } if (!scrPsgTo.Valid) { scrPsgTo.Focus(); e.Cancel = true; return; } } else if (DialogResult == DialogResult.OK && radImportEntire.Checked) { m_importSettings.StartRef = StartRef; m_importSettings.EndRef = EndRef; NonUndoableUnitOfWorkHelper.Do(ActionHandler, () => m_importSettings.SaveSettings()); } base.OnClosing(e); if (this.DialogResult == DialogResult.OK) { ImportEntire = radImportEntire.Checked; ImportTranslation = chkTranslation.Checked; ImportBackTranslation = chkBackTranslation.Checked; ImportBookIntros = chkBookIntros.Checked; ImportAnnotations = chkOther.Checked; s_StartRef = scrPsgFrom.ScReference; s_EndRef = scrPsgTo.ScReference; if (m_importSettings != null) { m_importSettings.StartRef = StartRef; m_importSettings.EndRef = EndRef; m_importSettings.ImportTranslation = chkTranslation.Checked; m_importSettings.ImportBackTranslation = chkBackTranslation.Checked; m_importSettings.ImportBookIntros = chkBookIntros.Checked; m_importSettings.ImportAnnotations = chkOther.Checked; } } }
/// <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); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Test to see if the ImportProjectIsAccessible method works for projects other than /// Paratext 6. /// </summary> /// ------------------------------------------------------------------------------------ private void ImportProjectIsAccessible_helper(IScrImportSet importSettings) { var fileOs = new MockFileOS(); try { FileUtils.Manager.SetFileAdapter(fileOs); string scrFile1 = fileOs.MakeSfFile("GEN", @"\p", @"\c 1", @"\v 1", @"\v 2"); string scrFile2 = fileOs.MakeSfFile("EXO", @"\p", @"\c 1", @"\v 1", @"\v 2"); string scrFile3 = fileOs.MakeSfFile("LEV", @"\p", @"\c 1", @"\v 1", @"\v 2"); string btFileDef = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1"); string btFileSpan = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1"); string annotFileCons = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1"); string annotFileTrans = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1"); importSettings.AddFile(scrFile1, ImportDomain.Main, null, null); importSettings.AddFile(scrFile2, ImportDomain.Main, null, null); importSettings.AddFile(scrFile3, ImportDomain.Main, null, null); importSettings.AddFile(btFileDef, ImportDomain.BackTrans, null, null); importSettings.AddFile(btFileSpan, ImportDomain.BackTrans, "es", null); var annDefnRepo = Cache.ServiceLocator.GetInstance <ICmAnnotationDefnRepository>(); importSettings.AddFile(annotFileCons, ImportDomain.Annotations, null, annDefnRepo.ConsultantAnnotationDefn); importSettings.AddFile(annotFileTrans, ImportDomain.Annotations, null, annDefnRepo.TranslatorAnnotationDefn); StringCollection filesNotFound; Assert.IsTrue(importSettings.ImportProjectIsAccessible(out filesNotFound)); Assert.AreEqual(0, filesNotFound.Count); importSettings.SaveSettings(); // Blow away some project files: should still return true, but should // report missing files. FileUtils.Delete(scrFile2); FileUtils.Delete(scrFile3); FileUtils.Delete(btFileDef); FileUtils.Delete(annotFileCons); FileUtils.Delete(annotFileTrans); // Now that we've saved the settings, we'll "revert" in order to re-load from the DB importSettings.RevertToSaved(); Assert.IsTrue(importSettings.ImportProjectIsAccessible(out filesNotFound)); Assert.AreEqual(5, filesNotFound.Count); Assert.IsTrue(filesNotFound.Contains(scrFile2)); Assert.IsTrue(filesNotFound.Contains(scrFile3)); Assert.IsTrue(filesNotFound.Contains(btFileDef)); Assert.IsTrue(filesNotFound.Contains(annotFileCons)); Assert.IsTrue(filesNotFound.Contains(annotFileTrans)); importSettings.SaveSettings(); // Blow away the rest of the project files: should return false and report // missing files. FileUtils.Delete(scrFile1); FileUtils.Delete(btFileSpan); // Now that we've saved the settings, we'll "revert" in order to re-load from the DB importSettings.RevertToSaved(); Assert.IsFalse(importSettings.ImportProjectIsAccessible(out filesNotFound)); Assert.AreEqual(7, filesNotFound.Count); Assert.IsTrue(filesNotFound.Contains(scrFile1)); Assert.IsTrue(filesNotFound.Contains(scrFile2)); Assert.IsTrue(filesNotFound.Contains(scrFile3)); Assert.IsTrue(filesNotFound.Contains(btFileDef)); Assert.IsTrue(filesNotFound.Contains(btFileSpan)); Assert.IsTrue(filesNotFound.Contains(annotFileCons)); Assert.IsTrue(filesNotFound.Contains(annotFileTrans)); } finally { FileUtils.Manager.Reset(); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Test to see if the ImportProjectIsAccessible method works for projects other than /// Paratext 6. /// </summary> /// ------------------------------------------------------------------------------------ private void ImportProjectIsAccessible_helper(IScrImportSet importSettings) { var fileOs = new MockFileOS(); try { FileUtils.Manager.SetFileAdapter(fileOs); string scrFile1 = fileOs.MakeSfFile("GEN", @"\p", @"\c 1", @"\v 1", @"\v 2"); string scrFile2 = fileOs.MakeSfFile("EXO", @"\p", @"\c 1", @"\v 1", @"\v 2"); string scrFile3 = fileOs.MakeSfFile("LEV", @"\p", @"\c 1", @"\v 1", @"\v 2"); string btFileDef = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1"); string btFileSpan = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1"); string annotFileCons = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1"); string annotFileTrans = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1"); importSettings.AddFile(scrFile1, ImportDomain.Main, null, null); importSettings.AddFile(scrFile2, ImportDomain.Main, null, null); importSettings.AddFile(scrFile3, ImportDomain.Main, null, null); importSettings.AddFile(btFileDef, ImportDomain.BackTrans, null, null); importSettings.AddFile(btFileSpan, ImportDomain.BackTrans, "es", null); var annDefnRepo = Cache.ServiceLocator.GetInstance<ICmAnnotationDefnRepository>(); importSettings.AddFile(annotFileCons, ImportDomain.Annotations, null, annDefnRepo.ConsultantAnnotationDefn); importSettings.AddFile(annotFileTrans, ImportDomain.Annotations, null, annDefnRepo.TranslatorAnnotationDefn); StringCollection filesNotFound; Assert.IsTrue(importSettings.ImportProjectIsAccessible(out filesNotFound)); Assert.AreEqual(0, filesNotFound.Count); importSettings.SaveSettings(); // Blow away some project files: should still return true, but should // report missing files. FileUtils.Delete(scrFile2); FileUtils.Delete(scrFile3); FileUtils.Delete(btFileDef); FileUtils.Delete(annotFileCons); FileUtils.Delete(annotFileTrans); // Now that we've saved the settings, we'll "revert" in order to re-load from the DB importSettings.RevertToSaved(); Assert.IsTrue(importSettings.ImportProjectIsAccessible(out filesNotFound)); Assert.AreEqual(5, filesNotFound.Count); Assert.IsTrue(filesNotFound.Contains(scrFile2)); Assert.IsTrue(filesNotFound.Contains(scrFile3)); Assert.IsTrue(filesNotFound.Contains(btFileDef)); Assert.IsTrue(filesNotFound.Contains(annotFileCons)); Assert.IsTrue(filesNotFound.Contains(annotFileTrans)); importSettings.SaveSettings(); // Blow away the rest of the project files: should return false and report // missing files. FileUtils.Delete(scrFile1); FileUtils.Delete(btFileSpan); // Now that we've saved the settings, we'll "revert" in order to re-load from the DB importSettings.RevertToSaved(); Assert.IsFalse(importSettings.ImportProjectIsAccessible(out filesNotFound)); Assert.AreEqual(7, filesNotFound.Count); Assert.IsTrue(filesNotFound.Contains(scrFile1)); Assert.IsTrue(filesNotFound.Contains(scrFile2)); Assert.IsTrue(filesNotFound.Contains(scrFile3)); Assert.IsTrue(filesNotFound.Contains(btFileDef)); Assert.IsTrue(filesNotFound.Contains(btFileSpan)); Assert.IsTrue(filesNotFound.Contains(annotFileCons)); Assert.IsTrue(filesNotFound.Contains(annotFileTrans)); } finally { FileUtils.Manager.Reset(); } }