Advertisement
loonerz

signalR function

Feb 13th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1. public static void SendEvento(string dispositivoId, Eventos evento)
  2.         {
  3.             Connection conn = new Connection("http://localhost:65097/Index");
  4.             Model1Container context = new Model1Container();
  5.             try
  6.             {
  7.                 conn.Start().Wait();
  8.                 context.Database.Connection.Open();
  9.                 Dispositivos dispositivo = DispositivosDao.GetDispositivo(dispositivoId);
  10.                 Pin pin = new Pin(dispositivo.Latitud, dispositivo.Longitud, evento.Fecha, evento.IntensidadMax, dispositivo.UniqueId, dispositivo.Alias);
  11.                 List<Pin> lista = new List<Pin>();
  12.                 lista.Add(pin);
  13.                 var json = new JavaScriptSerializer().Serialize(lista);
  14.                 conn.Send(json).Wait();
  15.                 Clusters cluster = ClustersDao.GetCluster(dispositivo.ClustersClusterId);
  16.                 List<Dispositivos> dispositivos = cluster.Dispositivos.ToList();
  17.                 var cont = 0;
  18.                 List<Eventos> listaEventosCluster = new List<Eventos>();
  19.                 for (var i = 0; cont < 3 && i < dispositivos.Count(); i++)
  20.                 {
  21.                     listaEventosCluster.AddRange(dispositivos.ElementAt(i).Eventos.ToList<Eventos>());
  22.                 }
  23.                 if (listaEventosCluster.Count() > 0)
  24.                 {
  25.                     listaEventosCluster.OrderByDescending(e => e.Fecha);
  26.                     DateTime endHour = evento.Fecha;
  27.                     DateTime startHour = endHour.AddHours(-1);
  28.                     var inHour = listaEventosCluster.Where(o => o.Fecha >= startHour && o.Fecha <= endHour);
  29.                     int count = inHour.Count();
  30.                     if (count >= 2)
  31.                     {
  32.                         json = new JavaScriptSerializer().Serialize(new { Alerta = "Sismo" });
  33.                         conn.Send(json).Wait();
  34.                     }
  35.                 }
  36.             }
  37.             catch (Exception ex)
  38.             {
  39.                 Debug.WriteLine("Error " + ex.Message + " \n Inner Exception " + ex.InnerException + " \n Stack Trace " + ex.StackTrace);
  40.             }
  41.             finally
  42.             {
  43.                 conn.Stop();
  44.                 conn.Disconnect();
  45.             }
  46.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement