Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="ScrSfFileList"/> class based on an
        /// existing ScrImportSFFiles in the DB.
        /// </summary>
        /// <param name="source">A DB-based collection of Standard Format files</param>
        /// <param name="mappingList">The mapping list to which mappings will be added if any
        /// new ones are found when scanning the files</param>
        /// <param name="importDomain">Main (vernacular Scripture), BT or Annotations</param>
        /// <param name="scanInlineBackslashMarkers"><c>true</c> to look for backslash markers
        /// in the middle of lines. (Toolbox dictates that fields tagged with backslash markers
        /// must start on a new line, but Paratext considers all backslashes in the data to be
        /// SF markers.)</param>
        /// <param name="helpFile">The path of the application help file.</param>
        /// ------------------------------------------------------------------------------------
        public ScrSfFileList(ScrImportSFFiles source, ScrMappingList mappingList,
                             ImportDomain importDomain, bool scanInlineBackslashMarkers, string helpFile) : this(null)
        {
            List <int> deleteList = new List <int>();
            // Load the files into an in-memory list
            foreach (ICmFile file in source.FilesOC)
            {
                try
                {
                    ScrImportFileInfo info = new ScrImportFileInfo(file, mappingList, importDomain,
                                                                   source.ICULocale, source.NoteTypeRAHvo, scanInlineBackslashMarkers);
                    Add(info);
                }
                catch (ScriptureUtilsException e)
                {
                    MessageBox.Show(string.Format(ScrFdoResources.kstidImportBadFile, e.Message), "", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, helpFile, HelpNavigator.Topic, e.HelpTopic);
                    deleteList.Add(file.Hvo);
                }
            }

            // delete all of the files that caused errors
            foreach (int deleteItem in deleteList)
            {
                source.Cache.DeleteObject(deleteItem);
            }

            m_modified = false;
        }
Example #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Save an in-memory list of files to the given source
		/// </summary>
		/// <param name="files">ScrSfFileList containing in-memory file list</param>
		/// <param name="source">ScrImportSFFiles in the database</param>
		/// ------------------------------------------------------------------------------------
		private void SaveFileList(ScrSfFileList files, ScrImportSFFiles source)
		{
			// If the file list has not changed, don't try to save it
			if (!files.Modified)
				return;

			UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("Save file list", "Save file list",
				m_cache.ServiceLocator.GetInstance<IActionHandler>(), () =>
			{
				source.FilesOC.Clear();
				foreach (IScrImportFileInfo fileInfo in files)
				{
					ICmFile file = Services.GetInstance<ICmFileFactory>().Create();
					source.FilesOC.Add(file);
					file.InternalPath = fileInfo.FileName;
				}
			});
		}
Example #3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="ScrSfFileList"/> class based on an
		/// existing ScrImportSFFiles in the DB.
		/// </summary>
		/// <param name="source">A DB-based collection of Standard Format files</param>
		/// <param name="mappingList">The mapping list to which mappings will be added if any
		/// new ones are found when scanning the files</param>
		/// <param name="importDomain">Main (vernacular Scripture), BT or Annotations</param>
		/// <param name="scanInlineBackslashMarkers"><c>true</c> to look for backslash markers
		/// in the middle of lines. (Toolbox dictates that fields tagged with backslash markers
		/// must start on a new line, but Paratext considers all backslashes in the data to be
		/// SF markers.)</param>
		/// <param name="helpFile">The path of the application help file.</param>
		/// ------------------------------------------------------------------------------------
		public ScrSfFileList(ScrImportSFFiles source, ScrMappingList mappingList,
			ImportDomain importDomain, bool scanInlineBackslashMarkers, string helpFile) : this(null)
		{
			List<int> deleteList = new List<int>();
			// Load the files into an in-memory list
			foreach (ICmFile file in source.FilesOC)
			{
				try
				{
					ScrImportFileInfo info = new ScrImportFileInfo(file, mappingList, importDomain,
						source.ICULocale, source.NoteTypeRAHvo, scanInlineBackslashMarkers);
					Add(info);
				}
				catch (ScriptureUtilsException e)
				{
					MessageBox.Show(string.Format(ScrFdoResources.kstidImportBadFile, e.Message), "", MessageBoxButtons.OK,
						MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, helpFile, HelpNavigator.Topic, e.HelpTopic);
					deleteList.Add(file.Hvo);
				}
			}

			// delete all of the files that caused errors
			foreach (int deleteItem in deleteList)
				source.Cache.DeleteObject(deleteItem);

			m_modified = false;
		}
