Пример #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>
        /// ------------------------------------------------------------------------------------
        public ScrSfFileList(IScrImportSFFiles source, ScrMappingList mappingList,
                             ImportDomain importDomain, bool scanInlineBackslashMarkers)
            : this(null)
        {
            var deleteList = new List <ICmFile>();
            // Load the files into an in-memory list
            foreach (ICmFile file in source.FilesOC)
            {
                try
                {
                    IScrImportFileInfo info = new ScrImportFileInfo(file, mappingList, importDomain,
                                                                    source.WritingSystem, source.NoteTypeRA, scanInlineBackslashMarkers);
                    Add(info);
                }
                catch (ScriptureUtilsException e)
                {
                    var userAction = source.Services.GetInstance <IFdoUI>();
                    userAction.DisplayMessage(MessageType.Error, string.Format(ScrFdoResources.kstidImportBadFile, e.Message), Strings.ksErrorCaption, e.HelpTopic);
                    deleteList.Add(file);
                }
            }

            // delete all of the files that caused errors
            foreach (ICmFile deleteItem in deleteList)
            {
                source.FilesOC.Remove(deleteItem);
            }

            m_modified = false;
        }
Пример #2
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Construct a ScrImportFileInfo from a CmFile. This is used when populating the
 /// file list from the database.
 /// </summary>
 /// <param name="file">The CmFile</param>
 /// <param name="mappingList">List of mappings to which newly found mappings
 /// should (and will) be added</param>
 /// <param name="domain">The import domain to which this file belongs</param>
 /// <param name="wsId">The ICU locale of the source to which this file belongs
 /// (null for Scripture source)</param>
 /// <param name="noteType">The CmAnnotationDefn of the source to which
 /// this file belongs (only used for Note sources)</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>
 /// ------------------------------------------------------------------------------------
 internal ScrImportFileInfo(ICmFile file, ScrMappingList mappingList, ImportDomain domain,
                            string wsId, ICmAnnotationDefn noteType, bool scanInlineBackslashMarkers) :
     this(file.AbsoluteInternalPath, mappingList, domain, wsId, noteType,
          scanInlineBackslashMarkers)
 {
     m_file = file;
 }
Пример #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(IScrImportSFFiles source, ScrMappingList mappingList,
                             ImportDomain importDomain, bool scanInlineBackslashMarkers, string helpFile)
            : this(null)
        {
            List <ICmFile> deleteList = new List <ICmFile>();
            // Load the files into an in-memory list
            foreach (ICmFile file in source.FilesOC)
            {
                try
                {
                    IScrImportFileInfo info = new ScrImportFileInfo(file, mappingList, importDomain,
                                                                    source.WritingSystem, source.NoteTypeRA, scanInlineBackslashMarkers);
                    Add(info);
                }
                catch (ScriptureUtilsException e)
                {
                    MessageBoxUtils.Show(string.Format(ScrFdoResources.kstidImportBadFile, e.Message), "", MessageBoxButtons.OK,
                                         MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, helpFile, HelpNavigator.Topic, e.HelpTopic);
                    deleteList.Add(file);
                }
            }

            // delete all of the files that caused errors
            foreach (ICmFile deleteItem in deleteList)
            {
                source.FilesOC.Remove(deleteItem);
            }

            m_modified = false;
        }
Пример #4
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Creates a <see cref="ScrImportFileInfo"/> based on a file. This is used to build an
 /// in-memory list of files.
 /// </summary>
 /// <param name="fileName">Name of the file whose info this represents</param>
 /// <param name="mappingList">Sorted list of mappings to which newly found mappings
 /// should (and will) be added</param>
 /// <param name="domain">The import domain to which this file belongs</param>
 /// <param name="wsId">The writing system identifier of the source to which this file
 /// belongs (null for Scripture source)</param>
 /// <param name="noteType">The CmAnnotationDefn of the source to which
 /// this file belongs (only used for Note sources)</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>
 /// ------------------------------------------------------------------------------------
 public virtual IScrImportFileInfo Create(string fileName, ScrMappingList mappingList,
                                          ImportDomain domain, string wsId, ICmAnnotationDefn noteType,
                                          bool scanInlineBackslashMarkers)
 {
     return(new ScrImportFileInfo(fileName, mappingList, domain, wsId, noteType,
                                  scanInlineBackslashMarkers));
 }
Пример #5
0
		private void DoCommonNonModelSetup()
		{
			m_scrMappingsList = new ScrMappingList(MappingSet.Main, m_stylesheet);
			m_notesMappingsList = new ScrMappingList(MappingSet.Notes, m_stylesheet);

			LoadInMemoryMappingLists();
			LoadSources(false);
		}
Пример #6
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Construct a ScrImportFileInfo based on a filename. This is used to build an
 /// in-memory list of files.
 /// </summary>
 /// <param name="fileName">Name of the file whose info this represents</param>
 /// <param name="mappingList">Sorted list of mappings to which newly found mappings
 /// should (and will) be added</param>
 /// <param name="domain">The import domain to which this file belongs</param>
 /// <param name="wsId">The writing system identifier of the source to which this file
 /// belongs (null for Scripture source)</param>
 /// <param name="noteType">The CmAnnotationDefn of the source to which
 /// this file belongs (only used for Note sources)</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>
 /// ------------------------------------------------------------------------------------
 public ScrImportFileInfo(string fileName, ScrMappingList mappingList, ImportDomain domain,
                          string wsId, ICmAnnotationDefn noteType, bool scanInlineBackslashMarkers)
 {
     m_fileName                 = fileName;
     m_mappingList              = mappingList;
     m_domain                   = domain;
     m_wsId                     = wsId;
     m_noteType                 = noteType;
     m_doStrictFileChecking     = false;
     ScanInlineBackslashMarkers = scanInlineBackslashMarkers;
     Initialize();
 }
