Esempio n. 1
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="icuLocale">The ICU locale of the source to which this file belongs
 /// (null for Scripture source)</param>
 /// <param name="noteTypeHvo">The HVO of 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(ICmFile file, ScrMappingList mappingList, ImportDomain domain,
                          string icuLocale, int noteTypeHvo, bool scanInlineBackslashMarkers) :
     this(file.AbsoluteInternalPath, mappingList, domain, icuLocale, noteTypeHvo,
          scanInlineBackslashMarkers)
 {
     m_file = file;
 }
Esempio n. 2
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;
        }
Esempio n. 3
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="icuLocale">The ICU locale of the source to which this file belongs
 /// (null for Scripture source)</param>
 /// <param name="noteTypeHvo">The HVO of 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 icuLocale, int noteTypeHvo, bool scanInlineBackslashMarkers)
 {
     m_fileName                 = fileName;
     m_mappingList              = mappingList;
     m_domain                   = domain;
     m_icuLocale                = icuLocale;
     m_noteTypeHvo              = noteTypeHvo;
     m_doStrictFileChecking     = false;
     ScanInlineBackslashMarkers = scanInlineBackslashMarkers;
     Initialize();
 }
Esempio n. 4
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.IcuLocale);

			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);
		}
		public void Init()
		{
			m_mappingList = new ScrMappingList(MappingSet.Main, null);
		}
Esempio n. 6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Load the mappings for a paratext project into the specified list.
        /// </summary>
        /// <param name="project">Paratext project ID</param>
        /// <param name="mappingList">ScrMappingList to which new mappings will be added</param>
        /// <param name="domain">The import domain for which this project is the source</param>
        /// <returns><c>true</c> if the Paratext mappings were loaded successfully; <c>false</c>
        /// otherwise</returns>
        /// ------------------------------------------------------------------------------------
        public static bool LoadParatextMappings(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.
            SCRIPTUREOBJECTSLib.ISCScriptureText3 scParatextText = null;
            try
            {
                scParatextText = new SCRIPTUREOBJECTSLib.SCScriptureTextClass();
                scParatextText.Load(project);
            }
            catch (Exception ex)
            {
                Logger.WriteEvent(string.Format(
                                      "Got {0} exception loading paratext mappings (ScrImportP6Project.LoadParatextMappings):\n{1}",
                                      ex.GetType(), ex.Message));
                return(false);
            }

            // TE-5802
            try
            {
                for (int i = 0; true; i++)
                {
                    SCRIPTUREOBJECTSLib.ISCTag tag = scParatextText.NthTag(i);
                    if (tag == null)
                    {
                        break;
                    }
                    string marker    = @"\" + tag.Marker;
                    string endMarker = string.Empty;
                    if (tag.Endmarker != string.Empty && tag.Endmarker != null)
                    {
                        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 == SCRIPTUREOBJECTSLib.SCStyleType.scEndStyle)
                    {
                        continue;
                    }

                    // Create a new mapping for this marker.
                    mappingList.AddDefaultMappingIfNeeded(marker, endMarker, domain, false, false);
                }
                SCRIPTUREOBJECTSLib.SCReference startRefPT = new SCRIPTUREOBJECTSLib.SCReference();
                SCRIPTUREOBJECTSLib.SCReference endRefPT   = new SCRIPTUREOBJECTSLib.SCReference();
                startRefPT.Parse("GEN 1:0");
                endRefPT.Parse("REV 22:21");
                SCRIPTUREOBJECTSLib.ISCTextEnum scParatextTextEnum = scParatextText.TextEnum(
                    (SCRIPTUREOBJECTSLib.SCReference)startRefPT, (SCRIPTUREOBJECTSLib.SCReference)endRefPT,
                    (SCRIPTUREOBJECTSLib.SCTextType) 0,                    //scTitle | scSection | scVerseText | scNoteText | scOther)
                    (SCRIPTUREOBJECTSLib.SCTextProperties) 0);

                SCRIPTUREOBJECTSLib.SCTextSegment scParatextTextSegment = new SCRIPTUREOBJECTSLib.SCTextSegmentClass();
                mappingList.ResetInUseFlags(domain);

                while (scParatextTextEnum.Next(scParatextTextSegment) != 0)
                {
                    string            sMarker = @"\" + scParatextTextSegment.Tag.Marker;
                    ImportMappingInfo mapping = mappingList[sMarker];
                    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.WriteEvent(string.Format(
                                      "Got {0} exception loading paratext mappings (ScrImportP6Project.LoadParatextMappings):\n{1}",
                                      ex.GetType(), ex.Message));
                return(false);
            }

            return(true);
        }
Esempio n. 7
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);
		}
