Пример #1
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);
        }