/// <summary> /// Constructor /// </summary> /// <param name="backendProviderType">Type of backend provider to create.</param> /// <param name="ui">The UI service.</param> /// <param name="dirs">The directories service.</param> /// <param name="settings">The LCM settings.</param> internal LcmServiceLocatorFactory(BackendProviderType backendProviderType, ILcmUI ui, ILcmDirectories dirs, LcmSettings settings) { m_backendProviderType = backendProviderType; m_ui = ui; m_dirs = dirs; m_settings = settings; }
public void LoadProject(string projectName) { LCModel.Core.Text.CustomIcu.InitIcuDataDir(); if (!Sldr.IsInitialized) { Sldr.Initialize(true); } var dirs = new PaFieldWorksHelper(); var projectPath = string.Empty; if (File.Exists(projectName)) { projectPath = projectName; } else { projectPath = Path.Combine(dirs.ProjectsDirectory, projectName, projectName + LcmFileHelper.ksFwDataXmlFileExtension); } var ui = new SilentLcmUI(SynchronizeInvoke); var settings = new LcmSettings { DisableDataMigration = false, UpdateGlobalWSStore = false }; SilTools.Utils.WaitCursors(true); using (var progressDlg = new PAProgress()) { m_cache = LcmCache.CreateCacheFromExistingData(new FWProjectId(BackendProviderType.kSharedXML, projectPath), Thread.CurrentThread.CurrentUICulture.Name, ui, dirs, settings, progressDlg); } SilTools.Utils.WaitCursors(false); }
static int Main(string[] args) { if (args.Length < 2) { WriteHelp(); return(0); } if (!File.Exists(args[0])) { Console.WriteLine("The FieldWorks project file could not be found."); return(1); } FwRegistryHelper.Initialize(); FwUtils.InitializeIcu(); Sldr.Initialize(); var synchronizeInvoke = new SingleThreadedSynchronizeInvoke(); var spanFactory = new ShapeSpanFactory(); var projectId = new ProjectIdentifier(args[0]); var logger = new ConsoleLogger(synchronizeInvoke); var dirs = new NullFdoDirectories(); var settings = new LcmSettings { DisableDataMigration = true }; var progress = new NullThreadedProgress(synchronizeInvoke); Console.WriteLine("Loading FieldWorks project..."); try { using (LcmCache cache = LcmCache.CreateCacheFromExistingData(projectId, "en", logger, dirs, settings, progress)) { Language language = HCLoader.Load(spanFactory, cache, logger); Console.WriteLine("Loading completed."); Console.WriteLine("Writing HC configuration file..."); XmlLanguageWriter.Save(language, args[1]); Console.WriteLine("Writing completed."); } return(0); } catch (LcmFileLockedException) { Console.WriteLine("Loading failed."); Console.WriteLine("The FieldWorks project is currently open in another application."); Console.WriteLine("Close the application and try to run this command again."); return(1); } catch (LcmDataMigrationForbiddenException) { Console.WriteLine("Loading failed."); Console.WriteLine("The FieldWorks project was created with an older version of FLEx."); Console.WriteLine("Migrate the project to the latest version by opening it in FLEx."); return(1); } }
private LcmCache TryGetLcmCache() { LcmCache lcmCache = null; var path = _project.Path; if (!File.Exists(path)) { return(null); } var settings = new LcmSettings { DisableDataMigration = !AllowDataMigration }; try { lcmCache = LcmCache.CreateCacheFromExistingData( _project, Thread.CurrentThread.CurrentUICulture.Name, _lcmUi, _project.LcmDirectories, settings, _progress); } catch (LcmDataMigrationForbiddenException) { MainClass.Logger.Error("LCM: Incompatible version (can't migrate data)"); return(null); } catch (LcmNewerVersionException) { MainClass.Logger.Error("LCM: Incompatible version (version number newer than expected)"); return(null); } catch (LcmFileLockedException) { MainClass.Logger.Error("LCM: Access denied"); return(null); } catch (LcmInitializationException e) { MainClass.Logger.Error("LCM: Unknown error: {0}", e.Message); return(null); } return(lcmCache); }
/// <summary> /// Constructor. /// </summary> internal MemoryOnlyBackendProvider(LcmCache cache, IdentityMap identityMap, ICmObjectSurrogateFactory surrogateFactory, IFwMetaDataCacheManagedInternal mdc, IDataMigrationManager dataMigrationManager, ILcmUI ui, ILcmDirectories dirs, LcmSettings settings) : base(cache, identityMap, surrogateFactory, mdc, dataMigrationManager, ui, dirs, settings) { m_projectSettingsStore = new MemorySettingsStore(); m_userSettingsStore = new MemorySettingsStore(); }
internal SharedXMLBackendProvider(LcmCache cache, IdentityMap identityMap, ICmObjectSurrogateFactory surrogateFactory, IFwMetaDataCacheManagedInternal mdc, IDataMigrationManager dataMigrationManager, ILcmUI ui, ILcmDirectories dirs, LcmSettings settings) : base(cache, identityMap, surrogateFactory, mdc, dataMigrationManager, ui, dirs, settings) { m_peerProcesses = new Dictionary <int, Process>(); m_peerID = Guid.NewGuid(); if (MiscUtils.IsMono) { // /dev/shm is not guaranteed to be available on all systems, so fall back to temp m_commitLogDir = Directory.Exists("/dev/shm") ? "/dev/shm" : Path.GetTempPath(); } }
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); }