Example #1
0
        public void Config_NetworkSet()
        {
            bool   gravou;
            string ip = repIP; // "192.168.0.147";

            // ATENÇÃO: se este teste falhar parcialmente todos os demais deve ser o ultimo teste a ser executado
            if (rep.GravarConfigRede(ip, "255.255.0.0", "192.168.0.1", 443, out gravou) && gravou)
            {
                Console.WriteLine("Nova configuração gravada");
                rep.Desconectar();
                Thread.Sleep(ip == repIP ? 5000 : 30000); // tempo para o ip mudar...
                if (rep.Conectar(ip, 443) == RepCid.ErrosRep.OK)
                {
                    Console.WriteLine("Conectado ao novo IP");
                    if (rep.GravarConfigRede(repIP, "255.255.254.0", "192.168.0.1", 443, out gravou) && gravou)
                    {
                        Thread.Sleep(ip == repIP ? 5000 : 30000); // tempo para o ip mudar...
                        Console.WriteLine("Voltou ao IP padrão");
                    }
                    else
                    {
                        Assert.Fail("Erro ao gravar configurações antiga de rede");
                    }
                }
                else
                {
                    Assert.Fail("Erro ao conectar o REP no novo IP:" + ip);
                }
            }
            else
            {
                Assert.Fail("Erro ao mudar configuração de rede");
            }
        }
Example #2
0
 public void ConnectLoop()
 {
     int tries = 10;
     Console.WriteLine("Tentando se conectar {0} vezes com REP no endereço {1}:{2}", tries, Config.repIP, Config.repPort);
     RepCid rep = new RepCid();
     int idle = 0;
     for (int i = 0; i < tries; i++)
     {
         rep.iDClassLogin = Config.repLogin;
         rep.iDClassPassword = Config.repSenha;
         rep.ConnectTimeout = 15000;
         var status = rep.Conectar(Config.repIP, Config.repPort);
         rep.Desconectar();
         switch (status)
         {
             case RepCid.ErrosRep.OK:
                 break;
             case RepCid.ErrosRep.ErroNaoOcioso:
                 Console.WriteLine("Tentativa {0}: não ocioso", i);
                 idle++;
                 break;
             default:
                 Assert.Fail("Tentativa {0}: erro inválido ({1})", i, status.ToString());
                 break;
         }
     }
     Console.WriteLine("Quantidade de tentativas com REP ocupado: {0}", idle);
 }
Example #3
0
        public void ConnectLoop()
        {
            int tries = 10;

            Console.WriteLine("Tentando se conectar {0} vezes com REP no endereço {1}:{2}", tries, Config.repIP, Config.repPort);
            RepCid rep  = new RepCid();
            int    idle = 0;

            for (int i = 0; i < tries; i++)
            {
                rep.iDClassLogin    = Config.repLogin;
                rep.iDClassPassword = Config.repSenha;
                rep.ConnectTimeout  = 15000;
                var status = rep.Conectar(Config.repIP, Config.repPort);
                rep.Desconectar();
                switch (status)
                {
                case RepCid.ErrosRep.OK:
                    break;

                case RepCid.ErrosRep.ErroNaoOcioso:
                    Console.WriteLine("Tentativa {0}: não ocioso", i);
                    idle++;
                    break;

                default:
                    Assert.Fail("Tentativa {0}: erro inválido ({1})", i, status.ToString());
                    break;
                }
            }
            Console.WriteLine("Quantidade de tentativas com REP ocupado: {0}", idle);
        }
