Esempio n. 1
0
        /// <summary>
        /// Starting with the original ZPI data file,
        /// produce source files for each BEP
        /// These source files are then used for the two types of tests.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BasicConversion(object sender, EventArgs e)
        {
            UpdateFilePaths();
            // Basic load of source BEP.
            using (var originalCache = FdoCache.CreateCacheFromExistingData(FDOBackendProviderType.kXML,
                                                                            new object[] { m_originalXml }, "en"))
            {
                var originalDataSetup = originalCache.ServiceLocator.GetInstance <IDataSetup>();
                var start             = DateTime.Now;
                originalDataSetup.StartupExtantLanguageProject(new object[] { m_txtSourceFile.Text }, false);
                var elapsedTime = DateTime.Now - start;
                MessageBox.Show(this, "Time to load original XML: " + elapsedTime.TotalMilliseconds);

                // Convert to test XML BEP.
                ConvertToTargetBEP(originalCache, FDOBackendProviderType.kXML, m_xmlTestFile,
                                   "Time to convert original XML to new XML BEP: ");
                // Convert to test DB4o BEP.
                ConvertToTargetBEP(originalCache, FDOBackendProviderType.kDb4o, m_dB4oTestFile,
                                   "Time to convert original XML to new DB4o BEP: ");
                // Convert to test MySQL MyISAM BEP
#if USING_MYSQL
                ConvertToTargetBEP(originalCache, FDOBackendProviderType.kMySqlClientServer, m_MySQLMyISAMCSTestFile,
                                   "Time to convert original XML to new MySQL MyISAM CS BEP: ");
                // Convert to test MySQL MyInnoDB BEP
                ConvertToTargetBEP(originalCache, FDOBackendProviderType.kMySqlClientServerInnoDB, m_MySQLInnoDBCSTestFile,
                                   "Time to convert original XML to new MySQL InnoDB CS BEP: ");
#endif
            }
        }
Esempio n. 2
0
        protected FdoCache BootstrapSystem(IProjectIdentifier projectId, BackendBulkLoadDomain loadType, FdoSettings settings)
        {
            var retval = m_internalRestart ? FdoCache.CreateCacheFromExistingData(projectId, "en", new DummyFdoUI(), FwDirectoryFinder.FdoDirectories, settings, new DummyProgressDlg()) :
                         FdoCache.CreateCacheWithNewBlankLangProj(projectId, "en", "fr", "en", new DummyFdoUI(), FwDirectoryFinder.FdoDirectories, settings);
            var dataSetup = retval.ServiceLocator.GetInstance <IDataSetup>();

            dataSetup.LoadDomain(loadType);
            return(retval);
        }
Esempio n. 3
0
        /// <summary>
        /// Actually create the system.
        /// Called by subclass overrides of CreateCache(), with parameters that suit
        /// the subclass.
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="loadType"></param>
        /// <returns>a working FdoCache</returns>
        protected FdoCache BootstrapSystem(IProjectIdentifier projectId, BackendBulkLoadDomain loadType)
        {
            // This thread helper will be disposed in FixtureTeardown along with the cache.
            var retval = m_internalRestart ? FdoCache.CreateCacheFromExistingData(projectId, "en", new DummyProgressDlg()) :
                         FdoCache.CreateCacheWithNewBlankLangProj(projectId, "en", "fr", "en", new ThreadHelper());
            var dataSetup = retval.ServiceLocator.GetInstance <IDataSetup>();

            dataSetup.LoadDomain(loadType);
            return(retval);
        }