Пример #7
0
		public void SetMappings_Main()
		{
			ScrMappingList list = new ScrMappingList(MappingSet.Main, null);
			list.Add(new ImportMappingInfo(@"\a", null, false, MappingTargetType.TEStyle, MarkerDomain.Default, ScrStyleNames.NormalParagraph, null));
			list.Add(new ImportMappingInfo(@"\a", null, false, MappingTargetType.TEStyle, MarkerDomain.BackTrans, ScrStyleNames.NormalParagraph, "es"));
			list.Add(new ImportMappingInfo(@"\b", null, false, MappingTargetType.TEStyle, MarkerDomain.Default, ScrStyleNames.NormalParagraph, null));
			list.Add(new ImportMappingInfo(@"\c", null, false, MappingTargetType.TEStyle, MarkerDomain.Default, "wrong style for chapter", null));
			list.Add(new ImportMappingInfo(@"\v", null, false, MappingTargetType.TEStyle, MarkerDomain.Default, "wrong style for verse", null));
			list.Add(new ImportMappingInfo(@"\id", null, false, MappingTargetType.TEStyle, MarkerDomain.Default, "id should be null", null));
			list.Add(new ImportMappingInfo(@"\btp", null, false, MappingTargetType.TEStyle, MarkerDomain.BackTrans, ScrStyleNames.NormalParagraph, null));

			Assert.AreEqual(6, list.Count);

			ImportMappingInfo mapping = list[0];
			Assert.AreEqual(@"\a", mapping.BeginMarker);
			Assert.IsNull(mapping.EndMarker);
			Assert.AreEqual(ScrStyleNames.NormalParagraph, mapping.StyleName);
			Assert.AreEqual(MarkerDomain.Default, mapping.Domain);
			Assert.IsFalse(mapping.IsExcluded);
			Assert.IsFalse(mapping.IsInline);
			Assert.AreEqual(MappingTargetType.TEStyle, mapping.MappingTarget);
			Assert.AreEqual("es", mapping.WsId);

			mapping = list[1];
			Assert.AreEqual(@"\b", mapping.BeginMarker);
			Assert.AreEqual(MarkerDomain.Default, mapping.Domain);

			mapping = list[2];
			Assert.AreEqual(@"\btp", mapping.BeginMarker);
			Assert.AreEqual(MarkerDomain.BackTrans, mapping.Domain);

			mapping = list[3];
			Assert.AreEqual(@"\c", mapping.BeginMarker);
			Assert.AreEqual(ScrStyleNames.ChapterNumber, mapping.StyleName);
			Assert.AreEqual(MarkerDomain.Default, mapping.Domain);

			mapping = list[4];
			Assert.AreEqual(@"\id", mapping.BeginMarker);
			Assert.IsNull(mapping.StyleName);
			Assert.AreEqual(MarkerDomain.Default, mapping.Domain);

			mapping = list[5];
			Assert.AreEqual(@"\v", mapping.BeginMarker);
			Assert.AreEqual(ScrStyleNames.VerseNumber, mapping.StyleName);
			Assert.AreEqual(MarkerDomain.Default, mapping.Domain);
		}