Example #4
0
        public static void TestRepUsers(object prm)
        {
            string cIP = (string)prm;
            int nREP = nTask;
            nTask++;
            RepCid rep = new RepCid();
            Controlid.RepCid.ErrosRep status = rep.Conectar(cIP, 1818);
            if (status == RepCid.ErrosRep.OK)
                Console.WriteLine("REP" + nREP + ": Conectado");
            else
            {
                Console.WriteLine(rep.LastLog());
                Assert.Fail("REP" + nREP + ": Erro ao conectar! " + status.ToString());
            }

            int qtd;
            if (!rep.CarregarUsuarios(true, out qtd))
                Assert.Fail("Erro ao carregar usuários do REP" + nREP);

            Console.WriteLine("REP" + nREP + ": Usuários: " + qtd);

            Int64 pis;
            string nome;
            int codigo;
            string senha;
            string barras;
            int rfid;
            int privilegios;
            int ndig;
            while (rep.LerUsuario(out pis, out nome, out codigo, out senha, out barras, out rfid, out privilegios, out ndig))
                Console.WriteLine(string.Format("REP" + nREP + ": {0}:{1} {2}:{3} {4}|{5} {6} {7}", pis, nome, codigo, senha, barras, rfid, privilegios, ndig));

        }
Example #5
0
        //public static RepCid ConectarREP(string ip, int port, uint @passcode, string user, string password)
        //{
        //    RepCid rep = null;
        //    if (rep == null)
        //    {
        //        rep = new RepCid();
        //        rep.iDClassLogin = user;
        //        rep.iDClassPassword = password;
        //        rep.iDClassPort = 8000;
        //        Controlid.RepCid.ErrosRep status = rep.Conectar(ip, port, @passcode);
        //        string Retorno = status == RepCid.ErrosRep.OK ? "Conectado" : "Erro ao Conectar";
        //    }
        //    return rep;
        //}

        private void Connect()
        {
            if (_rep != null)
            {
                _rep.Desconectar();
            }

            _rep = new RepCid();

            LogErro(_rep.Conectar(TerminalDados.IP, TerminalDados.Porta, Convert.ToUInt32(string.IsNullOrEmpty(TerminalDados.SupervisorCodigo) ? "0" : TerminalDados.SupervisorCodigo)));
        }
Example #6
0
 public static RepCid ConectarREP()
 {
     if (rep == null)
     {
         rep = new RepCid();
         rep.iDClassLogin = repLogin;
         rep.iDClassPassword = repSenha;
         Controlid.RepCid.ErrosRep status = rep.Conectar(repIP, repPort, repiDXSenha);
         if (status == RepCid.ErrosRep.OK)
             Console.WriteLine("REP Conectado");
         else
         {
             Console.WriteLine(rep.LastLog());
             Assert.Fail("Erro ao conectar: " + status.ToString());
         }
     }
     return rep;
 }
Example #7
0
 public static RepCid ConectarREP()
 {
     if (rep == null)
     {
         rep = new RepCid();
         Controlid.RepCid.ErrosRep status = rep.Conectar(repIP, repPort);
         if (status == RepCid.ErrosRep.OK)
         {
             Console.WriteLine("REP Conectado");
         }
         else
         {
             Console.WriteLine(rep.LastLog());
             Assert.Fail("Erro ao conectar: " + status.ToString());
         }
     }
     return(rep);
 }
Example #8
0
        private void Connect()
        {
            if (_rep != null)
            {
                _rep.Desconectar();
            }

            _rep = new RepCid();
            //string con = "";
            //if (TerminalDados.IP.Replace(" ", "").Contains("dns:"))
            //{
            //    IPAddress[] ip = Dns.GetHostAddresses(TerminalDados.IP.Replace(" ", "").Replace("dns:", ""));
            //    con = ip[0].ToString();
            //}
            //else
            //    con = TerminalDados.IP;

            LogErro(_rep.Conectar(TerminalDados.IP, TerminalDados.Porta, 0));//, Convert.ToUInt32(string.IsNullOrEmpty(TerminalDados.SupervisorCodigo) ? "0" : TerminalDados.SupervisorCodigo)));
        }
