Пример #1
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);
        }
Пример #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Advance the scripture text object enumerator to the next segment.
        /// </summary>
        /// <remarks>Virtual to support testing</remarks>
        /// <param name="sText">Set to the text of the current segment</param>
        /// <param name="sMarker">Set to the marker of the current segment tag</param>
        /// <param name="domain">Set to the domain of the stream being processed</param>
        /// <returns>True if successful. False if there are no more segments.</returns>
        /// ------------------------------------------------------------------------------------
        public virtual bool GetNextSegment(out string sText, out string sMarker,
                                           out ImportDomain domain)
        {
            int result = 0;

            domain = m_currentDomain;

            if (TypeOfImport == TypeOfImport.Paratext6)
            {
                result = m_scParatextTextEnum.Next(m_scParatextTextSegment);
                if (result != 0)
                {
                    sText   = m_scParatextTextSegment.Text;
                    sMarker = @"\" + m_scParatextTextSegment.Tag.Marker;

                    if (!ScrImportFileInfo.IsValidMarker(sMarker))
                    {
                        throw new ScriptureUtilsException(SUE_ErrorCode.InvalidCharacterInMarker, null, 0,
                                                          sMarker + sText, m_scParatextTextSegment.FirstReference.BBCCCVVV);
                    }
                    return(true);
                }
                else
                {
                    switch (m_currentDomain)
                    {
                    case ImportDomain.Main:
                    {
                        if (LoadParatextBackTranslationProject())
                        {
                            return(GetNextSegment(out sText, out sMarker, out domain));
                        }
                        goto case ImportDomain.BackTrans;
                    }

                    case ImportDomain.BackTrans:
                    {
                        if (LoadParatextNotesProject())
                        {
                            return(GetNextSegment(out sText, out sMarker, out domain));
                        }
                        break;
                    }
                    }
                }
            }
            else if (TypeOfImport == TypeOfImport.Other || TypeOfImport == TypeOfImport.Paratext5)
            {
                m_scTextSegment = m_scTextEnum.Next();
                if (m_scTextSegment != null)
                {
                    sText   = m_scTextSegment.Text;
                    sMarker = m_scTextSegment.Marker;
                    return(true);
                }
                else
                {
                    switch (m_currentDomain)
                    {
                    case ImportDomain.Main:
                    {
                        m_currentDomain = ImportDomain.BackTrans;
                        m_scSfmText     = new SCScriptureText(m_settings, ImportDomain.BackTrans);
                        // Now initialize the TextEnum with the range of scripture text we want
                        m_scTextEnum = m_scSfmText.TextEnum(m_settings.StartRef, m_settings.EndRef);
                        return(GetNextSegment(out sText, out sMarker, out domain));
                    }

                    case ImportDomain.BackTrans:
                    {
                        m_currentDomain = ImportDomain.Annotations;
                        m_scSfmText     = new SCScriptureText(m_settings, ImportDomain.Annotations);
                        // Now initialize the TextEnum with the range of scripture text we want
                        m_scTextEnum = m_scSfmText.TextEnum(m_settings.StartRef, m_settings.EndRef);
                        return(GetNextSegment(out sText, out sMarker, out domain));
                    }
                    }
                }
            }
            else
            {
                throw new Exception("GetNextSegment has an invalid import type");
            }

            sText   = null;
            sMarker = null;
            return(false);
        }