Пример #8
0
		public void AddDefaultMappingIfNeeded_btMappings()
		{
			IVwStylesheet stylesheet = MockRepository.GenerateStub<IVwStylesheet>();

			stylesheet.Stub(x => x.GetContext(ScrStyleNames.NormalFootnoteParagraph)).Return((int)ContextValues.Note);
			stylesheet.Stub(x => x.GetContext(ScrStyleNames.NormalParagraph)).Return((int)ContextValues.Text);
			stylesheet.Stub(x => x.GetContext("Emphasis")).Return((int)ContextValues.General);
			stylesheet.Stub(x => x.GetContext(ScrStyleNames.Remark)).Return((int)ContextValues.Annotation);

			stylesheet.Stub(x => x.GetType(ScrStyleNames.NormalFootnoteParagraph)).Return((int)StyleType.kstParagraph);
			stylesheet.Stub(x => x.GetType(ScrStyleNames.NormalParagraph)).Return((int)StyleType.kstParagraph);
			stylesheet.Stub(x => x.GetType("Emphasis")).Return((int)StyleType.kstCharacter);
			stylesheet.Stub(x => x.GetType(ScrStyleNames.Remark)).Return((int)StyleType.kstParagraph);

			ScrMappingList list = new ScrMappingList(MappingSet.Main, stylesheet);
			list.AddDefaultMappingIfNeeded(@"\bt", ImportDomain.Main, true);
			list.AddDefaultMappingIfNeeded(@"\btc", ImportDomain.Main, true);
			list.AddDefaultMappingIfNeeded(@"\btf", ImportDomain.Main, true);
			list.AddDefaultMappingIfNeeded(@"\btp", ImportDomain.Main, true);
			list.Add(new ImportMappingInfo(@"\emph", null, "Emphasis"));
			list.AddDefaultMappingIfNeeded(@"\btemph", ImportDomain.Main, true);
			list.AddDefaultMappingIfNeeded(@"\btrem", ImportDomain.Main, true);
			list.AddDefaultMappingIfNeeded(@"\bty", ImportDomain.Main, true);
			Assert.AreEqual(8, list.Count);

			// Test that \bt does not map automatically as a Back-trans marker.
			ImportMappingInfo info = list[@"\bt"];
			Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\bt should not map automatically as a Back-trans marker");
			Assert.IsFalse(info.IsExcluded);
			Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget);
			Assert.IsNull(info.StyleName);

			// Test that \btc does not map automatically as a Back-trans marker (this is a special exception to the rul).
			info = list[@"\btc"];
			Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\btc should not map automatically as a Back-trans marker");
			Assert.IsFalse(info.IsExcluded);
			Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget);
			Assert.IsNull(info.StyleName);

			// Test that \btf maps automatically as a Back-trans marker.
			info = list[@"\btf"];
			Assert.AreEqual(MarkerDomain.BackTrans | MarkerDomain.Footnote, info.Domain, @"\btf should map automatically as a Back-trans marker");
			Assert.IsFalse(info.IsExcluded);
			Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget);
			Assert.AreEqual(ScrStyleNames.NormalFootnoteParagraph, info.StyleName);

			// Test that \btp maps automatically as a Back-trans marker.
			info = list[@"\btp"];
			Assert.AreEqual(MarkerDomain.BackTrans, info.Domain, @"\btp should map automatically as a Back-trans marker");
			Assert.IsFalse(info.IsExcluded);
			Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget);
			Assert.AreEqual(ScrStyleNames.NormalParagraph, info.StyleName);

			// Test that \btemph maps automatically to the corresponding vernacular style but does not map
			// into the Back-trans marker domain because \emph is a character style.
			info = list[@"\btemph"];
			Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\btemph should not map automatically as a Back-trans marker");
			Assert.IsFalse(info.IsExcluded);
			Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget);
			Assert.AreEqual("Emphasis", info.StyleName);

			// Test that \btrem does not map automatically as a Back-trans marker (because \rem is a Note style).
			info = list[@"\btrem"];
			Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\btrem should not map automatically as a Back-trans marker");
			Assert.IsFalse(info.IsExcluded);
			Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget);
			Assert.IsNull(info.StyleName);

			// Test that \bty does not map automatically as a Back-trans marker (because \y has no default mapping).
			info = list[@"\bty"];
			Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\bty should not map automatically as a Back-trans marker");
			Assert.IsFalse(info.IsExcluded);
			Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget);
			Assert.IsNull(info.StyleName);
		}
Пример #9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Construct a ScrImportFileInfo based on a filename. This is used to build an
		/// in-memory list of files.
		/// </summary>
		/// <param name="fileName">Name of the file whose info this represents</param>
		/// <param name="mappingList">Sorted list of mappings to which newly found mappings
		/// should (and will) be added</param>
		/// <param name="domain">The import domain to which this file belongs</param>
		/// <param name="wsId">The writing system identifier of the source to which this file
		/// belongs (null for Scripture source)</param>
		/// <param name="noteType">The CmAnnotationDefn of the source to which
		/// this file belongs (only used for Note sources)</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>
		/// ------------------------------------------------------------------------------------
		public ScrImportFileInfo(string fileName, ScrMappingList mappingList, ImportDomain domain,
			string wsId, ICmAnnotationDefn noteType, bool scanInlineBackslashMarkers)
		{
			m_fileName = fileName;
			m_mappingList = mappingList;
			m_domain = domain;
			m_wsId = wsId;
			m_noteType = noteType;
			m_doStrictFileChecking = false;
			ScanInlineBackslashMarkers = scanInlineBackslashMarkers;
			Initialize();
		}
