Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private static bool GetSharedProject()
        {
            bool result;

            FwRegistryHelper.MigrateVersion7ValueIfNeeded();
            var value = FwRegistryHelper.FieldWorksRegistryKey.GetValue(ksSharedProjectKey, "false");

            return(bool.TryParse((string)value, out result) && result);
        }
Esempio n. 3
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);
            }
        }
        internal static void StartProvider(Uri providerLocation, object provider, Type providerType)
        {
            if (s_runningProviders.ContainsKey(providerType))
            {
                return;
            }

            string sNamedPipe = providerLocation.ToString();
            // REVIEW: we don't dispose ServiceHost. It might be better to add it to the
            // SingletonsContainer
            ServiceHost providerHost = null;

            try
            {
                providerHost = new ServiceHost(provider);
                // Named pipes are better for Windows...don't tie up a dedicated port and perform better.
                // However, Mono does not yet support them, so on Mono we use a different binding.
                // Note that any attempt to unify these will require parallel changes in Paratext
                // and some sort of coordinated release of the new versions.
#if __MonoCS__
                BasicHttpBinding binding = new BasicHttpBinding();
#else
                NetNamedPipeBinding binding = new NetNamedPipeBinding();
                binding.Security.Mode = NetNamedPipeSecurityMode.None;
#endif
                binding.MaxBufferSize                       *= 4;
                binding.MaxReceivedMessageSize              *= 4;
                binding.MaxBufferPoolSize                   *= 2;
                binding.ReaderQuotas.MaxBytesPerRead        *= 4;
                binding.ReaderQuotas.MaxArrayLength         *= 4;
                binding.ReaderQuotas.MaxDepth               *= 4;
                binding.ReaderQuotas.MaxNameTableCharCount  *= 4;
                binding.ReaderQuotas.MaxStringContentLength *= 4;

                providerHost.AddServiceEndpoint(providerType, binding, sNamedPipe);
                providerHost.Open();
            }
            catch (Exception e)
            {
                Logger.WriteError(e);
                providerHost = null;
                var paratextInstalled = FwRegistryHelper.Paratext7orLaterInstalled();
                if (paratextInstalled)
                {
                    MessageBox.Show(PtCommunicationProb, PtCommunicationProbTitle,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                return;
            }
            Logger.WriteEvent("Started provider " + providerLocation + " for type " + providerType + ".");
            s_runningProviders.Add(providerType, providerHost);
        }
Esempio n. 5
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            FwRegistryHelper.Initialize();
            FwUtils.InitializeIcu();
            Sldr.Initialize();
            using (var form = new LCMBrowserForm())
            {
                Application.Run(form);
            }

            Sldr.Cleanup();
        }
Esempio n. 6
0
 public void Setup()
 {
     FwRegistryHelper.Initialize();
     Assert.IsTrue(InitializeIcuData());
     m_sCustomCharsFile   = Path.Combine(CustomIcu.DefaultDataDirectory, "CustomChars.xml");
     m_sCustomCharsBackup = Path.Combine(CustomIcu.DefaultDataDirectory, "TestBackupForCustomChars.xml");
     if (File.Exists(m_sCustomCharsFile))
     {
         if (File.Exists(m_sCustomCharsBackup))
         {
             File.Delete(m_sCustomCharsBackup);
         }
         File.Move(m_sCustomCharsFile, m_sCustomCharsBackup);
     }
 }
Esempio n. 7
0
        internal static void StartProvider(Uri providerLocation, object provider, Type providerType)
        {
            if (s_runningProviders.ContainsKey(providerType))
            {
                return;
            }

            string sNamedPipe = providerLocation.ToString();
            // REVIEW: we don't dispose ServiceHost. It might be better to add it to the
            // SingletonsContainer
            ServiceHost providerHost = null;

            try
            {
                providerHost = new ServiceHost(provider);
                // TODO-Linux: various properties of NetNamedPipeBinding are marked with MonoTODO
                // attributes. Test if this affects us.
                NetNamedPipeBinding binding = new NetNamedPipeBinding();
                binding.Security.Mode                        = NetNamedPipeSecurityMode.None;
                binding.MaxBufferSize                       *= 4;
                binding.MaxReceivedMessageSize              *= 4;
                binding.MaxBufferPoolSize                   *= 2;
                binding.ReaderQuotas.MaxBytesPerRead        *= 4;
                binding.ReaderQuotas.MaxArrayLength         *= 4;
                binding.ReaderQuotas.MaxDepth               *= 4;
                binding.ReaderQuotas.MaxNameTableCharCount  *= 4;
                binding.ReaderQuotas.MaxStringContentLength *= 4;

                providerHost.AddServiceEndpoint(providerType, binding, sNamedPipe);
                providerHost.Open();
            }
            catch (Exception e)
            {
                Logger.WriteError(e);
                providerHost = null;
                var paratextInstalled = FwRegistryHelper.Paratext7orLaterInstalled();
                if (paratextInstalled)
                {
                    MessageBox.Show(PtCommunicationProb, PtCommunicationProbTitle,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                return;
            }

            Logger.WriteEvent("Started provider " + providerLocation + " for type " + providerType + ".");
            s_runningProviders.Add(providerType, providerHost);
        }
Esempio n. 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FwLexiconPlugin"/> class.
        /// </summary>
        public FwLexiconPlugin()
        {
            FwRegistryHelper.Initialize();

            // setup necessary environment variables on Linux
            if (MiscUtils.IsUnix)
            {
                // update ICU_DATA to location of ICU data files
                if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ICU_DATA")))
                {
                    string codeIcuDataPath = Path.Combine(ParatextLexiconPluginDirectoryFinder.CodeDirectory, "Icu" + CustomIcu.Version);
#if DEBUG
                    string icuDataPath = codeIcuDataPath;
#else
                    string icuDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), ".config/fieldworks/Icu" + CustomIcu.Version);
                    if (!Directory.Exists(icuDataPath))
                    {
                        icuDataPath = codeIcuDataPath;
                    }
#endif
                    Environment.SetEnvironmentVariable("ICU_DATA", icuDataPath);
                }
                // update COMPONENTS_MAP_PATH to point to code directory so that COM objects can be loaded properly
                if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("COMPONENTS_MAP_PATH")))
                {
                    string compMapPath = Path.GetDirectoryName(FileUtils.StripFilePrefix(Assembly.GetExecutingAssembly().CodeBase));
                    Environment.SetEnvironmentVariable("COMPONENTS_MAP_PATH", compMapPath);
                }
                // update FW_ROOTCODE so that strings-en.txt file can be found
                if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("FW_ROOTCODE")))
                {
                    Environment.SetEnvironmentVariable("FW_ROOTCODE", ParatextLexiconPluginDirectoryFinder.CodeDirectory);
                }
            }
            FwUtils.InitializeIcu();
            if (!Sldr.IsInitialized)
            {
                Sldr.Initialize();
            }

            m_syncRoot     = new object();
            m_lexiconCache = new FdoLexiconCollection();
            m_cacheCache   = new LcmCacheCollection();
            m_ui           = new ParatextLexiconPluginLcmUI();
        }
