Beispiel #1
0
        /// <summary>
        /// Gets the country of the requesting user
        /// </summary>
        /// <returns>A string containing the country code (e.g. PK)</returns>
        public string GetCountry()
        {
            var cip = HttpContext.Current.Request.UserHostAddress;
            var requestMessageProperties      = OperationContext.Current.IncomingMessageProperties;
            var remoteEndpointMessageProperty = requestMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

            if (remoteEndpointMessageProperty != null)
            {
                LogManager.CurrentInstance.InfoLogger.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().GetType(), "Ip address:" + remoteEndpointMessageProperty.Address);
                try
                {
                    return(GeoLocator.GetLocation(remoteEndpointMessageProperty.Address));
                }
                catch (ApplicationException appExp)
                {
                    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
                    return(null);
                }
            }
            else
            {
                LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().GetType(), "Endpoint message property is null.");
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.ServerInternalError);
                return(null);
            }
        }
Beispiel #2
0
        private async void RunGps()
        {
            this.SetSearchState(true);
            this.SearchDescription = "Bestimme aktuelle Position ...";
            GlobalCoordinate position = await GeoLocator.GetCurrentPosition();

            if (position == null)
            {
                this.SetSearchState(false);
                CrossToast.ShowToast("Positionsbestimmung fehlgeschlagen!");
                return;
            }
            this.SearchDescription = "Suche Tankstellen ...";
            List <PriceInfo> results = await ApiRequests.RequestGasStations(new GlobalCoordinate(position.Latitude, position.Longitude));

            if (results == null)
            {
                this.SetSearchState(false);
                CrossToast.ShowToast("Suche fehlgeschlagen!");
                return;
            }
            if (results.Count > 0)
            {
                // Add prices to the database
                DbDataProvider.Instance.AddPricesToHistory(results);
                this.ResultsFound?.Invoke(this, results);
                this.SearchDescription = String.Empty; // bug fix for small return delay
            }
            else
            {
                this.SetSearchState(false);
                CrossToast.ShowToast("Es wurden keine Tankstellen gefunden.");
            }
        }
Beispiel #3
0
        public void CheckThatGetLocationByIpCorrectlyDeterminesLocations()
        {
            string county;
            string city;

            GeoLocator locator = new GeoLocator();

            Assert.True(locator.GetLocationByIp("5.22.129.156", out county, out city));
            Assert.Equal("Israel", county);
            Assert.Equal("Tel Aviv", city);

            Assert.True(locator.GetLocationByIp("221.0.0.1", out county, out city));
            Assert.Equal("China", county);
            Assert.Equal("Jinan", city);

            Assert.True(locator.GetLocationByIp("121.0.0.1", out county, out city));
            Assert.Equal("Australia", county);
            Assert.Equal("Townsville", city);

            Assert.True(locator.GetLocationByIp("21.0.0.1", out county, out city));
            Assert.Equal("United States", county);
            Assert.True(city.Contains("Columbus"));

            Assert.True(locator.GetLocationByIp("81.0.0.1", out county, out city));
            Assert.Equal("Spain", county);
            Assert.True(city.Contains("San Sebasti"));
        }
        public SolradNwpForecast GetNearestForecasts(int latitude, int longitude)
        {
            using var dbContext = new SolarRadiationDataContext().WithEnabledDebugging(); // print generated SQL to Debug output

            var locator = new GeoLocator(dbContext);

            return(locator.FindNearestLocation(latitude, longitude)?.ToSolradNwpForecast());
        }
Beispiel #5
0
        public LocusPage()
        {
            InitializeComponent();

            locator    = GeoLocator.Instance;
            translator = GeoTranslator.Instance;

            NavigateToMyLocation();
            //mapSlider.Value = 0;
        }
 public IEnumerable <BranchDto> QueryBranchesByCenterPoint(SimplePoint center, double buffer)
 {
     return(InAUnitOfWork(session =>
     {
         var geoLocator = new GeoLocator(session);
         var geoPoint = _mappingEngine.Map <SimplePoint, Point>(center);
         var results = geoLocator.Locate <Branch>(geoPoint, buffer);
         return results.Select(r => _mappingEngine.Map <Branch, BranchDto>(r)).ToList();
     }));
 }
Beispiel #7
0
        protected string GetPositionByIp(string IpV4)
        {
            GeoLocator.Ip IpAddress = new GeoLocator.Ip {
                address_v4 = IpV4
            };
            string res = $"ip = { new JavaScriptSerializer().Serialize(IpAddress)}\n";

            GeoLocator.Position position = new GeoLocator(YandexKey).GetByIp(IpAddress);
            res += $"Position = { new JavaScriptSerializer().Serialize(position)}\n";
            return(res);
        }
