Handles acquiring a parser and safely subscribing to and receiving events from it.
Inheritance: SIL.Utils.FwDisposableBase, IAsyncResult
Example #1
0
        public void DisconnectFromParser()
        {
            CheckDisposed();

            if (Connection != null)
            {
                Connection.Dispose();
            }
            Connection = null;
        }
Example #2
0
        public void ConnectToParser(bool fParseAllWordforms)
        {
            CheckDisposed();

            if (Connection == null)
            {
                Connection = new ParserConnection(m_cache.ServerName, m_cache.DatabaseName,
                                                  m_cache.LangProject.Name.AnalysisDefaultWritingSystem, fParseAllWordforms);
                m_mediator.PropertyTable.SetProperty("ParserConnection", Connection);
            }
        }
Example #3
0
        public void DisconnectFromParser()
        {
            CheckDisposed();

            StopUpdateProgressTimer();
            if (m_parserConnection != null)
            {
                m_parserConnection.Dispose();
            }
            m_parserConnection = null;
        }
Example #4
0
        /// <summary>
        /// Put the wordform in the highest priority queue of the Parser
        /// </summary>
        /// <param name="wf"></param>
        public void UpdateWordformAsap(WfiWordform wf)
        {
            CheckDisposed();

            ParserConnection con = Connection;

            if (con != null && con.Parser != null &&
                wf.Form.VernacularDefaultWritingSystem != null)
            {
                con.Parser.ScheduleOneWordformForUpdate(wf.Hvo, WordWorks.Parser.ParserScheduler.Priority.ASAP);
            }
        }
        public bool ConnectToParser()
        {
            CheckDisposed();

            if (m_parserConnection == null)
            {
                if (!GetLock())
                {
                    return(false);
                }
                m_parserConnection = new ParserConnection(m_cache, m_mediator.IdleQueue);
            }
            StartProgressUpdateTimer();
            return(true);
        }
Example #6
0
        public bool ConnectToParser()
        {
            CheckDisposed();

            if (m_parserConnection == null)
            {
                // Don't bother if the lexicon is empty.  See FWNX-1019.
                if (m_cache.ServiceLocator.GetInstance <ILexEntryRepository>().Count == 0)
                {
                    return(false);
                }
                m_parserConnection = new ParserConnection(m_cache, m_mediator.IdleQueue);
            }
            StartProgressUpdateTimer();
            return(true);
        }
Example #7
0
        /// <summary>
        /// Executes in two distinct scenarios.
        ///
        /// 1. If disposing is true, the method has been called directly
        /// or indirectly by a user's code via the Dispose method.
        /// Both managed and unmanaged resources can be disposed.
        ///
        /// 2. If disposing is false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference (access)
        /// other managed objects, as they already have been garbage collected.
        /// Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing"></param>
        /// <remarks>
        /// If any exceptions are thrown, that is fine.
        /// If the method is being done in a finalizer, it will be ignored.
        /// If it is thrown by client code calling Dispose,
        /// it needs to be handled by fixing the bug.
        ///
        /// If subclasses override this method, they should call the base implementation.
        /// </remarks>
        protected virtual void Dispose(bool disposing)
        {
            //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
            // Must not be run more than once.
            if (m_isDisposed)
            {
                return;
            }

            // m_sda COM object block removed due to crash in Finializer thread LT-6124

            if (disposing)
            {
                // Dispose managed resources here.
                if (m_updateTimer != null)
                {
                    m_updateTimer.Stop();
                    m_updateTimer.Tick -= new EventHandler(m_updateTimer_Elapsed);
                    m_updateTimer.Dispose();
                }

                if (m_sda != null)
                {
                    m_sda.RemoveNotification(this);
                }
                m_mediator.RemoveColleague(this);
                ParserConnection cnx = Connection;
                if (cnx != null)
                {
                    // Remove ParserConnection from the PropertyTable.
                    m_mediator.PropertyTable.SetProperty("ParserConnection", null, false);
                    m_mediator.PropertyTable.SetPropertyPersistence("ParserConnection", false);
                    m_mediator.PropertyTable.SetProperty("ParserListener", null, false);
                    m_mediator.PropertyTable.SetPropertyPersistence("ParserListener", false);
                    cnx.Dispose();
                }
            }

            // Dispose unmanaged resources here, whether disposing is true or false.
            m_sda         = null;
            m_mediator    = null;
            m_cache       = null;
            m_updateTimer = null;
            m_traceSwitch = null;

            m_isDisposed = true;
        }