Пример #10
0
        public bool LoadProjectMappings(string project, ScrMappingList mappingList, ImportDomain domain)
        {
            // If the new project ID is null, then do not load mappings.
            if (project == null)
            {
                return(false);
            }

            // Load the tags from the paratext project and create mappings for them.
            ScrText scParatextText;

            try
            {
                // REVIEW (EberhardB): I'm not sure if ScrTextCollection.Get() returns a
                // reference to a ScrText or a new object (in which case we would have to
                // call Dispose() on it)
                scParatextText = ScrTextCollection.Get(project);
            }
            catch (Exception ex)
            {
                Logger.WriteError(ex);
                return(false);
            }

            mappingList.ResetInUseFlags(domain);
            try
            {
                foreach (ScrTag tag in scParatextText.DefaultStylesheet.Tags)
                {
                    if (tag == null)
                    {
                        break;
                    }
                    string marker    = @"\" + tag.Marker;
                    string endMarker = string.Empty;
                    if (!String.IsNullOrEmpty(tag.Endmarker))
                    {
                        endMarker = @"\" + tag.Endmarker;
                    }

                    // When the nth marker has an end marker, the nth + 1 marker will be
                    // that end marker. Therefore, we have to skip those "end style" markers.
                    if (tag.StyleType == ScrStyleType.scEndStyle)
                    {
                        continue;
                    }

                    // Create a new mapping for this marker.
                    mappingList.AddDefaultMappingIfNeeded(marker, endMarker, domain, false, false);
                }
                ScrParser parser = scParatextText.Parser();
                foreach (int bookNum in scParatextText.BooksPresentSet.SelectedBookNumbers())
                {
                    foreach (UsfmToken token in parser.GetUsfmTokens(new VerseRef(bookNum, 0, 0), false, true))
                    {
                        if (token.Marker == null)
                        {
                            continue;                             // Tokens alternate between text and marker types
                        }
                        ImportMappingInfo mapping = mappingList[@"\" + token.Marker];
                        if (mapping != null)
                        {
                            mapping.SetIsInUse(domain, true);
                        }

                        // ENHANCE (TE-4408): Consider Detecting markers that occur in the data but are missing
                        // from the STY file. How can we write a test for this?
                        //else if (ScrImportFileInfo.IsValidMarker(sMarker))
                        //{
                        //    mappingList.AddDefaultMappingIfNeeded(sMarker,domain, false, true);
                        //}
                        //else
                        //{
                        //    throw new ScriptureUtilsException(SUE_ErrorCode.InvalidCharacterInMarker, null, 0,
                        //        sMarker + sText, new ScrReference(scParatextTextSegment.FirstReference.BBCCCVVV));
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteError(ex);
                return(false);
            }
            return(true);
        }
Пример #11
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Save the in-memory mapping lists for the given mapping set
		/// </summary>
		/// <param name="mappingsOC">The owning collection of ScrMarkerMapping objects in the
		/// database</param>
		/// <param name="mappingInfoList">The in-memory list of ImportMappingInfo objects</param>
		/// ------------------------------------------------------------------------------------
		private void SaveMappings(IFdoOwningCollection<IScrMarkerMapping> mappingsOC, ScrMappingList mappingInfoList)
		{
			UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("Save mappings", "Save mappings",
				m_cache.ServiceLocator.GetInstance<IActionHandler>(), () =>
			{
				mappingsOC.Clear();
				foreach (ImportMappingInfo info in mappingInfoList)
				{
					IScrMarkerMapping mapping = Services.GetInstance<IScrMarkerMappingFactory>().Create();
					mappingsOC.Add(mapping);
					// The "Default Paragraph Characters" style is not a real style. So, we save it as
					// as separate target type. We want to set the style now for the in-memory info.
					if (info.StyleName == StyleUtils.DefaultParaCharsStyleName)
						info.MappingTarget = MappingTargetType.DefaultParaChars;
					else if (info.Style == null || info.Style.Name != info.StyleName)
						info.SetStyle(m_cache.LangProject.TranslatedScriptureOA.FindStyle(info.StyleName));
					((ScrMarkerMapping)mapping).InitFromImportMappingInfo(info);
				}
			});
		}
Пример #12
0
		public void SetMappings_Notes()
		{
			ScrMappingList list = new ScrMappingList(MappingSet.Notes, null);
			list.Add(new ImportMappingInfo(@"\a", null, false, MappingTargetType.TEStyle, MarkerDomain.Note, ScrStyleNames.Remark, null));
			list.Add(new ImportMappingInfo(@"\b", null, false, MappingTargetType.TEStyle, MarkerDomain.Default, ScrStyleNames.Remark, null));
			try
			{
				list.Add(new ImportMappingInfo(@"\q", null, false, MappingTargetType.TEStyle, MarkerDomain.BackTrans, ScrStyleNames.NormalParagraph, null));
				Assert.Fail("Illegal mapping (to BackTrans domain) was not caught");
			}
			catch (ArgumentException) {}

			Assert.AreEqual(2, list.Count);

			ImportMappingInfo mapping = list[0];
			Assert.AreEqual(@"\a", mapping.BeginMarker);
			Assert.AreEqual(MarkerDomain.Default, mapping.Domain);

			mapping = list[1];
			Assert.AreEqual(@"\b", mapping.BeginMarker);
			Assert.AreEqual(MarkerDomain.Default, mapping.Domain);
		}
Пример #13
0
		public void AddInfoWithNullMarker()
		{
			ScrMappingList list = new ScrMappingList(MappingSet.Main, null);
			list.Add(new ImportMappingInfo(null, null, null));
		}
Пример #14
0
		public void AddDefaultMappingIfNeeded_btNotFromTeStyle()
		{
			IVwStylesheet stylesheet = MockRepository.GenerateStrictMock<IVwStylesheet>();

			ScrMappingList list = new ScrMappingList(MappingSet.Main, stylesheet);
			list.Add(new ImportMappingInfo(@"\h", null, false, MappingTargetType.TitleShort,
				MarkerDomain.Default, null, null));
			list.AddDefaultMappingIfNeeded(@"\bth", ImportDomain.Main, true);
			list.Add(new ImportMappingInfo(@"\vt", null, false, MappingTargetType.DefaultParaChars,
				MarkerDomain.Default, null, null));
			list.AddDefaultMappingIfNeeded(@"\btvt", ImportDomain.Main, true);
			Assert.AreEqual(4, list.Count);

			// Test that \bth maps automatically to the corresponding vernacular import property
			// in the Back-trans marker domain.
			ImportMappingInfo info = list[@"\bth"];
			Assert.AreEqual(MarkerDomain.BackTrans, info.Domain);
			Assert.IsFalse(info.IsExcluded);
			Assert.AreEqual(MappingTargetType.TitleShort, info.MappingTarget);

			// Test that \btvt maps automatically to Default Paragraph Characters
			// in the Back-trans marker domain.
			info = list[@"\btvt"];
			Assert.AreEqual(MarkerDomain.BackTrans, info.Domain);
			Assert.IsFalse(info.IsExcluded);
			Assert.AreEqual(MappingTargetType.DefaultParaChars, info.MappingTarget);
		}
Пример #15
0
		public void Delete()
		{
			ScrMappingList list = new ScrMappingList(MappingSet.Main, null);
			list.Add(new ImportMappingInfo(@"\aa", null, false, MappingTargetType.TEStyle, MarkerDomain.Default, ScrStyleNames.Remark, null));
			list.Add(new ImportMappingInfo(@"\bb", null, false, MappingTargetType.TEStyle, MarkerDomain.Default, ScrStyleNames.Remark, null));
			list.Add(new ImportMappingInfo(@"\cc", null, false, MappingTargetType.TEStyle, MarkerDomain.BackTrans, ScrStyleNames.Remark, null));

			Assert.AreEqual(3, list.Count);

			list.Delete(list[1]);
			Assert.AreEqual(2, list.Count);

			Assert.AreEqual(@"\aa", list[0].BeginMarker);
			Assert.AreEqual(@"\cc", list[1].BeginMarker);
		}
Пример #16
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates a <see cref="ScrImportFileInfo"/> based on a file. This is used to build an
		/// in-memory list of files.
		/// </summary>
		/// <param name="fileName">Name of the file whose info this represents</param>
		/// <param name="mappingList">Sorted list of mappings to which newly found mappings
		/// should (and will) be added</param>
		/// <param name="domain">The import domain to which this file belongs</param>
		/// <param name="wsId">The writing system identifier of the source to which this file
		/// belongs (null for Scripture source)</param>
		/// <param name="noteType">The CmAnnotationDefn of the source to which
		/// this file belongs (only used for Note sources)</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>
		/// ------------------------------------------------------------------------------------
		public virtual IScrImportFileInfo Create(string fileName, ScrMappingList mappingList,
			ImportDomain domain, string wsId, ICmAnnotationDefn noteType,
			bool scanInlineBackslashMarkers)
		{
			return new ScrImportFileInfo(fileName, mappingList, domain, wsId, noteType,
				scanInlineBackslashMarkers);
		}
Пример #17
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Shuts down the FDO cache
		/// </summary>
		/// <remarks>This method is called after each test</remarks>
		/// ------------------------------------------------------------------------------------
		public override void TestTearDown()
		{
			m_builder.Dispose();
			m_builder = null;
			m_settings = null;
			m_mappingList = null;

			base.TestTearDown();
		}
Пример #18
0
		public override void FixtureSetup()
		{
			base.FixtureSetup();
			IWritingSystem wsSpanish;
			Cache.ServiceLocator.WritingSystemManager.GetOrSet("es", out wsSpanish);
			IWritingSystem wsGerman;
			Cache.ServiceLocator.WritingSystemManager.GetOrSet("de", out wsGerman);
			NonUndoableUnitOfWorkHelper.Do(m_actionHandler, () =>
			{
				Cache.ServiceLocator.WritingSystems.AnalysisWritingSystems.Add(wsSpanish);
				Cache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems.Add(wsSpanish);
				Cache.ServiceLocator.WritingSystems.AnalysisWritingSystems.Add(wsGerman);
				Cache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems.Add(wsGerman);
			});
			m_mappingList = new ScrMappingList(MappingSet.Main, null);
		}
Пример #19
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Construct a ScrImportFileInfo from a CmFile owned by a BT source. This is
		/// used when populating the file list from the database.
		/// </summary>
		/// <param name="file">The CmFile</param>
		/// <param name="mappingList">Sorted list of mappings to which newly found mappings
		/// should (and will) be added</param>
		/// <param name="domain">The import domain to which this file belongs</param>
		/// <param name="wsId">The ICU locale of the source to which this file belongs
		/// (null for Scripture source)</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>
		/// ------------------------------------------------------------------------------------
		internal ScrImportFileInfo(ICmFile file, ScrMappingList mappingList, ImportDomain domain,
			string wsId, bool scanInlineBackslashMarkers) :
			this(file, mappingList, domain, wsId, null, scanInlineBackslashMarkers)
		{
		}
Пример #20
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Construct a ScrImportFileInfo from a CmFile. This is used when populating the
		/// file list from the database.
		/// </summary>
		/// <param name="file">The CmFile</param>
		/// <param name="mappingList">List of mappings to which newly found mappings
		/// should (and will) be added</param>
		/// <param name="domain">The import domain to which this file belongs</param>
		/// <param name="wsId">The ICU locale of the source to which this file belongs
		/// (null for Scripture source)</param>
		/// <param name="noteType">The CmAnnotationDefn of the source to which
		/// this file belongs (only used for Note sources)</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>
		/// ------------------------------------------------------------------------------------
		internal ScrImportFileInfo(ICmFile file, ScrMappingList mappingList, ImportDomain domain,
			string wsId, ICmAnnotationDefn noteType, bool scanInlineBackslashMarkers) :
			this(file.AbsoluteInternalPath, mappingList, domain, wsId, noteType,
			scanInlineBackslashMarkers)
		{
			m_file = file;
		}
Пример #21
0
		public void AddDefaultMappingIfNeeded_btMappingsWithNonDefaultMappings()
		{
			IVwStylesheet stylesheet = MockRepository.GenerateStub<IVwStylesheet>();
			stylesheet.Stub(x => x.GetContext("Emphasis")).Return((int)ContextValues.General);
			stylesheet.Stub(x => x.GetType("Emphasis")).Return((int)StyleType.kstCharacter);

			ScrMappingList list = new ScrMappingList(MappingSet.Main, stylesheet);
			list.Add(new ImportMappingInfo(@"\p", null, "Emphasis"));
			list.AddDefaultMappingIfNeeded(@"\btp", ImportDomain.Main, true);
			Assert.AreEqual(2, list.Count);

			// Test that \btp maps automatically to the corresponding vernacular style ("Emphasis")
			// but does not map into the Back-trans marker domain because Emphasis is a character style.
			ImportMappingInfo info = list[@"\btp"];
			Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\btp should not map automatically as a Back-trans marker");
			Assert.IsFalse(info.IsExcluded);
			Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget);
			Assert.AreEqual("Emphasis", info.StyleName);
		}
Пример #22
0
		public void HasChanged()
		{
			ScrMappingList list = new ScrMappingList(MappingSet.Main, null);
			list.Add(new ImportMappingInfo(@"\aa", null, false, MappingTargetType.TEStyle, MarkerDomain.Default, ScrStyleNames.Remark, null));
			list.Add(new ImportMappingInfo(@"\bb", null, false, MappingTargetType.TEStyle, MarkerDomain.Default, ScrStyleNames.Remark, null));
			list.Add(new ImportMappingInfo(@"\cc", null, false, MappingTargetType.TEStyle, MarkerDomain.BackTrans, ScrStyleNames.Remark, null));
			Assert.IsTrue((bool)ReflectionHelper.GetProperty(list, "HasChanged"));

			Assert.AreEqual(3, list.Count);

			ReflectionHelper.SetProperty(list[0], "HasChanged", false);
			ReflectionHelper.SetProperty(list[1], "HasChanged", false);
			ReflectionHelper.SetProperty(list[2], "HasChanged", false);
			Assert.IsFalse((bool)ReflectionHelper.GetProperty(list, "HasChanged"));

			list.Delete(list[1]);
			Assert.AreEqual(2, list.Count);
			Assert.IsTrue((bool)ReflectionHelper.GetProperty(list, "HasChanged"));
		}
Пример #23
0
		public void Index_OutOfRange()
		{
			ScrMappingList list = new ScrMappingList(MappingSet.Notes, null);
			list.Add(new ImportMappingInfo(@"\a", null, false, MappingTargetType.TEStyle, MarkerDomain.Note, ScrStyleNames.Remark, null));

			// Access the second element which should throw an exception
			ImportMappingInfo info = list[1];
		}
Пример #24
0
		public void AddNullMappingInfo()
		{
			ScrMappingList list = new ScrMappingList(MappingSet.Main, null);
			list.Add(null);
		}
Пример #25
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Construct a ScrImportFileInfo based on a Toolbox (i.e., non-Paratext 5) filename.
 /// This is used only in tests.
 /// </summary>
 /// <param name="fileName">Name of the file whose info this represents</param>
 /// <param name="mappingList">Sorted list of mappings to which newly found mappings
 /// should (and will) be added</param>
 /// <param name="domain">The import domain to which this file belongs</param>
 /// <param name="wsId">The writing system identifier of the source to which this file
 /// belongs (null for Scripture source)</param>
 /// <param name="noteType">The CmAnnotationDefn of the source to which
 /// this file belongs (only used for Note sources)</param>
 /// ------------------------------------------------------------------------------------
 internal ScrImportFileInfo(string fileName, ScrMappingList mappingList, ImportDomain domain,
                            string wsId, ICmAnnotationDefn noteType)
     : this(fileName, mappingList, domain, wsId, noteType, false)
 {
 }
Пример #26
0
		public void AddBlankMarker()
		{
			ScrMappingList list = new ScrMappingList(MappingSet.Main, null);
			list.Add(new ImportMappingInfo(string.Empty, string.Empty, string.Empty));
		}
Пример #27
0
			/// ------------------------------------------------------------------------------------
			/// <summary>
			/// Construct a ScrImportFileInfo based on a filename. This is used to build an
			/// in-memory list of files.
			/// </summary>
			/// <param name="fileContents">String containing one or more "lines" of data, separated
			/// by Environment.NewLine</param>
			/// <param name="mappingList">Sorted list of mappings to which newly found mappings
			/// should (and will) be added</param>
			/// <param name="fParatext5"><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>
			/// ------------------------------------------------------------------------------------
			public DummyScrImportFileInfo(string fileContents, ScrMappingList mappingList,
				bool fParatext5) :
				base(fileContents, mappingList, ImportDomain.Main, null, null, fParatext5)
			{
			}
Пример #28
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates a mocked <see cref="IScrImportFileInfo"/>. This is used to build an
		/// in-memory list of files.
		/// </summary>
		/// <param name="fileName">Name of the file whose info this represents</param>
		/// <param name="mappingList">Sorted list of mappings to which newly found mappings
		/// should (and will) be added</param>
		/// <param name="domain">The import domain to which this file belongs</param>
		/// <param name="wsId">The writing system identifier of the source to which this file
		/// belongs (null for Scripture source)</param>
		/// <param name="noteType">The CmAnnotationDefn of the source to which
		/// this file belongs (only used for Note sources)</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>
		/// ------------------------------------------------------------------------------------
		public override IScrImportFileInfo Create(string fileName, ScrMappingList mappingList,
			ImportDomain domain, string wsId, ICmAnnotationDefn noteType, bool scanInlineBackslashMarkers)
		{
			IScrImportFileInfo info = MockRepository.GenerateStub<IScrImportFileInfo>();
			m_mockedScrImportFinfos[fileName] = info;
			info.Stub(x => x.FileName).Return(fileName);
			info.Stub(x => x.WsId).Return(wsId);
			info.Stub(x => x.NoteType).Return(noteType);
			return info;
		}
Пример #29
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>
		/// ------------------------------------------------------------------------------------
		public ScrSfFileList(IScrImportSFFiles source, ScrMappingList mappingList,
			ImportDomain importDomain, bool scanInlineBackslashMarkers)
			: this(null)
		{
			var deleteList = new List<ICmFile>();
			// Load the files into an in-memory list
			foreach (ICmFile file in source.FilesOC)
			{
				try
				{
					IScrImportFileInfo info = new ScrImportFileInfo(file, mappingList, importDomain,
						source.WritingSystem, source.NoteTypeRA, scanInlineBackslashMarkers);
					Add(info);
				}
				catch (ScriptureUtilsException e)
				{
					var userAction = source.Services.GetInstance<IFdoUI>();
					userAction.DisplayMessage(MessageType.Error, string.Format(ScrFdoResources.kstidImportBadFile, e.Message), Strings.ksErrorCaption, e.HelpTopic);
					deleteList.Add(file);
				}
			}

			// delete all of the files that caused errors
			foreach (ICmFile deleteItem in deleteList)
				source.FilesOC.Remove(deleteItem);

			m_modified = false;
		}
Пример #30
0
		public void Init()
		{
			m_mappingList = new ScrMappingList(MappingSet.Main, null);
			m_factory = new ScrImportFileInfoFactory();
			m_fileOs = new MockFileOS();
			FileUtils.Manager.SetFileAdapter(m_fileOs);
		}
Пример #31
0
		public void AddDefaultMappingIfNeeded_FigureMarkers()
		{
			IVwStylesheet stylesheet = MockRepository.GenerateMock<IVwStylesheet>();

			ScrMappingList list = new ScrMappingList(MappingSet.Main, stylesheet);
			list.AddDefaultMappingIfNeeded(@"\cap", ImportDomain.Main, true);
			list.AddDefaultMappingIfNeeded(@"\cat", ImportDomain.Main, true);
			list.AddDefaultMappingIfNeeded(@"\gmb", ImportDomain.Main, true);
			list.AddDefaultMappingIfNeeded(@"\gmbj", ImportDomain.Main, true);
			Assert.AreEqual(4, list.Count);

			ImportMappingInfo info = list[@"\cap"];
			Assert.AreEqual(MarkerDomain.Default, info.Domain);
			Assert.IsFalse(info.IsExcluded);
			Assert.AreEqual(MappingTargetType.FigureCaption, info.MappingTarget);
			Assert.IsNull(info.StyleName);

			info = list[@"\cat"];
			Assert.AreEqual(MarkerDomain.Default, info.Domain);
			Assert.IsFalse(info.IsExcluded);
			Assert.AreEqual(MappingTargetType.FigureFilename, info.MappingTarget);
			Assert.IsNull(info.StyleName);

			info = list[@"\gmb"];
			Assert.AreEqual(MarkerDomain.Default, info.Domain);
			Assert.IsFalse(info.IsExcluded);
			Assert.AreEqual(MappingTargetType.FigureFilename, info.MappingTarget);
			Assert.IsNull(info.StyleName);

			info = list[@"\gmbj"];
			Assert.AreEqual(MarkerDomain.Default, info.Domain);
			Assert.IsFalse(info.IsExcluded);
			Assert.AreEqual(MappingTargetType.FigureCaption, info.MappingTarget);
			Assert.IsNull(info.StyleName);
		}
Пример #32
0
		public void LookupByKey()
		{
			ScrMappingList list = new ScrMappingList(MappingSet.Notes, null);
			list.Add(new ImportMappingInfo(@"\aa", null, false, MappingTargetType.TEStyle, MarkerDomain.Note, ScrStyleNames.Remark, null));
			list.Add(new ImportMappingInfo(@"\bb", null, false, MappingTargetType.TEStyle, MarkerDomain.Note, ScrStyleNames.Remark, null));
			list.Add(new ImportMappingInfo(@"\cc", null, false, MappingTargetType.TEStyle, MarkerDomain.Note, ScrStyleNames.Remark, null));

			ImportMappingInfo info = list[@"\bb"];
			Assert.AreEqual(@"\bb", info.BeginMarker);
			Assert.AreEqual(list[1], info);
		}
Пример #33
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Construct a ScrImportFileInfo based on a Toolbox (i.e., non-Paratext 5) filename.
		/// This is used only in tests.
		/// </summary>
		/// <param name="fileName">Name of the file whose info this represents</param>
		/// <param name="mappingList">Sorted list of mappings to which newly found mappings
		/// should (and will) be added</param>
		/// <param name="domain">The import domain to which this file belongs</param>
		/// <param name="wsId">The writing system identifier of the source to which this file
		/// belongs (null for Scripture source)</param>
		/// <param name="noteType">The CmAnnotationDefn of the source to which
		/// this file belongs (only used for Note sources)</param>
		/// ------------------------------------------------------------------------------------
		internal ScrImportFileInfo(string fileName, ScrMappingList mappingList, ImportDomain domain,
			string wsId, ICmAnnotationDefn noteType)
			: this(fileName, mappingList, domain, wsId, noteType, false)
		{

		}
Пример #34
0
		public void LookupByKey_NonExistent()
		{
			ScrMappingList list = new ScrMappingList(MappingSet.Notes, null);
			Assert.IsNull(list["moogy"]);
		}
Пример #35
0
		public void Enumerator()
		{
			ScrMappingList list = new ScrMappingList(MappingSet.Notes, null);
			list.Add(new ImportMappingInfo(@"\aa", null, false, MappingTargetType.TEStyle, MarkerDomain.Note, ScrStyleNames.Remark, null));
			list.Add(new ImportMappingInfo(@"\bb", null, false, MappingTargetType.TEStyle, MarkerDomain.Note, ScrStyleNames.Remark, null));
			list.Add(new ImportMappingInfo(@"\cc", null, false, MappingTargetType.TEStyle, MarkerDomain.Note, ScrStyleNames.Remark, null));

			int i = 0;
			foreach (ImportMappingInfo info in list)
				Assert.AreEqual(list[i++], info);
			Assert.AreEqual(3, i);
		}
Пример #36
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Construct a ScrImportFileInfo from a CmFile owned by a BT source. This is
 /// used when populating the file list from the database.
 /// </summary>
 /// <param name="file">The CmFile</param>
 /// <param name="mappingList">Sorted list of mappings to which newly found mappings
 /// should (and will) be added</param>
 /// <param name="domain">The import domain to which this file belongs</param>
 /// <param name="wsId">The ICU locale of the source to which this file belongs
 /// (null for Scripture source)</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>
 /// ------------------------------------------------------------------------------------
 internal ScrImportFileInfo(ICmFile file, ScrMappingList mappingList, ImportDomain domain,
                            string wsId, bool scanInlineBackslashMarkers) :
     this(file, mappingList, domain, wsId, null, scanInlineBackslashMarkers)
 {
 }
Пример #37
0
			private bool LoadProjectMappings(string project, ScrMappingList mappingList, ImportDomain domain)
			{
				// If the new project ID is null, then do not load mappings.
				if (string.IsNullOrEmpty(project))
					return false;

				// Load the tags from the paratext project and create mappings for them.
				ScrText scParatextText;
				try
				{
					// REVIEW (EberhardB): I'm not sure if ScrTextCollection.Get() returns a
					// reference to a ScrText or a new object (in which case we would have to
					// call Dispose() on it)
					scParatextText = ScrTextCollection.Get(project);
				}
				catch (Exception ex)
				{
					Logger.WriteError(ex);
					m_IsParatextInitialized = false;
					return false;
				}

				foreach (ImportMappingInfo mapping in mappingList)
					mapping.SetIsInUse(domain, false);
				try
				{
					foreach (ScrTag tag in scParatextText.DefaultStylesheet.Tags)
					{
						if (tag == null)
							break;
						string marker = @"\" + tag.Marker;
						string endMarker = string.Empty;
						if (!String.IsNullOrEmpty(tag.Endmarker))
							endMarker = @"\" + tag.Endmarker;

						// When the nth marker has an end marker, the nth + 1 marker will be
						// that end marker. Therefore, we have to skip those "end style" markers.
						if (tag.StyleType == ScrStyleType.scEndStyle)
							continue;

						// Create a new mapping for this marker.
						mappingList.AddDefaultMappingIfNeeded(marker, endMarker, domain, false, false);
					}
					ScrParser parser = scParatextText.Parser;
					foreach (int bookNum in scParatextText.BooksPresentSet.SelectedBookNumbers)
					{
						foreach (UsfmToken token in parser.GetUsfmTokens(new VerseRef(bookNum, 0, 0), false, true))
						{
							if (token.Marker == null)
								continue; // Tokens alternate between text and marker types

							ImportMappingInfo mapping = mappingList[@"\" + token.Marker];
							if (mapping != null)
								mapping.SetIsInUse(domain, true);
						}
					}
				}
				catch (Exception ex)
				{
					Logger.WriteError(ex);
					// A lot goes on in the try block, so this exception doesn't necessarily mean Paratext is inaccessible,
					// so don't mark Paratext as uninitialized
					return false;
				}
				return true;
			}