Beispiel #8
0
        protected string GetPositionByWifi(string mac)
        {
            GeoLocator.WiFi[] wfs = new GeoLocator.WiFi[] { new GeoLocator.WiFi {
                                                                mac = "00-1C-F0-E4-BB-F5"
                                                            } };
            string res = $"wifi_networks = { new JavaScriptSerializer().Serialize(wfs)}\n";

            GeoLocator.Position position = new GeoLocator(YandexKey).GetByWiFi(wfs);
            res += $"Position = { new JavaScriptSerializer().Serialize(position)}\n";
            return(res);
        }
Beispiel #9
0
        protected string GetAddressByIp(string IpV4)
        {
            GeoLocator.Ip IpAddress = new GeoLocator.Ip {
                address_v4 = IpV4
            };
            string res = $"ip = { new JavaScriptSerializer().Serialize(new { IpV4 })}\n";

            GeoLocator.Position position = new GeoLocator(YandexKey).GetByIp(IpAddress);
            GeoDecoder.Address  address  = position != null ? new GeoDecoder(YandexKey).GetAddressByPoint(position.latitude, position.longitude) : null;
            res += $"Address = { new JavaScriptSerializer().Serialize(address)}\n";
            return(res);
        }
Beispiel #10
0
        protected string GetPositionByGsm(int countrycode, int operatorid, int cellid, int lac)
        {
            GeoLocator.Gsm[] cells = new GeoLocator.Gsm[] {
                new GeoLocator.Gsm {
                    countrycode = countrycode,
                    operatorid  = operatorid,
                    cellid      = cellid,
                    lac         = lac,
                }
            };
            string res = $"gsm_cells = { new JavaScriptSerializer().Serialize(cells)}\n";

            GeoLocator.Position position = new GeoLocator(YandexKey).GetByGsm(cells);
            res += $"Position = { new JavaScriptSerializer().Serialize(position)}\n";
            return(res);
        }
Beispiel #11
0
        public ActionResult SearchRetailers(string filter)
        {
            if (!string.IsNullOrEmpty(filter))
            {
                //verify zip code
                int pageNum = 1;
                List <RetailModel> listRetailers = new List <RetailModel>();
                var model = new WhereToBuyModel();

                if (isFilterByZipCode(filter))
                {
                    model.RetailList   = RetailManager.GetByZipCode(this.Session, filter, false, pageNum, PAGE_SIZE);
                    model.DiamondList  = RetailManager.GetByZipCode(this.Session, filter, true, pageNum, DIAMOND_PAGE_SIZE);
                    model.SearchByDesc = "Zip Code";
                }
                else
                {
                    var locator = new GeoLocator(filter);

                    Task.Run(() => locator.Locate()).Wait();

                    string city  = locator.City;
                    string state = locator.State;

                    model.RetailList  = RetailManager.GetByCityAndState(this.Session, city, state, false, pageNum, PAGE_SIZE);
                    model.DiamondList = RetailManager.GetByCityAndState(this.Session, city, state, true, pageNum, DIAMOND_PAGE_SIZE);
                }

                model.SearchByValue = filter;

                return(RenderMultipleViews(new List <RenderViewInfo>()
                {
                    new RenderViewInfo()
                    {
                        ViewName = "retailersView", ViewPath = "~/Views/Partials/WhereToBuy/_DealersPartial.cshtml", Model = model
                    },
                    new RenderViewInfo()
                    {
                        ViewName = "diamondsView", ViewPath = "~/Views/Partials/WhereToBuy/_DiamondDealersPartial.cshtml", Model = model
                    }
                }));
            }
            return(new EmptyResult());
        }
Beispiel #12
0
        public async Task ViewMapAsync()
        {
            if (IsBusy)
            {
                return;
            }

            try
            {
                Position position = await GeoLocator.GetPositionAsync((int)TimeSpan.FromSeconds(8).TotalMilliseconds);
                await NavigateTo(new MapPage(position.Latitude, position.Longitude));
            }
            catch (Exception ex)
            {
                await UserDialogs.Instance.AlertAsync(ex.Message, "Error", "OK");
            }
            finally
            {
                IsBusy = false;
            }
        }
        public static IEnumerable <string> Parse(IEnumerable <CustomerGEOItem> items)
        {
            var geoLocator = new GeoLocator();

            var customers = items.GroupBy(x => x.customerid);
            var inserts   = customers.Select(g =>
            {
                var customer        = g.First();
                var customerAddress = geoLocator.GetCoordinatesAsync(customer.address, customer.city, customer.state, customer.postalcode, customer.country).Result;
                var employeeAddress = geoLocator.GetCoordinatesAsync(customer.employeeaddress, customer.employeecity,
                                                                     customer.employeestate, customer.employeepostal, customer.employeecountry).Result;

                var template = $@"UPDATE CUSTOMER SET LOCATION = {BingAddresToSDO_POINT_TYPE(customerAddress)},
                                  ROADTOEMPLOYEE = {BingPointsToLine(customerAddress, employeeAddress)}, X = {customerAddress.Coordinates.Longitude.ToDotted()}, Y = {customerAddress.Coordinates.Latitude.ToDotted()}
                                  WHERE CUSTOMERID = {g.Key};";
                return(template);
            });

            inserts = inserts.Append("commit; \r\n").Append("exit;");
            inserts = inserts.Prepend("SET SQLBLANKLINES ON;");
            return(inserts);
        }
