Exemple #1
0
        public ActionResult InvoiceDragUpload(string paramOne)
        {
            if (paramOne.Length != 6 && !paramOne.All(char.IsDigit))
            {
                return(RedirectToAction("DailyInvoicing"));
            }

            ArchivesChecker.CreateArchiveDirectory(paramOne);

            foreach (string file in Request.Files)
            {
                HttpPostedFileBase fileContent = Request.Files[file];

                Stream stream = fileContent.InputStream;

                int existingFileCount = Directory
                                        .GetFiles(Path.Combine(ArchivesChecker._archivePath, paramOne), "*.msg").Length;

                string fileName = Path.GetFileName(paramOne + (existingFileCount > 0 ? "_" + ++existingFileCount : "") + ".msg");

                string path = Path.Combine(Path.Combine(ArchivesChecker._archivePath, paramOne), fileName);

                using (var fileStream = System.IO.File.Create(path))
                {
                    stream.CopyTo(fileStream);
                }
            }

            return(RedirectToAction("DailyInvoicing"));
        }
Exemple #2
0
        public ActionResult DailyInvoicingGetOrder(string paramOne)
        {
            if (paramOne.Length != 6 && !paramOne.All(char.IsDigit))
            {
                return(RedirectToAction("DailyInvoicing"));
            }

            ArchivesChecker.PopulateOrdersByOrderNo(paramOne);
            return(RedirectToAction("DailyInvoicing"));
        }
Exemple #3
0
        internal static void LoadInitializers()
        {
            ArchivesChecker.GetEntireArchive();
            LoadSettings();
            ImportEmailFile();
            Readiness.DeleteBlockerFile();

            if (!Environment.MachineName.Contains("ROBIN"))
            {
                //Global.GetAllEmails();
            }
        }
Exemple #4
0
        public ActionResult DailyOrderRefresh(string paramOne)
        {
            DateTime refDate = new DateTime();

            if (paramOne.Length > 5)
            {
                refDate = DateTime.ParseExact(paramOne, "MM-dd-yyyy",
                                              CultureInfo.InvariantCulture);
            }

            ArchivesChecker.PopulateOrdersByOrderDate(refDate);
            return(RedirectToAction("DailyOrders"));
        }
Exemple #5
0
        public ActionResult AuditDownload(string paramOne)
        {
            string archivePackagePath = ArchivesChecker.CreateAuditPackage(paramOne);

            if (archivePackagePath.Length == 0)
            {
                return(RedirectToAction("AuditorView"));
            }

            byte[] fileBytes = System.IO.File.ReadAllBytes(archivePackagePath);
            string fn        = "AuditPackage.zip";

            return(File(fileBytes, "application/octet-stream", fn));
        }
Exemple #6
0
        public ActionResult DailyInvoicingRefresh(string paramOne)
        {
            DateTime refDate = new DateTime();

            if (paramOne.Length > 5 && DateTime.TryParse(paramOne, out refDate))
            {
                refDate = DateTime.ParseExact(paramOne, "MM-dd-yyyy",
                                              CultureInfo.InvariantCulture);
            }

            ArchivesChecker.ProcessEmailsForArchive();
            ArchivesChecker.PopulateOrdersByInvoiceDate(refDate);
            ArchivesChecker.CheckPendingOrders();
            return(RedirectToAction("DailyInvoicing"));
        }
Exemple #7
0
        public string GetFilesById(string id)
        {
            // Setup virtual path and delete existing content
            string virtualPath = Server.MapPath("~/Temp");

            Directory.GetFiles(virtualPath).ForEach(x => System.IO.File.Delete(x));

            List <string> fileList = ArchivesChecker.GetFilesForOrder(id);

            string returnStr = "";


            List <string> IgnoreFileExtensions = new List <string>()
            {
                ".dwg", ".msg"
            };

            for (int i = 0; i < fileList.Count; i++)
            {
                if (IgnoreFileExtensions.Any(x => fileList[i].Contains(x)))
                {
                    returnStr += String.Format("<a href=\"#\">{0}</a>", fileList[i]);
                }
                else
                {
                    returnStr += String.Format("<a href=\"{1}\" target=\"_blank\">{0}</a>", fileList[i],
                                               Path.Combine("/temp/", fileList[i]));

                    // Copy file to virtual server
                    System.IO.File.Copy(Path.Combine(ArchivesChecker._archivePath + id, fileList[i]),
                                        Path.Combine(virtualPath, fileList[i]));
                }

                if (i <= fileList.Count - 1)
                {
                    returnStr += "<br>";
                }
            }

            //return String.Join("<br />", );
            return(returnStr);
        }
