Ejemplo n.º 1
0
        internal GlobalFileWritingSystemStore(string path)
        {
            m_path = path;
            if (!Directory.Exists(m_path))
            {
                DirectoryInfo di;

                // Provides FW on Linux multi-user access. Overrides the system
                // umask and creates the directory with the permissions "775".
                // The "fieldworks" group was created outside the app during
                // configuration of the package which allows group access.
                using (new FileModeOverride())
                {
                    di = Directory.CreateDirectory(m_path);
                }

                if (!MiscUtils.IsUnix)
                {
                    // NOTE: GetAccessControl/ModifyAccessRule/SetAccessControl is not implemented in Mono
                    DirectorySecurity ds = di.GetAccessControl();
                    var        sid       = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
                    AccessRule rule      = new FileSystemAccessRule(sid, FileSystemRights.Write | FileSystemRights.ReadAndExecute
                                                                    | FileSystemRights.Modify, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                                                                    PropagationFlags.InheritOnly, AccessControlType.Allow);
                    bool modified;
                    ds.ModifyAccessRule(AccessControlModification.Add, rule, out modified);
                    di.SetAccessControl(ds);
                }
            }
            m_mutex = SingletonsContainer.Get(typeof(Mutex).FullName + m_path,
                                              () => new Mutex(false, m_path.Replace('\\', '_').Replace('/', '_')));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GlobalFileWritingSystemStore"/> class.
 /// </summary>
 /// <param name="path">The path.</param>
 public GlobalFileWritingSystemStore(string path)
 {
     m_path = path;
     Directory.CreateDirectory(m_path);
     m_mutex = SingletonsContainer.Get(typeof(Mutex).FullName + m_path,
                                       () => new Mutex(false, m_path.Replace('\\', '_').Replace('/', '_')));
 }
Ejemplo n.º 3
0
        ///<summary>
        ///</summary>
        public static void Release()
        {
            if (!SingletonsContainer.Contains <LogFileImpl>())
            {
                return;
            }

            AddLine("----- LogFile Object Released -----");
            SingletonsContainer.Get <LogFileImpl>().Shutdown();
            SingletonsContainer.Remove(SingletonsContainer.Get <LogFileImpl>());
        }
Ejemplo n.º 4
0
 private static void RetrieveDefaultWritingSystemsFromLift(string liftPath, out CoreWritingSystemDefinition wsVern,
                                                           out CoreWritingSystemDefinition wsAnalysis)
 {
     PerformLdmlMigrationInClonedLiftRepo(liftPath);
     using (var liftReader = new StreamReader(liftPath, Encoding.UTF8))
     {
         string vernWsId, analysisWsId;
         using (var reader = XmlReader.Create(liftReader))
             RetrieveDefaultWritingSystemIdsFromLift(reader, out vernWsId, out analysisWsId);
         var wsManager = new WritingSystemManager(SingletonsContainer.Get <CoreGlobalWritingSystemRepository>());
         wsManager.GetOrSet(vernWsId, out wsVern);
         wsManager.GetOrSet(analysisWsId, out wsAnalysis);
     }
 }
Ejemplo n.º 5
0
        public FwProject(LfMergeSettings settings, string database)
        {
            // We don't want to use a global writing system store, so we insert a null singleton
            if (!SingletonsContainer.Contains <CoreGlobalWritingSystemRepository>())
            {
                SingletonsContainer.Add(typeof(CoreGlobalWritingSystemRepository).FullName, null);
            }

            _project = new ProjectIdentifier(settings.LcmDirectorySettings, database);
            _lcmUi   = new ConsoleLcmUi(_progress.SynchronizeInvoke);
            Cache    = TryGetLcmCache();
            if (Cache != null)
            {
                ServiceLocator = new FwServiceLocatorCache(Cache.ServiceLocator);
            }
        }
Ejemplo n.º 6
0
        public void Dispose()
        {
            _mongoConnection?.Reset();

            MainClass.Container?.Dispose();
            MainClass.Container = null;
            if (_resetLfProjectsDuringCleanup)
            {
                LanguageForgeProjectAccessor.Reset();
            }
            _languageForgeServerFolder?.Dispose();
            Settings = null;
            if (_releaseSingletons)
            {
                SingletonsContainer.Release();
            }

            Environment.SetEnvironmentVariable("FW_CommonAppData", null);
        }
Ejemplo n.º 7
0
 public TestEnvironment(bool registerSettingsModelDouble          = true,
                        bool registerProcessingStateDouble        = true,
                        bool resetLfProjectsDuringCleanup         = true,
                        TemporaryFolder languageForgeServerFolder = null)
 {
     _resetLfProjectsDuringCleanup = resetLfProjectsDuringCleanup;
     _languageForgeServerFolder    = languageForgeServerFolder ?? new TemporaryFolder(TestName + Path.GetRandomFileName());
     Environment.SetEnvironmentVariable("FW_CommonAppData", _languageForgeServerFolder.Path);
     MainClass.Container = RegisterTypes(registerSettingsModelDouble,
                                         registerProcessingStateDouble, _languageForgeServerFolder.Path).Build();
     Settings         = MainClass.Container.Resolve <LfMergeSettings>();
     MainClass.Logger = MainClass.Container.Resolve <ILogger>();
     Directory.CreateDirectory(Settings.LcmDirectorySettings.ProjectsDirectory);
     Directory.CreateDirectory(Settings.LcmDirectorySettings.TemplateDirectory);
     Directory.CreateDirectory(Settings.StateDirectory);
     _mongoConnection = MainClass.Container.Resolve <IMongoConnection>() as MongoConnectionDouble;
     // only call SingletonsContainer.Release() at the end if we actually create the
     // singleton
     _releaseSingletons = !SingletonsContainer.Contains <CoreGlobalWritingSystemRepository>();
 }
Ejemplo n.º 8
0
 ///<summary>
 ///</summary>
 private static LogFileImpl GetLogFile()
 {
     return(SingletonsContainer.Get <LogFileImpl>());
 }
Ejemplo n.º 9
0
 static SpellingHelper()
 {
     // The SingletonToDispose will be disposed during system shutdown.
     // This will clear m_spellers and properly dispose of all the engines (and the C++ memory they allocate).
     SingletonsContainer.Add(new SingletonToDispose());
 }
Ejemplo n.º 10
0
        private void m_btnOK_Click(object sender, EventArgs e)
        {
            var reportingSettings = Settings.Default.Reporting;

            reportingSettings.OkToPingBasicUsageData = m_okToPingCheckBox.Checked;
            Settings.Default.AutoCheckForUpdates     = checkForUpdatesBox.Checked;
            Settings.Default.CheckForBetaUpdates     = includeBetasBox.Checked;

            Settings.Default.AutoCheckForUpdates = checkForUpdatesBox.Checked;
            Settings.Default.CheckForBetaUpdates = includeBetasBox.Checked;

#if !__MonoCS__
            var sparkle = SingletonsContainer.Item("Sparkle") as Sparkle;
            if (sparkle != null)
            {
                var appCastUrl = Settings.Default.IsBTE
                                                                        ? (Settings.Default.CheckForBetaUpdates
                                                                                ? CoreImpl.Properties.Resources.ResourceManager.GetString("kstidAppcastBteBetasUrl")
                                                                                : CoreImpl.Properties.Resources.ResourceManager.GetString("kstidAppcastBteUrl"))
                                                                        : (Settings.Default.CheckForBetaUpdates
                                                                                ? CoreImpl.Properties.Resources.ResourceManager.GetString("kstidAppcastSeBetasUrl")
                                                                                : CoreImpl.Properties.Resources.ResourceManager.GetString("kstidAppcastSeUrl"));
                sparkle.AppcastUrl = appCastUrl;
            }
#endif


            Settings.Default.Save();
            m_sNewUserWs = m_userInterfaceChooser.NewUserWs;
            if (m_sUserWs != m_sNewUserWs)
            {
                CultureInfo ci = MiscUtils.GetCultureForWs(m_sNewUserWs);
                if (ci != null)
                {
                    FormLanguageSwitchSingleton.Instance.ChangeCurrentThreadUICulture(ci);
                    FormLanguageSwitchSingleton.Instance.ChangeLanguage(this);
#if __MonoCS__
                    // Mono leaves the wait cursor on, unlike .Net itself.
                    Cursor.Current = Cursors.Default;
#endif
                }
                // This needs to be consistent with Common/FieldWorks/FieldWorks.SetUICulture().
                FwRegistryHelper.FieldWorksRegistryKey.SetValue(FwRegistryHelper.UserLocaleValueName, m_sNewUserWs);
                //The writing system the user selects for the user interface may not be loaded yet into the project
                //database. Therefore we need to check this first and if it is not we need to load it.
                IWritingSystem ws;
                m_cache.ServiceLocator.WritingSystemManager.GetOrSet(m_sNewUserWs, out ws);
                m_cache.ServiceLocator.WritingSystemManager.UserWritingSystem = ws;
                // Reload the mediator's string table with the appropriate language data.
                m_mediator.StringTbl.Reload(m_sNewUserWs);
            }

            // Handle installing/uninstalling plugins.
            if (m_lvPlugins.Items.Count > 0)
            {
                List <XmlDocument> pluginsToInstall   = new List <XmlDocument>();
                List <XmlDocument> pluginsToUninstall = new List <XmlDocument>();
                foreach (ListViewItem lvi in m_lvPlugins.Items)
                {
                    string      name       = lvi.Text;
                    XmlDocument managerDoc = lvi.Tag as XmlDocument;
                    if (lvi.Checked && !m_plugins[name])
                    {
                        // Remember we need to install it.
                        pluginsToInstall.Add(managerDoc);
                    }
                    else if (!lvi.Checked && m_plugins[name])
                    {
                        // Remember we need to uninstall it.
                        pluginsToUninstall.Add(managerDoc);
                    }
                }
                m_pluginsUpdated = pluginsToInstall.Count > 0 || pluginsToUninstall.Count > 0;
                string basePluginPath = FwDirectoryFinder.GetCodeSubDirectory(@"Language Explorer\Configuration\Available Plugins");
                // The extension XML files should be stored in the data area, not in the code area.
                // This reduces the need for users to have administrative privileges.
                string baseExtensionPath = Path.Combine(FwDirectoryFinder.DataDirectory, @"Language Explorer\Configuration");
                // Really do the install now.
                foreach (XmlDocument managerDoc in pluginsToInstall)
                {
                    XmlNode managerNode     = managerDoc.SelectSingleNode("/manager");
                    string  srcDir          = Path.Combine(basePluginPath, managerNode.Attributes["name"].Value);
                    XmlNode configfilesNode = managerNode.SelectSingleNode("configfiles");
                    string  extensionPath   = Path.Combine(baseExtensionPath, configfilesNode.Attributes["targetdir"].Value);
                    Directory.CreateDirectory(extensionPath);
                    foreach (XmlNode fileNode in configfilesNode.SelectNodes("file"))
                    {
                        string filename          = fileNode.Attributes["name"].Value;
                        string extensionPathname = Path.Combine(extensionPath, filename);
                        try
                        {
                            File.Copy(
                                Path.Combine(srcDir, filename),
                                extensionPathname,
                                true);
                            File.SetAttributes(extensionPathname, FileAttributes.Normal);
                        }
                        catch
                        {
                            // Eat copy exception.
                        }
                    }
                    string fwInstallDir = FwDirectoryFinder.CodeDirectory;
                    foreach (XmlNode dllNode in managerNode.SelectNodes("dlls/file"))
                    {
                        string filename    = dllNode.Attributes["name"].Value;
                        string dllPathname = Path.Combine(fwInstallDir, filename);
                        try
                        {
                            File.Copy(
                                Path.Combine(srcDir, filename),
                                dllPathname,
                                true);
                            File.SetAttributes(dllPathname, FileAttributes.Normal);
                        }
                        catch
                        {
                            // Eat copy exception.
                        }
                    }
                }
                // Really do the uninstall now.
                foreach (XmlDocument managerDoc in pluginsToUninstall)
                {
                    XmlNode managerNode = managerDoc.SelectSingleNode("/manager");
                    string  shutdownMsg = XmlUtils.GetOptionalAttributeValue(managerNode, "shutdown");
                    if (!String.IsNullOrEmpty(shutdownMsg))
                    {
                        m_mediator.SendMessage(shutdownMsg, null);
                    }
                    XmlNode configfilesNode = managerNode.SelectSingleNode("configfiles");
                    string  extensionPath   = Path.Combine(baseExtensionPath, configfilesNode.Attributes["targetdir"].Value);
                    Directory.Delete(extensionPath, true);
                    // Leave any dlls in place since they may be shared, or in use for the moment.
                }
            }
            CoreImpl.Properties.Settings.Default.UpdateGlobalWSStore = !updateGlobalWS.Checked;
            CoreImpl.Properties.Settings.Default.Save();
            AutoOpenLastProject = m_autoOpenCheckBox.Checked;
            DialogResult        = DialogResult.OK;
        }
Ejemplo n.º 11
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Release the project settings.
 /// NOTE: This method should only be used in tests!
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public static void Release()
 {
     Instance.Dispose();
     SingletonsContainer.Remove(Instance);
 }
Ejemplo n.º 12
0
        /// <summary/>
        public FwNewLangProjectModel(bool useMemoryWsManager = false)
        {
            WritingSystemManager = useMemoryWsManager ? new WritingSystemManager() : new WritingSystemManager(SingletonsContainer.Get <CoreGlobalWritingSystemRepository>());
            CoreWritingSystemDefinition englishWs;

            WritingSystemManager.GetOrSet("en", out englishWs);
            _allAnalysis.Add(englishWs);
            _curAnalysis.Add(englishWs);
            WritingSystemContainer = new MemoryWritingSystemContainer(_allAnalysis, _allVern, _curAnalysis, _curVernWss, _curPron);
        }
 /// <summary>
 /// Installs this fake keyboard controller instead of the real one
 /// </summary>
 public static void Install()
 {
     SingletonsContainer.Add(typeof(IKeyboardController).FullName, new FakeKeyboardController());
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Release all singletons
 /// </summary>
 public override void AfterTest(TestDetails testDetails)
 {
     base.AfterTest(testDetails);
     SingletonsContainer.Release();
 }
Ejemplo n.º 15
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        /// ------------------------------------------------------------------------------------
        private void Init(PrintPageEventArgs e)
        {
#if false
            long x1 = System.DateTime.Now.Ticks;
#endif
            // Set these now because the Graphics object will be locked below.
            m_rcDst = m_rcSrc = new Rect(0, 0, (int)e.Graphics.DpiX, (int)e.Graphics.DpiY);

            int dpix;
            if (MiscUtils.IsUnix)
            {
                dpix = 72;
            }
            else
            {
                dpix = (int)e.Graphics.DpiX;
            }

            m_dxpAvailWidth = PixelsFrom100ths(e.MarginBounds.Width, dpix);

            // Create and initialize a print context.
            m_vwPrintContext = VwPrintContextWin32Class.Create();

            // TODO: When we provide a way for the user to specify the nFirstPageNo (i.e. the
            // first argument to SetPagePrintInfo), then change the arguments to
            // SetPagePrintInfo.
            m_vwPrintContext.SetPagePrintInfo(1, 1, 65535, 1, false);
            SetMargins(e);

            IVwGraphics vwGraphics = VwGraphicsWin32Class.Create();
            IntPtr      hdc        = IntPtr.Zero;
            try
            {
                // Get the printer's hdc and use it to initialize other stuff.
                hdc = e.Graphics.GetHdc();
                ((IVwGraphicsWin32)vwGraphics).Initialize(hdc);
                m_vwPrintContext.SetGraphics(vwGraphics);

                // Make a rootbox for printing and initialize it.
                m_rootb = VwRootBoxClass.Create();
                m_rootb.RenderEngineFactory = SingletonsContainer.Get <RenderEngineFactory>();
                m_rootb.TsStrFactory        = TsStringUtils.TsStrFactory;
                m_rootb.SetSite(this);
                m_rootb.DataAccess = m_sda;
                m_rootb.SetRootObject(m_hvo, m_vc, m_frags, m_styleSheet);
                m_rootb.InitializePrinting(m_vwPrintContext);
                m_totalNumberOfPages = m_rootb.GetTotalPrintPages(m_vwPrintContext);
                m_psettings          = e.PageSettings.PrinterSettings;
                SetPrintRange();
            }
            catch (Exception ex)
            {
                m_rootb = null;

                throw new ContinuableErrorException("An error has occurred during the setup required for printing.", ex);
            }
            finally
            {
                if (hdc != IntPtr.Zero)
                {
                    vwGraphics.ReleaseDC();
                    e.Graphics.ReleaseHdc(hdc);
                }
            }
#if false
            long x2 = System.DateTime.Now.Ticks;
            Debug.WriteLine("PrintRootSite.Init() took " + DeltaTime(x1, x2) + " seconds.");
#endif
        }