Example #9
0
        public static void TestRepUsers(object prm)
        {
            string cIP  = (string)prm;
            int    nREP = nTask;

            nTask++;
            RepCid rep = new RepCid();

            Controlid.RepCid.ErrosRep status = rep.Conectar(cIP, 1818);
            if (status == RepCid.ErrosRep.OK)
            {
                Console.WriteLine("REP" + nREP + ": Conectado");
            }
            else
            {
                Console.WriteLine(rep.LastLog());
                Assert.Fail("REP" + nREP + ": Erro ao conectar! " + status.ToString());
            }

            int qtd;

            if (!rep.CarregarUsuarios(true, out qtd))
            {
                Assert.Fail("Erro ao carregar usuários do REP" + nREP);
            }

            Console.WriteLine("REP" + nREP + ": Usuários: " + qtd);

            Int64  pis;
            string nome;
            int    codigo;
            string senha;
            string barras;
            int    rfid;
            int    privilegios;
            int    ndig;

            while (rep.LerUsuario(out pis, out nome, out codigo, out senha, out barras, out rfid, out privilegios, out ndig))
            {
                Console.WriteLine(string.Format("REP" + nREP + ": {0}:{1} {2}:{3} {4}|{5} {6} {7}", pis, nome, codigo, senha, barras, rfid, privilegios, ndig));
            }
        }
Example #10
0
        public override bool Connect(int Terminal)
        {
            if (_rep != null)
            {
                _rep.Desconectar();
            }

            Controlid.RepCid.ErrosRep status;
            bool gravou;
            bool Retorno;

            _rep = new RepCid();
            _rep.iDClassLogin    = TerminalDados.OperadorLogin;
            _rep.iDClassPassword = TerminalDados.OperadorSenha;
            _rep.iDClassPort     = TerminalDados.Porta;
            status  = _rep.Conectar(TerminalDados.IP, TerminalDados.Porta, Convert.ToUInt32(string.IsNullOrEmpty(TerminalDados.SupervisorCodigo) ? "0" : TerminalDados.SupervisorCodigo));
            Retorno = status == RepCid.ErrosRep.OK ? true : false;

            LogErro(status);
            return(Retorno);
        }
Example #11
0
        public static Int64 pisTEST = 1; //012468202319;

        public static RepCid ConectarREP()
        {
            if (rep == null)
            {
                rep = new RepCid();
                rep.iDClassLogin    = repLogin;
                rep.iDClassPassword = repSenha;
                //rep.iDClassPort = 80; // Define o número da porta que deve ser considerado ser um iDClass (default 443)
                Controlid.RepCid.ErrosRep status = rep.Conectar(repIP, repPort, repiDXSenha); // Manda conectar na porta correta
                if (status == RepCid.ErrosRep.OK)
                {
                    Console.WriteLine("REP Conectado");
                }
                else
                {
                    Console.WriteLine(rep.LastLog());
                    Assert.Fail("Erro ao conectar: " + status.ToString());
                }
            }
            return(rep);
        }
Example #12
0
    private bool conexao(bool conect, TBPontoEletronicoModel dados)
    {
        if (_rep != null)
        {
            _rep.Desconectar();
        }
        _rep = new RepCid();
        if (_rep.Conectar(dados.PontoEletronico_Ip.Trim(), dados.PontoEletronico_Porta, (uint)0) == RepCid.ErrosRep.OK)
        {
            if (!conect)
            {
                return(true);
            }
        }
        else
        {
            return(false);
        }

        return(true);
    }
Example #13
0
        private void Connect()
        {
            if (_rep != null)
            {
                _rep.Desconectar();
            }

            _rep = new RepCid();
            string con = "";

            if (TerminalDados.IP.Contains("www."))
            {
                IPAddress[] ip = Dns.GetHostAddresses(TerminalDados.IP);
                con = ip[0].ToString();
            }
            else
            {
                con = TerminalDados.IP;
            }

            LogErro(_rep.Conectar(con, TerminalDados.Porta, Convert.ToUInt32(string.IsNullOrEmpty(TerminalDados.SupervisorCodigo) ? "0" : TerminalDados.SupervisorCodigo)));
        }
