コード例 #1
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.
                IScrText scParatextText;

                try
                {
                    // ParatextShared has a static collection that is responsible for the dispose of any IScrText objects
                    scParatextText = ScriptureProvider.Get(project);
                }
                catch (Exception ex)
                {
                    Logger.WriteError(ex);
                    m_IsParatextInitialized = false;
                    return(false);
                }

                foreach (ImportMappingInfo mapping in mappingList)
                {
                    mapping.SetIsInUse(domain, false);
                }
                try
                {
                    foreach (var 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);
                    }
                    var parser = scParatextText.Parser;
                    foreach (int bookNum in scParatextText.BooksPresentSet.SelectedBookNumbers)
                    {
                        foreach (var token in parser.GetUsfmTokens(ScriptureProvider.MakeVerseRef(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);
            }