Ejemplo n.º 1
0
        public void TestParsing6()
        {
            string path = @"c:\ezbob\test-data\pacnet\pacnet20160121.pdf";

            byte[]          data = System.IO.File.ReadAllBytes(path);
            ParsePacNetText p    = new ParsePacNetText();

            ParsePacNetText.Logger = new ConsoleLog();
            p.ParsePdf(data);
            PacNetBalance.SavePacNetBalanceToDb();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parse pdf to text string
        /// </summary>
        /// <param name="data">pdf data stream</param>
        public void ParsePdf(byte[] data)
        {
            this.pacNetBalanceRows = new List <PacNetBalanceRow>();
            var reader = new PdfReader(data);

            for (int page = 1; page <= reader.NumberOfPages; page++)
            {
                string   text  = PdfTextExtractor.GetTextFromPage(reader, page);
                string[] lines = text.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string line in lines)
                {
                    HandleLine(line);
                }
            }             // for

            reader.Close();


            PacNetBalance.PopulateList(date, openingBalance, closingBalance, credits, debits, this.pacNetBalanceRows, this.loginAddress, this.loginPassword);
        }         // ParsePdf
Ejemplo n.º 3
0
        }         // Init

        public void Run()
        {
            DateTime oStartTime = DateTime.UtcNow;

            for ( ; ;)
            {
                DateTime oNow = DateTime.UtcNow;

                if (oNow.Subtract(oStartTime).CompareTo(m_oTotalWaitingTime) > 0)
                {
                    Error("Email did not arrive, not waiting for it any more.");
                    break;
                }                 // if

                try
                {
                    var imap = new Imap
                    {
                        // Enable SSL/TLS if necessary
                        SslMode = MailBee.Security.SslStartupMode.OnConnect
                    };

                    // Connect to IMAP server
                    imap.Connect(m_oConf.Server, m_oConf.Port);
                    Info("Connected to the server");

                    // Log into IMAP account
                    imap.Login(m_oConf.LoginAddress, m_oConf.LoginPassword);
                    Info("Logged into the server");

                    // Select Inbox folder
                    imap.SelectFolder("Inbox");

                    UidCollection uids = (UidCollection)imap.Search(true, "UNSEEN", null);

                    Debug("Unseen email count: {0}", uids.Count);

                    if (uids.Count > 0)
                    {
                        Debug("Fetching unseen messages...");

                        MailMessageCollection msgs = imap.DownloadEntireMessages(uids.ToString(), true);

                        bool handledMail = false;

                        foreach (MailMessage msg in msgs)
                        {
                            Info("Recent message index: {0} Subject: {1}", msg.IndexOnServer, msg.Subject);

                            if (msg.HasAttachments)
                            {
                                foreach (Attachment attachment in msg.Attachments)
                                {
                                    if (Consts.AttachmentContentTypes.Contains(attachment.ContentType))
                                    {
                                        Info("Has pdf attachment {0}", attachment.Filename);
                                        byte[]          data            = attachment.GetData();
                                        ParsePacNetText parsePacNetText = new ParsePacNetText(m_oConf.LoginAddress, m_oConf.LoginPassword);
                                        parsePacNetText.ParsePdf(data);
                                        handledMail = true;
                                    }             // if appropriate attachment type
                                }                 // foreach attachment
                            }                     // if has attachment
                        }                         // foreach email

                        if (handledMail)
                        {
                            PacNetBalance.SavePacNetBalanceToDb();
                        }

                        Debug("Fetching unseen messages complete.");

                        if (handledMail)
                        {
                            break;
                        }
                    }                     // if

                    imap.Disconnect();
                }
                catch (PacNetBalanceException pex)
                {
                    Error("PacNetBalanceException: {0}", pex);
                    Mailer.Mailer.SendMail(m_oConf.LoginAddress, m_oConf.LoginPassword, "PacNet Balance Report Error", pex.ToString(),
                                           "*****@*****.**");
                }
                catch (MailBeeStreamException mex)
                {
                    Error("MailBeeStreamException: {0}", mex);
                }
                catch (Exception e) {
                    Error("Some generic Exception: {0}", e);
                }                 // try

                Debug("Sleeping...");
                Thread.Sleep(m_oConf.MailboxReconnectionIntervalSeconds * 1000);
            }     // for
        }         // Run