Exemplo n.º 1
0
        private void BatchVerifierThreadCallBack()
        {
            bool isRevisionsEnabled = false;

            try
            {
                // Check if revisions are visible, if so make them invisible and turn them back on in the end
                isRevisionsEnabled = DocumentUtils.IsRevisionsEnabled(m_verifier.Document);
                if (isRevisionsEnabled)
                {
                    DocumentUtils.ChangeShowingRevisions(m_verifier.Document, false);
                }

                int docPageCount = -1;
                foreach (RangeWrapper par in RangeWrapper.ReadParagraphs(m_verifier.Document))
                {
                    if (m_cancelationPending)
                    {
                        break;
                    }

                    if (docPageCount <= 0)
                    {
                        docPageCount = par.NumberOfPagesInDocument;
                    }

                    int curPage = par.PageNumber;

                    if (curPage > 0 && docPageCount > 0)
                    {
                        ShowPageNumberProgress(curPage, docPageCount);
                    }
                    //System.Diagnostics.Debug.WriteLine("Page: " + curPage + " of " + docPageCount);

                    SendParagraphForVerification(par);

                    if (m_cancelationPending)
                    {
                        break;
                    }
                } // end of foreach par
            }
            finally
            {
                // Check if revisions are visible, if so make them invisible and turn them back on in the end
                if (isRevisionsEnabled)
                {
                    DocumentUtils.ChangeShowingRevisions(m_verifier.Document, true);
                }

                m_eventVerifierThreadStoped.Set();
            }

            if (!m_isFormClosed)
            {
                StopThreadsAndClose();
            }
        }
        void ApplicationDocumentBeforeClose(Microsoft.Office.Interop.Word.Document Doc, ref bool Cancel)
        {
            if (!Doc.Equals(m_verifier.Document))
            {
                return;
            }

            m_cancelationPending = true;
            m_isDocumentClosed   = true;

            // Check if revisions are visible, if so make them invisible and turn them back on in the end
            if (m_isRevisionsEnabled)
            {
                DocumentUtils.ChangeShowingRevisions(m_verifier.Document, true);
                m_isRevisionsEnabled = false;
            }

            VerificationController.UnregisterInteractiveVerifier(m_verifier.GetType(), m_verifier.Document);

            ForceThreadsToClose();
        }
        private void VerifierThreadCallBack()
        {
            LastUserAction = UserSelectedActions.None;
            IEnumerable <RangeWrapper> parEnumerable = RangeWrapper.ReadParagraphsStartingFromCursor(m_verifier.Document);

            try
            {
                // Check if revisions are visible, if so make them invisible and turn them back on in the end
                m_isRevisionsEnabled = DocumentUtils.IsRevisionsEnabled(m_verifier.Document);
                if (m_isRevisionsEnabled)
                {
                    DocumentUtils.ChangeShowingRevisions(m_verifier.Document, false);
                }

                while (!m_cancelationPending)
                {
                    foreach (RangeWrapper par in parEnumerable)
                    {
                        SendParagraphForVerification(par);

                        if (m_cancelationPending)
                        {
                            break;
                        }

                        if (m_cancelationPending || LastUserAction == UserSelectedActions.Resume)
                        {
                            break;
                        }
                    } // end of foreach par

                    // if resume was pressed without been cancelled, then restart from the beginning
                    if (!m_cancelationPending && LastUserAction == UserSelectedActions.Resume)
                    {
                        parEnumerable  = RangeWrapper.ReadParagraphsStartingFromCursor(m_verifier.Document);
                        LastUserAction = UserSelectedActions.None;
                    }
                    // otherwise it means that we actually reached the end of the text
                    else if (!m_cancelationPending)
                    {
                        m_verifierRequestType = VerifierRequestTypes.RequestEndOfLoop;
                        m_eventUserInputRequest.Set();
                        m_eventUserInputAvailable.WaitOne();

                        if (!m_cancelationPending)
                        {
                            // make it read from the beginning of the document
                            parEnumerable  = RangeWrapper.ReadParagraphs(m_verifier.Document);
                            LastUserAction = UserSelectedActions.None;
                            HideResumeButton();
                            GoIdle();
                        }
                    }
                } // end of while
            }
            finally
            {
                // Check if revisions are visible, if so make them invisible and turn them back on in the end
                if (m_isRevisionsEnabled && !m_isDocumentClosed)
                {
                    DocumentUtils.ChangeShowingRevisions(m_verifier.Document, true);
                }
                //m_eventVerifierThreadStoped.Set();
            }
        }