Ejemplo n.º 1
0
        public string PushToFirebase(LatLngModel LatLngList)
        {
            string res          = string.Empty;
            string FireBaseURL  = ConfigurationManager.AppSettings["FirebaseURL"];
            string FireBaseAuth = ConfigurationManager.AppSettings["FirebaseAUTH"];
            string url          = string.Empty;

            try
            {
                Stopwatch s = new Stopwatch();
                s.Start();
                url = FireBaseURL + LatLngList.deviceid + "/.json?auth=" + FireBaseAuth;
                string resultOfPost = string.Empty;

                HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url);
                httpRequest.Method      = "PATCH";
                httpRequest.ContentType = "application/json";

                var buffer = Encoding.UTF8.GetBytes(CreateJson(LatLngList));
                httpRequest.ContentLength = buffer.Length;
                httpRequest.GetRequestStream().Write(buffer, 0, buffer.Length);
                var response = httpRequest.GetResponse();

                response.Close();
                httpRequest.GetRequestStream().Close();
                httpRequest.GetRequestStream().Flush();
                res = " " + url + " |  Success - " + s.Elapsed;
                s.Stop();
            }
            catch (Exception ex)
            {
                Log.Error("Error:" + url + " | " + ex);
            }
            return(res);
        }
Ejemplo n.º 2
0
        public ViewResult Weather(LatLngModel x)
        {
            Debug.WriteLine("***** TEST : " + x.lat.ToString());
            Rootobject r = GetWeather("43", "-79");

            return(View("Weather", r));
        }
Ejemplo n.º 3
0
        public string GenerateWEBURL(LatLngModel LatLng, string GMURL, string DefZoomLvl)
        {
            string res = string.Empty;

            try
            {
                GMURL += "maps?f=q&q=" + LatLng.Lat + "," + LatLng.Lng + "&z=" + DefZoomLvl;
                res    = GMURL;
            }
            catch (Exception ex)
            {
                //ignored
                Log.Error(ex);
            }
            return(res);
        }
Ejemplo n.º 4
0
        public string GenerateWEBURL(LatLngModel LatLng)
        {
            string res        = string.Empty;
            string GMURL      = ConfigurationManager.AppSettings["GMbaseURL"];
            string DefZoomLvl = ConfigurationManager.AppSettings["DefaultZoomLevel"];

            try
            {
                GMURL += "maps?f=q&q=" + LatLng.Lat + "," + LatLng.Lng + "&z=" + DefZoomLvl;
                res    = GMURL;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
            return(res);
        }
Ejemplo n.º 5
0
 public void PerformGETCallback()
 {
     try
     {
         string resultOfPost = string.Empty;
         string url          = GenerateURL();
         //initialize
         HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url);
         httpRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
         httpRequest.Credentials            = new NetworkCredential("*****@*****.**", "eleazgpsdemo");
         List <PositionModel> pos          = new List <PositionModel>();
         List <Logger>        logs         = new List <Logger>();
         HttpWebResponse      httpResponse = (HttpWebResponse)httpRequest.GetResponse();
         using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()))
         {
             resultOfPost = streamReader.ReadToEnd();
             pos          = JsonConvert.DeserializeObject <List <PositionModel> >(resultOfPost);
             streamReader.Close();
         }
         httpResponse.GetResponseStream().Close();
         httpResponse.GetResponseStream().Flush();
         foreach (var entry in pos)
         {
             LatLngModel _LatLng = new LatLngModel {
                 deviceid = Convert.ToInt32(entry.deviceId), Lat = Convert.ToDouble(entry.latitude), Lng = Convert.ToDouble(entry.longitude)
             };
             if (LatLngList.Where(x => x.deviceid == _LatLng.deviceid).Count() == 0)
             {
                 LatLngList.Add(_LatLng);
             }
             Log.Info(GenerateWEBURL(_LatLng) + PushToFirebase(_LatLng) + " GPSDeviceCount (" + LatLngList.Count() + ")");
         }
         //Log.Info(GenerateWEBURL(LatLngList) + PushToFirebase(LatLngList));
     }
     catch (Exception ex)
     {
         Log.Error(ex);
     }
     finally
     {
         NLog.LogManager.Flush();
     }
 }
Ejemplo n.º 6
0
        public LatLngModel UpdateLatLng(LatLngModel Latlng)
        {
            LatLngModel res = new LatLngModel();

            try
            {
                LatLngModel _entry = LatLngList.First(x => x.deviceid == Latlng.deviceid);
                _entry.PrevLat = (_entry.Lat == _entry.PrevLat) ? _entry.PrevLat : _entry.Lat;
                _entry.PrevLng = (_entry.Lng == _entry.PrevLng) ? _entry.PrevLng : _entry.Lng;
                _entry.Lat     = Latlng.Lat;
                _entry.Lng     = Latlng.Lng;
                res            = _entry;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
            return(res);
        }
Ejemplo n.º 7
0
        public ViewResult WeatherForm(LatLngModel x)
        {
            //Debug.WriteLine("***** TEST : " + x.lat.ToString());

            try
            {
                Rootobject r = GetWeather(x.lat.ToString(), x.lng.ToString());
                if (r.query.results != null)
                {
                    return(View("Weather", r));
                }
            } catch (Exception e)
            {
                ModelState.AddModelError(x.lat.ToString(), "Location not valid");
                return(View(x));
            }
            ModelState.AddModelError("lat", "Location not valid");
            return(View(x));
        }
Ejemplo n.º 8
0
        public string CreateJson(LatLngModel Latlng)
        {
            string res = string.Empty;

            try
            {
                Latlng = UpdateLatLng(Latlng);
                res    = JsonConvert.SerializeObject(new LatLngModel
                {
                    Lat      = Latlng.Lat,
                    Lng      = Latlng.Lng,
                    PrevLat  = Latlng.PrevLat,
                    PrevLng  = Latlng.PrevLng,
                    deviceid = Latlng.deviceid
                });
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
            return(res);
        }
Ejemplo n.º 9
0
 public List <PharmacyDto> GetByNear(LatLngModel latLngModel)
 {
     return(PharmacyLogic.GetByNear(latLngModel.Lat, latLngModel.Lng, latLngModel.MedicineCode));
 }