Example #8
0
        public bool OnDisplayReparseAllWords(object commandObject, ref UIItemDisplayProperties display)
        {
            CheckDisposed();

            ParserConnection con    = Connection;
            ParserScheduler  parser = null;

            if (con != null)
            {
                parser = con.Parser;
            }
            // must wait for the queue to empty before we can fill it up again or else we run the risk of breaking the parser thread
            display.Enabled = ((con != null) && (parser != null) &&
                               parser.GetQueueSize(ParserScheduler.Priority.eventually) == 0);

            return(true);               //we handled this.
        }
        /// <summary>
        /// Executes in two distinct scenarios.
        ///
        /// 1. If disposing is true, the method has been called directly
        /// or indirectly by a user's code via the Dispose method.
        /// Both managed and unmanaged resources can be disposed.
        ///
        /// 2. If disposing is false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference (access)
        /// other managed objects, as they already have been garbage collected.
        /// Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing"></param>
        /// <remarks>
        /// If any exceptions are thrown, that is fine.
        /// If the method is being done in a finalizer, it will be ignored.
        /// If it is thrown by client code calling Dispose,
        /// it needs to be handled by fixing the bug.
        ///
        /// If subclasses override this method, they should call the base implementation.
        /// </remarks>
        protected virtual void Dispose(bool disposing)
        {
            Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
            // Must not be run more than once.
            if (m_isDisposed)
            {
                return;
            }

            // m_sda COM object block removed due to crash in Finializer thread LT-6124

            if (disposing)
            {
                // other clients may now parse
                // Dispose managed resources here.
                if (m_timer != null)
                {
                    m_timer.Stop();
                    m_timer.Tick -= m_timer_Tick;
                }
                if (m_sda != null)
                {
                    m_sda.RemoveNotification(this);
                }
                m_mediator.RemoveColleague(this);
                if (m_parserConnection != null)
                {
                    m_parserConnection.Dispose();
                }
                if (m_lock != null)
                {
                    m_lock.Dispose();
                }
            }

            // Dispose unmanaged resources here, whether disposing is true or false.
            m_timer            = null;
            m_sda              = null;
            m_mediator         = null;
            m_cache            = null;
            m_traceSwitch      = null;
            m_lock             = null;
            m_parserConnection = null;

            m_isDisposed = true;
        }
Example #10
0
        public bool OnReparseAllWords(object argument)
        {
            CheckDisposed();

            ParserConnection con = Connection;

            if (con != null)
            {
                ParserScheduler parser = con.Parser;
                if (parser != null)
                {
                    parser.ParseAllWordforms = true;
                    parser.LoadGrammarAndLexiconIfNeeded();
                    parser.InvalidateAllWordforms();
                }
            }
            return(true);               //we handled this.
        }
Example #11
0
        /// <summary>
        /// Put all (unique) wordforms of the text in the medium priority queue of the Parser
        /// </summary>
        /// <param name="text"></param>
        public void UpdateWordformsInText(StText text)
        {
            CheckDisposed();

            int[] aiWordformHvos = text.UniqueWordforms();

            ParserConnection con = Connection;

            if (con != null)
            {
                ParserScheduler parser = con.Parser;
                if (parser != null)
                {
                    parser.LoadGrammarAndLexiconIfNeeded();
                    parser.ScheduleWordformsForUpdate(aiWordformHvos, WordWorks.Parser.ParserScheduler.Priority.soon);
                }
            }
        }
Example #12
0
        public bool OnIdle(object argument)
        {
            CheckDisposed();

            m_mediator.PropertyTable.SetProperty("StatusPanelProgress", GetParserQueueString() + " " + GetParserActivityString());
            m_mediator.PropertyTable.SetPropertyPersistence("StatusPanelProgress", false);

            ParserConnection con = Connection;

            if (con != null)
            {
                string notification = con.GetAndClearNotification();
                if (notification != null)
                {
                    m_mediator.SendMessage("ShowNotification", notification);
                }

                // It is possible that the Activity will be Idle (at least not 'Update',
                // but there are still items in the Sync$ table to process.
                // We have to check here for that case, or some items won't be processed,
                // which will result in the PropChanges not being done, and thus,
                // the display not being updated.
                int countSimpleEdits   = 0;
                int countFullRefreshes = 0;
                if (CurrentWordformHvo > 0)
                {
                    countSimpleEdits   = SimpleEdits.Count;
                    countFullRefreshes = FullRefreshes.Count;
                }
                if (con.Activity.IndexOf(ParserUIStrings.ksUpdate) >= 0 || countSimpleEdits > 0 || countFullRefreshes > 0)
                {
                    m_updateTimer.Start();
                }
                else
                {
                    m_updateTimer.Stop();
                }
            }

            return(false);            // Don't stop other people from getting the idle message
        }