Esempio n. 9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Displays a dialog that allows the user to choose an FW language project.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public bool ShowOpenProject(Form owner, ref Rectangle dialogBounds,
                                    ref int dialogSplitterPos, out string name, out string server)
        {
            FwRegistryHelper.Initialize();
            FwUtils.InitializeIcu();

            using (var dlg = new ChooseLangProjectDialog(dialogBounds, dialogSplitterPos))
            {
                if (dlg.ShowDialog(owner) == DialogResult.OK)
                {
                    name              = dlg.Project;
                    server            = null;
                    dialogBounds      = dlg.Bounds;
                    dialogSplitterPos = dlg.SplitterPosition;
                    return(true);
                }
            }

            name   = null;
            server = null;
            return(false);
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            Form window      = null;
            var  needCleanup = true;

            try
            {
                // needed to access proper registry values
                FwRegistryHelper.Initialize();
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                switch (args.FirstOrDefault())
                {
                case "-i":
                case "-install":
                case "--install":
                    // If we have any custom character data, install it!
                    FwUtils.InitializeIcu();
                    var customCharsFile = CharEditorWindow.CustomCharsFile;
                    if (File.Exists(customCharsFile))
                    {
                        new PUAInstaller().InstallPUACharacters(customCharsFile);
                    }
                    break;

                case "--cleanup":
                    // If the second argument is a Process ID (int), wait up to five minutes for the proces to exit and then clean up;
                    // otherwise, silently do nothing.
                    needCleanup = false;
                    int pid;
                    if (int.TryParse(args.LastOrDefault(), out pid))
                    {
                        var iterationCount = 0;
                        while (Process.GetProcesses().Any(p => p.Id == pid) && iterationCount < 300)
                        {
                            // wait 1s then try again
                            Thread.Sleep(1000);
                            iterationCount++;
                        }

                        if (iterationCount < 300)
                        {
                            DeleteTemporaryFiles();
                        }
                    }
                    break;

                case null:
                    // There were no arguments (the program was double-clicked or opened through the Start menu); run the graphical interface
                    FwUtils.InitializeIcu();
                    window = new CharEditorWindow();
                    Application.Run(window);
                    break;

                default:
                    // An unrecognized argument was passed
                    MessageBox.Show("Only one command line argument is recognized:" + Environment.NewLine +
                                    "\t-i means to install the custom character definitions (as a command line program).",
                                    "Unicode Character Editor");
                    break;
                }
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message, "Unicode Character Properties Editor");
            }
            catch (Exception ex)
            {
                // Be very, very careful about changing stuff here. Code here MUST not throw exceptions,
                // even when the application is in a crashed state.
                try
                {
                    ErrorReporter.ReportException(ex, null, null, window, true);
                }
                catch
                {
                    MessageBox.Show(ex.Message, "Unicode Character Properties Editor");
                }
            }
            finally
            {
                window?.Dispose();
                LogFile.Release();
                if (needCleanup)
                {
                    StartCleanup();
                }
            }
        }