Exemple #8
0
        public static int _SyncBuffer  = 5; // How much time post-sync to toggle _syncReady? (_SyncHour + _SyncBuffer must be <= 23 -- 24 hours)

        public static void MinutelyTaskChecker()
        {
            if (_SyncReady && DateTime.Now.Hour == Convert.ToInt32(Settings.GetSettingsValue("EmailSyncHour", "1")) && Settings.GetSettingsValue("EmailSyncOn", "0") == "1")
            {
                Log.Append("***Scheduled synchronizations and updates started***");
                _SyncReady = false;
                PSTImporter.SyncPSTFiles();
                Global.GetAllEmails();
            }
            else if (!_SyncReady && DateTime.Now.Hour == Convert.ToInt32(Settings.GetSettingsValue("EmailSyncHour", "1")) + _SyncBuffer)
            {
                _SyncReady = true;
            }

            // Archive check every 30 minutes
            if (Environment.MachineName.Contains("EXCOTRACK3") && DateTime.Now.Minute % 30 == 0)
            {
                Log.Append("Checking Pending Invoices to generate");

                // Pull archival data from emails
                ArchivesChecker.ProcessEmailsForArchive();
                // Update orders pending
                ArchivesChecker.CheckPendingOrders();
            }

            // Archive check every 5 minutes
            if (DateTime.Now.Minute % 5 == 0)
            {
                ArchivesChecker.ProcessCacheFiles();
            }

            // Refresh archives every 10 minutes on a separate thread
            if (DateTime.Now.Minute % 10 == 0)
            {
                // Refresh archives
                ArchivesChecker.GetEntireArchive();
            }
        }