Esempio n. 8
0
		public void AddInfoWithNullMarker()
		{
			ScrMappingList list = new ScrMappingList(MappingSet.Main, null);
			list.Add(new ImportMappingInfo(null, null, null));
		}
Esempio n. 9
0
		public void AddDefaultMappingIfNeeded_btMappingsWithNonDefaultMappings()
		{
			DynamicMock mockStylesheet = new DynamicMock(typeof(IVwStylesheet));
			mockStylesheet.SetupResultForParams("GetContext", (int)ContextValues.General, "Emphasis");
			mockStylesheet.SetupResultForParams("GetType", (int)StyleType.kstCharacter, "Emphasis");

			ScrMappingList list = new ScrMappingList(MappingSet.Main, (IVwStylesheet)mockStylesheet.MockInstance);
			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);
		}
Esempio n. 10
0
		public void AddDefaultMappingIfNeeded_FigureMarkers()
		{
			DynamicMock mockStylesheet = new DynamicMock(typeof(IVwStylesheet));

			ScrMappingList list = new ScrMappingList(MappingSet.Main, (IVwStylesheet)mockStylesheet.MockInstance);
			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);
		}
Esempio n. 11
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="icuLocale">The ICU locale of the source to which this file belongs
		/// (null for Scripture source)</param>
		/// <param name="noteTypeHvo">The HVO of the CmAnnotationDefn of the source to which
		/// this file belongs (only used for Note sources)</param>
		/// ------------------------------------------------------------------------------------
		public ScrImportFileInfo(string fileName, ScrMappingList mappingList, ImportDomain domain,
			string icuLocale, int noteTypeHvo) : this(fileName,
			mappingList, domain, icuLocale, noteTypeHvo, false)
		{

		}
Esempio n. 12
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Load the mappings for a paratext project into the specified list.
		/// </summary>
		/// <param name="project">Paratext project ID</param>
		/// <param name="mappingList">ScrMappingList to which new mappings will be added</param>
		/// <param name="domain">The import domain for which this project is the source</param>
		/// <returns><c>true</c> if the Paratext mappings were loaded successfully; <c>false</c>
		/// otherwise</returns>
		/// ------------------------------------------------------------------------------------
		public static bool LoadParatextMappings(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.
			SCRIPTUREOBJECTSLib.ISCScriptureText3 scParatextText = null;
			try
			{
				scParatextText = new SCRIPTUREOBJECTSLib.SCScriptureTextClass();
				scParatextText.Load(project);
			}
			catch (Exception ex)
			{
				Logger.WriteEvent(string.Format(
					"Got {0} exception loading paratext mappings (ScrImportP6Project.LoadParatextMappings):\n{1}",
					ex.GetType(), ex.Message));
				return false;
			}

			// TE-5802
			try
			{
				for (int i = 0; true; i++)
				{
					SCRIPTUREOBJECTSLib.ISCTag tag = scParatextText.NthTag(i);
					if (tag == null)
						break;
					string marker = @"\" + tag.Marker;
					string endMarker = string.Empty;
					if (tag.Endmarker != string.Empty && tag.Endmarker != null)
						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 == SCRIPTUREOBJECTSLib.SCStyleType.scEndStyle)
						continue;

					// Create a new mapping for this marker.
					mappingList.AddDefaultMappingIfNeeded(marker, endMarker, domain, false, false);
				}
				SCRIPTUREOBJECTSLib.SCReference startRefPT = new SCRIPTUREOBJECTSLib.SCReference();
				SCRIPTUREOBJECTSLib.SCReference endRefPT = new SCRIPTUREOBJECTSLib.SCReference();
				startRefPT.Parse("GEN 1:0");
				endRefPT.Parse("REV 22:21");
				SCRIPTUREOBJECTSLib.ISCTextEnum scParatextTextEnum = scParatextText.TextEnum(
					(SCRIPTUREOBJECTSLib.SCReference)startRefPT, (SCRIPTUREOBJECTSLib.SCReference)endRefPT,
					(SCRIPTUREOBJECTSLib.SCTextType)0, //scTitle | scSection | scVerseText | scNoteText | scOther)
					(SCRIPTUREOBJECTSLib.SCTextProperties)0);

				SCRIPTUREOBJECTSLib.SCTextSegment scParatextTextSegment = new SCRIPTUREOBJECTSLib.SCTextSegmentClass();
				mappingList.ResetInUseFlags(domain);

				while (scParatextTextEnum.Next(scParatextTextSegment) != 0)
				{
					string sMarker = @"\" + scParatextTextSegment.Tag.Marker;
					ImportMappingInfo mapping = mappingList[sMarker];
					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.WriteEvent(string.Format(
					"Got {0} exception loading paratext mappings (ScrImportP6Project.LoadParatextMappings):\n{1}",
					ex.GetType(), ex.Message));
				return false;
			}

			return true;
		}
