コード例 #1
0
        // when processing file
        // - first move the file
        // - then update the doc record to say processed
        public bool ProcessPdfFile(string fileName, string uniqName, bool bExtractImages, bool bDontOverwriteExistingImages, bool bExtractText, bool bRecogniseDoc,
                                bool bAddToDocInfoDb, bool bAddToDocPagesDb)
        {
            // First check if doc details are already in db
            if (!ScanDocInfoRecordExists(uniqName))
                return false;

            // Make a copy of the file in the archive location
            string archiveFileName = ScanDocHandler.GetArchiveFileName(uniqName);
            if (!Delimon.Win32.IO.File.Exists(archiveFileName))
            {
                string statusStr = "";
                bool bResult = CopyFile(fileName, archiveFileName, ref statusStr);
                if (!bResult)
                {
                    logger.Error("Can't make archive copy {0} excp {1}", archiveFileName, statusStr);
                    return false;
                }
            }
            else
            {
                logger.Info("Archive file already exists {0}", archiveFileName);
            }

            // Extract text blocks from file
            ScanPages scanPages = new ScanPages(uniqName);
            int totalNumPages = 0;
            if (bExtractText)
            {
                PdfTextAndLocExtractor pdfExtractor = new PdfTextAndLocExtractor();
                scanPages = pdfExtractor.ExtractDocInfo(uniqName, fileName, _scanConfig._maxPagesForText, ref totalNumPages);
            }

            // Extract images from file
            if (bExtractImages)
            {
                bool procImages = (!bDontOverwriteExistingImages) | (!Delimon.Win32.IO.File.Exists(PdfRasterizer.GetFilenameOfImageOfPage(_scanConfig._docAdminImgFolderBase, uniqName, 1, false)));
                if (procImages)
                {
                    PdfRasterizer rs = new PdfRasterizer(fileName, THUMBNAIL_POINTS_PER_INCH);
                    try
                    {
                        List<string> imgFileNames = rs.GeneratePageFiles(uniqName, scanPages, _scanConfig._docAdminImgFolderBase, _scanConfig._maxPagesForImages, false);
                    }
                    finally
                    {
                        rs.Close();
                    }

                }
            }

            // Form partial document info
            DateTime fileDateTime = Delimon.Win32.IO.File.GetCreationTime(fileName);
            ScanDocInfo scanDocInfo = new ScanDocInfo(uniqName, totalNumPages, scanPages.scanPagesText.Count, fileDateTime, fileName.Replace('\\', '/'), false);

            // Add records to mongo databases
            if (bAddToDocPagesDb)
                AddScanPagesRecToMongo(scanPages);
            if (bAddToDocInfoDb)
                AddDocInfoRecToMongo(scanDocInfo);

            // Request update to unfiled documents list
            _scanDocInfoCache.RequestUnfiledListUpdate();

            return true;
        }
コード例 #2
0
        public void StartProcessFilingOfDoc(ReportStatus reportStatusCallback, ReportStatus filingCompleteCallback, ScanDocInfo sdi, FiledDocInfo fdi, string emailPassword, out string rsltText)
        {
            _docFilingReportStatus = reportStatusCallback;
            _filingCompleteCallback = filingCompleteCallback;

            // Start the worker thread to do the copy and move
            if (!_fileProcessBkgndWorker.IsBusy)
            {
                object[] args = new object[] { sdi, fdi, emailPassword };
                _fileProcessBkgndWorker.RunWorkerAsync(args);
                rsltText = "Processing file ...";
            }
            else
            {
                rsltText = "Busy ... please wait";
            }
            _docFilingStatusStr = rsltText;
        }
コード例 #3
0
        public void AddDocInfoRecToMongo(ScanDocInfo scanDocInfo)
        {
            // Mongo append
            try
            {
                MongoCollection<ScanDocInfo> collection_sdinfo = GetDocInfoCollection();
                collection_sdinfo.Insert(scanDocInfo);
                // Log it
                logger.Info("Added scandocinfo record for {0}", scanDocInfo.uniqName);

                // Update cache
                _scanDocInfoCache.UpdateDocInfo(scanDocInfo.uniqName);
                _scanDocLikelyDocType.UpdateDocInfo(scanDocInfo.uniqName);
            }
            catch (Exception excp)
            {
                logger.Error("Cannot insert scandoc recinfo into {0} Coll... {1} for file {2} excp {3}",
                            _scanConfig._dbNameForDocs, _scanConfig._dbCollectionForDocInfo, scanDocInfo.uniqName,
                            excp.Message);
            }
        }
コード例 #4
0
 public bool AddOrUpdateScanDocRecInDb(ScanDocInfo scanDocInfo)
 {
     // Mongo save
     try
     {
         MongoCollection<ScanDocInfo> collection_sdinfo = GetDocInfoCollection();
         collection_sdinfo.Save(scanDocInfo);
         // Log it
         logger.Info("Added/updated scandocinfo record for {0}", scanDocInfo.uniqName);
         // Update cache
         _scanDocInfoCache.UpdateDocInfo(scanDocInfo.uniqName);
         _scanDocLikelyDocType.UpdateDocInfo(scanDocInfo.uniqName);
     }
     catch (Exception excp)
     {
         logger.Error("Cannot add/update scandocinfo into {0} Coll... {1} for file {2} excp {3}",
                     Properties.Settings.Default.DbNameForDocs, Properties.Settings.Default.DbCollectionForDocInfo, scanDocInfo.uniqName,
                     excp.Message);
         return false;
     }
     return true;
 }
