Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void SendEvento(string dispositivoId, Eventos evento)
- {
- Connection conn = new Connection("http://localhost:65097/Index");
- Model1Container context = new Model1Container();
- try
- {
- conn.Start().Wait();
- context.Database.Connection.Open();
- Dispositivos dispositivo = DispositivosDao.GetDispositivo(dispositivoId);
- Pin pin = new Pin(dispositivo.Latitud, dispositivo.Longitud, evento.Fecha, evento.IntensidadMax, dispositivo.UniqueId, dispositivo.Alias);
- List<Pin> lista = new List<Pin>();
- lista.Add(pin);
- var json = new JavaScriptSerializer().Serialize(lista);
- conn.Send(json).Wait();
- Clusters cluster = ClustersDao.GetCluster(dispositivo.ClustersClusterId);
- List<Dispositivos> dispositivos = cluster.Dispositivos.ToList();
- var cont = 0;
- List<Eventos> listaEventosCluster = new List<Eventos>();
- for (var i = 0; cont < 3 && i < dispositivos.Count(); i++)
- {
- listaEventosCluster.AddRange(dispositivos.ElementAt(i).Eventos.ToList<Eventos>());
- }
- if (listaEventosCluster.Count() > 0)
- {
- listaEventosCluster.OrderByDescending(e => e.Fecha);
- DateTime endHour = evento.Fecha;
- DateTime startHour = endHour.AddHours(-1);
- var inHour = listaEventosCluster.Where(o => o.Fecha >= startHour && o.Fecha <= endHour);
- int count = inHour.Count();
- if (count >= 2)
- {
- json = new JavaScriptSerializer().Serialize(new { Alerta = "Sismo" });
- conn.Send(json).Wait();
- }
- }
- }
- catch (Exception ex)
- {
- Debug.WriteLine("Error " + ex.Message + " \n Inner Exception " + ex.InnerException + " \n Stack Trace " + ex.StackTrace);
- }
- finally
- {
- conn.Stop();
- conn.Disconnect();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement