Esempio n. 1
0
        /// <summary>
        /// Gets the language based on the users' location.
        /// 1. Language branch for the users country
        /// 2. null
        /// </summary>
        public LanguageBranch GetLanguageByCountry(IGeolocationResult location)
        {
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            return(_enabledLanguageBranches
                   .Where(IsLanguageBranchForCountry(location))
                   .FirstOrDefault());
        }
Esempio n. 2
0
        public static GeoCoordinate GetUsersPosition()
        {
            var requestIp = GetRequestIp();
            //requestIp = "146.185.31.213";//Temp, provoke error
            var ip       = IPAddress.Parse(requestIp);
            var provider = ServiceLocator.Current.GetInstance <GeolocationProviderBase>();
            IGeolocationResult result = provider.Lookup(ip);

            return(result != null ? result.Location : provider.Lookup(IPAddress.Parse("8.8.8.8")).Location);

            //return new GeoCoordinate(59.33, 18.07);
        }
        public static CoordinatesModel GetCoordinatesFromIp(IPAddress IpAddress)
        {
            IGeolocationResult location = GetLocationFromIp(IpAddress);

            if (location == null)
            {
                Debug.WriteLine("GeoLocationHelper.GetProvider(): Geolocation provider returned null for IP: " + IpAddress.ToString());
                return(null);
            }

            return(new CoordinatesModel {
                Latitude = location.Location.Latitude, Longitude = location.Location.Longitude
            });
        }
Esempio n. 4
0
 public static GeoCoordinate GetUsersPositionOrNull()
 {
     try
     {
         var requestIp             = GetRequestIp();
         var ip                    = IPAddress.Parse(requestIp);
         var provider              = ServiceLocator.Current.GetInstance <GeolocationProviderBase>();
         IGeolocationResult result = provider.Lookup(ip);
         return(result != null ? result.Location : null);
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 5
0
 public static GeoCoordinate GetUsersPositionOrNull()
 {
     try
     {
         var requestIp = GetRequestIp();
         //requestIp = "146.185.31.213";//Temp, provoke error
         var ip       = IPAddress.Parse(requestIp);
         var provider = ServiceLocator.Current.GetInstance <GeolocationProviderBase>();
         IGeolocationResult result = provider.Lookup(ip);
         return(result?.Location);
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 6
0
 public static GeoCoordinate GetUsersPositionOrNull()
 {
     try
     {
         var requestIp = GetRequestIp();
         //requestIp = "146.185.31.213";//Temp, provoke error
         var ip       = IPAddress.Parse(requestIp);
         var provider = Geolocation.Provider as GeolocationProvider;
         IGeolocationResult result = provider.Lookup(ip);
         return(result != null ? result.Location : null);
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Gets the language based on the users' location AND browser preferences.
        /// 1. Language branch for users' location AND browser preferences
        /// 2. null
        /// </summary>
        public LanguageBranch GetLanguageByCountryAndBrowserLanguage(IGeolocationResult location, IEnumerable <string> userBrowserLanguages)
        {
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            if (userBrowserLanguages == null)
            {
                throw new ArgumentNullException(nameof(userBrowserLanguages));
            }

            return(_enabledLanguageBranches
                   .Where(IsLanguageBranchForCountry(location))
                   .Where(IsLanguageBranchForBrowserLanguage(userBrowserLanguages))
                   .FirstOrDefault());
        }
Esempio n. 8
0
 //TODO: Add try-catch.
 public static IGeolocationResult GetUsersLocation()
 {
     try
     {
         var requestIp = GetRequestIp();
         //requestIp = "146.185.31.213";//Temp, provoke error
         var ip       = IPAddress.Parse(requestIp);
         var provider = ServiceLocator.Current.GetInstance <GeolocationProviderBase>();
         IGeolocationResult result = provider.Lookup(ip);
         return(result ?? provider.Lookup(IPAddress.Parse("8.8.8.8")));
     }
     catch
     {
         var provider = ServiceLocator.Current.GetInstance <GeolocationProviderBase>();
         return(provider.Lookup(IPAddress.Parse("8.8.8.8")));
     }
 }
Esempio n. 9
0
 //TODO: Add try-catch.
 public static IGeolocationResult GetUsersLocation()
 {
     try
     {
         var requestIp = GetRequestIp();
         //requestIp = "146.185.31.213";//Temp, provoke error
         var ip       = IPAddress.Parse(requestIp);
         var provider = Geolocation.Provider as GeolocationProvider;
         IGeolocationResult result = provider.Lookup(ip);
         return(result ?? provider.Lookup(IPAddress.Parse("8.8.8.8")));
     }
     catch
     {
         var provider = Geolocation.Provider as GeolocationProvider;
         return(provider.Lookup(IPAddress.Parse("8.8.8.8")));
     }
 }
Esempio n. 10
0
 public static string GetCountryCodeByIp()
 {
     try
     {
         var prov     = Geolocation.Provider as GeolocationProvider;
         var ipAdress = GetIpAddress();
         if (log.IsDebugEnabled)
         {
             log.Debug(string.Format("Guest IP adress: {0}", ipAdress));
         }
         IPAddress          ip     = IPAddress.Parse(ipAdress);
         IGeolocationResult result = prov.Lookup(ip);
         return(result.CountryCode);
     }
     catch (Exception)
     {
         return(string.Empty);
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Gets the market based on the IP address.
        /// </summary>
        /// <param name="geolocationResult">The geolocation result.</param>
        /// <returns></returns>
        public IMarket GetMarket(IGeolocationResult geolocationResult)
        {
            if (geolocationResult == null)
            {
                throw new System.ArgumentNullException(nameof(geolocationResult));
            }

            // Get ISO3166 country as commerce is using alpha3 codes and we only have an alpha2 code
            var country = Countries.GetCountryByAlpha2(geolocationResult.CountryCode);

            if (country == null)
            {
                return(null);
            }

            // Get market with this country enabled
            var marketsWithCountry =
                EnabledMarkets.Where(market => market.Countries.Any(c => c.Equals(country.Alpha3)));

            return(marketsWithCountry.FirstOrDefault());
        }
Esempio n. 12
0
 private Func <LanguageBranch, bool> IsLanguageBranchForCountry(IGeolocationResult location)
 {
     return(x => x.Culture.Name.Contains('-') &&
            x.Culture.Name.EndsWith(location.CountryCode));
 }
Esempio n. 13
0
 public static GeoLocation ToFindLocation(this IGeolocationResult geoLocationResult)
 {
     return(new GeoLocation(geoLocationResult.Location.Latitude, geoLocationResult.Location.Longitude));
 }
Esempio n. 14
0
        private (IMarket market, CultureInfo uiLanguage) GetMarket(HttpRequestBase request, IGeolocationResult geolocationResult)
        {
            var marketWithCountry = GetMarket(geolocationResult);

            if (marketWithCountry == null)
            {
                return(null, null);
            }

            var language = GetLanguage(request, marketWithCountry);

            return(marketWithCountry, language ?? marketWithCountry.DefaultLanguage);
        }
Esempio n. 15
0
        public IGeolocationResult GetGeolocation(IPAddress ip)
        {
            IGeolocationResult result = _geolocationProviderBase.Lookup(ip);

            return(result);
        }