Ejemplo n.º 1
0
        public void CheckStatus(string ip, string port)
        {
            try
            {
                isConnection = "Error";
                isAuth       = "Error";
                string Uri = "http://" + ip + ":" + port + "/api/v0/sip/status";
                request = (HttpWebRequest)WebRequest.Create(Uri);
                string passmd5 = driver.Encrypt(textBox3.Text);
                driver.ipPart = ip;
                string result = driver.Auth(ip, port, textBox2.Text, passmd5);
                if (result.Contains("OK"))
                {
                    nameOfDevice = driver.GetDeviceName(ip, port, driver.token);
                    isConnection = "Yes";
                    isAuth       = "Yes";
                }
                else
                {
                    nameOfDevice = driver.GetDeviceName(ip, port, driver.token);
                    if (nameOfDevice == "BAS-IP multi-apartment panel")
                    {
                        driver.LogOut(ip, port, driver.token);
                    }
                    request.Timeout = 100;
                    response        = (HttpWebResponse)request.GetResponse();
                    response.Close();
                    isAuth          = "Ok";
                    button1.Enabled = true;
                }

                MessageBox.Show("Панель: \"" + nameOfDevice + "\"" + Environment.NewLine +
                                Environment.NewLine + "Подключение:\"" + isConnection +
                                "\"" + Environment.NewLine + Environment.NewLine +
                                "Авторизация:\"" + isAuth + "\"", "");
            }

            catch (WebException ex)
            {
                string answer = driver.HandleException(ex);
                if (answer.Contains("Время ожидания"))
                {
                    isAuth       = "Error";
                    isConnection = "Error";
                    MessageBox.Show("Панель: \"" + nameOfDevice + "\"" + Environment.NewLine +
                                    Environment.NewLine + "Подключение:\"" + isConnection +
                                    "\"" + Environment.NewLine + Environment.NewLine +
                                    "Авторизация:\"" + isAuth + "\"", "");
                }
                else
                {
                    button1.Enabled = true;
                    MessageBox.Show("Панель: \"" + nameOfDevice + "\"" + Environment.NewLine +
                                    Environment.NewLine + "Подключение:\"" + isConnection +
                                    "\"" + Environment.NewLine + Environment.NewLine +
                                    "Авторизация:\"" + isAuth + "\"", "");
                }
            }
        }