Exemplo n.º 1
0
        public ActionResult StatusDispositivos(int?id)
        {
            var usuario = db.ClienteModels.FirstOrDefault(u => u.Smtp == User.Identity.Name);

            if ((id == null) || (id != usuario.Codigo))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            int codigoCliente = Convert.ToInt32(id);

            var dispositivos = db.DispositivoModels.Where(t => t.CodigoCliente == codigoCliente).ToList();

            //status
            StringBuilder retorno = new StringBuilder();

            retorno.AppendLine("<br /><br /><br />");
            retorno.AppendLine("<h2>Status dos Dispositivos</h2>");

            retorno.AppendLine("<table class='table'>");
            retorno.AppendLine("  <tr>");
            retorno.AppendLine("    <th>Dispositivo</th>");
            retorno.AppendLine("    <th>Número de Série</th>");
            retorno.AppendLine("    <th>SMTP Sala de Reunião</th>");
            retorno.AppendLine("    <th>Data da Ativação</th>");
            retorno.AppendLine("    <th>Fuso Horário</th>");
            retorno.AppendLine("    <th>Status de Cadastro</th>");
            retorno.AppendLine("    <th>Última Atualização</th>");
            retorno.AppendLine("    <th>Último Status do Sensor</th>");
            retorno.AppendLine("  </tr>");

            foreach (var item in dispositivos)
            {
                var status = new DispositivoController().GetSala(item.Serial);

                retorno.AppendLine("  <tr>");
                retorno.AppendLine("    <td>" + item.Nome.ToString() + "</td>");
                retorno.AppendLine("    <td>" + item.Serial.ToString() + "</td>");
                retorno.AppendLine("    <td>" + item.Smtp.ToString() + "</td>");
                retorno.AppendLine("    <td>" + item.DataAtivacao.ToString() + "</td>");
                retorno.AppendLine("    <td>" + item.TimeZone.ToString() + "</td>");
                retorno.AppendLine("    <td>" + (item.Ativo ? "Ativo" : "Inativo") + "</td>");
                if ((status != null) && (status.Result != null))
                {
                    retorno.AppendLine("    <td>" + status.Result.DataAtualizacao.ToString() + "</td>");
                    retorno.AppendLine("    <td>" + (status.Result.HasPeople ? "Sala Não Vazia" : "Sala Vazia") + "</td>");
                }
                else
                {
                    retorno.AppendLine("    <td>Sem atualização</td>");
                    retorno.AppendLine("    <td>Sem atualização</td>");
                }
                retorno.AppendLine("  </tr>");
            }
            retorno.AppendLine("</table>");

            ViewBag.Retorno = retorno.ToString();

            return(View());
        }
Exemplo n.º 2
0
 private void Inicio(Object state)
 {
     try
     {
         //Finalizo el timer una vez ejecutado
         timer1.Change(Timeout.Infinite, Timeout.Infinite);
         File.AppendAllText(@"C:\logger.log", Environment.NewLine + "---------------------------------------------------------------------------- " + DateTime.Now + Environment.NewLine);
         File.AppendAllText(@"C:\logger.log", "(INICIO)" + Environment.NewLine);
         //Traigo los dispositivos del server
         listaDispositivos = DispositivoController.Lista();
         //Conecto con cada dispositivo y gestiono los datos
         foreach (var d in listaDispositivos)
         {
             Conectar(d);
         }
     }
     catch (WebException ex)
     {
         File.AppendAllText(@"C:\logger.log", DateTime.Now + "  ERROR de Red: " + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine);
         if (!Conectado)
         {
             timer1.Change(300000, Timeout.Infinite); //Re intento a los 5 minutos
         }
     }
     catch (ProtocolViolationException ex)
     {
         File.AppendAllText(@"C:\logger.log", DateTime.Now + "  ERROR de Red: " + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine);
         if (!Conectado)
         {
             timer1.Change(300000, Timeout.Infinite); //Re intento a los 5 minutos
         }
     }
     catch (Exception ex)
     {
         File.AppendAllText(@"C:\logger.log", DateTime.Now + "  REG-ppal: " + ex.Message + Environment.NewLine);
         if (!Conectado)
         {
             timer1.Change(300000, Timeout.Infinite); //Re intento a los 5 minutos
         }
     }
 }