Esempio n. 4
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);
            }

            RegistryHelper.CompanyName = DirectoryFinder.CompanyName;
            Icu.InitIcuDataDir();
            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 FdoSettings {
                DisableDataMigration = true
            };
            var progress = new NullThreadedProgress(synchronizeInvoke);

            Console.WriteLine("Loading FieldWorks project...");
            try
            {
                using (FdoCache cache = FdoCache.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 (FdoFileLockedException)
            {
                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 (FdoDataMigrationForbiddenException)
            {
                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);
            }
        }
        public void CreateNewLangProject()
        {
            const string dbName          = "Maileingwij2025";
            string       storePath       = FdoFileHelper.GetWritingSystemDir(Path.Combine(FwDirectoryFinder.ProjectsDirectory, dbName));
            string       sharedStorePath = DirectoryFinder.GlobalWritingSystemStoreDirectory;

            using (var dlg = new DummyFwNewLangProject())
            {
                FdoCache cache = null;
                if (DbExists(dbName))
                {
                    DestroyDb(dbName, true);
                }

                dlg.setProjectName(dbName);
                try
                {
                    dlg.CreateNewLangProj();

                    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 = FdoCache.CreateCacheFromExistingData(
                        new TestProjectId(FDOBackendProviderType.kXML, DbFilename(dbName)), "en", new DummyFdoUI(), FwDirectoryFinder.FdoDirectories,
                        new FdoSettings(), new DummyProgressDlg());
                    CheckInitialSetOfPartsOfSpeech(cache);

                    Assert.AreEqual(1, cache.ServiceLocator.WritingSystems.AnalysisWritingSystems.Count);
                    Assert.AreEqual("English", cache.ServiceLocator.WritingSystems.AnalysisWritingSystems.First().LanguageName);
                    Assert.AreEqual(1, cache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems.Count);
                    Assert.AreEqual("English", cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.LanguageName);
                    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);
                }
            }
        }
Esempio n. 6
0
        private void Import()
        {
            var bepType          = FDOBackendProviderType.kDb4oClientServer;
            var msg              = "MySQL";
            var exportedPathname = m_MySQLMyISAMCSTestFile;

            if (m_rbTargetDB4o.Checked)
            {
                bepType          = FDOBackendProviderType.kDb4o;
                msg              = "DB4o";
                exportedPathname = Path.Combine(m_path, @"Exported.db4o");
            }
            else if (m_rbTargetXml.Checked)
            {
                bepType          = FDOBackendProviderType.kXML;
                msg              = "XML";
                exportedPathname = Path.Combine(m_path, @"Exported.xml");
            }
            else if (m_rbTargetGit.Checked)
            {
                bepType          = FDOBackendProviderType.kGit;
                exportedPathname = Path.Combine(m_path, @"ExportedGit");
                msg = "Git";
            }
#if USING_MYSQL
            else if (m_rbTargetMySQLMyISAMCS.Checked)
            {
                bepType          = FDOBackendProviderType.kMySqlClientServer;
                exportedPathname = @"MySQLMyISAMExported";
                msg = "MySQL MyISAM CS";
            }
            else if (m_rbTargetMySQLInnoDBCS.Checked)
            {
                bepType          = FDOBackendProviderType.kMySqlClientServerInnoDB;
                exportedPathname = @"MySQLInnoDBExported";
                msg = "MySQL InnoDB CS";
            }
#endif

            // Basic load of source BEP.
            using (var originalCache = FdoCache.CreateCacheFromExistingData(FDOBackendProviderType.kXML, new object[] { m_txtSourceFile.Text }, "en"))
            {
                // Import to test XML BEP.
                Import(originalCache, bepType, msg, exportedPathname);
            }
        }
Esempio n. 7
0
        private FdoCache TryGetFdoCache()
        {
            FdoCache fdoCache = null;
            var      path     = _project.Path;

            if (!File.Exists(path))
            {
                return(null);
            }

            var settings = new FdoSettings {
                DisableDataMigration = !AllowDataMigration
            };

            try
            {
                fdoCache = FdoCache.CreateCacheFromExistingData(
                    _project, Thread.CurrentThread.CurrentUICulture.Name, _fdoUi,
                    _project.FdoDirectories, settings, _progress);
            }
            catch (FdoDataMigrationForbiddenException)
            {
                MainClass.Logger.Error("FDO: Incompatible version (can't migrate data)");
                return(null);
            }
            catch (FdoNewerVersionException)
            {
                MainClass.Logger.Error("FDO: Incompatible version (version number newer than expected)");
                return(null);
            }
            catch (FdoFileLockedException)
            {
                MainClass.Logger.Error("FDO: Access denied");
                return(null);
            }
            catch (StartupException)
            {
                MainClass.Logger.Error("FDO: Unknown error");
                return(null);
            }

            return(fdoCache);
        }
