private void FindMatchingDocs_DoWork(object sender, DoWorkEventArgs e) { MatchDocsResult mdResult = new MatchDocsResult(); e.Result = mdResult; BackgroundWorker worker = sender as BackgroundWorker; List<ScanDocInfo> sdiList = _scanDocHandler.GetListOfScanDocs(); int docsFound = 0; // Get args - document type to match and start position for filling list (this is // so we don't swamp the list by including all results) object[] args = (object[])e.Argument; DocType docTypeToMatch = (DocType)args[0]; int includeInListFromIdx = (int)args[1]; // Match results mdResult.bNotAllResultsShow = false; mdResult.totalFilesScanned = sdiList.Count; mdResult.bMatchedResultsOnly = (docTypeToMatch != null); mdResult.indexOfFirstFileDisplayed = -1; // Start index in list int nStartIdx = (docTypeToMatch == null) ? includeInListFromIdx : 0; int nEndIdx = includeInListFromIdx + MAX_NUM_DOCS_TO_ADD_TO_LIST - 1; if ((docTypeToMatch != null) || (nEndIdx > sdiList.Count - 1)) nEndIdx = sdiList.Count - 1; for (int nDocIdx = nStartIdx; nDocIdx <= nEndIdx; nDocIdx++) { if ((worker.CancellationPending == true)) { e.Cancel = true; break; } ScanDocInfo sdi = sdiList[nDocIdx]; // Check if all docs required DocCompareRslt rslt = new DocCompareRslt(); bool bShowDoc = false; if (docTypeToMatch == null) { ScanPages scanPages = _scanDocHandler.GetScanPages(sdi.uniqName); // See if doc has been filed - result maybe null FiledDocInfo fdi = _scanDocHandler.GetFiledDocInfo(sdi.uniqName); bShowDoc = true; rslt.uniqName = sdi.uniqName; rslt.bMatches = true; rslt.bMatchesButShouldnt = false; rslt.docTypeFiled = (fdi == null) ? "" : fdi.filedAs_docType; rslt.matchStatus = (fdi == null) ? "NOT-FILED" : "FILED"; rslt.scanPages = scanPages; mdResult.totalMatchesFound++; } else { rslt = CheckIfDocMatches(sdi, docTypeToMatch); if (rslt.bMatches) mdResult.totalMatchesFound++; if (rslt.bDoesntMatchButShould) mdResult.totalDoesntMatchButShould++; if (rslt.bMatchesButShouldnt) mdResult.totalMatchesButShouldnt++; if (rslt.bMatches || rslt.bDoesntMatchButShould) bShowDoc = true; } mdResult.totalFilesSearched++; _lastFindNumFound = mdResult.totalFilesSearched; if (bShowDoc) { // Check for a limit to avoid swamping list docsFound++; if ((docsFound > includeInListFromIdx-nStartIdx) && (docsFound <= includeInListFromIdx - nStartIdx + MAX_NUM_DOCS_TO_ADD_TO_LIST)) { if (mdResult.indexOfFirstFileDisplayed == -1) mdResult.indexOfFirstFileDisplayed = nDocIdx; this.Dispatcher.BeginInvoke((Action)delegate() { _docCompareRslts.Add(rslt); }); } else { // Indicate that not all results are shown mdResult.bNotAllResultsShow = true; } } // Update status worker.ReportProgress((int)(nDocIdx * 100 / sdiList.Count)); if (((nDocIdx % 10) == 0) || (nDocIdx == nEndIdx)) { string rsltStr = DocMatchFormatResultStr(mdResult); this.Dispatcher.BeginInvoke((Action)delegate() { SetDocMatchStatusText(rsltStr); }); } } e.Result = mdResult; }
private string DocMatchFormatResultStr(MatchDocsResult mdResult) { string fileStatStr = ""; if (mdResult.totalFilesScanned <= 0) { fileStatStr = "No files"; return fileStatStr; } if (mdResult.bMatchedResultsOnly) { fileStatStr = "Searched: " + mdResult.totalFilesSearched.ToString() + (mdResult.bNotAllResultsShow ? "*" : "") + " (" + mdResult.totalFilesScanned.ToString() + ")\n"; fileStatStr += "~1Matched: " + mdResult.totalMatchesFound.ToString() + "\n" + "~2Shouldn't: " + mdResult.totalMatchesButShouldnt.ToString() + "\n" + "~3Should: " + mdResult.totalDoesntMatchButShould.ToString(); } else { fileStatStr = "Showing: " + mdResult.indexOfFirstFileDisplayed.ToString() + " - " + (mdResult.indexOfFirstFileDisplayed + mdResult.totalMatchesFound - 1).ToString() + "\n"; fileStatStr += "Total Files: " + mdResult.totalFilesScanned.ToString(); } return fileStatStr; }