public void Write(string note) { Log lg = new Log { user_id = "Admin", page = "http://193.27.73.63/Predict/CPStart.html", function_query = "Predict", error = "", note = note, datestamp = DateTime.UtcNow, recipient = Properties.Settings.Default.emails }; try { using (DB_A4A060_csEntities context = new DB_A4A060_csEntities()) { context.Logs.Add(lg); context.SaveChanges(); } } catch (Exception ex) { EmailBox em = new EmailBox(); em.SendEmail("*****@*****.**", Properties.Settings.Default.UserName, "Predict - " + ex.Message, "Predict error"); throw; } }
static void Predict(List <SP_Predict_AnimalList_Result> animal_list) { //1. Define predict date DateTime currentUTC = DateTime.UtcNow.AddHours(-Properties.Settings.Default.TimeIntervalPredict); DateTime predict_date = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(currentUTC, "Eastern Standard Time"); //test--------------------------------------------------------------------------------------------------------------------- // predict_date = DateTime.Parse("2020/11/29 13:00:00"); //2020 - 11 - 29 13:02:00.0000000 //test--------------------------------------------------------------------------------------------------------------------- //3. run prediction routines PredictManager pm = new PredictManager(); //3.1 Extract the temperature data from the database for the specified animal_id //and for datetime from 0:00 on dat-2 to 18:00 on dat. double result = 0; double missing_gaps = 0; string email_massage = string.Empty; foreach (var item in animal_list) { result = pm.GetMeasDataByAnimalId(item.bolus_id, predict_date); missing_gaps = pm.MissingGapsProc(item.bolus_id, predict_date); //email preparation if (result >= 0.5 && (1 - missing_gaps) <= 0.5) { email_massage += EmailMessageBuilder(item, predict_date, result, missing_gaps); } // Save data in database pm.SaveResult(predict_date, item, result, missing_gaps); } //Send result---------------------------------------------------------------- if (!string.IsNullOrEmpty(email_massage)) { string addr = Properties.Settings.Default.emails; EmailBox em = new EmailBox(); em.SendEmail(Properties.Settings.Default.email_sender, addr, email_massage, Properties.Settings.Default.email_subject); } }