Ejemplo n.º 1
0
        public static int IsConnected()
        {
            int fail;

            System.Uri Url = new System.Uri("http://www.microsoft.com"); //é sempre bom por um site que costuma estar sempre on, para n haver problemas

            System.Net.WebRequest  WebReq;
            System.Net.WebResponse Resp;
            WebReq = System.Net.WebRequest.Create(Url);

            try
            {
                Resp = WebReq.GetResponse();
                Resp.Close();
                WebReq = null;
                fail   = 0; //consegue conexão à internet
                return(fail);
            }

            catch
            {
                MessageBox.Show("Não existe nenhuma ligação à internet.\n\nLiga-te à internet e tenta de novo.", "Erro de ligação!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                WebReq = null;
                fail   = 1; //falhou a conexão à internet
                return(fail);
            }
        }
Ejemplo n.º 2
0
        public static bool IsConnected()
        {
            bool fail;

            System.Uri Url = new System.Uri("http://www.microsoft.com"); //é sempre bom por um site que costuma estar sempre on, para n haver problemas

            System.Net.WebRequest  WebReq;
            System.Net.WebResponse Resp;
            WebReq = System.Net.WebRequest.Create(Url);

            try
            {
                Resp = WebReq.GetResponse();
                Resp.Close();
                WebReq = null;
                fail   = true; //consegue conexão à internet
                return(fail);
            }

            catch
            {
                MessageBox.Show("Você não está conectado a internet!", "Atenção", MessageBoxButtons.OK);
                WebReq = null;
                fail   = false; //falhou a conexão à internet
                return(fail);
            }
        }
Ejemplo n.º 3
0
        private void Timer1_Tick(object sender, EventArgs e)
        {
            if (progressBar1.Value < 100)
            {
                progressBar1.Value = progressBar1.Value + 2;
            }
            if (progressBar1.Value == 100)
            {
                Principal frmPrincipal = new Principal();
                frmPrincipal.Show(); // abre o form principal
                timer1.Stop();       // para o relógio
                this.Hide();         //fecha a janela após completar os 100%
            }

            if (progressBar1.Value == 10)
            {
                System.Uri             Url = new System.Uri("http://www.google.com"); //é sempre bom por um site que costuma estar sempre on para testar a conexão
                System.Net.WebRequest  WebReq;
                System.Net.WebResponse Resp;
                WebReq = System.Net.WebRequest.Create(Url);

                try
                {
                    Resp = WebReq.GetResponse();
                    Resp.Close();
                    WebReq = null;
                }
                catch
                {
                    timer1.Stop();  // para o relógio em caso de erro
                    MessageBox.Show("Não existe conexão com a internet.");
                    this.Dispose(); // encerra o sistema
                }
            }
        }
Ejemplo n.º 4
0
        public static bool IsConnectedToInternet(Uri urlToCheck)
        {
            try
            {
                if (urlToCheck == null)
                {
                    urlToCheck = new System.Uri("http://www.microsoft.com");
                }


                System.Net.WebRequest  WebReq;
                System.Net.WebResponse Resp;
                WebReq = System.Net.WebRequest.Create(urlToCheck);

                try
                {
                    Resp = WebReq.GetResponse();
                    Resp.Close();
                    WebReq = null;
                    return(true);
                }

                catch
                {
                    WebReq = null;
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 5
0
        public static bool checkConectionOk()
        {
            bool conection_ok = false;

            System.Uri Url = new System.Uri("http://www.microsoft.com"); //é sempre bom por um site que costuma estar sempre on, para n haver problemas

            System.Net.WebRequest  WebReq;
            System.Net.WebResponse Resp;
            WebReq = System.Net.WebRequest.Create(Url);

            try
            {
                Resp = WebReq.GetResponse();
                Resp.Close();
                WebReq       = null;
                conection_ok = true;
            }
            catch
            {
                WebReq       = null;
                conection_ok = false;
            }

            Console.WriteLine(conection_ok);

            return(conection_ok);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks if server is available.
        /// </summary>
        /// <param name="WebServerToCheck"> Web server to check. </param>
        /// <returns>
        /// True - if there is a  connection.
        /// Otherwise it will return false
        /// </returns>
        public static bool CheckForInternetConnection(string WebServerToCheck)
        {
            // Get the url from server properties
            Uri Url = new Uri(WebServerToCheck);

            WebRequest  WebReq;
            WebResponse Response;

            // Make an empty request.
            WebReq = WebRequest.Create(Url);

            try
            {
                // Get the response.
                Response = WebReq.GetResponse();
                Response.Close();

                // Server is available.
                return(true);
            }
            catch
            {
                // Server is unavailable.
                return(false);
            }
            finally
            {
                WebReq   = null;
                Response = null;
                Url      = null;
            }
        }
Ejemplo n.º 7
0
        public static bool IsConnected()
        {
            bool fail;

            System.Uri Url = new System.Uri("http://www.google.com"); //é sempre bom por um site que costuma estar sempre on, para n haver problemas

            System.Net.WebRequest WebReq;
            System.Net.WebResponse Resp;
            WebReq = System.Net.WebRequest.Create(Url);

            try
            {
                Resp = WebReq.GetResponse();
                Resp.Close();
                WebReq = null;
                fail = true; //consegue conexão à internet
                return fail;
            }

            catch
            {
                WebReq = null;
                fail = false; //falhou a conexão à internet
                return fail;
            }
        }
Ejemplo n.º 8
0
 public bool IsConnected()
 {
     System.Uri             Url = new System.Uri("http://www.google.com");
     System.Net.WebRequest  WebReq;
     System.Net.WebResponse Resp;
     WebReq = System.Net.WebRequest.Create(Url);
     try
     {
         Resp = WebReq.GetResponse();
         Resp.Close();
         WebReq = null;
         return(true);
     }
     catch
     {
         WebReq = null;
         return(false);
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Verifica se existe conexão com a internet através do site www.google.com.br
        /// </summary>
        /// <returns>True - existe conexão | False - não há conexão</returns>
        public static bool IsConnected()
        {
            Uri Url = new Uri("http://www.google.com.br");             //é sempre bom por um site que costuma estar sempre on, para não haver problemas

            System.Net.WebRequest  WebReq;
            System.Net.WebResponse Resp;
            WebReq = System.Net.WebRequest.Create(Url);

            try
            {
                Resp = WebReq.GetResponse();
                Resp.Close();
                return(WebReq.Equals(null));
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Herhangi bir Url'lin canlı olup olmadığını verilen timeout ile kontrol eder.
        /// </summary>
        /// <param name="url"></param>
        /// <param name="_TimeOut"></param>
        /// <returns></returns>
        public static bool Varmi_Baglanti(string url, int _TimeOut = 1000)
        {
            try
            {
                System.Uri Url = new System.Uri(url);

                System.Net.WebRequest  WebReq;
                System.Net.WebResponse Resp;
                WebReq = System.Net.WebRequest.Create(Url);

                WebReq.Timeout = _TimeOut;

                Resp = WebReq.GetResponse();
                Resp.Close();
                WebReq = null;
                return(true);
            }

            catch
            {
                return(false);
            }
        }
Ejemplo n.º 11
0
        public static void GetSensorBathRoom(out double temperature, out int luminiscence, out int humidity, out bool movement)
        {
            HttpWebRequest  WebReq;
            HttpWebResponse WebResp;

            Debug.GC(true);

            temperature  = 0;
            luminiscence = 0;
            humidity     = 0;
            movement     = false;
            try
            {
                var request = System.Net.WebRequest.Create("http://192.168.2.25:8083/ZAutomation/api/v1/devices/") as System.Net.HttpWebRequest;
                request.KeepAlive = true;

                request.Method = "PUT";

                request.ContentType = "application/json";
                byte[] byteArray = System.Text.Encoding.UTF8.GetBytes("{\"id\":\"ZWayVDev_20:0:49:1\",\"deviceType\":\"probe\",\"metrics\":{\"probeTitle\":\"Temperature\",\"scaleTitle\":\"°C\",\"level\":7.599999904632568,\"title\":\"Temperature Sensor\",\"iconBase\":\"zwave\"},\"tags\":[],\"location\":null,\"updateTime\":1387882443}");
                request.ContentLength = byteArray.Length;
                using (var writer = request.GetRequestStream()) { writer.Write(byteArray, 0, byteArray.Length); }

                string responseContent = null;
                using (var response = request.GetResponse() as System.Net.HttpWebResponse)
                {
                    using (var reader = new System.IO.StreamReader(response.GetResponseStream()))
                    {
                        responseContent = reader.ReadToEnd();
                    }
                }

                WebReq                  = (HttpWebRequest)WebRequest.Create("http://192.168.2.25:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_5-0-48-1/command/update");
                WebReq.KeepAlive        = true;
                WebReq.Method           = "GET";
                WebReq.Timeout          = 1000;
                WebReq.ReadWriteTimeout = 1000;
                WebResp                 = (HttpWebResponse)WebReq.GetResponse();
                WebResp.Close();
                WebReq  = (HttpWebRequest)WebRequest.Create("http://192.168.2.25:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_5-0-49-1/command/update");
                WebResp = (HttpWebResponse)WebReq.GetResponse();
                WebResp.Close();
                WebReq  = (HttpWebRequest)WebRequest.Create("http://192.168.2.25:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_5-0-49-3/command/update");
                WebResp = (HttpWebResponse)WebReq.GetResponse();
                WebResp.Close();
                WebReq  = (HttpWebRequest)WebRequest.Create("http://192.168.2.25:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_5-0-49-5/command/update");
                WebResp = (HttpWebResponse)WebReq.GetResponse();
                WebResp.Close();

                WebReq  = (HttpWebRequest)WebRequest.Create("http://192.168.2.25:8083/ZWaveAPI/Run/devices[5].instances[0].commandClasses[0x31].data[0x01].val.value");
                WebResp = (HttpWebResponse)WebReq.GetResponse();
                using (var reader = new StreamReader(WebResp.GetResponseStream()))
                {
                    double result2 = double.Parse(reader.ReadToEnd().ToString()) * 10;
                    int    result1 = (int)result2;
                    double result  = (double)result1 / 10;
                    Logging.LogMessageToFile("Main - Temperature = [" + result.ToString() + "]", "SENSOR");
                    temperature = result;
                    reader.Close();
                }
                WebResp.Close();
                WebReq  = (HttpWebRequest)WebRequest.Create("http://192.168.2.25:8083/ZWaveAPI/Run/devices[5].instances[0].commandClasses[0x31].data[0x03].val.value");
                WebResp = (HttpWebResponse)WebReq.GetResponse();
                using (var reader = new StreamReader(WebResp.GetResponseStream()))
                {
                    int result = Int32.Parse(reader.ReadToEnd().ToString()); // do something fun...
                    Logging.LogMessageToFile("Main - Luminiscence = [" + result.ToString() + "]", "SENSOR");
                    luminiscence = result;
                    reader.Close();
                }
                WebResp.Close();
                WebReq  = (HttpWebRequest)WebRequest.Create("http://192.168.2.25:8083/ZWaveAPI/Run/devices[5].instances[0].commandClasses[0x31].data[0x05].val.value");
                WebResp = (HttpWebResponse)WebReq.GetResponse();
                using (var reader = new StreamReader(WebResp.GetResponseStream()))
                {
                    int result = Int32.Parse(reader.ReadToEnd().ToString()); // do something fun...
                    Logging.LogMessageToFile("Main - Humidity = [" + result.ToString() + "]", "SENSOR");
                    humidity = result;
                    reader.Close();
                }
                WebResp.Close();

                WebReq  = (HttpWebRequest)WebRequest.Create("http://192.168.2.25:8083/ZWaveAPI/Run/devices[5].instances[0].commandClasses[0x30].data[1].level.value");
                WebResp = (HttpWebResponse)WebReq.GetResponse();
                using (var reader = new StreamReader(WebResp.GetResponseStream()))
                {
                    if (reader.ReadToEnd().ToString().ToUpper() == "FALSE")
                    {
                        Logging.LogMessageToFile("Main - Movement = [FALSE]", "SENSOR");
                        movement = false;
                    }
                    else
                    {
                        Logging.LogMessageToFile("Main - Movement = [TRUE]", "SENSOR");
                        movement = true;
                    }
                    reader.Close();
                }
                WebResp.Close();
                Debug.Print(DateTime.Now + "," + temperature.ToString().Substring(0, 4) + "," + humidity.ToString() + "," + luminiscence.ToString() + "," + movement.ToString());
            }
            catch (Exception e)
            {
                Debug.Print("*********" + e.Message);
            }
        }
Ejemplo n.º 12
0
    private void start_get()
    {
        Movie movies;
        //CHANGE PATH
        string         text = File.ReadAllText(@"C:\Users\Gaurav And Jai\Desktop\1.3\IOT\imdb2\movies.txt");
        HttpWebRequest WebReq;

        HttpWebResponse WebResp;

        string jsonString;

        /*using (Stream stream = WebResp.GetResponseStream())   //modified from your code since the using statement disposes the stream automatically when done
         * {
         *  StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8);
         *  jsonString = reader.ReadToEnd();
         * }*/

        List <Item> items = JsonConvert.DeserializeObject <List <Item> >(text);

        string[] result;

        conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Users\Gaurav And Jai\Desktop\1.3\IOT\imdb2\users.accdb'";


        for (int i = 0; i < items.Count; i++)
        {
            result = items[i].url.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);

            WebReq        = (HttpWebRequest)WebRequest.Create(string.Format("http://www.omdbapi.com/?apikey=84739f5e&i=" + result[1]));
            WebReq.Method = "GET";
            WebResp       = (HttpWebResponse)WebReq.GetResponse();

            using (Stream stream = WebResp.GetResponseStream())
            {
                StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8);
                jsonString = reader.ReadToEnd();
            }

            movies = JsonConvert.DeserializeObject <Movie>(jsonString);

            Label1.Text = "Adding " + i;

            OleDbCommand cmdd = new OleDbCommand("INSERT into top100(imdbId,title,plot,poster,release,rating,pos) Values(@id,@name,@plot,@poster,@date,@rating,@pos)");

            cmdd.Parameters.Add("@Id", OleDbType.VarChar).Value     = movies.imdbID;
            cmdd.Parameters.Add("@name", OleDbType.VarChar).Value   = movies.Title;
            cmdd.Parameters.Add("@rating", OleDbType.VarChar).Value = movies.imdbRating;
            //cmdd.Parameters.AddWithValue("@rated", movies.Rated);
            cmdd.Parameters.Add("@date", OleDbType.VarChar).Value = movies.Released;
            //cmdd.Parameters.AddWithValue("@genre",  movies.Genre);
            cmdd.Parameters.Add("@poster", OleDbType.VarChar).Value = movies.Poster;
            cmdd.Parameters.Add("@plot", OleDbType.VarChar).Value   = movies.Plot;
            cmdd.Parameters.Add("@pos", OleDbType.VarChar).Value    = items[i].position;

            /* cmdd.Parameters.AddWithValue("@director", movies.Director);
             * cmdd.Parameters.AddWithValue("@writer", movies.Writer);
             * cmdd.Parameters.AddWithValue("@actors", movies.Actors);*/

            cmdd.Connection = conn;
            try
            {
                conn.Open();
                cmdd.ExecuteNonQuery();
                Label1.Text = "Data Added";
                conn.Close();
                //Response.Redirect("login.aspx");
            }

            catch (OleDbException ex)
            {
                Label1.Text = ex.Message;
                conn.Close();
            }

            finally
            {
                conn.Close();
            }
        }
    }