示例#1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Load the Paratext project and enumerator, preparing us to read the data files.
        /// </summary>
        /// <param name="paratextProjectId">3-letter Paratext project ID</param>
        /// <returns>true if the project was loaded, else false</returns>
        /// ------------------------------------------------------------------------------------
        protected virtual void LoadParatextProject(string paratextProjectId)
        {
            try
            {
                m_ptProjectText = new ScrText(paratextProjectId);
            }
            catch (Exception e)
            {
                // Can't load Paratext project if Paratext is not installed.
                throw new ParatextLoadException(
                          TeResourceHelper.GetResourceString("kstidCheckParatextInstallation"), e);
            }

            try
            {
                // create ref objs of the Paratext lib
                Logger.WriteEvent("Loading Paratext project " + paratextProjectId + " to import from " +
                                  m_settings.StartRef.AsString + " to " + m_settings.EndRef.AsString);

                // Now initialize the TextEnum with the range of Scripture text we want
                m_ptParser   = m_ptProjectText.Parser();
                m_ptCurrBook = new VerseRef(m_settings.StartRef.Book, 0, 0);
                ResetParatextState();
            }
            catch (Exception e)
            {
                string msg = string.Format(
                    TeResourceHelper.GetResourceString("kstidParatextProjectLoadFailure"),
                    paratextProjectId);
                throw new ParatextLoadException(msg, e);
            }
        }
示例#2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Load the Paratext project and enumerator, preparing us to read the data files.
		/// </summary>
		/// <param name="paratextProjectId">3-letter Paratext project ID</param>
		/// <returns>true if the project was loaded, else false</returns>
		/// ------------------------------------------------------------------------------------
		protected virtual void LoadParatextProject(string paratextProjectId)
		{
			try
			{
				m_ptProjectText = new ScrText(paratextProjectId);
			}
			catch (Exception e)
			{
				// Can't load Paratext project if Paratext is not installed.
				throw new ParatextLoadException(
					TeResourceHelper.GetResourceString("kstidCheckParatextInstallation"), e);
			}

			try
			{
				// create ref objs of the Paratext lib
				Logger.WriteEvent("Loading Paratext project " + paratextProjectId + " to import from " +
					m_settings.StartRef.AsString + " to " + m_settings.EndRef.AsString);

				// Now initialize the TextEnum with the range of Scripture text we want
				m_ptParser = m_ptProjectText.Parser;
				m_ptCurrBook = new VerseRef(m_settings.StartRef.Book, 0, 0);
				ResetParatextState();
			}
			catch (Exception e)
			{
				string msg = string.Format(
					TeResourceHelper.GetResourceString("kstidParatextProjectLoadFailure"),
					paratextProjectId);
				throw new ParatextLoadException(msg, e);
			}
		}
        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);
        }
示例#4
0
 public Pt8ParserWrapper(ScrParser parser)
 {
     ptParser = parser;
 }
示例#5
0
 public Pt7ParserWrapper(ScrParser parser)
 {
     pt7Parser = parser;
 }
示例#6
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);
            }