public bool Initialize(SpellCheckSettingsChangedEventArgs e) { m_spellCheckerSettings = new SpellCheckerConfig(e.Settings.DicPath, e.Settings.EditDistance, e.Settings.SuggestionCount) { StemPath = e.Settings.StemPath }; SetDictionaries(e.CustomDictionaries); m_prespellCorrectBe = e.PrespellCorrectBe; m_prespellCorrectPrefixes = e.PrespellCorrectPrefixes; m_prespellCorrectSuffixes = e.PrespellCorrectSuffixes; return(InitializeCore(e)); }
/// <summary> /// Initializes this instance. /// </summary> /// <returns></returns> public bool InitializeCore(SpellCheckSettingsChangedEventArgs e) { bool isFirstLoad = (e == null); try { if (m_spellCheckerEngine == null) { isFirstLoad = true; m_spellCheckerEngine = new PersianSpellChecker(m_spellCheckerSettings); } else if (e != null && e.ReloadSpellCheckerEngine) { m_spellCheckerEngine.ClearDictionary(); m_spellCheckerEngine.Reconfigure(m_spellCheckerSettings); } #region Prespelling Rules if (m_prespellCorrectPrefixes) { m_spellCheckerEngine.SetOnePassCorrectionRules(OnePassCorrectionRules.CorrectPrefix); } else { m_spellCheckerEngine.UnsetOnePassCorrectionRules(OnePassCorrectionRules.CorrectPrefix); } if (m_prespellCorrectSuffixes) { m_spellCheckerEngine.SetOnePassCorrectionRules(OnePassCorrectionRules.CorrectSuffix); } else { m_spellCheckerEngine.UnsetOnePassCorrectionRules(OnePassCorrectionRules.CorrectSuffix); } if (m_prespellCorrectBe) { m_spellCheckerEngine.SetOnePassCorrectionRules(OnePassCorrectionRules.CorrectBe); } else { m_spellCheckerEngine.UnsetOnePassCorrectionRules(OnePassCorrectionRules.CorrectBe); } #endregion } catch (FileLoadException ex) { LogHelper.DebugException("Some DLLs could not be loaded.", ex); IsInitialized = false; m_spellCheckerEngine = null; if (e != null) { e.CancelLoadingUserDictionary = true; } return(false); } catch (Exception ex) { LogHelper.DebugException("", ex); IsInitialized = false; m_spellCheckerEngine = null; if (e != null) { e.CancelLoadingUserDictionary = true; } return(false); } if (isFirstLoad || e.ReloadSpellCheckerEngine) { foreach (string t in m_dictionaries) { try { if (!m_spellCheckerEngine.AppendDictionary(t)) { throw new Exception(); } } catch (Exception) { if (e != null) { e.ErroneousUserDictionaries.Add(t); } } } } IsInitialized = true; Enabled = true; return(IsInitialized); }