Exemple #9
0
        public List <Email> GetArchiveEmails()
        {
            int errorLevel = 0;

            Log.Append(String.Format("Getting new emails from archive..."));


            List <Email> newEmails = new List <Email>();

            int emailSyncCount = 0;

            using (var client = new MailKit.Net.Imap.ImapClient())
            {
                try
                {
                    //For demo-purposes, accept all SSL certificates
                    client.ServerCertificateValidationCallback = (s, c, h, e) => true;

                    #region Connect using receiving parameters

                    try
                    {
                        client.Connect(ReceivingProtocol, Convert.ToInt32(ReceivingPort), true);
                    }
                    catch
                    {
                        Log.Append(String.Format("ERROR: Failed to connect to {0} using {1}:{2}", Email,
                                                 ReceivingProtocol, ReceivingPort));
                        return(new List <Email>());
                    }

                    #endregion

                    // Note: since we don't have an OAuth2 token, disable
                    // the XOAUTH2 authentication mechanism.
                    client.AuthenticationMechanisms.Remove("XOAUTH2");

                    #region Login using credentials

                    try
                    {
                        client.Authenticate(Email, Password);
                    }
                    catch
                    {
                        Log.Append(String.Format("ERROR: Failed to login using user credentials for '{0}'", Email));
                        return(new List <Email>());
                    }

                    #endregion

                    #region Inbox

                    // The Inbox folder is always available on all IMAP servers...
                    var inbox = client.Inbox;
                    inbox.Open(FolderAccess.ReadWrite);

                    var query = SearchQuery.DeliveredAfter(LastUpdateTime);

                    foreach (var uid in inbox.Search(query))
                    {
                        try
                        {
                            if (Readiness.CheckTerminationStatus(true))
                            {
                                break;
                            }

                            string workingID = Global.GetAttachmentID();

                            try
                            {
                                MimeMessage message = inbox.GetMessage(uid);

                                var date = message.Date.ToString();

                                Email email = new Email()
                                {
                                    UID      = uid.ToString(),
                                    ID       = workingID,
                                    MailDate = Convert.ToDateTime(date),
                                    From     = message.From.ToString(),
                                    To       = Email,
                                    Subject  = message.Subject,
                                };

                                if (email.Subject.Trim().Length != 6 || !email.Subject.Trim().All(char.IsDigit))
                                {
                                    Random r = new Random();
                                    email.CreateEmailMsgFile(message,
                                                             ArchivesChecker._errorPath + DateTime.Now.Month + "_" + DateTime.Now.Day +
                                                             "_" + DateTime.Now.Year + "_" + r.Next(10000, 99999), true);
                                }
                                else
                                {
                                    emailSyncCount++;

                                    email.CreateEmailMsgFile(message, ArchivesChecker.CreateArchiveDirectory(email.Subject) + @"\" + email.Subject);

                                    newEmails.Add(email);
                                }

                                inbox.AddFlags(new[] { uid }, MessageFlags.Deleted, true);
                                inbox.Expunge();
                            }
                            catch
                            {
                                Log.Append(String.Format("ERROR: Email can't be processed with ID={0}", workingID));
                            }
                        }
                        catch (Exception ex)
                        {
                            errorLevel++;
                            Log.Append(String.Format("ERROR [Inbox]: {0}", ex));
                            // Undetermined error from automated system
                        }
                    }

                    #endregion

                    #region Subfolders

                    var personal = client.GetFolder(client.PersonalNamespaces[0]);
                    foreach (var folder in personal.GetSubfolders(false))
                    {
                        if (folder.Name.ToLower() != "sent")
                        {
                            if (Readiness.CheckTerminationStatus(true))
                            {
                                break;
                            }

                            try
                            {
                                folder.Open(FolderAccess.ReadOnly);

                                query = SearchQuery.DeliveredAfter(LastUpdateTime);

                                foreach (var uid in folder.Search(query))
                                {
                                    if (Readiness.CheckTerminationStatus())
                                    {
                                        return(newEmails);
                                    }

                                    MimeMessage message = folder.GetMessage(uid);

                                    var date = message.Date.ToString();

                                    Email email = new Email
                                    {
                                        UID      = uid.ToString(),
                                        ID       = Global.GetAttachmentID(),
                                        MailDate = Convert.ToDateTime(date),
                                        From     = message.From.ToString(),
                                        To       = Email,
                                        Subject  = message.Subject,
                                    };

                                    if (email.Subject.Trim().Length != 6 || !email.Subject.Trim().All(char.IsDigit))
                                    {
                                        Random r = new Random();
                                        email.CreateEmailMsgFile(message,
                                                                 ArchivesChecker._errorPath + DateTime.Now.Month + "_" + DateTime.Now.Day +
                                                                 "_" + DateTime.Now.Year + "_" + r.Next(10000, 99999));
                                    }
                                    else
                                    {
                                        emailSyncCount++;

                                        email.CreateEmailMsgFile(message, ArchivesChecker.CreateArchiveDirectory(email.Subject) + @"\" + email.Subject);

                                        newEmails.Add(email);
                                    }


                                    inbox.AddFlags(new[] { uid }, MessageFlags.Deleted, true);
                                    inbox.Expunge();
                                }
                            }
                            catch
                            {
                                Log.Append(String.Format("  Sub folder IMAP retrieval error for folder=\"{0}\"",
                                                         folder.Name));
                            }
                        }
                    }

                    #endregion

                    client.Disconnect(true);
                }
                catch (Exception ex)
                {
                    errorLevel++;
                    Log.Append(String.Format("ERROR [Overall]: {0}", ex));
                }
            }


            Log.Append(String.Format("{0} emails archived.", emailSyncCount));

            if (errorLevel <= 0)
            {
                Log.Append("Complete!");
            }

            return(newEmails);
        }
Exemple #10
0
 public ActionResult RefreshArchives()
 {
     ArchivesChecker.GetEntireArchive();
     return(RedirectToAction("SearchArchive"));
 }