private void MainCycle(object sender, System.Timers.ElapsedEventArgs e) { lock (mainLock) { if (Active) { Console.WriteLine("Entered to MainCycle"); using (var a = new DB_SAPEntities()) { using (var b = new DataAnalysisContext()) { Executor _do = new Executor(a, b); var _dataSQL = a.ADDD.FirstOrDefault(); _do.UpdateSubtances(); _do.UpdatePosts(); _do.UpdateWeather(); _do.UpdateMeasurments(); b.SaveChanges(); } } Console.WriteLine("Exit from MainCycle"); } } }
// POST api/values public void Post([FromBody] string data) { JObject obj = JObject.Parse(data); List <Prediction> predictions = new List <Prediction>(); StringBuilder message = new StringBuilder(); var notify = new Notification.Notifier(); _log.Trace($"API CALL / Records received {obj.Count}"); try { using (var b = new DataAnalysisContext()) { foreach (var x in obj) { string name = x.Key; JToken value = x.Value; var itemPrediction = new Prediction { MeasurementID = (long?)value["id"], PontID = (long)value["point"], SubstanceID = (long)value["substance"], PredictedValue = (double)value["predicted"], PredictionTime = Convert.ToDateTime(value["time"]).Add(TimeSpan.FromMinutes((int?)value["prediction_range"] ?? 20)), PreditionRange = TimeSpan.FromMinutes((int?)value["prediction_range"] ?? 20) }; b.Predictions.Add(itemPrediction); double rate = (double)value["rate"]; if (rate >= 0.95) { message.AppendLine($"{itemPrediction.ToString()} критичный уровень {rate.ToString("F2")} ПДК"); } else if (rate >= 0.80) { message.AppendLine($"{itemPrediction.ToString()} повышенный уровень {rate.ToString("F2")} ПДК"); } else { message.AppendLine($"{itemPrediction.ToString()} {rate.ToString("F2")} ПДК"); } } if (message.Length > 0) { notify.SendTelegramChannel(message.ToString()); } b.SaveChanges(); } } catch (Exception e) { _log.Error(e); notify.SendTelegramChannel($"API CALL / Error {e.Message}"); } _log.Trace($"API CALL / Prediction is done"); }
private void DataUpdater(object sender, System.Timers.ElapsedEventArgs e) { Console.WriteLine("Entered to MainCycle"); DateTime time = new DateTime(2018, 1, 1); using (var a = new DB_SAPEntities()) { using (var b = new DataAnalysisContext()) { Executor _do = new Executor(a, b); _do.AllWeatherDataCheker(time); b.SaveChanges(); } } Console.WriteLine("Exit from MainCycle"); }