Esempio n. 13
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="icuLocale">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>
 /// ------------------------------------------------------------------------------------
 public ScrImportFileInfo(CmFile file, ScrMappingList mappingList, ImportDomain domain,
                          string icuLocale, bool scanInlineBackslashMarkers) :
     this(file, mappingList, domain, icuLocale, 0, scanInlineBackslashMarkers)
 {
 }
Esempio n. 14
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="icuLocale">The ICU locale of the source to which this file belongs
 /// (null for Scripture source)</param>
 /// <param name="noteTypeHvo">The HVO of the CmAnnotationDefn of the source to which
 /// this file belongs (only used for Note sources)</param>
 /// ------------------------------------------------------------------------------------
 public ScrImportFileInfo(string fileName, ScrMappingList mappingList, ImportDomain domain,
                          string icuLocale, int noteTypeHvo) : this(fileName,
                                                                    mappingList, domain, icuLocale, noteTypeHvo, false)
 {
 }
Esempio n. 15
0
		public override void Exit()
		{
			CheckDisposed();

			m_builder.Dispose();
			m_builder = null;
			m_settings = null;
			m_mappingList = null;

			base.Exit();
		}
Esempio n. 16
0
		/// <summary>
		/// Executes in two distinct scenarios.
		///
		/// 1. If disposing is true, the method has been called directly
		/// or indirectly by a user's code via the Dispose method.
		/// Both managed and unmanaged resources can be disposed.
		///
		/// 2. If disposing is false, the method has been called by the
		/// runtime from inside the finalizer and you should not reference (access)
		/// other managed objects, as they already have been garbage collected.
		/// Only unmanaged resources can be disposed.
		/// </summary>
		/// <param name="disposing"></param>
		/// <remarks>
		/// If any exceptions are thrown, that is fine.
		/// If the method is being done in a finalizer, it will be ignored.
		/// If it is thrown by client code calling Dispose,
		/// it needs to be handled by fixing the bug.
		///
		/// If subclasses override this method, they should call the base implementation.
		/// </remarks>
		protected override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			if (disposing)
			{
				// Dispose managed resources here.
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_mappingList = null;

			base.Dispose(disposing);
		}
Esempio n. 17
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);
		}
Esempio n. 18
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="icuLocale">The ICU locale of the source to which this file belongs
		/// (null for Scripture source)</param>
		/// <param name="noteTypeHvo">The HVO of 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 icuLocale, int noteTypeHvo, bool scanInlineBackslashMarkers)
		{
			m_fileName = fileName;
			m_mappingList = mappingList;
			m_domain = domain;
			m_icuLocale = icuLocale;
			m_noteTypeHvo = noteTypeHvo;
			m_doStrictFileChecking = false;
			ScanInlineBackslashMarkers = scanInlineBackslashMarkers;
			Initialize();
		}
Esempio n. 19
0
		public void AddDefaultMappingIfNeeded_btMappings()
		{
			DynamicMock mockStylesheet = new DynamicMock(typeof(IVwStylesheet));
			mockStylesheet.SetupResultForParams("GetContext", (int)ContextValues.Note, ScrStyleNames.NormalFootnoteParagraph);
			mockStylesheet.SetupResultForParams("GetContext", (int)ContextValues.Text, ScrStyleNames.NormalParagraph);
			mockStylesheet.SetupResultForParams("GetContext", (int)ContextValues.General, "Emphasis");
			mockStylesheet.SetupResultForParams("GetContext", (int)ContextValues.Annotation, ScrStyleNames.Remark);
			mockStylesheet.SetupResultForParams("GetType", (int)StyleType.kstParagraph, ScrStyleNames.NormalFootnoteParagraph);
			mockStylesheet.SetupResultForParams("GetType", (int)StyleType.kstParagraph, ScrStyleNames.NormalParagraph);
			mockStylesheet.SetupResultForParams("GetType", (int)StyleType.kstCharacter, "Emphasis");
			mockStylesheet.SetupResultForParams("GetType", (int)StyleType.kstParagraph, ScrStyleNames.Remark);

			ScrMappingList list = new ScrMappingList(MappingSet.Main, (IVwStylesheet)mockStylesheet.MockInstance);
			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);
		}
Esempio n. 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="icuLocale">The ICU locale of the source to which this file belongs
		/// (null for Scripture source)</param>
		/// <param name="noteTypeHvo">The HVO of 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(ICmFile file, ScrMappingList mappingList, ImportDomain domain,
			string icuLocale, int noteTypeHvo, bool scanInlineBackslashMarkers):
			this(file.AbsoluteInternalPath, mappingList, domain, icuLocale, noteTypeHvo,
			scanInlineBackslashMarkers)
		{
			m_file = file;
		}
Esempio n. 21
0
		public void AddDefaultMappingIfNeeded_btNotFromTeStyle()
		{
			DynamicMock mockStylesheet = new DynamicMock(typeof(IVwStylesheet));
			mockStylesheet.Strict = true;

			ScrMappingList list = new ScrMappingList(MappingSet.Main, (IVwStylesheet)mockStylesheet.MockInstance);
			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);
		}
Esempio n. 22
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="icuLocale">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>
		/// ------------------------------------------------------------------------------------
		public ScrImportFileInfo(CmFile file, ScrMappingList mappingList, ImportDomain domain,
			string icuLocale, bool scanInlineBackslashMarkers):
			this(file, mappingList, domain, icuLocale, 0, scanInlineBackslashMarkers)
		{
		}
Esempio n. 23
0
		public void AddNullMappingInfo()
		{
			ScrMappingList list = new ScrMappingList(MappingSet.Main, null);
			list.Add(null);
		}
Esempio n. 24
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);
		}
Esempio n. 25
0
		public void AddBlankMarker()
		{
			ScrMappingList list = new ScrMappingList(MappingSet.Main, null);
			list.Add(new ImportMappingInfo(string.Empty, string.Empty, string.Empty));
		}
Esempio n. 26
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"));
		}
Esempio n. 27
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;
		}
Esempio n. 28
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];
		}
Esempio n. 29
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);
		}
Esempio n. 30
0
		public void LookupByKey_NonExistent()
		{
			ScrMappingList list = new ScrMappingList(MappingSet.Notes, null);
			Assert.IsNull(list["moogy"]);
		}
Esempio n. 31
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 \r\n</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, 0, fParatext5)
			{
			}
Esempio n. 32
0
		public override void FixtureSetup()
		{
			CheckDisposed();
			base.FixtureSetup();

			m_mappingList = new ScrMappingList(MappingSet.Main, null);
		}