Beispiel #14
0
        public async Task GetUserLocationAsync()
        {
            if (IsBusy)
            {
                return;
            }

            if (!GeoLocator.IsGeolocationEnabled)
            {
                await Application.Current.MainPage.DisplayAlert("Error Localizacion", "Es necesario activar el GPS", "Ok");

                IsBusy = false;
                return;
            }
            try
            {
                UserDialogs.Instance.ShowLoading("Obteniendo Ubicacion...");
                Position position = await GeoLocator.GetPositionAsync((int)TimeSpan.FromSeconds(8).TotalMilliseconds);

                UserDialogs.Instance.HideLoading();
                if (position == null)
                {
                    await Application.Current.MainPage.DisplayAlert("Error Localizacion", "No se pudo obtener tu ubicacion.", "Ok");

                    IsBusy = false;
                    return;
                }
                LatLong = position.Latitude.ToString() + "," + position.Longitude.ToString();
            }
            catch (Exception ex)
            {
                await UserDialogs.Instance.AlertAsync(ex.Message, "Error", "OK");
            }
            finally
            {
                IsBusy = false;
            }
        }
        public static IEnumerable <string> Parse(IEnumerable <EmployeeGEOItem> items)
        {
            var geoLocator = new GeoLocator();

            var inserts = items.Select(x =>
            {
                var employeeAddress = geoLocator.GetCoordinatesAsync(x.address, x.city, x.state, x.postalcode, x.country).Result;

                //var template = @$"UPDATE EMPLOYEE SET WORKINGAREA = {BingPointToCircle(employeeAddress, RADIUS)},
                //                    X = {employeeAddress.Coordinates.Longitude.ToDotted()},
                //                    Y = {employeeAddress.Coordinates.Latitude.ToDotted()},
                //                    radius = {RADIUS}
                //                  WHERE EMPLOYEEID = {x.employeeid};";

                var xx = employeeAddress.Coordinates.Longitude;
                var y  = employeeAddress.Coordinates.Latitude;


                var template = $@"UPDATE EMPLOYEE SET WORKINGAREA = SDO_GEOMETRY(
                    2003,
                    NULL,
                    NULL,
                    SDO_ELEM_INFO_ARRAY(1,1003,4),
                    SDO_ORDINATE_ARRAY({xx-RADIUS},{y},{xx},{y+RADIUS},{xx+RADIUS},{y})
                  ),
                    X = {employeeAddress.Coordinates.Longitude.ToDotted()},
                    Y = {employeeAddress.Coordinates.Latitude.ToDotted()},
                    radius = {RADIUS}
                  WHERE EMPLOYEEID = {x.employeeid};";
                return(template);
            });

            inserts = inserts.Append("commit; \r\n").Append("exit;");
            inserts = inserts.Prepend("SET SQLBLANKLINES ON;");
            return(inserts);
        }
Beispiel #16
0
        public void GetCountrySaudiTest()
        {
            var res = GeoLocator.GetCountry("45.135.115.234");

            Assert.True(res.Country.IsoCode == "SA", $"Country are Incorrect -> {res.Country.IsoCode}");
        }
Beispiel #17
0
 public GeoLocatorTests()
 {
     GeoLocator.SetCityDbPath("../../../../eqranews.geo/GeoDb/GeoLite2-City.mmdb");
     GeoLocator.SetCountryPath("../../../../eqranews.geo/GeoDb/GeoLite2-Country.mmdb");
 }
Beispiel #18
0
        public void GetCityTest()
        {
            var res = GeoLocator.GetCity("156.205.192.88");

            Assert.True(res.City.Name == "Cairo", $"City Incorrect -> {res.City.Name}");
        }
Beispiel #19
0
        public void GetCountryEgyptTest()
        {
            var res = GeoLocator.GetCountry("156.205.192.88");

            Assert.True(res.Country.IsoCode == "EG", "Country are Incorrect");
        }
 public void init()
 {
     instance = this;
     StartCoroutine(startGeoService());
 }