Пример #1
0
 public void DoSomething(bool isConnected = true)
 {
     ConsoleMsg("DoSomething",MsgType.NewCall);
     try
     {
         //Do the emails need to be sent?
         EmailBatch eBatch = (from eb in _db.EmailBatches orderby eb.Created descending select eb).FirstOrDefault();
         if (eBatch == null)
         {
             //Make fake batch for prev Monday am
             DateTime fakeTime = DateTime.Today.AddHours(2);
             fakeTime = fakeTime.AddDays((((int)fakeTime.DayOfWeek) - 1) * -1);
             fakeTime = fakeTime.AddDays(-7);
             eBatch = new EmailBatch
             {
                 Created = fakeTime
             };
         }
         if ((DateTime.Now - eBatch.Created).TotalDays >= 7)
             SendClaimEmails();
         else
             HarvestTrainJourneyInfo(isConnected);
     }
     catch (Exception ex)
     {
         ConsoleMsg(ex.Message,MsgType.Error);
         var db = new DR_Entities();
         LogType ltError = (from lt in db.LogTypes where lt.LogTypeName == "Error" select lt).FirstOrDefault();
         var log = new Log
         {
             LogType = ltError,
             Header = ex.Message,
             Message = ex.StackTrace,
             Timestamp = DateTime.Now
         };
         db.Logs.Add(log);
         db.SaveChanges();
         db.Dispose();
     }
 }
Пример #2
0
        public void TestEMail()
        {
            ConsoleMsg("TestEMail", MsgType.FunctionCall);
            try
            {
                var mm = new MailMessage
                {
                    From = new MailAddress("*****@*****.**"),
                    Subject = "Delay Repay Test EMail - " + DateTime.Now.ToString("dd MMM yyyy HH:mm")
                };

                var smtp = new SmtpClient
                {
                    Host = Properties.Settings.Default.SmtpClient,
                    Port = Properties.Settings.Default.SmtpPort,
                    UseDefaultCredentials = false,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    Credentials = new NetworkCredential(Properties.Settings.Default.SmtpUsername, Properties.Settings.Default.SmtpPassword),
                    EnableSsl = true,
                    Timeout = 20000
                };

                mm.Body = "Test email";
                mm.To.Add(new MailAddress("*****@*****.**"));
                smtp.Send(mm);
            }
            catch (Exception ex)
            {
                ConsoleMsg(ex.Message, MsgType.Error);
                var db = new DR_Entities();
                LogType ltError = (from lt in db.LogTypes where lt.LogTypeName == "Error" select lt).FirstOrDefault();
                var log = new Log
                {
                    LogType = ltError,
                    Header = ex.Message,
                    Message = ex.StackTrace,
                    Timestamp = DateTime.Now
                };
                db.Logs.Add(log);
                db.SaveChanges();
                db.Dispose();
            }
        }