示例#1
0
        public void AddFileAndCheckAccessibility_Locked()
        {
            IScrImportSet importSettings = Cache.ServiceLocator.GetInstance <IScrImportSetFactory>().Create();

            Cache.LanguageProject.TranslatedScriptureOA.ImportSettingsOC.Add(importSettings);
            importSettings.ImportTypeEnum = TypeOfImport.Other;

            var fileOs = new MockFileOS();

            try
            {
                FileUtils.Manager.SetFileAdapter(fileOs);
                string filename = fileOs.MakeSfFile("EPH", @"\c 1", @"\v 1");
                fileOs.LockFile(filename);

                IScrImportFileInfo info = importSettings.AddFile(filename, ImportDomain.Main, null, null);
                Assert.AreEqual(Encoding.ASCII, info.FileEncoding);
                Assert.AreEqual(1, importSettings.GetImportFiles(ImportDomain.Main).Count);
                StringCollection notFound;
                Assert.IsFalse(importSettings.ImportProjectIsAccessible(out notFound));
                Assert.AreEqual(1, notFound.Count);
                Assert.AreEqual(filename, notFound[0]);
            }
            finally
            {
                FileUtils.Manager.Reset();
            }
        }
        public void ImportProjectIsAccessible_Paratext6()
        {
            IScrImportSet importSettings = Cache.ServiceLocator.GetInstance <IScrImportSetFactory>().Create();

            Cache.LanguageProject.TranslatedScriptureOA.ImportSettingsOC.Add(importSettings);
            importSettings.ImportTypeEnum = TypeOfImport.Paratext6;

            var fileOs = new MockFileOS();
            MockParatextHelper ptHelper = null;
            var saveScriptureProvider   = ScriptureProvider._scriptureProvider;

            ScriptureProvider._scriptureProvider = new MockScriptureProvider();
            try
            {
                FileUtils.Manager.SetFileAdapter(fileOs);
                ptHelper = new MockParatextHelper();
                ParatextHelper.Manager.SetParatextHelperAdapter(ptHelper);
                string paratextDir = ScriptureProvider.SettingsDirectory;
                Assert.NotNull(paratextDir, "Setup problem - ProjectsDirectory should not be null.");
                ptHelper.AddProject("TEV", null, null, true, false, "100001");

                fileOs.AddExistingFile(Path.Combine(paratextDir, "TEV.ssf"));

                importSettings.ParatextScrProj = "KAM";
                importSettings.ParatextBTProj  = "TEV";

                StringCollection projectsNotFound;
                Assert.IsFalse(importSettings.ImportProjectIsAccessible(out projectsNotFound));
                Assert.AreEqual(1, projectsNotFound.Count);
                Assert.AreEqual("KAM", projectsNotFound[0]);

                fileOs.AddExistingFile(Path.Combine(paratextDir, "KAM.ssf"));
                ptHelper.AddProject("KAM", null, null, true, false, "000101");
                Assert.IsTrue(importSettings.ImportProjectIsAccessible(out projectsNotFound));
            }
            finally
            {
                ParatextHelper.Manager.Reset();
                if (ptHelper != null)
                {
                    ptHelper.Dispose();
                }
                FileUtils.Manager.Reset();
                ScriptureProvider._scriptureProvider = saveScriptureProvider;
            }
        }
示例#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();
            }
        }
示例#4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get the settings for Import, either from database or from wizard
        /// </summary>
        /// <returns>Import settings, or <c>null</c> if user canceled dialog.</returns>
        /// ------------------------------------------------------------------------------------
        protected IScrImportSet GetImportSettings()
        {
            ILangProject  proj           = m_cache.LangProject;
            IScripture    scr            = proj.TranslatedScriptureOA;
            IScrImportSet importSettings = null;

            NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
            {
                importSettings =
                    scr.FindOrCreateDefaultImportSettings(TypeOfImport.Unknown);
            });
            importSettings.StyleSheet = m_styleSheet;

            importSettings.OverlappingFileResolver = new ConfirmOverlappingFileReplaceDialog(m_helpTopicProvider);
            if (!importSettings.BasicSettingsExist)
            {
                using (NonUndoableUnitOfWorkHelper undoHelper = new NonUndoableUnitOfWorkHelper(
                           m_cache.ServiceLocator.GetInstance <IActionHandler>()))
                {
                    using (ImportWizard importWizard = new ImportWizard(m_cache.ProjectId.Name,
                                                                        scr, m_styleSheet, m_helpTopicProvider, m_app))
                    {
                        if (importWizard.ShowDialog() == DialogResult.Cancel)
                        {
                            return(null);
                        }
                        // Scripture reference range may have changed
                        ImportDialog.ClearDialogReferences();
                        importSettings = scr.DefaultImportSettings;
                    }
                    undoHelper.RollBack = false;
                }
            }
            else
            {
                StringCollection sInvalidFiles;
                bool             fCompletedWizard = false;
                while (!importSettings.ImportProjectIsAccessible(out sInvalidFiles))
                {
                    // Display the "Project Not Found" message box
                    using (ScrImportSetMessage dlg = new ScrImportSetMessage())
                    {
                        string[] files = new string[sInvalidFiles.Count];
                        sInvalidFiles.CopyTo(files, 0);
                        dlg.InvalidFiles       = files;
                        dlg.HelpURL            = m_helpTopicProvider.HelpFile;
                        dlg.HelpTopic          = "/Beginning_Tasks/Import_Standard_Format/Project_Files_Unavailable.htm";
                        dlg.DisplaySetupOption = true;
                        switch (dlg.ShowDialog())
                        {
                        case DialogResult.OK:                                 // Setup...
                        {
                            using (NonUndoableUnitOfWorkHelper undoHelper = new NonUndoableUnitOfWorkHelper(
                                       m_cache.ServiceLocator.GetInstance <IActionHandler>()))
                            {
                                using (ImportWizard importWizard = new ImportWizard(
                                           m_cache.ProjectId.Name, scr, m_styleSheet, m_helpTopicProvider, m_app))
                                {
                                    if (importWizard.ShowDialog() == DialogResult.Cancel)
                                    {
                                        return(null);
                                    }
                                    // Scripture reference range may have changed
                                    ImportDialog.ClearDialogReferences();
                                    importSettings   = scr.DefaultImportSettings;
                                    fCompletedWizard = true;
                                }
                                undoHelper.RollBack = false;
                            }
                            break;
                        }

                        case DialogResult.Cancel:
                            return(null);

                        case DialogResult.Retry:
                            // Loop around until user gets tired.
                            break;
                        }
                    }
                }
                if (!fCompletedWizard)
                {
                    if (ParatextProjHasUnmappedMarkers(importSettings))
                    {
                        // TODO: Show message box and then bring up import wizard
                    }
                }
            }

            return(importSettings);
        }
		/// ------------------------------------------------------------------------------------
		/// <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();
			}
		}