Esempio n. 8
0
        private void LoadSource(FDOBackendProviderType bepType, string sourcePathname, string msg)
        {
            // Do a dry run, to get it precompiled.
            using (var cache = FdoCache.CreateCacheFromExistingData(bepType, new object[] { sourcePathname }, "en"))
            {
            }

            // Do a load for each count.
            var elapsedTime = new TimeSpan(0);

            for (var i = 0; i < numericUpDown1.Value; ++i)
            {
                var start = DateTime.Now;
                using (var cache = FdoCache.CreateCacheFromExistingData(bepType, new object[] { sourcePathname }, "en"))
                {
                    //var dataSetup = cache.ServiceLocator.GetInstance<IDataSetup>();
                    //dataSetup.StartupExtantLanguageProject(new object[] { sourcePathname });
                    elapsedTime += DateTime.Now - start;
                }
            }
            MessageBox.Show(this, string.Format("Average time to load {0}: {1}",
                                                msg, elapsedTime.TotalMilliseconds / (int)numericUpDown1.Value));
        }
        public void PortAllBEPsTestsUsingAnUnopenedSource()
        {
            var path = Path.Combine(Path.GetTempPath(), "FieldWorksTest");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            foreach (var sourceBackendStartupParameters in m_sourceInfo)
            {
                if (sourceBackendStartupParameters == null)
                {
                    continue;
                }

                // The Memory only source BEP can't tested here, since it can't be deleted, created, and restarted
                // which is required of all source BEPs in this test.
                // The source memory BEP is tested in 'PortAllBEPsTestsUsingAnAlreadyOpenedSource',
                // since source BEPs are only created once and the open connection is reused for all targets.
                if (sourceBackendStartupParameters.ProjectId.Type == FDOBackendProviderType.kMemoryOnly)
                {
                    continue;
                }

                DeleteDatabase(sourceBackendStartupParameters);
                var createSource = true;
                var sourceGuids  = new List <Guid>();
                foreach (var targetBackendStartupParameters in m_targetInfo)
                {
                    if (targetBackendStartupParameters == null)
                    {
                        continue;
                    }

                    DeleteDatabase(targetBackendStartupParameters);

                    if (createSource)                     // When 'createSource' is true, the source is created ex-nihilo.
                    {
                        DeleteDatabase(sourceBackendStartupParameters);
                    }

                    // Set up data source, but only do it once.
                    TestProjectId projId = new TestProjectId(sourceBackendStartupParameters.ProjectId.Type,
                                                             sourceBackendStartupParameters.ProjectId.Path);
                    IThreadedProgress progressDlg = new DummyProgressDlg();
                    using (FdoCache sourceCache = createSource ? FdoCache.CreateCacheWithNewBlankLangProj(
                               projId, "en", "fr", "en", progressDlg.ThreadHelper) :
                                                  FdoCache.CreateCacheFromExistingData(projId, "en", progressDlg))
                    {
                        // BEP is a singleton, so we shouldn't call Dispose on it. This will be done
                        // by service locator.
                        var sourceDataSetup = GetMainBEPInterface(sourceCache);
                        if (createSource)
                        {
                            sourceCache.ServiceLocator.GetInstance <IUndoStackManager>().Save(); // persist the new db so we can reopen it.
                            createSource = false;                                                // Next time, only load it.
                        }
                        sourceDataSetup.LoadDomain(BackendBulkLoadDomain.All);
                        foreach (var obj in GetAllCmObjects(sourceCache))
                        {
                            sourceGuids.Add(obj.Guid);                             // Collect up all source Guids.
                        }
                    }

                    // Migrate source data to new BEP.
                    using (var targetCache = FdoCache.CreateCacheWithNoLangProj(
                               new TestProjectId(targetBackendStartupParameters.ProjectId.Type, null), "en", progressDlg.ThreadHelper))
                    {
                        // BEP is a singleton, so we shouldn't call Dispose on it. This will be done
                        // by service locator.
                        var targetDataSetup = GetMainBEPInterface(targetCache);
                        targetDataSetup.InitializeFromSource(new TestProjectId(targetBackendStartupParameters.ProjectId.Type,
                                                                               targetBackendStartupParameters.ProjectId.Path), sourceBackendStartupParameters, "en", progressDlg);
                        targetDataSetup.LoadDomain(BackendBulkLoadDomain.All);
                        CompareResults(sourceGuids, targetCache);
                    }
                    sourceGuids.Clear();
                }
            }
        }
 private FdoCache OpenExistingFile(string filename)
 {
     return(FdoCache.CreateCacheFromExistingData(
                new TestProjectId(FDOBackendProviderType.kXMLWithMemoryOnlyWsMgr, filename), "en", new DummyProgressDlg()));
 }
