//Десериализуем полученную строку из файла JSON и // отправляем на сервер // public static void SendGEO(object n) public static async Task SendGEO(object n) { try { DateTime localDate = DateTime.Now; //получаем время // Random rnd = new Random(); //string url = "https://localhost:44359/home/inputgeoJSON"; //string url = "http://random-red.ddns.net:62424/home/inputgeoJSON"; string jsonstr = printJSON(); GEO testgeo = JsonConvert.DeserializeObject <GEO>(jsonstr); GeoCoordinates GCcore = new GeoCoordinates(); await GCcore.InitGeoCoordinates(); int n1 = int.Parse(n.ToString()); //перобразовываем из n - object в n1 int //try //{ //GeoCoordinates GCcore = new GeoCoordinates(); for (int i = 0; i < n1; i++) { //Thread.Sleep(2000); Thread.Sleep(1000); //ждём одну секунду await GCcore.InitGeoCoordinates(); testgeo.LatitudeX = GCcore.printXGeoCoordinates(); testgeo.LongitudeY = GCcore.printYGeoCoordinates(); testgeo.geoDT = localDate.ToString("dd.MM.yyyy"); testgeo.geoTM = localDate.ToString("HH:mm:ss"); string json = JsonConvert.SerializeObject(testgeo); var httpRequest = (HttpWebRequest)WebRequest.Create(testgeo.url0); httpRequest.Method = "POST"; httpRequest.ContentType = "application/json"; using (var requestStream = httpRequest.GetRequestStream()) using (var writer = new StreamWriter(requestStream)) { writer.Write(json); } using (var httpResponse = httpRequest.GetResponse()) using (var responseStream = httpResponse.GetResponseStream()) using (var reader = new StreamReader(responseStream)) { string response = reader.ReadToEnd(); } //await GCcore.InitGeoCoordinates(); } } catch (WebException e) { var geogenlogpath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "geogen.log"); using (var log = File.CreateText(geogenlogpath)) { log.WriteLine(e); } //using (StreamWriter log = File.CreateText(pathlog)) //{ // log.WriteLine(e); // log.WriteLine("-----"); //} // Console.WriteLine(e); //показываем ошибку //Console.WriteLine(""); } //Console.WriteLine("===>OK<==="); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); //SetContentView(Resource.Layout.layout1); //========== //LocationManager locationManager; //=========== EditText countertext = FindViewById <EditText>(Resource.Id.textInputEditText1); EditText periodtext = FindViewById <EditText>(Resource.Id.textInputEditText2); TextView printtext = FindViewById <TextView>(Resource.Id.textView1); TextView printmess = FindViewById <TextView>(Resource.Id.textView2); //инфо1 TextView info2 = FindViewById <TextView>(Resource.Id.textView5); Button startbutton = FindViewById <Button>(Resource.Id.button1); Button geobutton = FindViewById <Button>(Resource.Id.button2); Button StartGEObutton = FindViewById <Button>(Resource.Id.button3); Button StopGEObutton = FindViewById <Button>(Resource.Id.button4); Button Settingsbutton = FindViewById <Button>(Resource.Id.button5); //========== //========== startbutton.Click += (sender, e) => { // int n0 = int.Parse(countertext.Text); //countertext.Text = "2"; int n0; if (int.TryParse(countertext.Text, out n0)) { Geocore.Settings.startSend(n0); } else { periodtext.Text = "В поле period укажите число."; } }; GeoStartStop GS = new GeoStartStop(); StartGEObutton.Click += (sender, e) => { // int n0 = int.Parse(countertext.Text); //countertext.Text = "2"; int m0; if (int.TryParse(periodtext.Text, out m0)) { GS.StartGeo(m0); info2.Text = "Начал отправку координат"; } else { info2.Text = "В поле укажите число."; } }; StopGEObutton.Click += (sender, e) => { // int n0 = int.Parse(countertext.Text); //countertext.Text = "2"; GS.StopGeo(); info2.Text = GS.mess(); }; GeoCoordinates GC = new GeoCoordinates(); GC.InitGeoCoordinates(); geobutton.Click += (sender, e) => { GC.InitGeoCoordinates(); double X0Latitude = GC.printXGeoCoordinates(); double Y0Longitude = GC.printYGeoCoordinates(); printmess.Text = X0Latitude.ToString() + ";" + Y0Longitude.ToString(); }; Settingsbutton.Click += (sender, e) => { //SetContentView(Resource.Layout.layout_settings); Intent intent = new Intent(this, typeof(SettingsLayout)); StartActivity(intent); }; }