コード例 #1
0
ファイル: WordPredictionManager.cs プロジェクト: angellcq/src
        /// <summary>
        /// Creates the word predictor using reflection on the
        /// specified type and makes it the active one.  If it fails,
        /// it set the null word predictor as the active one.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private bool createAndSetActiveWordPredictor(Type type)
        {
            bool retVal = true;

            try
            {
                var wordPredictor = (IWordPredictor)Activator.CreateInstance(type);
                retVal = wordPredictor.Init();
                if (retVal)
                {
                    saveSettings(wordPredictor);
                    _activeWordPredictor = wordPredictor;
                }
            }
            catch (Exception ex)
            {
                Log.Debug("Unable to load WordPredictor " + type + ", assembly: " + type.Assembly.FullName + ". Exception: " + ex.ToString());
                retVal = false;
            }

            if (!retVal)
            {
                _activeWordPredictor = _nullWordPredictor;
            }

            return(retVal);
        }
コード例 #2
0
ファイル: WordPredictionManager.cs プロジェクト: angellcq/src
        /// <summary>
        /// Sets the active word predictor represented by id
        /// as a Guid or name.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool SetActiveWordPredictor(String idOrName)
        {
            bool retVal = true;
            Guid guid   = Guid.Empty;

            if (!Guid.TryParse(idOrName, out guid))
            {
                guid = _wordPredictors.GetByName(idOrName);
            }

            Type type = Guid.Equals(idOrName, Guid.Empty) ?
                        type = typeof(NullWordPredictor) :
                               _wordPredictors.Lookup(guid);

            if (type != null)
            {
                if (_activeWordPredictor != null)
                {
                    _activeWordPredictor.Dispose();
                    _activeWordPredictor = null;
                }

                retVal = createAndSetActiveWordPredictor(type);
            }
            else
            {
                createAndSetActiveWordPredictor(typeof(NullWordPredictor));
                retVal = false;
            }

            return(retVal);
        }
コード例 #3
0
ファイル: WordPredictionManager.cs プロジェクト: zezo010/acat
        /// <summary>
        /// Switch language to the specified one.
        /// </summary>
        /// <param name="ci">culture to switch to</param>
        /// <returns>true on success</returns>
        public bool SwitchLanguage(CultureInfo ci)
        {
            if (_activeWordPredictor != null)
            {
                _activeWordPredictor.Dispose();
                _activeWordPredictor = null;
            }

            return(SetActiveWordPredictor(ci));
        }
コード例 #4
0
ファイル: WordPredictionManager.cs プロジェクト: zezo010/acat
        /// <summary>
        /// Initializes and instance of the WordPredictionManager class.
        /// </summary>
        private WordPredictionManager()
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;

            Context.EvtCultureChanged     += Context_EvtCultureChanged;
            currentDomain.AssemblyResolve += currentDomain_AssemblyResolve;

            _activeWordPredictor = WordPredictors.NullWordPredictor;

            _userWordPredictorRootDir = UserManagement.UserManager.GetFullPath(WordPredictorsRootName);
            _profileRootDir           = UserManagement.ProfileManager.GetFullPath(WordPredictorsRootName);
        }
コード例 #5
0
ファイル: WordPredictionManager.cs プロジェクト: angellcq/src
        /// <summary>
        /// Initializes and instance of the WordPredictionManager class.
        /// </summary>
        private WordPredictionManager()
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.AssemblyResolve += currentDomain_AssemblyResolve;

            _nullWordPredictor = new NullWordPredictor();
            _nullWordPredictor.Init();
            _activeWordPredictor = _nullWordPredictor;

            _userWordPredictorRootDir = UserManagement.UserManager.GetFullPath(WordPredictorsRootName);
            _profileRootDir           = UserManagement.ProfileManager.GetFullPath(WordPredictorsRootName);
        }
コード例 #6
0
ファイル: WordPredictionManager.cs プロジェクト: zezo010/acat
        /// <summary>
        /// Creates the word predictor using reflection on the
        /// specified type and makes it the active one.  If it fails,
        /// it set the null word predictor as the active one.
        /// </summary>
        /// <param name="type">Type of the word predictor class</param>
        /// <param name="ci">Culture</param>
        /// <returns>true</returns>
        private bool createAndSetActiveWordPredictor(Type type, CultureInfo ci)
        {
            bool retVal;

            try
            {
                var wordPredictor = (IWordPredictor)Activator.CreateInstance(type);
                retVal = wordPredictor.Init(ci);
                if (retVal)
                {
                    _activeWordPredictor = wordPredictor;
                }
            }
            catch (Exception ex)
            {
                Log.Debug("Unable to load WordPredictor " + type + ", assembly: " + type.Assembly.FullName + ". Exception: " + ex);
                retVal = false;
            }

            return(retVal);
        }
コード例 #7
0
ファイル: WordPredictionManager.cs プロジェクト: angellcq/src
 /// <summary>
 /// Saves settings for the specified wordpredictor
 /// </summary>
 /// <param name="wordPredictor"></param>
 private void saveSettings(IWordPredictor wordPredictor)
 {
     wordPredictor.SaveSettings("dummy");
 }
