/// ------------------------------------------------------------------------------------ /// <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_scParatextText = new SCRIPTUREOBJECTSLib.SCScriptureTextClass(); m_scParatextTextSegment = new SCRIPTUREOBJECTSLib.SCTextSegmentClass(); } catch (Exception e) { // Can't load Paratext project if Paratext is not installed. throw new ParatextLoadException( TeResourceHelper.GetResourceString("kstidCheckParatextInstallation"), e); } try { m_scParatextText.Load(paratextProjectId); // create ref objs of the Paratext lib SCRIPTUREOBJECTSLib.SCReference startRefPT = new SCRIPTUREOBJECTSLib.SCReference(); SCRIPTUREOBJECTSLib.SCReference endRefPT = new SCRIPTUREOBJECTSLib.SCReference(); startRefPT.Parse(m_settings.StartRef.AsString); endRefPT.Parse(m_settings.EndRef.AsString); // Now initialize the TextEnum with the range of scripture text we want m_scParatextTextEnum = m_scParatextText.TextEnum(startRefPT, endRefPT, (SCRIPTUREOBJECTSLib.SCTextType) 0, //scTitle | scSection | scVerseText | scNoteText | scOther) (SCRIPTUREOBJECTSLib.SCTextProperties) 0); } catch (Exception e) { string msg = string.Format( TeResourceHelper.GetResourceString("kstidParatextProjectLoadFailure"), paratextProjectId); throw new ParatextLoadException(msg, e); } }
/// ------------------------------------------------------------------------------------ /// <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); }
/// ------------------------------------------------------------------------------------ /// <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_scParatextText = new SCRIPTUREOBJECTSLib.SCScriptureTextClass(); m_scParatextTextSegment = new SCRIPTUREOBJECTSLib.SCTextSegmentClass(); } catch (Exception e) { // Can't load Paratext project if Paratext is not installed. throw new ParatextLoadException( TeResourceHelper.GetResourceString("kstidCheckParatextInstallation"), e); } try { m_scParatextText.Load(paratextProjectId); // create ref objs of the Paratext lib SCRIPTUREOBJECTSLib.SCReference startRefPT = new SCRIPTUREOBJECTSLib.SCReference(); SCRIPTUREOBJECTSLib.SCReference endRefPT = new SCRIPTUREOBJECTSLib.SCReference(); startRefPT.Parse(m_settings.StartRef.AsString); endRefPT.Parse(m_settings.EndRef.AsString); // Now initialize the TextEnum with the range of scripture text we want m_scParatextTextEnum = m_scParatextText.TextEnum(startRefPT, endRefPT, (SCRIPTUREOBJECTSLib.SCTextType)0, //scTitle | scSection | scVerseText | scNoteText | scOther) (SCRIPTUREOBJECTSLib.SCTextProperties)0); } catch (Exception e) { string msg = string.Format( TeResourceHelper.GetResourceString("kstidParatextProjectLoadFailure"), paratextProjectId); throw new ParatextLoadException(msg, e); } }