예제 #1
0
        static void Main(string[] args)
        {
            //var test = new EmailSender();
            //test.SendMail("Test Email: " + DateTime.Now, "Testing my Email Server");

            //using(var context = new WebScrapeDbContext())
            //{
            //    context.Database.Delete();
            //    context.Database.Create();
            //}

            var coinscrape = new CoinScraper();

            coinscrape.Start();

            if (coinscrape.InsertCoins())
            {
                //Get the number of Coins and SendMail
                var queryContext = new WebScrapeDbContext();
                var newrecords   = queryContext.DbSet_Coin
                                   .Where(c => c.dateTime == coinscrape.DateTime_onSite)
                                   .Select(c => c.Name)
                                   .ToList();
                var count          = newrecords.Count();
                var SuccessEmailer = new EmailSender();
                SuccessEmailer.SendMail("Crypto DB Updated: " + DateTime.Now, "Records inserted: " + count.ToString());
            }
        }
예제 #2
0
 public DateTime GetLastUpdatefromDB()
 {
     using (var db = new WebScrapeDbContext())
     {
         var maxdateinDB = from coin in db.DbSet_Coin
                           orderby coin.dateTime descending
                           select coin.dateTime;
         return(maxdateinDB.FirstOrDefault());
     }
 }
예제 #3
0
 public bool InsertCoins()
 {
     using (var context = new WebScrapeDbContext())
     {
         var log = context.Database.Log;
         try
         {
             //context.Database.Log = Console.WriteLine;
             context.DbSet_Coin.AddRange(Coins);
             context.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             //PK_Udemy show how to Iterate development
             Console.ReadKey();
             EmailSender sender = new EmailSender();
             sender.SendMail("DB Insert Exception", ex.Message + "/n" + log.ToString());
             return(false);
         }
     }
 }