public void SetUp() { // Force initialization in ILRepacked SIL.WritingSystems assembly, // even if a referenced SIl.WritingSystems assembly somewhere down // the dependency chain, that we won't be using, was initialized. if (!Sldr.IsInitialized) { Sldr.Initialize(); } FwRegistryHelper.Initialize(); m_threadHelper = new ThreadHelper(); var ui = new DummyLcmUI(m_threadHelper); var projectId = new ParatextLexiconPluginProjectId(BackendProviderType.kMemoryOnly, "Test.fwdata"); m_cache = LcmCache.CreateCacheWithNewBlankLangProj(projectId, "en", "fr", "en", ui, ParatextLexiconPluginDirectoryFinder.LcmDirectories, new LcmSettings()); NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () => { m_cache.ServiceLocator.WritingSystems.AddToCurrentAnalysisWritingSystems(m_cache.ServiceLocator.WritingSystemManager.Get("fr")); m_cache.ServiceLocator.WritingSystems.AddToCurrentVernacularWritingSystems(m_cache.ServiceLocator.WritingSystemManager.Get("en")); m_cache.LangProject.MorphologicalDataOA.ParserParameters = "<ParserParameters><XAmple><MaxNulls>1</MaxNulls><MaxPrefixes>5</MaxPrefixes><MaxInfixes>1</MaxInfixes><MaxSuffixes>5</MaxSuffixes><MaxInterfixes>0</MaxInterfixes><MaxAnalysesToReturn>10</MaxAnalysesToReturn></XAmple><ActiveParser>XAmple</ActiveParser></ParserParameters>"; }); m_lexicon = new FdoLexicon("Test", "FieldWorks:Test", m_cache, m_cache.DefaultVernWs); }
private LexicalProjectValidationResult TryGetLcmCache(string projectId, string langId, out LcmCache fdoCache) { fdoCache = null; if (string.IsNullOrEmpty(langId)) { return(LexicalProjectValidationResult.InvalidLanguage); } if (m_cacheCache.Contains(projectId)) { fdoCache = m_cacheCache[projectId]; } else { var path = Path.Combine(ParatextLexiconPluginDirectoryFinder.ProjectsDirectory, projectId, projectId + LcmFileHelper.ksFwDataXmlFileExtension); if (!File.Exists(path)) { return(LexicalProjectValidationResult.ProjectDoesNotExist); } var settings = new LcmSettings { DisableDataMigration = true }; using (RegistryKey fwKey = ParatextLexiconPluginRegistryHelper.FieldWorksRegistryKeyLocalMachine) { if (fwKey != null) { var sharedXMLBackendCommitLogSize = (int)fwKey.GetValue("SharedXMLBackendCommitLogSize", 0); if (sharedXMLBackendCommitLogSize > 0) { settings.SharedXMLBackendCommitLogSize = sharedXMLBackendCommitLogSize; } } } try { var progress = new ParatextLexiconPluginThreadedProgress(m_ui.SynchronizeInvoke) { IsIndeterminate = true, Title = $"Opening {projectId}" }; var lcmProjectId = new ParatextLexiconPluginProjectId(BackendProviderType.kSharedXML, path); fdoCache = LcmCache.CreateCacheFromExistingData(lcmProjectId, Thread.CurrentThread.CurrentUICulture.Name, m_ui, ParatextLexiconPluginDirectoryFinder.LcmDirectories, settings, progress); } catch (LcmDataMigrationForbiddenException) { return(LexicalProjectValidationResult.IncompatibleVersion); } catch (LcmNewerVersionException) { return(LexicalProjectValidationResult.IncompatibleVersion); } catch (LcmFileLockedException) { return(LexicalProjectValidationResult.AccessDenied); } catch (LcmInitializationException) { return(LexicalProjectValidationResult.UnknownError); } m_cacheCache.Add(fdoCache); } if (fdoCache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.All(ws => ws.Id != langId)) { DisposeLcmCacheIfUnused(fdoCache); fdoCache = null; return(LexicalProjectValidationResult.InvalidLanguage); } return(LexicalProjectValidationResult.Success); }