Пример #1
0
        public async System.Threading.Tasks.Task  armarAsync(int uno, int dos, string tres,
                                                             string cuatro, string MacAddress1, string macRouter)
        {
            geo      _geo      = new geo();
            Position _position = await _geo.GetPosition();

            MiPing iping = manejador.getPing();

            Datos datos = new Datos()
            {
                lat          = (Double)_position.Latitude,
                lng          = (Double)_position.Longitude,
                RTT          = iping.RTTdeMiPing,
                status       = iping.status,
                address      = iping.Address,
                jitter       = calculate.getJitter(iping.RTTdeMiPing),
                lantency     = calculate.getLatency(iping.RTTdeMiPing),
                LinkSpeed    = uno,
                SignLevel    = dos,
                ssid         = tres,
                DefaultGate  = cuatro,
                MacAddress   = MacAddress1,
                mail         = Settings.email,
                pass         = Settings.pass,
                MacDelRouter = macRouter,
            };


            string  x       = envia.sendJson(datos);
            changer changer = new changer();

            changer.changerStatus(x);
        }
Пример #2
0
        public string sendJson(Datos datos)
        {
            changer status = new changer();
            var     result = "";

            try
            {
                var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://192.168.0.99" + "/api/data/data_gather"); //Settings.url + " /api/data/data_gather");

                httpWebRequest.ContentType = "application/json";                                                         //tipo de archivo que contiene o MIME
                httpWebRequest.Method      = "POST";                                                                     //METODO
                httpWebRequest.Timeout     = 10000;

                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = JsonConvert.SerializeObject(datos);

                    streamWriter.Write(json);
                    streamWriter.Flush();
                    streamWriter.Close();
                }

                HttpWebResponse myResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                if (myResponse.StatusCode == HttpStatusCode.OK)
                {
                    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        result = streamReader.ReadToEnd();
                    }
                }

                status.changerStatus(myResponse.StatusDescription);
                myResponse.Close();

                if (result != null)
                {
                    Console.WriteLine("envie un json");
                    Console.WriteLine("resultado es " + result.ToString());
                }
                else
                {
                    Console.WriteLine("resultado es " + result.ToString());
                }
            }
            catch (WebException ex)
            {
                var response = ex.Response as HttpWebResponse;
                if (response == null)
                {
                    throw;
                }
                return(response.StatusCode.ToString());
            }



            return(result);
        }
Пример #3
0
        private async void Button_click(object sender, EventArgs e)
        {
            //---------------------



            //var url = this.FindViewById<EditText>(Resource.Id.url);
            //Settings.url = url.Text;


            var    mail  = this.FindViewById <EditText>(Resource.Id.text_email);
            string email = mail.Text;

            if (email == "")
            {
                Toast.MakeText(ApplicationContext, "Debe introducir su correo electronico",
                               ToastLength.Long).Show();
            }
            else
            {
                Settings.email = email;
                // Toast.MakeText(ApplicationContext, Settings.email, ToastLength.Long).Show();
            }

            var    pass    = this.FindViewById <EditText>(Resource.Id.pass);
            string passwor = pass.Text;

            if (passwor == "")
            {
                Toast.MakeText(ApplicationContext, "Debe introducir su contraseña", ToastLength.Long).Show();
            }
            else
            {
                Settings.pass = passwor;
            }
            if (email != "" && passwor != "")
            {
                Toast.MakeText(ApplicationContext, "¡Enviando datos!", ToastLength.Long).Show();
                changer changer = new changer();
                try
                {
                    todologa todologa = new todologa();
                    todologa.request(this.ApplicationContext);
                }
                catch (Exception)
                {
                    // changer.changerStatus(x);
                }

                RunOnUiThread(() =>
                {
                    Intent testActivity = new Intent(this, typeof(MainStatus));
                    StartActivity(testActivity);
                });


                // Toast.MakeText(ApplicationContext, "¡Enviando Información!", ToastLength.Long).Show();
                //services1 sr = new services1();
                //sr.jsonencode();

                //    changer.changerStatus(response.status);

                // StartService(new Intent(this, typeof(services1)));
                ////StartService(new Intent(this, typeof(services1)));
                //try
                //{
                //    todologa todologa = new todologa();
                //    todologa.request(this.ApplicationContext);
                //    response response = JsonConvert.DeserializeObject<response>(Settings.estado);
                //    Toast.MakeText(ApplicationContext, response.status, ToastLength.Long).Show();

                //    changer.changerStatus(response.status);

                //    Toast.MakeText(ApplicationContext, "holaaaaa", ToastLength.Long).Show();


                //}
                //catch (Exception)
                //{
                //    Toast.MakeText(ApplicationContext, "No se encuentra el servidor", ToastLength.Long).Show();
                //    changer.changerStatus("404");

                //}
                ////string statusSwitch = response.status;
                //if (response.status != null)
                //{


                //}
                //else
                //{

                //}

                //switch (statusSwitch)
                //{
                //    case "200":
                //        Settings.estado = "Conectada";
                //        break;
                //    case "403":
                //        Settings.estado = "Error al conectarse";
                //        break;

                //    case "404":
                //        Settings.estado = "No se encuentra el AP";
                //        break;

                //    case "500":
                //        Settings.estado = "Error en el servidor";
                //        break;

                //    default:

                //        break;

                //}



                ////
            }


            // // Calculate calculate = new Calculate();
            //  //calculate.getJitter(ping.RTTdeMiPing);
            //escribir(email);
            //  leerFicheroMemoriaInterna();


            // bool y = await ManagerFicheros.IsFileExistAsync("prueba");

            // Toast.MakeText(ApplicationContext, y.ToString(), ToastLength.Long).Show();


            // x = await ManagerFicheros.ReadAllTextAsync("prueba");



            //    Thread hiloprincipal = new Thread(new ThreadStart(hilo2))
            //    {
            //        IsBackground = true
            //    };
            //    hiloprincipal.Start();
            //}


            //private void hilo2()
            //{
            //    try
            //    {
            //        Timer = new System.Timers.Timer();
            //        timer.Interval = 3000;
            //        timer.Elapsed += OnTimedEvent;
            //        timer.Enabled = true;
            //        timer.Start();
            //    }
            //    catch (Exception ex)
            //    {
            //       // Toast.MakeText(ApplicationContext, ex.Message, ToastLength.Long).Show();
            //    }

            //}

            //private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
            //{

            //    Thread hilo = new Thread(new ThreadStart(ejecutarhilo))
            //    {
            //        IsBackground = true
            //    };
            //    hilo.Start();
            //}
            //private async void ejecutarhilo()
            //{
            //    RunOnUiThread(async () =>
            //    {

            //todo lo que ponga aquí se repite cada x (ahora 1) segundo

            //ManegadorWifi manejador = new ManegadorWifi();

            // Context context = this.ApplicationContext;



            // double x = manejador.getPing("8.8.8.8");



            //geo _geo = new geo();
            //Position _position = await _geo.GetPosition();
            //Toast.MakeText(ApplicationContext, _position.Latitude.ToString() + "," + _position.Longitude, ToastLength.Long).Show();


            //ArmaJson miJson = new ArmaJson();
            // await miJson.armarAsync();



            //    });
        }