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);
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        public void FwNewLangProjectModel_VerifyCreateNewLangProject()
        {
            LcmCache cache = null;

            var testProject = new FwNewLangProjectModel(true)
            {
                LoadProjectNameSetup = () => { },
                LoadVernacularSetup  = () => { },
                LoadAnalysisSetup    = () => { },
                AnthroModel          = new FwChooseAnthroListModel {
                    CurrentList = FwChooseAnthroListModel.ListChoice.UserDef
                }
            };

            try
            {
                testProject.ProjectName = DbName;
                testProject.Next();
                testProject.SetDefaultWs(new LanguageInfo {
                    LanguageTag = "fr"
                });
                testProject.Next();
                testProject.SetDefaultWs(new LanguageInfo {
                    LanguageTag = "de"
                });
                using (var threadHelper = new ThreadHelper())
                {
                    testProject.CreateNewLangProj(new DummyProgressDlg(), threadHelper);
                }

                Assert.IsTrue(DbExists(DbName));

                // despite of the name is DummyProgressDlg no real dialog (doesn't derive from Control), so
                // we don't need a 'using'
                cache = LcmCache.CreateCacheFromExistingData(
                    new TestProjectId(BackendProviderType.kXMLWithMemoryOnlyWsMgr, DbFilename(DbName)), "en", new DummyLcmUI(),
                    FwDirectoryFinder.LcmDirectories, new LcmSettings(), new DummyProgressDlg());
                CheckInitialSetOfPartsOfSpeech(cache);

                Assert.AreEqual(2, cache.ServiceLocator.WritingSystems.AnalysisWritingSystems.Count);
                Assert.AreEqual("German", cache.ServiceLocator.WritingSystems.AnalysisWritingSystems.First().LanguageName);
                Assert.AreEqual("English", cache.ServiceLocator.WritingSystems.AnalysisWritingSystems.Last().LanguageName);
                Assert.AreEqual(2, cache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems.Count);
                Assert.AreEqual("German", cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.LanguageName);
                Assert.AreEqual("English", cache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems.Last().LanguageName,
                                "English should be selected as an analysis writing system even if the user tried to remove it");
                Assert.AreEqual(1, cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Count);
                Assert.AreEqual("French", cache.ServiceLocator.WritingSystems.VernacularWritingSystems.First().LanguageName);
                Assert.AreEqual(1, cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Count);
                Assert.AreEqual("French", cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.LanguageName);
            }
            finally
            {
                // Blow away the database to clean things up
                if (cache != null)
                {
                    cache.Dispose();
                }
                DestroyDb(DbName, false);
            }
        }