コード例 #8
0
ファイル: WordPredictionManager.cs プロジェクト: angellcq/src
 /// <summary>
 /// Loads default settings for the specified word predictor
 /// </summary>
 /// <param name="wordPredictor"></param>
 private void loadDefaultSettings(IWordPredictor wordPredictor)
 {
     wordPredictor.LoadDefaultSettings();
 }
コード例 #9
0
 /// <summary>
 /// Saves settings for the specified wordpredictor
 /// </summary>
 /// <param name="wordPredictor"></param>
 private void saveSettings(IWordPredictor wordPredictor)
 {
     wordPredictor.SaveSettings("dummy");
 }
コード例 #10
0
 /// <summary>
 /// Loads default settings for the specified word predictor
 /// </summary>
 /// <param name="wordPredictor"></param>
 private void loadDefaultSettings(IWordPredictor wordPredictor)
 {
     wordPredictor.LoadDefaultSettings();
 }
コード例 #11
0
        /// <summary>
        /// Creates the word predictor using reflection on the
        /// specified type and makes it the active one.  If it fails,
        /// it set the null word predictor as the active one.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private bool createAndSetActiveWordPredictor(Type type)
        {
            bool retVal = true;

            try
            {
                var wordPredictor = (IWordPredictor)Activator.CreateInstance(type);
                retVal = wordPredictor.Init();
                if (retVal)
                {
                    saveSettings(wordPredictor);
                    _activeWordPredictor = wordPredictor;
                }
            }
            catch (Exception ex)
            {
                Log.Debug("Unable to load WordPredictor " + type + ", assembly: " + type.Assembly.FullName + ". Exception: " + ex.ToString());
                retVal = false;
            }

            if (!retVal)
            {
                _activeWordPredictor = _nullWordPredictor;
            }

            return retVal;
        }
コード例 #12
0
        /// <summary>
        /// Sets the active word predictor represented by id
        /// as a Guid or name.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool SetActiveWordPredictor(String idOrName)
        {
            bool retVal = true;
            Guid guid = Guid.Empty;

            if (!Guid.TryParse(idOrName, out guid))
            {
                guid = _wordPredictors.GetByName(idOrName);
            }

            Type type = Guid.Equals(idOrName, Guid.Empty) ?
                            type = typeof(NullWordPredictor) :
                            _wordPredictors.Lookup(guid);

            if (type != null)
            {
                if (_activeWordPredictor != null)
                {
                    _activeWordPredictor.Dispose();
                    _activeWordPredictor = null;
                }

                retVal = createAndSetActiveWordPredictor(type);
            }
            else
            {
                createAndSetActiveWordPredictor(typeof(NullWordPredictor));
                retVal = false;
            }

            return retVal;
        }
コード例 #13
0
        /// <summary>
        /// Initializes and instance of the WordPredictionManager class.
        /// </summary>
        private WordPredictionManager()
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;
            currentDomain.AssemblyResolve += currentDomain_AssemblyResolve;

            _nullWordPredictor = new NullWordPredictor();
            _nullWordPredictor.Init();
            _activeWordPredictor = _nullWordPredictor;

            _userWordPredictorRootDir = UserManagement.UserManager.GetFullPath(WordPredictorsRootName);
            _profileRootDir = UserManagement.ProfileManager.GetFullPath(WordPredictorsRootName);
        }
コード例 #14
0
ファイル: WordPredictionManager.cs プロジェクト: zezo010/acat
        /// <summary>
        /// Sets the active word predictor for the specified culture. If
        /// culture is null, the default culture is used
        /// </summary>
        /// <param name="ci">culture info</param>
        /// <returns>true on success</returns>
        public bool SetActiveWordPredictor(CultureInfo ci = null)
        {
            bool retVal             = true;
            Guid guid               = Guid.Empty;
            Guid cultureNeutralGuid = Guid.Empty;

            if (ci == null)
            {
                ci = CultureInfo.DefaultThreadCurrentUICulture;
            }

            guid = _wordPredictors.GetPreferredOrDefaultByCulture(ci);
            cultureNeutralGuid = _wordPredictors.GetPreferredOrDefaultByCulture(null);

            if (!Equals(guid, Guid.Empty))  // found something for the specific culture
            {
                var type = _wordPredictors.Lookup(guid);

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

                retVal = createAndSetActiveWordPredictor(type, ci);

                if (!retVal)
                {
                    _activeWordPredictor = WordPredictors.NullWordPredictor;
                }
            }
            else
            {
                if (!Equals(cultureNeutralGuid, Guid.Empty))
                {
                    var type = _wordPredictors.Lookup(cultureNeutralGuid);
                    retVal = createAndSetActiveWordPredictor(type, ci);

                    if (!retVal)
                    {
                        ci   = new CultureInfo("en-US");
                        guid = _wordPredictors.GetDefaultByCulture(ci);
                        if (!Equals(guid, Guid.Empty))
                        {
                            type   = _wordPredictors.Lookup(guid);
                            retVal = createAndSetActiveWordPredictor(type, ci);
                        }
                    }
                }
                else
                {
                    retVal = false;
                }

                if (!retVal)
                {
                    _activeWordPredictor = WordPredictors.NullWordPredictor;
                }
            }

            return(retVal);
        }