Esempio n. 11
0
        static int Main(string[] rgArgs)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            for (int i = 0; i < rgArgs.Length; ++i)
            {
                if (rgArgs[i] == "-debug")
                {
                    s_fDebug = true;
                }
                else if (rgArgs[i] == "-autoclose")
                {
                    s_fAutoClose = true;
                }
                else if (rgArgs[i] == "-chars")
                {
                    s_fMigrateChars = true;
                }
            }
            FwRegistryHelper.Initialize();             // needed to access proper registry values

            if (s_fMigrateChars && s_fDebug)
            {
                MessageBox.Show("Warning: MigrateSqlDbs called with no-longer valid argument, '-chars'. Run 'UnicodeCharEditor -i' instead.");
            }

            // TE-9422. If we had an older version of FW7 installed, ldml files are < verion 2, so will cause
            // a crash if we don't migrate the files to version 2 before opening a project with the current version.
            // TODO (WS_FIX): should we migrate all the way to version 3?
            string globalWsFolder = LcmFileHelper.OldGlobalWritingSystemStoreDirectory;
            var    globalMigrator = new LdmlInFolderWritingSystemRepositoryMigrator(globalWsFolder, NoteMigration, 2);

            globalMigrator.Migrate();

            using (var threadHelper = new ThreadHelper())
                using (var progressDlg = new ProgressDialogWithTask(threadHelper))
                {
                    ImportFrom6_0 importer = new ImportFrom6_0(progressDlg, FwDirectoryFinder.ConverterConsoleExe, FwDirectoryFinder.DbExe, s_fDebug);
                    if (!importer.IsFwSqlServerInstalled())
                    {
                        return(-1);
                    }
                    string version;
                    if (!importer.IsValidOldFwInstalled(out version))
                    {
                        if (!String.IsNullOrEmpty(version) && version.CompareTo("5.4") < 0)
                        {
                            string launchesFlex = "0";
                            if (RegistryHelper.KeyExists(FwRegistryHelper.FieldWorksRegistryKey, "Language Explorer"))
                            {
                                using (RegistryKey keyFlex = FwRegistryHelper.FieldWorksRegistryKey.CreateSubKey("Language Explorer"))
                                    launchesFlex = keyFlex.GetValue("launches", "0") as string;
                            }
                            if (launchesFlex == "0")
                            {
                                FwRegistryHelper.FieldWorksRegistryKey.SetValue("MigrationTo7Needed", "true");
                            }
                            using (var dlg = new FWVersionTooOld(version))
                            {
                                dlg.ShowDialog();
                            }
                        }
                        return(-1);
                    }
                    List <string> projects = GetProjectList();
                    if (projects.Count > 0)
                    {
                        using (var migrateProjects = new MigrateProjects(importer, version, projects, s_fAutoClose))
                        {
                            Application.Run(migrateProjects);
                        }
                    }
                    else if (s_fDebug)
                    {
                        MessageBox.Show("No FieldWorks (SQL) projects were detected.", "DEBUG!");
                    }
                }
            return(s_ReturnValue);
        }
Esempio n. 12
0
 /// <summary/>
 public override void BeforeTest(TestDetails testDetails)
 {
     base.BeforeTest(testDetails);
     FwRegistryHelper.Initialize();
 }