Exemple #1
0
 public App()
 {
     Current.DispatcherUnhandledException       += App_DispatcherUnhandledException;
     AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
     ThreadPool.QueueUserWorkItem((object state) =>
     {
         //WebMap.HttpGet("http://api.ipstack.com/check?access_key=c4358b1d5570b8a0fdc733e18c1045c6");
         WebAPIUtil.HttpGet("https://api.ipgeolocation.io/ipgeo?apiKey=01d110a5e710445b91306d8d3345657e");
     }, null);
     // Set this code once in App.xaml.cs or application startup
     SciChart.Charting.Visuals.SciChartSurface.SetRuntimeLicenseKey("//iyHPm7S5TmIROHMtSNDZ3aPNDr3ZKdPpDX7i3s5lNmnDFsA+g0fWBQgJLGrD6eUHBTjFul/uBiRmySEo3pH/RP3e81GiQpdqO1GG6+KjtAmPjTKvAa+ULLjfgxxIar19BQfpoNRgxtE0njKqr6w4+PFCg0zEaybGNq+w91eL/9bVo+9tYkSMdG00F/uSvuKpAGirLBj5f7PwDsvdpPrvWATZDzeQV4hZf01lEvecN2iXIlbvh4mmR6JMvodGmDhNveDrIQHXYSl+reIn1L0GIKkH6/63UXvioV5MS8Ir18mW4lLQAtQ+gdRrTgOd6UeppX4/+s/oqVzhGJgQd6nSnxr72dfr/1epVKyr5+omPsn1u8i6wNFFtRWuev0oSLpqwH4Q6um5QcH+2wXEF+bYMeb9rIJ2/Wgm2FNzjeWnN3Ale98QQpnvaQpWcaqi9VqCF/CQXkI14HCBYQktAQ/7+OjQTRSLlao6N3TUCN9SP/y6IDi7UPIBC0XC1/MrZdMTo1TZFFIp44BI70N08qTl63syK9r3/mn/2NBbbh5dv3HZ6TmJDKjiFywJVUt1Zj6hQqf/kQMSFmkfznNDrmT8WuPrbReqdzmb4hIk+/A04RpzhqL9mSxejdZrhQqhG66XT9BQ==");
 }
 public WebMap()
 {
     InitializeComponent();
     ThreadPool.QueueUserWorkItem((object state) =>
     {
         //var res = HttpGet("http://api.ipstack.com/check?access_key=c4358b1d5570b8a0fdc733e18c1045c6");
         //Format.IpStackApi location = JsonConvert.DeserializeObject<Format.IpStackApi>(res);
         var res = WebAPIUtil.HttpGet("https://api.ipgeolocation.io/ipgeo?apiKey=01d110a5e710445b91306d8d3345657e");
         if (res == null)
         {
             return;              //Stop if GET method catched an excption
         }
         Format.IpgeoLocationApi location = JsonConvert.DeserializeObject <Format.IpgeoLocationApi>(res);
         Application.Current.Dispatcher.Invoke(() => //Use invoke to refresh UI elements
         {
             if (myMap.ZoomLevel < 7)
             {
                 myMap.Center    = new Location(location.latitude, location.longitude);
                 myMap.ZoomLevel = 13;
             }
         });
     }, null);
 }
        /// <summary>
        /// Upload the data list to database and empty the data list if upload success.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void Upload(Object source, ElapsedEventArgs e)
        {
            int length = dataString.Length;

            if (length < 1)
            {
                return;
            }
            string data;

            lock (o)
            {
                data       = dataString;
                dataString = "";
            }
            string auth = Info.NeedAuth ? ("&u=" + Info.UserName + "&p=" + Info.PassWord) : "";
            string url  = Info.DataBaseAddress + "/write?db=" + Info.DataBaseName + "&precision=ms" + auth;//Dedabase name is WSN. Time precision is mill seconds.
            var    res  = WebAPIUtil.HttpPost(url, data);

            if (res == null && data.Length < 1000000)//limit maximum data length
            {
                dataString = data + dataString;
            }
        }