public bool DeleteFile(string uniqName, FiledDocInfo fdi, string fullSourceName, bool dueToFileEditing) { // Delete the physical file bool fileDeleteOk = false; string errStr = ""; if (fullSourceName.Trim() != "") { try { // Check file exists if (!Delimon.Win32.IO.File.Exists(fullSourceName)) { logger.Error("Trying to delete non-existent file {0}", fullSourceName); fileDeleteOk = true; } else if (Properties.Settings.Default.TestModeFileTo == "") { Delimon.Win32.IO.File.Delete(fullSourceName); } else { logger.Info("TEST would be deleting {0}", fullSourceName); } fileDeleteOk = true; } catch (Exception e) { errStr = e.Message; } } if (!fileDeleteOk) return false; // Record the deletion in the filed docs database if (fdi == null) fdi = new FiledDocInfo(uniqName); fdi.SetDeletedInfo(dueToFileEditing); return AddOrUpdateFiledDocRecInDb(fdi); }
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; }
public void AddMeetingRequestToMsg(MailMessage msg, FiledDocInfo fdi) { StringBuilder str = new StringBuilder(); str.AppendLine("BEGIN:VCALENDAR"); str.AppendLine("VERSION:2.0"); str.AppendLine("METHOD:REQUEST"); str.AppendLine("BEGIN:VEVENT"); str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", fdi.filedAs_eventDateTime)); str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", fdi.filedAs_eventDateTime.ToUniversalTime())); str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", fdi.filedAs_eventDateTime.Add(fdi.filedAs_eventDuration))); str.AppendLine(string.Format("LOCATION: {0}", fdi.filedAs_eventLocation)); str.AppendLine(string.Format("UID:{0}", Guid.NewGuid())); str.AppendLine(string.Format("DESCRIPTION:{0}", fdi.filedAs_eventDescr)); str.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", fdi.filedAs_eventDescr)); str.AppendLine(string.Format("SUMMARY:{0}", fdi.filedAs_eventName)); str.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", msg.From.Address)); foreach (MailAddress emto in msg.To) str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", emto.DisplayName, emto.Address)); str.AppendLine("BEGIN:VALARM"); str.AppendLine("TRIGGER:-PT15M"); str.AppendLine("ACTION:DISPLAY"); str.AppendLine("DESCRIPTION:Reminder"); str.AppendLine("END:VALARM"); str.AppendLine("END:VEVENT"); str.AppendLine("END:VCALENDAR"); System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar"); ct.Parameters.Add("method", "REQUEST"); AlternateView avCal = AlternateView.CreateAlternateViewFromString(str.ToString(), ct); msg.AlternateViews.Add(avCal); }
public bool AddOrUpdateFiledDocRecInDb(FiledDocInfo filedDocInfo) { // Mongo save try { MongoCollection<FiledDocInfo> collection_fdinfo = GetFiledDocsCollection(); collection_fdinfo.Save(filedDocInfo); // Log it logger.Info("Added/updated fileddoc record for {0} filedAt {1}", filedDocInfo.uniqName, filedDocInfo.filedAs_pathAndFileName); // Update cache _scanDocInfoCache.UpdateDocInfo(filedDocInfo.uniqName); } catch (Exception excp) { logger.Error("Cannot add/update fileddoc rec into {0} Coll... {1} for file {2} excp {3}", Properties.Settings.Default.DbNameForDocs, Properties.Settings.Default.DbCollectionForFiledDocs, filedDocInfo.uniqName, excp.Message); return false; } return true; }
public static string GetFiledDocInfoText(FiledDocInfo filedDocInfo) { string filedDocStr = "Unfiled"; if (filedDocInfo != null) { filedDocStr = "UniqName:\t" + filedDocInfo.uniqName; filedDocStr += "\n" + "FiledAt:\t\t" + filedDocInfo.filedAt_dateAndTime.ToShortDateString() + " " + filedDocInfo.filedAt_dateAndTime.ToShortTimeString(); filedDocStr += "\n" + "FinalStatus:\t" + filedDocInfo.filedAt_finalStatus; filedDocStr += "\n" + "ErrorMessage:\t" + filedDocInfo.filedAt_errorMsg; if (filedDocInfo.filedAs_pathAndFileName != "") { string tmpStr = ""; try { tmpStr += "\n" + "FiledToName:\t" + System.IO.Path.GetFileName(filedDocInfo.filedAs_pathAndFileName); tmpStr += "\n" + "FiledToPath:\t" + System.IO.Path.GetDirectoryName(filedDocInfo.filedAs_pathAndFileName); filedDocStr += tmpStr; } finally { } } if (filedDocInfo.filedAt_finalStatus == FiledDocInfo.DocFinalStatus.STATUS_FILED) { filedDocStr += "\n" + "FiledDocType:\t" + filedDocInfo.filedAs_docType; filedDocStr += "\n" + "FiledDocDate:\t" + filedDocInfo.filedAs_dateOfDoc.ToShortDateString() + " " + filedDocInfo.filedAs_dateOfDoc.ToShortTimeString(); filedDocStr += "\n" + "FiledMoney:\t" + filedDocInfo.filedAs_moneyInfo; } filedDocStr += "\n" + "FlagRefiling:\t" + filedDocInfo.filedAs_flagForRefilingInfo; filedDocStr += "\n" + "IncludeInXCheck:\t" + (filedDocInfo.includeInXCheck ? "YES" : "NO"); filedDocStr += "\n" + "FollowUp:\t" + filedDocInfo.filedAs_followUpNeeded; filedDocStr += "\n" + "AddToCal:\t" + filedDocInfo.filedAs_addToCalendar; if (filedDocInfo.filedAs_addToCalendar != "") { filedDocStr += "\n" + "EventName:\t" + filedDocInfo.filedAs_eventName; filedDocStr += "\n" + "EventDateTime:\t" + filedDocInfo.filedAs_eventDateTime.ToShortDateString() + " " + filedDocInfo.filedAs_eventDateTime.ToShortTimeString(); filedDocStr += "\n" + "EventDuration:\t" + filedDocInfo.filedAs_eventDuration.ToString(); filedDocStr += "\n" + "EventDescr:\t" + filedDocInfo.filedAs_eventDescr; filedDocStr += "\n" + "EventLocn:\t" + filedDocInfo.filedAs_eventLocation; filedDocStr += "\n" + "AttachFile:\t" + filedDocInfo.filedAs_flagAttachFile; } } return filedDocStr; }
public bool AddFiledDocRecToMongo(FiledDocInfo filedDocInfo) { // Mongo append bool bOk = false; try { MongoCollection<FiledDocInfo> collection_fileddoc = GetFiledDocsCollection(); WriteConcernResult rslt = collection_fileddoc.Insert(filedDocInfo); bOk = rslt.Ok; // Log it logger.Info("Added fileddoc record for {0}", filedDocInfo.uniqName); // Update cache _scanDocInfoCache.UpdateDocInfo(filedDocInfo.uniqName); } catch (Exception excp) { logger.Error("Cannot insert fileddoc into {0} Coll... {1} for file {2} excp {3}", _scanConfig._dbNameForDocs, _scanConfig._dbCollectionForFiledDocs, filedDocInfo.uniqName, excp.Message); } return bOk; }
private void SendEmailsForFollowUpOrCalendar(FiledDocInfo fdi, string emailPassword) { string smtpAddress = Properties.Settings.Default.EmailService; int portNumber = 587; Int32.TryParse(Properties.Settings.Default.EmailServicePort, out portNumber); bool enableSSL = true; MailAddress emailFrom = new MailAddress(Properties.Settings.Default.EmailFrom); List<MailAddress> emailTo = GetEmailToAddresses(); using (MailMessage mail = new MailMessage()) { mail.From = emailFrom; string[] followUpNames = fdi.filedAs_followUpNeeded.Split(' '); foreach (MailAddress emto in emailTo) { if (fdi.filedAs_addToCalendar != "") { mail.To.Add(emto); } else { foreach (string name in followUpNames) { if (emto.DisplayName.Trim().IndexOf(name.Trim(), StringComparison.CurrentCultureIgnoreCase) == 0) { mail.To.Add(emto); break; } } } } if (mail.To.Count == 0) return; mail.Subject = fdi.filedAs_eventName; mail.Body = fdi.filedAs_eventDescr; mail.IsBodyHtml = true; // Check for attachment if (fdi.filedAs_flagAttachFile != "") { try { mail.Attachments.Add(new Attachment(fdi.filedAs_pathAndFileName)); } catch (Exception excp) { logger.Error("Failed to attach {0} excp {1}", fdi.filedAs_pathAndFileName, excp.Message); } } if (fdi.filedAs_addToCalendar != "") AddMeetingRequestToMsg(mail, fdi); using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber)) { smtp.Credentials = new NetworkCredential(emailFrom.Address, emailPassword); smtp.EnableSsl = enableSSL; smtp.Send(mail); } } }
public static void LoadAuditFileToDb(string fileName, ScanDocHandler scanDocHandler) { bool TEST_ON_LOCAL_DATA = false; bool PROCESS_PDF_FILE = true; bool CREATE_RECORD_IN_DB = true; Dictionary<string, bool> uniqNamesTest = new Dictionary<string, bool>(); // Read file using (StreamReader sr = new StreamReader(fileName)) { while (sr.Peek() >= 0) { string line = sr.ReadLine(); string[] fields = line.Split('\t'); if ((fields[6] != "OK") || ((fields[5] == "TEST") || (fields[5] == "DELETED"))) continue; NewAuditData ad = new NewAuditData(); string uniqName = ScanDocInfo.GetUniqNameForFile(fields[4], fields[0]); if (uniqNamesTest.ContainsKey(uniqName)) { Console.WriteLine("File {0} UNIQNAME IS NOT UNIQUE", uniqName); continue; } uniqNamesTest.Add(uniqName, true); ad.ProcDateAndTime = fields[0]; ad.DocType = fields[1]; if (ad.DocType == "") { Console.WriteLine("File {0} BLANK DOC TYPE", uniqName); } ad.OrigFileName = fields[2]; ad.UniqName = uniqName; ad.DestFile = fields[3]; ad.ArchiveFile = fields[4]; if (TEST_ON_LOCAL_DATA) ad.ArchiveFile = ad.ArchiveFile.Replace(@"\\N7700PRO\Archive\ScanAdmin\ScanBackups\", @"C:\Users\Rob\Dropbox\20140227 Train\ScanBackups\"); ad.ProcMessage = fields[5]; ad.ProcStatus = fields[6]; ad.DestOk = File.Exists(ad.DestFile) ? "" : "NO"; bool arcvExists = File.Exists(ad.ArchiveFile); if (!arcvExists) { Console.WriteLine("File {0} ARCHIVE FILE missing {1}", uniqName, ad.ArchiveFile); continue; } ad.ArcvOk = arcvExists ? "" : "NO"; // Process file if (PROCESS_PDF_FILE) { if (scanDocHandler.ProcessPdfFile(ad.ArchiveFile, uniqName, true, true, true, false, true, true)) { // Create filed info record if (CREATE_RECORD_IN_DB) { DateTime docDateFiled = DateTime.ParseExact(ad.ProcDateAndTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); FiledDocInfo fdi = new FiledDocInfo(ad.UniqName); fdi.SetDocFilingInfo(ad.DocType, ad.DestFile.Replace('\\', '/'), docDateFiled, "", "", "", "", DateTime.MinValue, new TimeSpan(), "", "", ""); fdi.SetFiledAtInfo(true, docDateFiled, ad.ProcStatus + ", " + ad.ProcMessage, FiledDocInfo.DocFinalStatus.STATUS_FILED); scanDocHandler.AddFiledDocRecToMongo(fdi); } } } } } logger.Info("Finished loading from old log"); //// Sort to find duplicates //bool sortIt = false; //if (sortIt) //{ // var sortedAd = from item in _auditDataColl // orderby item.UniqName // select item; // string lastuniq = ""; // foreach (AuditData ad in sortedAd) // { // if (lastuniq == ad.UniqName) // { // Console.WriteLine("Duplicate name " + ad.UniqName); // } // lastuniq = ad.UniqName; // } //} //// Check validity //for (int rowidx = 0; rowidx < auditListView.Items.Count; rowidx++) //{ // AuditData audData = (AuditData)(auditListView.Items[rowidx]); // string destFile = audData.DestFile; // if (File.Exists(destFile)) // auditListView. //} }
private void btnProcessDoc_Click(object sender, RoutedEventArgs e) { if (_curDocScanDocInfo == null) return; // Check not already busy filing a doc if (_scanDocHandler.IsBusy()) return; // Check a doc type has been selected bool quickDocTypeMode = isQuickDocTypeMode(); if (txtDocTypeName.Text.Trim() == "") { lblStatusBarProcStatus.Content = "A document type must be selected"; lblStatusBarProcStatus.Foreground = Brushes.Red; return; } // Check validity string rsltText = ""; string fullPathAndFileNameForFilingTo = FormFullPathAndFileNameForFiling(); bool rslt = _scanDocHandler.CheckOkToFileDoc(fullPathAndFileNameForFilingTo, out rsltText); if (!rslt) { lblStatusBarProcStatus.Content = rsltText; lblStatusBarProcStatus.Foreground = Brushes.Red; return; } // Get follow up strings string followUpStr = (bool)chkFollowUpB.IsChecked ? chkFollowUpB.Tag.ToString() : " "; followUpStr = followUpStr + ((bool)chkFollowUpA.IsChecked ? chkFollowUpA.Tag.ToString() : ""); followUpStr = followUpStr.Trim(); string addToCalendarStr = (bool)chkCalendarEntry.IsChecked ? "Calendar" : ""; string flagAttachFile = (bool)chkAttachFile.IsChecked ? "Attached" : ""; // Check if email is required but password not set if ((followUpStr.Trim() != "") || (addToCalendarStr.Trim() != "")) { if (txtEmailPassword.Password.Trim() == "") { lblStatusBarProcStatus.Content = "Email password must be set"; lblStatusBarProcStatus.Foreground = Brushes.Red; return; } } // Save time as filed _lastDocFiledAsDateTime = GetDateFromRollers(); // Warn if date outside ranges if (_lastDocFiledAsDateTime > DateTime.Now) { MessageBoxButton btnMessageBox = MessageBoxButton.YesNoCancel; MessageBoxImage icnMessageBox = MessageBoxImage.Question; MessageBoxResult rsltMessageBox = MessageBox.Show("Date is in the future - is this Correct?", "Date Question", btnMessageBox, icnMessageBox); if ((rsltMessageBox == MessageBoxResult.Cancel) || (rsltMessageBox == MessageBoxResult.No)) return; } // Warn if more than X years old const int MAX_YEARS_OLD = 10; if (_lastDocFiledAsDateTime < (DateTime.Now - new TimeSpan(365 * MAX_YEARS_OLD, 0, 0, 0))) { MessageBoxButton btnMessageBox = MessageBoxButton.YesNoCancel; MessageBoxImage icnMessageBox = MessageBoxImage.Question; MessageBoxResult rsltMessageBox = MessageBox.Show("Date is several years ago - is this Correct?", "Date Question", btnMessageBox, icnMessageBox); if ((rsltMessageBox == MessageBoxResult.Cancel) || (rsltMessageBox == MessageBoxResult.No)) return; } // Process the doc rsltText = ""; FiledDocInfo fdi = _curFiledDocInfo; if (fdi == null) fdi = new FiledDocInfo(_curDocScanDocInfo.uniqName); DateTime selectedDateTime = DateTime.MinValue; TimeSpan eventDuration = new TimeSpan(); // Check for calendar entry if (addToCalendarStr != "") { selectedDateTime = GetEventDateAndTime((DateTime)datePickerEventDate.SelectedDate, txtEventTime.Text); if (selectedDateTime == DateTime.MinValue) { lblStatusBarProcStatus.Content = "Event time/date problem"; lblStatusBarProcStatus.Foreground = Brushes.Red; return; } eventDuration = GetEventDurationFromString((string)lblEventDuration.Text); if (eventDuration.TotalDays == 0) { lblStatusBarProcStatus.Content = "Event duration problem"; lblStatusBarProcStatus.Foreground = Brushes.Red; return; } } // If in quick doc type mode check that the doc type is valid string fileAsDocTypeName = ""; if (quickDocTypeMode) { fileAsDocTypeName = txtDocTypeName.Text.Trim(); // Ensure doc type contains a dash if (!fileAsDocTypeName.Contains("-")) { MessageBoxButton btnMessageBox = MessageBoxButton.OK; MessageBoxImage icnMessageBox = MessageBoxImage.Information; MessageBoxResult rsltMessageBox = MessageBox.Show("Document Type name should be in a 'MasterType - SubType' format", "Quick DocType Problem", btnMessageBox, icnMessageBox); return; } // Ensure the new name is unique DocType testDocType = _docTypesMatcher.GetDocType(fileAsDocTypeName); if (testDocType != null) { MessageBoxButton btnMessageBox = MessageBoxButton.OK; MessageBoxImage icnMessageBox = MessageBoxImage.Information; MessageBoxResult rsltMessageBox = MessageBox.Show("There is already a Document Type with this name", "Quick DocType Problem", btnMessageBox, icnMessageBox); return; } // Create the new doctype DocType docType = new DocType(); docType.docTypeName = fileAsDocTypeName; docType.isEnabled = true; docType.matchExpression = ""; docType.dateExpression = ""; docType.moveFileToPath = _docTypesMatcher.ComputeMinimalPath(System.IO.Path.GetDirectoryName(fullPathAndFileNameForFilingTo)); string defaultRenameToContents = Properties.Settings.Default.DefaultRenameTo; docType.renameFileTo = defaultRenameToContents; _docTypesMatcher.AddOrUpdateDocTypeRecInDb(docType); _scanDocHandler.DocTypeAddedOrChanged(docType.docTypeName); } else { fileAsDocTypeName = _curSelectedDocType.docTypeName; } // Set the filing information fdi.SetDocFilingInfo(fileAsDocTypeName, fullPathAndFileNameForFilingTo, GetDateFromRollers(), txtMoneySum.Text, followUpStr, addToCalendarStr, txtEventName.Text, selectedDateTime, eventDuration, txtEventDesc.Text, txtEventLocn.Text, flagAttachFile); // Start filing the document lblStatusBarProcStatus.Content = "Processing ..."; lblStatusBarProcStatus.Foreground = Brushes.Black; _scanDocHandler.StartProcessFilingOfDoc(SetStatusText, FilingCompleteCallback, _curDocScanDocInfo, fdi, txtEmailPassword.Password, out rsltText); // Save password to db _scanDocHandler.SetEmailPassword(txtEmailPassword.Password); }
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(); }
public ScanDocAllInfo(ScanDocInfo sdi, ScanPages spages, FiledDocInfo fdi) { scanDocInfo = sdi; scanPages = spages; filedDocInfo = fdi; }