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(); } }
private void PerformReplaceAll(KeyValuePair <NumberChangeRule.InputFormats, NumberChangeRule.InputDigitLanguages> ruleKey, KeyValuePair <NumberChangeRule.OutputFormats, NumberChangeRule.OutputDigitLanguages> ruleValue) { foreach (var par in RangeWrapper.ReadParagraphs(Document)) { if (CancelationPending) { break; } if (!par.IsRangeValid) { continue; } string rawParText = par.Text; string parText = rawParText; if (NeedRefinedStrings) { parText = StringUtil.RefineAndFilterPersianWord(parText); } int startFrom = 0; int len = parText.Length; var sbRawText = new StringBuilder(rawParText); var sbParText = new StringBuilder(parText); string parToVerify = parText; // parToVerify is going to shrink while parText is fixed while (startFrom < len) { var lstPats = FindNumberPatterns(parToVerify); if (lstPats == null || lstPats.Count <= 0) { break; } if (CancelationPending) { break; } IPatternInfo minPi = lstPats[0]; int startIndex = minPi.Index + startFrom; int endIndex = minPi.Index + minPi.Length - 1 + startFrom; int rawStartIndex = StringUtil.IndexInNotFilterAndRefinedString(sbRawText.ToString(), startIndex); int rawEndIndex = StringUtil.IndexInNotFilterAndRefinedString(sbRawText.ToString(), endIndex); NumberChangeRule.InputFormats inpFormat; NumberChangeRule.InputDigitLanguages inpLang; NumberChangeRule.DectectInputFormat(minPi.Content, out inpFormat, out inpLang); int forwardingOffset = 0; if (ruleKey.Key == inpFormat && ruleKey.Value == inpLang) { string suggestion = NumberParsersSuggestions.CreateSuggestionFor(minPi, ruleValue); if (!String.IsNullOrEmpty(suggestion)) { RangeWrapper foundRange; if (NeedRefinedStrings) { foundRange = par.GetRangeWithCharIndex(rawStartIndex, rawEndIndex); } else { foundRange = par.GetRangeWithCharIndex(startIndex, endIndex); } if (foundRange.IsRangeValid && foundRange.Text != suggestion) { if (foundRange.TryChangeText(suggestion)) { if (NeedRefinedStrings) { sbRawText.Remove(rawStartIndex, rawEndIndex - rawStartIndex + 1); sbRawText.Insert(rawStartIndex, suggestion); } sbParText.Remove(startIndex, endIndex - startIndex + 1); sbParText.Insert(startIndex, suggestion); //System.Diagnostics.Debug.WriteLine(sbParText); //System.Diagnostics.Debug.WriteLine("---------------------------"); len = sbParText.Length; forwardingOffset = suggestion.Length - minPi.Length; } } } // end if (suggestions count > 0) } // end if (minPi content matches change rule) startFrom = endIndex + 1 + forwardingOffset; if (startFrom >= len) { break; } parToVerify = sbParText.ToString().Substring(startFrom); } } }
private void PerformReplaceAll(int selectedIndex) { foreach (var par in RangeWrapper.ReadParagraphs(Document)) { if (CancelationPending) { break; } if (!par.IsRangeValid) { continue; } string rawParText = par.Text; string parText = rawParText; if (NeedRefinedStrings) { parText = StringUtil.RefineAndFilterPersianWord(parText); } m_punctuationCheckerEngine.InitInputString(parText); m_punctuationCheckerEngine.FindMistake(); while (m_punctuationCheckerEngine.IsErrorFound()) { if (CancelationPending) { break; } var curSug = m_punctuationCheckerEngine.GetMultiSubstitutionString()[selectedIndex]; int startIndex = m_punctuationCheckerEngine.GetMistakeIndex(); int endIndex = m_punctuationCheckerEngine.GetMistakeLength() + startIndex - 1; RangeWrapper foundRange; if (NeedRefinedStrings) { foundRange = par.GetRangeWithCharIndex( StringUtil.IndexInNotFilterAndRefinedString(rawParText, startIndex), StringUtil.IndexInNotFilterAndRefinedString(rawParText, endIndex) ); } else { foundRange = par.GetRangeWithCharIndex(startIndex, endIndex); } if (foundRange.IsRangeValid && foundRange.Text != curSug) { if (foundRange.TryChangeText(curSug)) { m_punctuationCheckerEngine.CorrectMistake(selectedIndex); } else { m_punctuationCheckerEngine.SkipMistake(); } } else { m_punctuationCheckerEngine.SkipMistake(); } m_punctuationCheckerEngine.FindMistake(); } } }
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(); } }