Exemplo n.º 1
0
        public void PingHost(Host host, int numeroTestes)
        {
            bool pingou = true;
            Ping pinger = new Ping();
            try
            {
                for (int i = 0; i < numeroTestes; i++)
                {
                    if (!pingou)
                        break;
                    PingReply reply = pinger.Send(host.ip);
                    pingou = reply.Status == IPStatus.Success;
                }
            }
            catch (PingException)
            {
                pingou = false;
            }

            if (host.em_pe != pingou)
            {
                host.em_pe = pingou;
                host.ultima_alteracao = DateTime.Now.ToString();
                banco.atualizarHost(host);
            }
        }
Exemplo n.º 2
0
        public void removerHost(Host host)
        {
            DataTable dt = new DataTable();
            String insSQL = "DELETE FROM TB_HOST WHERE ID_HOST = " + host.id_host;

            SQLiteDataAdapter da = new SQLiteDataAdapter(insSQL, stringConn);

            da.Fill(dt);
        }
Exemplo n.º 3
0
        public void atualizarHost(Host host)
        {
            DataTable dt = new DataTable();
            String insSQL = "UPDATE TB_HOST SET NOME = '" + host.nome + "', IP='" + host.ip + "', ATIVO = '" + host.ativo + "', EM_PE = '" + host.em_pe + "', ULTIMA_ALTERACAO = '" + host.ultima_alteracao +"' WHERE ID_HOST = "+host.id_host;

            SQLiteDataAdapter da = new SQLiteDataAdapter(insSQL, stringConn);

            da.Fill(dt);
        }
Exemplo n.º 4
0
        public void inserirHost(Host host)
        {
            DataTable dt = new DataTable();
            String insSQL = "INSERT INTO TB_HOST (NOME, IP, ATIVO, EM_PE, ULTIMA_ALTERACAO) VALUES ('"+
                             host.nome + "', '" + host.ip + "','" + host.ativo + "','" + host.em_pe + "', '" + host.ultima_alteracao + "')";

            SQLiteDataAdapter da = new SQLiteDataAdapter(insSQL, stringConn);

            da.Fill(dt);
        }
Exemplo n.º 5
0
        private void btn_cadastrar_Click(object sender, EventArgs e)
        {
            host = new Host();
            host.nome = txt_nome.Text;
            host.ip = txt_ip.Text;
            host.em_pe = false;
            host.ativo = true;
            host.ultima_alteracao = DateTime.Now.ToString();
            banco.inserirHost(host);
            cadastrou = true;

            this.Close();
        }
Exemplo n.º 6
0
        public List<Host> obterHosts()
        {
            DataTable dt = new DataTable();
            List<Host> hosts = new List<Host>();
            String insSQL = "select id_host, nome, ip, cast (ativo as varchar) as ativo, cast(em_pe as varchar) as em_pe, ultima_alteracao from TB_HOST";

            SQLiteDataAdapter da = new SQLiteDataAdapter(insSQL, stringConn);

            da.Fill(dt);

            for (int i = 0; i < dt.Rows.Count; i++ )
            {
                Host h = new Host();

                h.id_host = Convert.ToInt32(dt.Rows[i]["ID_HOST"].ToString());
                h.nome = dt.Rows[i]["NOME"].ToString();
                h.ip = dt.Rows[i]["IP"].ToString();
                h.ativo = Convert.ToBoolean(dt.Rows[i]["ATIVO"]);
                h.em_pe = Convert.ToBoolean(dt.Rows[i]["EM_PE"]);
                h.ultima_alteracao = dt.Rows[i]["ULTIMA_ALTERACAO"].ToString();
                hosts.Add(h);
            }
            return hosts;
        }
Exemplo n.º 7
0
 public void vaiTestando(Host host)
 {
     while (host.ativo)
     {
         Thread t = new Thread(() => PingHost(host, 5));
         t.Start();
         Thread.Sleep(5000);
     }
 }