Esempio n. 11
0
        static void Main(string[] arguments)
        {
            // <summary>
            // any filters that we want, for example, to only output items which satisfy their constraint.
            // </summary>
            IFilterStrategy[] filters = null;

            if (arguments.Length < 3)
            {
                Console.WriteLine("usage: fxt dbName fxtTemplatePath xmlOutputPath (-guids)");
                Console.WriteLine("");
                Console.WriteLine("example using current directory: fxt TestLangProj WebPageSample.xhtml LangProj.xhtml");
                Console.WriteLine("example with environment variables: fxt ZPU \"%fwroot%/distfiles/fxtTest.fxt\" \"%temp%/fxtTest.xml\"");
                return;
            }


            string fxtPath = System.Environment.ExpandEnvironmentVariables(arguments[1]);

            if (!File.Exists(fxtPath))
            {
                Console.WriteLine("could not find the file " + fxtPath);
                return;
            }

            string outputPath = System.Environment.ExpandEnvironmentVariables(arguments[2]);

            FdoCache cache = null;

            try
            {
                Console.WriteLine("Initializing cache...");
                var bepType      = GetBEPTypeFromFileExtension(fxtPath);
                var isMemoryBEP  = bepType == FDOBackendProviderType.kMemoryOnly;
                var threadHelper = new ThreadHelper();
                var consoleProj  = new ConsoleProgress();

                if (isMemoryBEP)
                {
                    cache = FdoCache.CreateCacheWithNewBlankLangProj(new BrowserProjectId(bepType, null), "en", "en", "en", threadHelper);
                }
                else
                {
                    using (var progressDlg = new ProgressDialogWithTask(consoleProj))
                    {
                        cache = FdoCache.CreateCacheFromExistingData(new BrowserProjectId(bepType, fxtPath), "en", progressDlg);
                    }
                }
            }
            catch (Exception error)
            {
                Console.WriteLine(error.Message);
                return;
            }
            //try
            //{
            //    Console.WriteLine("Initializing cache...");
            //    Dictionary<string, string> cacheOptions = new Dictionary<string, string>();
            //    cacheOptions.Add("db", arguments[0]);
            //    cache = FdoCache.Create(cacheOptions);
            //}
            //catch (Exception error)
            //{
            //    Console.WriteLine(error.Message);
            //    return;
            //}

            Console.WriteLine("Beginning output...");
            DateTime dtstart = DateTime.Now;
            XDumper  d       = new XDumper(cache);

            if (arguments.Length == 4)
            {
                if (arguments[3] == "-parserDump")
                {
                    filters = new IFilterStrategy[] { new ConstraintFilterStrategy() };
                }
                else
                {
                    //boy do we have a brain-dead argument parser in this app!
                    System.Diagnostics.Debug.Assert(arguments[3] == "-guids");
                }
                d.OutputGuids = true;
            }
            try
            {
                d.Go(cache.LangProject as ICmObject, fxtPath, File.CreateText(outputPath), filters);

                //clean up, add the <?xml tag, etc. Won't be necessary if/when we make the dumper use an xmlwriter instead of a textwriter
                //was introducing changes such as single quote to double quote				XmlDocument doc=new XmlDocument();
                //				doc.Load(outputPath);
                //				doc.Save(outputPath);
            }
            catch (Exception error)
            {
                if (cache != null)
                {
                    cache.Dispose();
                }

                Console.WriteLine(error.Message);
                return;
            }


            TimeSpan tsTimeSpan = new TimeSpan(DateTime.Now.Ticks - dtstart.Ticks);

            Console.WriteLine("Finished: " + tsTimeSpan.TotalSeconds.ToString() + " Seconds");

            if (outputPath.ToLower().IndexOf("fxttestout") > -1)
            {
                System.Diagnostics.Debug.WriteLine(File.OpenText(outputPath).ReadToEnd());
            }

            if (cache != null)
            {
                cache.Dispose();
            }

            System.Diagnostics.Debug.WriteLine("Finished: " + tsTimeSpan.TotalSeconds.ToString() + " Seconds");
        }
Esempio n. 12
0
        private LexicalProjectValidationResult TryGetFdoCache(string projectId, string langId, out FdoCache fdoCache)
        {
            fdoCache = null;
            if (string.IsNullOrEmpty(langId))
            {
                return(LexicalProjectValidationResult.InvalidLanguage);
            }

            if (m_fdoCacheCache.Contains(projectId))
            {
                fdoCache = m_fdoCacheCache[projectId];
            }
            else
            {
                var    backendProviderType = FDOBackendProviderType.kSharedXML;
                string path = Path.Combine(ParatextLexiconPluginDirectoryFinder.ProjectsDirectory, projectId, projectId + FdoFileHelper.ksFwDataXmlFileExtension);
                if (!File.Exists(path))
                {
                    backendProviderType = FDOBackendProviderType.kDb4oClientServer;
                    path = Path.Combine(ParatextLexiconPluginDirectoryFinder.ProjectsDirectory, projectId, projectId + FdoFileHelper.ksFwDataDb4oFileExtension);
                    if (!File.Exists(path))
                    {
                        return(LexicalProjectValidationResult.ProjectDoesNotExist);
                    }
                }

                var settings = new FdoSettings {
                    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 = string.Format("Opening {0}", projectId)
                    };
                    fdoCache = FdoCache.CreateCacheFromExistingData(new ParatextLexiconPluginProjectID(backendProviderType, path), Thread.CurrentThread.CurrentUICulture.Name, m_ui,
                                                                    ParatextLexiconPluginDirectoryFinder.FdoDirectories, settings, progress);
                }
                catch (FdoDataMigrationForbiddenException)
                {
                    return(LexicalProjectValidationResult.IncompatibleVersion);
                }
                catch (FdoNewerVersionException)
                {
                    return(LexicalProjectValidationResult.IncompatibleVersion);
                }
                catch (FdoFileLockedException)
                {
                    return(LexicalProjectValidationResult.AccessDenied);
                }
                catch (StartupException)
                {
                    return(LexicalProjectValidationResult.UnknownError);
                }

                m_fdoCacheCache.Add(fdoCache);
            }

            if (fdoCache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.All(ws => ws.Id != langId))
            {
                DisposeFdoCacheIfUnused(fdoCache);
                fdoCache = null;
                return(LexicalProjectValidationResult.InvalidLanguage);
            }

            return(LexicalProjectValidationResult.Success);
        }