Example #4
0
		public void ConvertFromBlobSettings_Other_Version0x104()
		{
			CheckDisposed();

			// Create a blob of settings.
			ArrayList mappingList = new ArrayList();
			mappingList.Add(new MappingInfo(@"\btp", null, false, null, MarkerDomain.BackTrans, ScrStyleNames.NormalParagraph, null, false, MappingTargetType.TEStyle));
			mappingList.Add(new MappingInfo(@"\btp_fr", null, false, null, MarkerDomain.BackTrans, ScrStyleNames.NormalParagraph, "fr", false, MappingTargetType.TEStyle));
			mappingList.Add(new MappingInfo(@"\c", null, false, null, MarkerDomain.Default, ScrStyleNames.ChapterNumber, null, false, MappingTargetType.TEStyle));
			mappingList.Add(new MappingInfo(@"|i{", @"}", true, null, MarkerDomain.Default, "Emphasis", null, false, MappingTargetType.TEStyle));
			mappingList.Add(new MappingInfo(@"\ex", null, false, null, MarkerDomain.Default, null, null, true, MappingTargetType.TEStyle));
			mappingList.Add(new MappingInfo(@"\f", null, false, null, MarkerDomain.Default, ScrStyleNames.NormalFootnoteParagraph, null, false, MappingTargetType.TEStyle));
			mappingList.Add(new MappingInfo(@"\fig", null, false, null, MarkerDomain.Default, null, null, false, MappingTargetType.Figure));
			mappingList.Add(new MappingInfo(@"\h", null, false, null, MarkerDomain.Default, null, null, false, MappingTargetType.TitleShort));
			mappingList.Add(new MappingInfo(@"\id", null, false, null, MarkerDomain.Default, null, null, false, MappingTargetType.TEStyle));
			mappingList.Add(new MappingInfo(@"\rem", null, false, null, MarkerDomain.Note, ScrStyleNames.Remark, null, false, MappingTargetType.TEStyle));
			mappingList.Add(new MappingInfo(@"\v", null, false, null, MarkerDomain.Default, ScrStyleNames.VerseNumber, null, false, MappingTargetType.TEStyle));
			mappingList.Add(new MappingInfo(@"|x{", "}", true, null, MarkerDomain.Default | MarkerDomain.Footnote, ScrStyleNames.CrossRefFootnoteParagraph, null, false, MappingTargetType.TEStyle));

			ArrayList fileList = new ArrayList(2);
			fileList.Add(@"c:\my data\first file.sf");
			fileList.Add(@"c:\my data\tom's file.sf");

			m_importSettings.ImportType = (int)TypeOfImport.Other;

			DynamicMock mockStyleSheet = new DynamicMock(typeof(IVwStylesheet));
			mockStyleSheet.SetupResultForParams("GetContext", ContextValues.Note, ScrStyleNames.NormalFootnoteParagraph);
			mockStyleSheet.SetupResultForParams("GetContext", ContextValues.General, new IsAnything()); // We don't care about anything else for these tests

			ReflectionHelper.SetField(m_importSettings, "m_stylesheet", (IVwStylesheet)mockStyleSheet.MockInstance);

			// Call ConvertFromBlobSettings, which should cause the blob to be converted.
			ReflectionHelper.CallMethod(m_importSettings, "ConvertFromBlobSettings",
				GetEcProjectSettingsArray(mappingList, fileList));

			// Make sure that the blob and deprecated footnote settings are eliminated and
			// that the settings are correct in the database.
			Assert.AreEqual(0, ImportSettings.Length);
			Assert.AreEqual(12, m_importSettings.ScriptureMappingsOC.Count);
			Assert.AreEqual(0, m_importSettings.NoteMappingsOC.Count);

			IEnumerator<IScrMarkerMapping> mappings = m_importSettings.ScriptureMappingsOC.GetEnumerator();
			//mappings.Reset(); // Throws NotSupportedException exception on generic enumerator
			VerifyNextMapping(mappings, @"\btp", null, MarkerDomain.BackTrans, ScrStyleNames.NormalParagraph, null, false, MappingTargetType.TEStyle);
			VerifyNextMapping(mappings, @"\btp_fr", null, MarkerDomain.BackTrans, ScrStyleNames.NormalParagraph, "fr", false, MappingTargetType.TEStyle);
			VerifyNextMapping(mappings, @"\c", null, MarkerDomain.Default /* NOT Default! */, ScrStyleNames.ChapterNumber, null, false, MappingTargetType.TEStyle);
			VerifyNextMapping(mappings, @"|i{", @"}", MarkerDomain.Default, "Emphasis", null, false, MappingTargetType.TEStyle);
			VerifyNextMapping(mappings, @"\ex", null, MarkerDomain.Default, null, null, true, MappingTargetType.TEStyle);
			VerifyNextMapping(mappings, @"\f", null, MarkerDomain.Footnote, ScrStyleNames.NormalFootnoteParagraph, null, false, MappingTargetType.TEStyle);
			VerifyNextMapping(mappings, @"\fig", null, MarkerDomain.Default, null, null, false, MappingTargetType.Figure);
			VerifyNextMapping(mappings, @"\h", null, MarkerDomain.Default, null, null, false, MappingTargetType.TitleShort);
			VerifyNextMapping(mappings, @"\id", null, MarkerDomain.Default, null, null, false, MappingTargetType.TEStyle);
			VerifyNextMapping(mappings, @"\rem", null, MarkerDomain.Note, ScrStyleNames.Remark, null, false, MappingTargetType.TEStyle);
			VerifyNextMapping(mappings, @"\v", null, MarkerDomain.Default /* NOT Default! */, ScrStyleNames.VerseNumber, null, false, MappingTargetType.TEStyle);
			VerifyNextMapping(mappings, @"|x{", "}", MarkerDomain.Footnote, ScrStyleNames.CrossRefFootnoteParagraph, null, false, MappingTargetType.TEStyle);
			Assert.IsFalse(mappings.MoveNext(), "This is just a sanity check to make sure we remembered to check all the mappings in this test.");

			Assert.AreEqual(1, m_importSettings.ScriptureSourcesOC.Count);
			Assert.AreEqual(0, m_importSettings.BackTransSourcesOC.Count);
			Assert.AreEqual(0, m_importSettings.NoteSourcesOC.Count);

			ScrImportSFFiles scriptureSource = new ScrImportSFFiles(Cache, m_importSettings.ScriptureSourcesOC.HvoArray[0]);
			Assert.AreEqual((int)FileFormatType.Other, scriptureSource.FileFormat);
			Assert.AreEqual(2, scriptureSource.FilesOC.Count);
			int[] cmFileHvos = scriptureSource.FilesOC.HvoArray;
			CmFile file = new CmFile(Cache, cmFileHvos[0]);
			Assert.AreEqual((string)fileList[0], file.AbsoluteInternalPath);
			file = new CmFile(Cache, cmFileHvos[1]);
			Assert.AreEqual((string)fileList[1], file.AbsoluteInternalPath);
		}