// POST api/values public Value Post(Value value) { //queueClient = new QueueClient(ServiceBusConnectionString, QueueName); using (IrigationDBEntities1 context = new IrigationDBEntities1()) { value.Timestemp = DateTime.Now; //string json = JsonConvert.SerializeObject(value); // byte[] messageBody = Encoding.Unicode.GetBytes(json); // queueClient.SendAsync(new Message(messageBody)); if (value.Pompa == null) { value.Pompa = "Off"; } Microsoft.ServiceBus.Messaging.QueueClient client2 = Microsoft.ServiceBus.Messaging.QueueClient.CreateFromConnectionString(ServiceBusConnectionString, QueueName); Microsoft.ServiceBus.Messaging.BrokeredMessage message = new Microsoft.ServiceBus.Messaging.BrokeredMessage(); message.Properties["Temperatura"] = value.Temperatura; message.Properties["Umiditate"] = value.Umiditate; message.Properties["Pompa"] = value.Pompa; message.Properties["Id_senzor"] = value.Id_senzor; client2.SendAsync(message); //value.Senzori = context.Senzoris.Include(sen => sen.Values).Include(sen => sen.Istorics).Where(sen => sen.Id == value.Id_senzor).First(); //context.Values.Add(value); //context.SaveChanges(); } return(value); }
public void Put(Senzori sen) { using (IrigationDBEntities1 context = new IrigationDBEntities1()) { Senzori senzor = context.Senzoris.FirstOrDefault(s => s.Id == sen.Id); senzor.Locatie = sen.Locatie; context.SaveChanges(); } }
public List <Value> Get() { using (IrigationDBEntities1 context = new IrigationDBEntities1()) { var list = context.Values.Include(val => val.Senzori).ToList(); list.ForEach(x => x.Senzori = null); return(list); } }
// GET api/values/05-Dec-18 7:33:57 PM public Value Get(DateTime timestemp) { using (IrigationDBEntities1 context = new IrigationDBEntities1()) { Value value = context.Values.Include(val => val.Senzori).FirstOrDefault(v => v.Timestemp.Equals(timestemp)); value.Senzori = null; return(value); } }
// DELETE api/values/5 public void Delete(int id) { using (IrigationDBEntities1 context = new IrigationDBEntities1()) { Value value = context.Values.Include(val => val.Senzori).FirstOrDefault(v => v.Id == id); context.Values.Remove(value); context.SaveChanges(); } }
public void Delete(int id) { using (IrigationDBEntities1 context = new IrigationDBEntities1()) { Senzori senzor = context.Senzoris.FirstOrDefault(s => s.Id == id); context.Senzoris.Remove(senzor); context.SaveChanges(); } }
public Senzori Post(Senzori senzor) { using (IrigationDBEntities1 context = new IrigationDBEntities1()) { // value.Senzori = context.Senzoris.Include(sen => sen.Values).Include(sen => sen.Istorics).Where(sen => sen.Id == value.Id_senzor).First(); context.Senzoris.Add(senzor); context.SaveChanges(); } return(senzor); }
public Senzori Get(int id) { using (IrigationDBEntities1 context = new IrigationDBEntities1()) { //var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(obj); // var s = context.Senzoris.Where(sen => sen.Id == id).First(); Senzori s = context.Senzoris.Include(sen => sen.Values).Include(sen => sen.Istorics).Where(sen => sen.Id == id).First(); return(s); } }
// GET api/values/5 public Value Get(int id) { using (IrigationDBEntities1 context = new IrigationDBEntities1()) { Value value = context.Values.Include(val => val.Senzori).Where(s => s.Id_senzor == id).ToList().LastOrDefault(); //Value value = context.Values.Include(sel => sel.Senzori).Where(val => val.Id == id).First(); value.Senzori = null; return(value); } }
public List <Istoric> Get(int id) { List <Istoric> istorics; using (IrigationDBEntities1 context = new IrigationDBEntities1()) { istorics = context.Istorics.Include(i => i.Senzori).Where(i => i.Id_senzor == id).ToList <Istoric>(); istorics.ForEach(x => x.Senzori = null); } return(istorics); }
// DELETE api/values/05-Dec-18 7:33:57 PM public void Delete(DateTime timestemp) { using (IrigationDBEntities1 context = new IrigationDBEntities1()) { //istorics = context.Istorics.Include(i => i.Senzori).Where(i => i.Data.Equals(datetime)).ToList<Istoric>(); // istorics.ForEach(x => x.Senzori = null); Value value = context.Values.Include(val => val.Senzori).FirstOrDefault(v => v.Timestemp == timestemp); context.Values.Remove(value); context.SaveChanges(); } }
public Istoric Get(int id, DateTime datetime) { Istoric istoric; using (IrigationDBEntities1 context = new IrigationDBEntities1()) { istoric = context.Istorics.Include(i => i.Senzori).Where(h => h.Id_senzor == id).Where(i => i.Data.Equals(datetime)).ToList <Istoric>().LastOrDefault(); istoric.Senzori = null; } return(istoric); }
// PUT api/values/5 public void Put(int id, string pompa) { using (IrigationDBEntities1 context = new IrigationDBEntities1()) { Value value = context.Values.FirstOrDefault(v => v.Id == id); value.Timestemp = DateTime.Now; // value.Temperatura = temp; //value.Umiditate = umiditate; value.Pompa = pompa; context.SaveChanges(); } }
public List <Istoric> Get(DateTime datetime) { List <Istoric> istorics; using (IrigationDBEntities1 context = new IrigationDBEntities1()) { istorics = context.Istorics.Include(i => i.Senzori).Where(i => i.Data.Equals(datetime)).ToList <Istoric>(); istorics.ForEach(x => x.Senzori = null); } return(istorics); }
public List <Senzori> Get() { using (IrigationDBEntities1 context = new IrigationDBEntities1()) { var list = context.Senzoris.Include(val => val.Values).Include(val => val.Istorics).ToList(); //var list = context.Senzoris.Include(s => s.Values).ToList(); list.ForEach(x => x.Istorics = null); list.ForEach(x => x.Values = null); // var json = JsonConvert.SerializeObject(list); return(list); } }
public void Put(Value value) { using (IrigationDBEntities1 context = new IrigationDBEntities1()) { Value value2 = context.Values.FirstOrDefault(v => v.Id == value.Id); value2.Timestemp = DateTime.Now; if (value.Temperatura != null) { value2.Temperatura = value.Temperatura; } if (value.Umiditate != null) { value2.Umiditate = value.Umiditate; } if (value.Pompa != null) { value2.Pompa = value.Pompa; } context.SaveChanges(); } }
// This function will get triggered/executed when a new message is written // on an Azure Queue called queue. public static void ProcessQueueMessage([ServiceBusTrigger("queue")] BrokeredMessage message, TextWriter log) { try { //byte[] msg = message.Body; //string json = Encoding.UTF8.GetString(msg); //var json = Encoding.Unicode.GetString(message); //Value value = message.GetBody<Value>(); // Value value = JsonConvert.DeserializeObject<Value>(json); // Console.WriteLine($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber} Body:{Encoding.UTF8.GetString(message.Body)}"); Value value = new Value(); value.Temperatura = (double)message.Properties["Temperatura"]; value.Umiditate = (double)message.Properties["Umiditate"]; value.Pompa = message.Properties["Pompa"].ToString(); value.Id_senzor = (int)message.Properties["Id_senzor"]; message.Complete(); double previousTemp = 0; double tempTreshold = 10; double tempMax = 50; double tempMin = -50; double umidityTreshhold = 35; double umidityUpLimit = 80; using (IrrigationAPI.Models.IrigationDBEntities1 context = new IrigationDBEntities1()) { Value previousvalue = context.Values.Include(val => val.Senzori).Where(s => s.Id_senzor == value.Id_senzor).ToList().LastOrDefault(); if (previousvalue != null) { previousTemp = (double)previousvalue.Temperatura; } else { previousTemp = 0; } // Verify data if (value.Umiditate > 100) { value.Umiditate = 100; } else if (value.Umiditate < 0) { value.Umiditate = 0; } //Start pompa if umiditate is below umidityTreshhold if (value.Umiditate < umidityTreshhold) { value.Pompa = "On"; } else if (value.Umiditate > umidityUpLimit) { value.Pompa = "Off"; } if (previousTemp == 0) { if (value.Temperatura > tempMax) { previousTemp = tempMax; } else if (value.Temperatura < tempMin) { previousTemp = tempMin; } else { previousTemp = (double)value.Temperatura; } } if (value.Temperatura < previousTemp - tempTreshold) { value.Temperatura = previousTemp - tempTreshold; previousTemp = (double)value.Temperatura; } else if (value.Temperatura > previousTemp + tempTreshold) { value.Temperatura = previousTemp + tempTreshold; previousTemp = (double)value.Temperatura; } else { previousTemp = (double)value.Temperatura; } //value.Senzori = context.Senzoris.Include(sen => sen.Values).Where(sen => sen.Id == value.Id_senzor).First(); value.Timestemp = DateTime.Now; context.Values.Add(value); context.SaveChanges(); // Thread.Sleep(5000); } } catch (Exception e) { // Thread.Sleep(5000); //message.RenewLock(); } }
// every day at 00:00:00 public static void Run([TimerTrigger("0 0 0 * * *")] TimerInfo myTimer, TraceWriter log) { double tempmin, tempmax, tempavg, umidmin, umidmax, umidavg; int count; using (IrigationDBEntities1 context = new IrigationDBEntities1()) { // .Include(val => val.Values).Include(val => val.Istorics) List <Senzori> senzoriList = context.Senzoris.ToList(); foreach (Senzori s in senzoriList) { tempmin = 100; tempmax = -100; tempavg = 0; umidmin = 100; umidmax = 0; umidavg = 0; List <Value> valuesList = context.Values.Where(v => v.Id_senzor == s.Id).ToList(); //list.ForEach(x => x.Senzori = null); count = valuesList.Count; foreach (Value v in valuesList) { tempavg += (double)v.Temperatura; umidavg += (double)v.Umiditate; if (v.Umiditate > umidmax) { umidmax = (double)v.Umiditate; } if (v.Temperatura > tempmax) { tempmax = (double)v.Temperatura; } if (v.Umiditate < umidmin) { umidmin = (double)v.Umiditate; } if (v.Temperatura < tempmin) { tempmin = (double)v.Temperatura; } //delete value context.Values.Remove(v); context.SaveChanges(); } umidavg /= count; tempavg /= count; Istoric istoric = new Istoric(); istoric.Id_senzor = s.Id; istoric.MaxTemperatura = tempmax; istoric.MinTemperatura = tempmin; istoric.MedieTemperatura = tempavg; istoric.MaxUmiditate = umidmax; istoric.MaxUmiditate = umidmax; istoric.MedieUmiditate = umidavg; istoric.Data = DateTime.Now; context.Istorics.Add(istoric); context.SaveChanges(); } } //log.Info($"C# Timer trigger function executed at: {DateTime.Now}"); }