Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Disposer. Release resources and cleanup.
        /// </summary>
        /// <param name="disposing">true to dispose managed resources</param>
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!_disposed)
            {
                Log.Debug();

                if (disposing)
                {
                    // dispose all managed resources.
                    if (_activeWordPredictor != null)
                    {
                        _activeWordPredictor.Dispose();
                    }

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

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

                // Release unmanaged resources.
            }

            _disposed = true;
        }
Exemplo n.º 3
0
        /// <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);
        }