Exemplo n.º 1
0
        static ScriptureProvider()
        {
            var scriptureProvider = new ScriptureProvider();
            var catalog           = new AggregateCatalog();

            //Adds all the parts found in the same assembly as the ScriptureProvider class
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(ScriptureProvider).Assembly));
            //Adds all the parts found in assemblies ending in Plugin.dll that reside in the FLExExe path
            var extensionPath = Path.Combine(Path.GetDirectoryName(FwDirectoryFinder.FlexExe));

            catalog.Catalogs.Add(new DirectoryCatalog(extensionPath, "*Plugin.dll"));
            //Create the CompositionContainer with the parts in the catalog
            var container = new CompositionContainer(catalog);

            container.SatisfyImportsOnce(scriptureProvider);

            // Choose the ScriptureProvider that reports the newest version
            // (If both Paratext 7 and 8 are installed, the plugin handling 8 will be used)
            foreach (var provider in scriptureProvider._potentialScriptureProviders)
            {
                if (_scriptureProvider == null || provider.Value.MaximumSupportedVersion > _scriptureProvider.MaximumSupportedVersion)
                {
                    _scriptureProvider = provider.Value;
                }
            }
#if DEBUG
            if (_scriptureProvider == null)
            {
                throw new ApplicationException("No scripture providers discovered by MEF");
            }
#endif // DEBUG
            InitializeIfNeeded();
        }
Exemplo n.º 2
0
 /// --------------------------------------------------------------------------------
 /// <summary>
 /// Refreshes the list of Paratext projects.
 /// </summary>
 /// --------------------------------------------------------------------------------
 public void RefreshProjects()
 {
     try
     {
         if (ScriptureProvider.IsInstalled)
         {
             if (!m_IsParatextInitialized)
             {
                 // It is possible that the Projects directory was not available when we first initialized
                 // ScrTextCollection, but it now is (e.g. USB drive plugged or unplugged).  So we initialize
                 // again. ScrTextCollection.Initialize is safe to call multiple times and also refreshes texts.
                 // We pass the directory (rather than passing no arguments, and letting the paratext dll figure
                 // it out) because the figuring out goes wrong on Linux, where both programs are simulating
                 // the registry in different places. TODO NOT (Hasso) 2017.07
                 ScriptureProvider.Initialize();
                 m_IsParatextInitialized = true;
             }
             else
             {
                 ScriptureProvider.RefreshScrTexts();
             }
         }
         else
         {
             m_IsParatextInitialized = false;
         }
     }
     catch (Exception e)
     {
         Logger.WriteError(e);
         m_IsParatextInitialized = false;
     }
 }
Exemplo n.º 3
0
            /// --------------------------------------------------------------------------------
            /// <summary>
            /// Gets the list of Paratext projects.
            /// </summary>
            /// --------------------------------------------------------------------------------
            public IEnumerable <IScrText> GetProjects()
            {
                RefreshProjects();

                if (m_IsParatextInitialized)
                {
                    try
                    {
                        // The booleans say we are including resources (translations etc that are part of the Paratext release)
                        // and non-Scripture items (not sure what these are).
                        // Most likely neither of these are necessary, but I'm preserving the behavior we had with 7.3,
                        // which did not have these arguments.
                        // We also filter out invalid ScrTexts, because there is a bug in Paratext that allows them to get through.
                        return(ScriptureProvider.ScrTexts().Where(st => Directory.Exists(st.Directory)));
                    }
                    catch (Exception e)
                    {
                        Logger.WriteError(e);
                        m_IsParatextInitialized = false;
                    }
                }
                return(new IScrText[0]);
            }
Exemplo n.º 4
0
 public IEnumerable <IScrText> ScrTexts()
 {
     return(ScriptureProvider.WrapPtCollection(ScrTextCollection.ScrTexts(true, true),
                                               new Func <ScrText, IScrText>(ptText => new PT7ScrTextWrapper(ptText))));
 }
Exemplo n.º 5
0
 public IEnumerable <IUsfmToken> GetUsfmTokens(IVerseRef verseRef, bool b, bool b1)
 {
     return(ScriptureProvider.WrapPtCollection(pt7Parser.GetUsfmTokens((VerseRef)verseRef.CoreVerseRef, b, b1),
                                               new Func <UsfmToken, IUsfmToken>(token => new PT7TokenWrapper(token))));
 }
Exemplo n.º 6
0
 public IEnumerable <IVerseRef> AllVerses(bool v)
 {
     return(ScriptureProvider.WrapPtCollection(pt7VerseRef.AllVerses(v),
                                               new Func <VerseRef, IVerseRef>(verseRef => new PT7VerseRefWrapper(verseRef))));
 }
Exemplo n.º 7
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);
            }