Example #14
0
        // Tenta efetuar a conexão e define a váriável '_rep' que será encapsulada
        private bool Connect(bool lShowOK)
        {
            if (_rep != null)
            {
                _rep.Desconectar();
            }

            _rep = new RepCid();

            string ip = txtIP.Text;

            if (_rep.Conectar(ip, (int)nudPort.Value, (uint)nudPassCode.Value) == RepCid.ErrosRep.OK)
            {
                if (!lShowOK)
                {
                    // Se não for para exibir os dialogos de confirmação de conexão já retorna a instancia da conexão
                    return(true);
                }
                string sn;
                uint   tam_bobina;
                uint   restante_bobina;
                uint   uptime;
                uint   cortes;
                uint   papel_acumulado;
                uint   nsr_atual;
                if (_rep.LerInfo(out sn, out tam_bobina, out restante_bobina, out uptime, out cortes, out papel_acumulado, out nsr_atual))
                {
                    if (sn == null)
                    {
                        sn = "?";
                    }
                }
                else
                {
                    sn = "(falhou)";
                }

                if (txtIP.Text != TesteRepCid.Properties.Settings.Default.IP ||
                    nudPort.Value != TesteRepCid.Properties.Settings.Default.Porta)
                {
                    if (MessageBox.Show("Conexão Aceita\r\n" +
                                        "SN: " + sn + "\r\n" +
                                        "NSR: " + nsr_atual.ToString() + "\r\n" +
                                        "Papel restante: " + (restante_bobina / 10.0f).ToString("0.0") + " m\r\n" +
                                        "\r\nDeseja gravar esta conexão", "REP", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        Settings.Default.IP       = txtIP.Text;
                        Settings.Default.Porta    = (int)nudPort.Value;
                        Settings.Default.PassCode = (uint)nudPassCode.Value;
                        Settings.Default.Save();
                    }
                }
                else
                {
                    MessageBox.Show("Sucesso na conexão com o REP!\r\n\r\n" +
                                    "SN: " + sn + "\r\n" +
                                    "NSR: " + nsr_atual.ToString() + "\r\n" +
                                    "Papel restante: " + (restante_bobina / 10.0f).ToString("0.0") + " m",
                                    "REP", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("Conexão com o REP não está funcionando", "REP", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }
Example #15
0
        // Tenta efetuar a conexão e define a váriável '_rep' que será encapsulada
        private bool Connect(bool lShowOK)
        {
            if (_rep != null)
                _rep.Desconectar();

            _rep = new RepCid();

            string ip = txtIP.Text;
            if (_rep.Conectar(ip, (int)nudPort.Value, (uint)nudPassCode.Value) == RepCid.ErrosRep.OK)
            {
                if (!lShowOK)
                    // Se não for para exibir os dialogos de confirmação de conexão já retorna a instancia da conexão
                    return true;
                string sn;
                uint tam_bobina;
                uint restante_bobina;
                uint uptime;
                uint cortes;
                uint papel_acumulado;
                uint nsr_atual;
                if (_rep.LerInfo(out sn, out tam_bobina, out restante_bobina, out uptime, out cortes, out papel_acumulado, out nsr_atual))
                {
                    if (sn == null) sn = "?";
                }
                else
                    sn = "(falhou)";

                if (txtIP.Text != TesteRepCid.Properties.Settings.Default.IP ||
                    nudPort.Value != TesteRepCid.Properties.Settings.Default.Porta)
                {
                    if (MessageBox.Show("Conexão Aceita\r\n" +
                        "SN: " + sn + "\r\n" +
                        "NSR: " + nsr_atual.ToString() + "\r\n" +
                        "Papel restante: " + (restante_bobina / 10.0f).ToString("0.0") + " m\r\n" +
                        "\r\nDeseja gravar esta conexão", "REP", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        Settings.Default.IP = txtIP.Text;
                        Settings.Default.Porta = (int)nudPort.Value;
                        Settings.Default.PassCode = (uint)nudPassCode.Value;
                        Settings.Default.Save();
                    }
                }
                else
                    MessageBox.Show("Sucesso na conexão com o REP!\r\n\r\n" +
                        "SN: " + sn + "\r\n" +
                        "NSR: " + nsr_atual.ToString() + "\r\n" +
                        "Papel restante: " + (restante_bobina / 10.0f).ToString("0.0") + " m",
                        "REP", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Conexão com o REP não está funcionando", "REP", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            return true;
        }