Esempio n. 1
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);
        }
Esempio n. 2
0
        ///-------------------------------------------------------------------------------
        /// <summary>
        /// When the Source button is clicked, display the import wizard.
        /// </summary>
        ///-------------------------------------------------------------------------------
        private void btnSource_Click(object sender, System.EventArgs e)
        {
            using (ImportWizard importWizard = new ImportWizard(m_scr.Cache.ProjectId.Name,
                                                                m_scr, m_StyleSheet, m_helpTopicProvider, m_app))
            {
                using (NonUndoableUnitOfWorkHelper undoHelper = new NonUndoableUnitOfWorkHelper(ActionHandler))
                {
                    if (importWizard.ShowDialog() == DialogResult.Cancel)
                    {
                        // Ditch any in-memory changes made to the settings. Reload from the DB.
                        m_importSettings.RevertToSaved();
                    }
                    else
                    {
                        undoHelper.RollBack = false;
                    }
                }

                // If there are no files after showing the wizard, close the import dialog
                if (InitBookNameList() == 0)
                {
                    MessageBox.Show(this, DlgResources.ResourceString("kstidImportFilesUnavailable"),
                                    m_app.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Close();
                    return;
                }

                // The default set of settings may have changed.
                m_importSettings = m_scr.DefaultImportSettings;

                // Update the file ranges for import because they may have changed.
                InitializeStartAndEndRefControls();

                // Update the passage controls to reflect the new range of files available
                // Only make changes that do not expand the available range of books since a
                // range may have been specified before the wizard was run that we do not
                // want to overwrite
                if (!scrPsgFrom.IsReferenceValid(scrPsgFrom.ScReference))
                {
                    SetStartRefToFirstImportableBook();
                }

                if (!scrPsgTo.IsReferenceValid(scrPsgTo.ScReference))
                {
                    SetEndRefToLastImportableBook();
                }
            }
            btnOK.Focus();
        }
Esempio n. 3
0
        /// ------------------------------------------------------------------------------------
        /// <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();
			}
		}