コード例 #5
0
 public static string GetScanDocInfoText(ScanDocInfo scanDocInfo)
 {
     string scanDocStr = "UniqName:\t" + scanDocInfo.uniqName;
     scanDocStr += "\n" + "Pages:\t\t" + scanDocInfo.numPages.ToString();
     scanDocStr += "\n" + "PagesWithText:\t" + scanDocInfo.numPagesWithText.ToString();
     scanDocStr += "\n" + "CreateDate:\t" + scanDocInfo.createDate.ToShortDateString() + " " + scanDocInfo.createDate.ToShortTimeString();
     scanDocStr += "\n" + "OrigFileName:\t" + scanDocInfo.origFileName;
     scanDocStr += "\n" + "FlagForHelp:\t" + (scanDocInfo.flagForHelpFiling ? "YES" : "NO");
     return scanDocStr;
 }
コード例 #6
0
        private DocCompareRslt CheckIfDocMatches(ScanDocInfo sdi, DocType docTypeToMatch)
        {
            DocCompareRslt compRslt = new DocCompareRslt();
            ScanDocAllInfo scanDocAllInfo = _scanDocHandler.GetScanDocAllInfoCached(sdi.uniqName);

            // Check for a match
            DocTypeMatchResult matchResult = _docTypesMatcher.CheckIfDocMatches(scanDocAllInfo.scanPages, docTypeToMatch, false, null);
            if (matchResult.matchCertaintyPercent == 100)
            {
                compRslt.bMatches = true;
                compRslt.bMatchesButShouldnt = (scanDocAllInfo.filedDocInfo != null) && TestForMatchesButShouldnt(scanDocAllInfo.filedDocInfo.filedAs_docType, docTypeToMatch);
                compRslt.uniqName = sdi.uniqName;
                compRslt.docTypeFiled = (scanDocAllInfo.filedDocInfo == null) ? "" : scanDocAllInfo.filedDocInfo.filedAs_docType;
                compRslt.matchStatus = (scanDocAllInfo.filedDocInfo == null) ? "NOT-FILED" : (compRslt.bMatchesButShouldnt ? "MATCH-BUT-SHOULDN'T" : "OK");
                compRslt.scanPages = scanDocAllInfo.scanPages;
            }
            else
            {
                compRslt.bDoesntMatchButShould = (scanDocAllInfo.filedDocInfo != null) && (scanDocAllInfo.filedDocInfo.filedAs_docType == docTypeToMatch.docTypeName);
                if (compRslt.bDoesntMatchButShould)
                {
                    compRslt.uniqName = sdi.uniqName;
                    compRslt.docTypeFiled = (scanDocAllInfo.filedDocInfo == null) ? "" : scanDocAllInfo.filedDocInfo.filedAs_docType;
                    compRslt.matchStatus = "SHOULD-BUT-DOESN'T";
                    compRslt.scanPages = scanDocAllInfo.scanPages;
                }
            }
            compRslt.matchFactorStr = matchResult.matchCertaintyPercent.ToString() + " + " + matchResult.matchFactor.ToString() + "%";
            return compRslt;
        }
コード例 #7
0
        public void ShowDocTypeList(string selDocTypeName, ScanDocInfo unfiledScanDocInfo, ScanPages unfiledScanDocPages)
        {
            _curUnfiledScanDocInfo = unfiledScanDocInfo;
            _curUnfiledScanDocPages = unfiledScanDocPages;
            DocType selDocType = null;
            List<DocType> docTypes = _docTypesMatcher.ListDocTypes();
            var docTypesSorted = from docType in docTypes
                           orderby !docType.isEnabled, docType.docTypeName
                           select docType;
            _docTypeColl.Clear();
            foreach (DocType dt in docTypesSorted)
            {
                _docTypeColl.Add(dt);
                if (dt.docTypeName == selDocTypeName)
                    selDocType = dt;
            }
            docTypeListView.ItemsSource = _docTypeColl;
            if (selDocType != null)
                docTypeListView.SelectedItem = selDocType;

            // Display example doc
            if ((_curUnfiledScanDocInfo != null) && (_curUnfiledScanDocPages != null))
            {
                DisplayExampleDoc(_curUnfiledScanDocInfo.uniqName, 1, _curUnfiledScanDocPages);
                btnShowDocToBeFiled.IsEnabled = true;
            }
            else
            {
                btnShowDocToBeFiled.IsEnabled = false;
            }
        }
コード例 #8
0
        private void ShowDocumentFirstTime(string uniqName)
        {
            // Load document info from db
            ScanDocAllInfo scanDocAllInfo = _scanDocHandler.GetScanDocAllInfoCached(uniqName);
            if ((scanDocAllInfo == null) || (scanDocAllInfo.scanDocInfo == null))
            {
                _curDocScanPages = null;
                _curDocScanDocInfo = null;
                _curFiledDocInfo = null;
                _curSelectedDocType = null;
            }
            else
            {
                _curDocScanPages = scanDocAllInfo.scanPages;
                _curDocScanDocInfo = scanDocAllInfo.scanDocInfo;
                _curFiledDocInfo = scanDocAllInfo.filedDocInfo;
            }

            // Display image of first page
            DisplayScannedDocImage(1);

            // Signal that the cur doc has changed
            _newCurDocProcessingCancel = true;
            _newCurDocSignal.Set();
        }
コード例 #9
0
ファイル: ScanDocInfo.cs プロジェクト: robdobsn/ScanMonitor
 public ScanDocAllInfo(ScanDocInfo sdi, ScanPages spages, FiledDocInfo fdi)
 {
     scanDocInfo = sdi;
     scanPages = spages;
     filedDocInfo = fdi;
 }