public override WhoIsInformation GetInformationByIp(string ip) { var whois = new WhoIsInformation(); try { var city = Reader.City(ip); if (city != null) { whois.Country = city.Country.IsoCode; whois.City = city.City.Name; whois.PostalCode = city.Postal.Code; whois.Region = city.MostSpecificSubdivision.IsoCode; whois.Latitude = city.Location.Latitude; whois.Longitude = city.Location.Longitude; } else { Sitecore.Diagnostics.Log.Warn("Ip Address Not Found", this); } } catch (Exception ex) { Sitecore.Diagnostics.Log.Error("GeoIP Lookup Failed", ex, this); } return(whois); }
public override WhoIsInformation GetInformationByIp(string ip) { if (string.IsNullOrEmpty(ip)) { var ipaddress = GetUserIpAddress(); if (ipaddress == null) { return(null); } ip = ipaddress.ToString(); } string url = string.Format(Configuration.Settings.IpStackApiUrl, ip, Configuration.Settings.IpStackApiAccessKey); string jsonData = GetDataFromExternalService(url); if (string.IsNullOrEmpty(jsonData)) { return(null); } dynamic data = Json.Decode(jsonData); WhoIsInformation info = new WhoIsInformation { Country = data.country_code, City = data.city, Latitude = (double?)data.latitude, Longitude = (double?)data.longitude, Region = data.region_name, PostalCode = data.zip }; return(info); }
private WhoIsInformation GetGeoData() { var lat = this.Item.GetDouble(Templates.DemoContent.Fields.Latitude) ?? 0; var lon = this.Item.GetDouble(Templates.DemoContent.Fields.Longitude) ?? 0; if (lat == 0 || lon == 0) { return(null); } var geoData = new WhoIsInformation { Latitude = this.Item.GetDouble(Templates.DemoContent.Fields.Latitude) ?? 0, Longitude = this.Item.GetDouble(Templates.DemoContent.Fields.Longitude) ?? 0, AreaCode = this.Item[Templates.DemoContent.Fields.AreaCode], BusinessName = this.Item[Templates.DemoContent.Fields.BusinessName], City = this.Item[Templates.DemoContent.Fields.City], Country = this.Item[Templates.DemoContent.Fields.Country], Dns = this.Item[Templates.DemoContent.Fields.DNS], Isp = this.Item[Templates.DemoContent.Fields.ISP], MetroCode = this.Item[Templates.DemoContent.Fields.MetroCode], PostalCode = this.Item[Templates.DemoContent.Fields.PostalCode], Region = this.Item[Templates.DemoContent.Fields.Region], Url = this.Item[Templates.DemoContent.Fields.Url], IsUnknown = false }; return(geoData); }
public virtual void Add(string ip, WhoIsInformation value) { Assert.ArgumentNotNull(ip, "ip"); Assert.ArgumentNotNull(value, "value"); if (!Enabled) { return; } InnerCache.Add(ip, value, Settings.GeoIpCacheExpiryTime); }
public void UpdateSession(Session session, RequestInfo requestInfo) { if (requestInfo.Visitor != null) { var whois = new WhoIsInformation(); if (requestInfo.Visitor.Variables.SetIfPresent("Country", v => whois.Country = v) | requestInfo.Visitor.Variables.SetIfPresent("Region", v => whois.Region = v) | requestInfo.Visitor.Variables.SetIfPresent("City", v => whois.City = v)) { session.Interaction.SetWhoIsInformation(whois); } } }
private WhoIsInformation GetMockData() { var result = new WhoIsInformation(); var managerPath = Settings.GetSetting("GeoIpFallback.Mocks.ManagerPath", "/sitecore/system/Modules/GeoIP Fallback/New GepIP Manager"); if (!string.IsNullOrWhiteSpace(managerPath)) { var manager = Sitecore.Configuration.Factory.GetDatabase(_database).GetItem(managerPath); if (manager != null) { var cvCurrentLocation = CurrentLocation; if (manager.Statistics.Updated <= LastModified && cvCurrentLocation != null) { return(cvCurrentLocation); } if (cvCurrentLocation != null) { Tracker.Current.Session.Interaction.CustomValues.Remove(LocationCustomValuesKey); Tracker.Current.Session.Interaction.CustomValues.Remove(LastModifiedCustomValuesKey); } Sitecore.Data.Fields.ReferenceField currentLocation = manager.Fields[Constants.CurrentLocationFieldName]; if (currentLocation != null && currentLocation.TargetItem != null) { result.Country = currentLocation.TargetItem[Constants.CountryFieldName]; result.City = currentLocation.TargetItem[Constants.CityFieldName]; result.PostalCode = currentLocation.TargetItem[Constants.PostalCodeFieldName]; result.Longitude = currentLocation.TargetItem.Fields[Constants.LongitudeFieldName].HasValue ? double.Parse(currentLocation.TargetItem.Fields[Constants.LongitudeFieldName].Value) : (double?)null; result.Latitude = currentLocation.TargetItem.Fields[Constants.LatitudeFieldName].HasValue ? double.Parse(currentLocation.TargetItem.Fields[Constants.LongitudeFieldName].Value) : (double?)null; result.AreaCode = currentLocation.TargetItem[Constants.AreaCodeFieldName]; result.BusinessName = currentLocation.TargetItem[Constants.BusinessNameFieldName]; result.Dns = currentLocation.TargetItem[Constants.DnsFieldName]; result.Isp = currentLocation.TargetItem[Constants.IspFieldName]; result.MetroCode = currentLocation.TargetItem[Constants.MetroCodeFieldName]; result.Region = currentLocation.TargetItem[Constants.RegionFieldName]; result.Url = currentLocation.TargetItem[Constants.UrlFieldName]; CurrentLocation = result; LastModified = manager.Statistics.Updated; return(result); } } } result.BusinessName = "Not Available"; return(result); }
/// <summary>Retrieves the geo location information by IP.</summary> /// <param name="ip">The IP address.</param> /// <returns>The <see cref="WhoIsInformation"/>.</returns> public override WhoIsInformation GetInformationByIp(string ip) { Assert.ArgumentNotNullOrEmpty(ip, nameof(ip)); if (ip == "127.0.0.1" || ip == "::1") { ip = this.LocalIpReplacement; } GeoIpCache geoIpCache = GeoIpCacheManager.GeoIpCache; WhoIsInformation information = geoIpCache.Get(ip); if (information != null) { return(information); } try { GeoVisitorInformation info = new IpApiServiceAgent().GetVisitorInformation(ip); information = new WhoIsInformation { City = info.City, Country = info.Country, Isp = info.Isp, Latitude = info.Lat, Longitude = info.Lon, PostalCode = info.Zip, Region = info.Region }; geoIpCache.Add(ip, information); return(information); } catch (Exception ex) { HandleLookupErrorArgs handleLookupErrorArgs = new HandleLookupErrorArgs(ex); CorePipeline.Run(HandleLookupErrorPipelineName, handleLookupErrorArgs); if (handleLookupErrorArgs.Fallback == null) { throw; } if (handleLookupErrorArgs.CacheFallback) { geoIpCache.Add(ip, handleLookupErrorArgs.Fallback); } return(handleLookupErrorArgs.Fallback); } }
public override WhoIsInformation GetInformationByIp(string ip) { WhoIsInformation information = new WhoIsInformation(); var headerValue = HttpContext.Current.Request.Headers["X-Akamai-Edgescape"]; information.Country = ExtractValue("country_code", headerValue); information.PostalCode = ExtractValue("zip", headerValue); information.City = ExtractValue("city", headerValue); information.Region = ExtractValue("region_code", headerValue); information.Latitude = ExtractValue("lat", headerValue); information.Longitude = ExtractValue("long", headerValue); information.AreaCode = ExtractValue("areacode", headerValue); //ToDo: double check if I forgot any relevant values... I personalise only on country and city... return(information); }
public override WhoIsInformation Resolve(IPAddress ip) { var whoIsInformation = new WhoIsInformation(); var lookUpService = new LookupService(HostingEnvironment.MapPath(_databasePath), LookupService.GEOIP_STANDARD); var location = lookUpService.getLocation(ip); if (location != null) { Sitecore.Diagnostics.Log.Info("GeoIPFallback: current location was resolved by local MaxMind database.", this); whoIsInformation.Country = location.countryCode ?? string.Empty; Sitecore.Diagnostics.Log.Debug("GeoIPFallback: Country: " + whoIsInformation.Country, this); whoIsInformation.Region = location.regionName ?? string.Empty; Sitecore.Diagnostics.Log.Debug("GeoIPFallback: Region: " + whoIsInformation.Region, this); whoIsInformation.City = location.city ?? string.Empty; Sitecore.Diagnostics.Log.Debug("GeoIPFallback: City: " + whoIsInformation.City, this); whoIsInformation.PostalCode = location.postalCode ?? string.Empty; Sitecore.Diagnostics.Log.Debug("GeoIPFallback: Postal Code: " + whoIsInformation.PostalCode, this); whoIsInformation.Latitude = location.latitude; Sitecore.Diagnostics.Log.Debug("GeoIPFallback: Latitude: " + whoIsInformation.Latitude, this); whoIsInformation.Longitude = location.longitude; Sitecore.Diagnostics.Log.Debug("GeoIPFallback: Longitude: " + whoIsInformation.Longitude, this); whoIsInformation.MetroCode = location.metro_code <= 0 ? string.Empty : location.metro_code.ToString(); Sitecore.Diagnostics.Log.Debug("GeoIPFallback: Metro Code: " + whoIsInformation.MetroCode, this); whoIsInformation.AreaCode = location.area_code <= 0 ? string.Empty : location.area_code.ToString(); Sitecore.Diagnostics.Log.Debug("GeoIPFallback: Area Code: " + whoIsInformation.AreaCode, this); } else { Sitecore.Diagnostics.Log.Info( "GeoIPFallback: current location was not resolved by local MaxMind database.", this); whoIsInformation.BusinessName = "Not Available"; } return(whoIsInformation); }
private WhoIsInformation CreateWhoIsInformation(XDocument dom) { WhoIsInformation who = new WhoIsInformation(); foreach (var e in dom.Root.Elements()) { string key = e.Name.LocalName; string value = e.Value; FillWhoIsInformation(key, value, who); } if (who.IsEmpty) { return(WhoIsInformation.Unknown); } return(who); }
public void GetCurrent_NullLongitude_ReturnNull(double? latitude, ITracker tracker, CurrentInteraction interaction, WhoIsInformation whoIsInformation) { //Arrange whoIsInformation.Latitude = latitude; whoIsInformation.Longitude = null; interaction.HasGeoIpData.Returns(true); interaction.GeoData.Returns(new ContactLocation(() => whoIsInformation)); tracker.Interaction.Returns(interaction); var locationRepository = new LocationRepository(); using (new TrackerSwitcher(tracker)) { //Act var location = locationRepository.GetCurrent(); //Assert location.Should().BeNull(); } }
private void FillInforation(WhoIsInformation information) { information.Country = _dictionary.ContainsKey(Const.GeoIpProperties.CountryCode) ? _dictionary[Const.GeoIpProperties.CountryCode] : ""; information.Region = _dictionary.ContainsKey(Const.GeoIpProperties.GeoRegion) ? _dictionary[Const.GeoIpProperties.GeoRegion] : ""; information.City = _dictionary.ContainsKey(Const.GeoIpProperties.City) ? _dictionary[Const.GeoIpProperties.City] : ""; information.AreaCode = _dictionary.ContainsKey(Const.GeoIpProperties.AreaCode) ? _dictionary[Const.GeoIpProperties.AreaCode] : ""; information.PostalCode = _dictionary.ContainsKey(Const.GeoIpProperties.Zip) ? _dictionary[Const.GeoIpProperties.Zip] : ""; information.Isp = _dictionary.ContainsKey(Const.GeoIpProperties.Network) ? _dictionary[Const.GeoIpProperties.Network] : ""; string latitude = _dictionary.ContainsKey(Const.GeoIpProperties.Latitude) ? _dictionary[Const.GeoIpProperties.Latitude] : ""; double.TryParse(latitude, out double doubleLatitude); information.Latitude = doubleLatitude; string longitude = _dictionary.ContainsKey(Const.GeoIpProperties.Longitude) ? _dictionary[Const.GeoIpProperties.Longitude] : ""; double.TryParse(longitude, out double doubleLongitude); information.Longitude = doubleLongitude; }
public override WhoIsInformation Resolve(IPAddress ip) { var whoIsInformation = new WhoIsInformation(); using (var reader = new DatabaseReader(HostingEnvironment.MapPath(_databasePath))) { var city = reader.City(ip); if (city != null) { Sitecore.Diagnostics.Log.Info("GeoIPFallback: current location was resolved by local MaxMind database.", this); whoIsInformation.Country = city.Country.IsoCode; Sitecore.Diagnostics.Log.Debug("GeoIPFallback: Country: " + whoIsInformation.Country, this); whoIsInformation.City = city.City.Name; Sitecore.Diagnostics.Log.Debug("GeoIPFallback: City: " + whoIsInformation.City, this); whoIsInformation.PostalCode = city.Postal.Code; Sitecore.Diagnostics.Log.Debug("GeoIPFallback: Postal Code: " + whoIsInformation.PostalCode, this); whoIsInformation.Latitude = city.Location.Latitude; Sitecore.Diagnostics.Log.Debug("GeoIPFallback: Latitude: " + whoIsInformation.Latitude, this); whoIsInformation.Longitude = city.Location.Longitude; Sitecore.Diagnostics.Log.Debug("GeoIPFallback: Longitude: " + whoIsInformation.Longitude, this); whoIsInformation.MetroCode = city.MostSpecificSubdivision.Name; Sitecore.Diagnostics.Log.Debug("GeoIPFallback: Metro Code: " + whoIsInformation.MetroCode, this); whoIsInformation.AreaCode = city.MostSpecificSubdivision.IsoCode; Sitecore.Diagnostics.Log.Debug("GeoIPFallback: Area Code: " + whoIsInformation.AreaCode, this); } else { Sitecore.Diagnostics.Log.Info( "GeoIPFallback: current location was not resolved by local MaxMind database.", this); whoIsInformation.BusinessName = "Not Available"; } } return(whoIsInformation); }
public static bool UpdateGeoIpFromCookie(CurrentInteraction interaction) { bool html5Geolocation = Settings.GetBoolSetting("Analytics.HTML5Geolocation.Enabled", true); bool html5GeolocationSuccess = false; if (html5Geolocation && HttpContext.Current.Request.Cookies.AllKeys.Contains("Analytics.HTML5ReverseLookupResult")) { Log.Info("Analytics - Trying to resolve address by HTML5 geolocation cookie.", typeof(GeoIpHelper)); var geolocationCookie = HttpContext.Current.Request.Cookies["Analytics.HTML5ReverseLookupResult"]; if (geolocationCookie != null && !string.IsNullOrEmpty(geolocationCookie.Value)) { var cookieValue = WebUtility.UrlDecode(geolocationCookie.Value); try { dynamic geoData = JObject.Parse(cookieValue); var whois = new WhoIsInformation { Latitude = geoData.Lat, Longitude = geoData.Long, PostalCode = geoData.PostalCode, Country = geoData.Country, City = geoData.City, Region = geoData.Region }; interaction.SetGeoData(whois); html5GeolocationSuccess = true; } catch (Exception e) { Log.Error("Analytics - Error during HTML5 geolocation", e, typeof(GeoIpHelper)); } } } return(html5GeolocationSuccess); }
public HttpResponseMessage WhoAmI() { HttpResponseMessage response; try { var userIpAddress = GeoIpService.GetUserIpAddress(); WhoIsInformation whoami = LookupManager.GetInformationByIp(userIpAddress.ToString()); var userAgent = Request.Headers.UserAgent.ToString(); var di = DeviceDetectionManager.GetDeviceInformation(userAgent); response = Request.CreateResponse(HttpStatusCode.OK, new { Ip = userIpAddress.ToString(), whoami.Country, whoami.City, whoami.Region, whoami.PostalCode, Latitude = whoami.Latitude ?? 0, Longitude = whoami.Longitude ?? 0, Device = new { di.DeviceIsSmartphone, di.DeviceModelName, di.Browser, DeviceType = Enum.GetName(typeof(DeviceType), di.DeviceType), di.DeviceVendor } }); return(response); } catch (Exception ex) { Log.Error($"HomeController.WhoAmI(): Error while getting user's GeoIP and Device Detection information.", ex, this); response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Oops, it looks like something went wrong. Please try again."); return(response); } }
public void GetCurrent_Call_ReturnCityAndCountry(string city, string country, ITracker tracker, CurrentInteraction interaction, WhoIsInformation whoIsInformation) { //Arrange whoIsInformation.City = city; whoIsInformation.Country = country; interaction.HasGeoIpData.Returns(true); interaction.GeoData.Returns(new ContactLocation(() => whoIsInformation)); tracker.Interaction.Returns(interaction); var locationRepository = new LocationRepository(); using (new TrackerSwitcher(tracker)) { //Act var location = locationRepository.GetCurrent(); //Assert location.Should().NotBeNull(); location.City.Should().Be(city); location.Country.Should().Be(country); } }
/// <summary> /// Create WhoIsInformation object /// </summary> /// <param name="reader"></param> /// <returns></returns> private WhoIsInformation CreateWhoIsInformation(XmlReader reader) { WhoIsInformation who = new WhoIsInformation(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { string key = reader.Name; // move to content reader.Read(); string value = reader.Value; FillWhoIsInformation(key, value, who); } } if (who.IsEmpty) { return(WhoIsInformation.Unknown); } return(who); }
public override WhoIsInformation GetInformationByIp(string ip) { //IP doesn't matter here, but it is present in LookupProviderBase definition var information = new WhoIsInformation(); if (HttpContext.Current != null && HttpContext.Current.Request != null) { if (!string.IsNullOrEmpty(HttpContext.Current.Request.Headers[Const.HeaderNames.GeoIP])) { var headerValue = HttpContext.Current.Request.Headers[Const.HeaderNames.GeoIP]; if (!string.IsNullOrEmpty(headerValue)) { _dictionary = headerValue.ParseAkamaiHeader(); FillInforation(information); } return(information); } Sitecore.Diagnostics.Log.Error("X-Akamai-Edgescape header is not present, please configure Akamain in proper way: https://community.akamai.com/customers/s/article/Content-Targeting-a-basic-introduction?language=en_US", this); return(null); } Sitecore.Diagnostics.Log.Error("Foundation.Akamai.GeoIp.GetInformationByIp was called from thread where HttpContext.Current is not present", this); return(null); }
public static void GenerateHandlerEvent(string hostName, Guid userId, MessageItem messageItem, ExmEvents exmEvent, DateTime dateTime, string userAgent = null, WhoIsInformation geoData = null, string link = null) { string eventHandler; switch (exmEvent) { case ExmEvents.Open: eventHandler = "RegisterEmailOpened.ashx"; break; case ExmEvents.Unsubscribe: eventHandler = "RedirectUrlPage.aspx"; link = "/sitecore/Unsubscribe.aspx"; break; case ExmEvents.UnsubscribeFromAll: eventHandler = "RedirectUrlPage.aspx"; link = "/sitecore/UnsubscribeFromAll.aspx"; break; case ExmEvents.Click: eventHandler = "RedirectUrlPage.aspx"; break; default: throw new InvalidEnumArgumentException("No such event in ExmEvents"); } var queryStrings = GetQueryParameters(userId, messageItem, link); var encryptedQueryString = QueryStringEncryption.GetDefaultInstance().Encrypt(queryStrings); var parameters = encryptedQueryString.ToQueryString(true); var url = $"{hostName}/sitecore/{eventHandler}{parameters}"; var fakeData = new ExmFakeData { UserAgent = userAgent, RequestTime = dateTime, GeoData = geoData }; RequestUrl(url, fakeData); }
public void GetCurrent_Call_ReturnCityAndCountry(string city, string country, ITracker tracker, CurrentInteraction interaction, WhoIsInformation whoIsInformation) { //Arrange whoIsInformation.City = city; whoIsInformation.Country = country; interaction.HasGeoIpData.Returns(true); interaction.GeoData.Returns(new ContactLocation(() => whoIsInformation)); tracker.Interaction.Returns(interaction); var locationRepository = new LocationRepository(); using (new TrackerSwitcher(tracker)) { //Act var location = locationRepository.GetCurrent(); //Assert location.Should().NotBeNull(); location.City.Should().Be(city); location.Country.Should().Be(country); } }
public override WhoIsInformation GetInformationByIp(string ip) { #region Variable Declarations const string ModuleName = "SharedSource.GeoLite"; WhoIsInformation information = new WhoIsInformation(); #endregion Assert.ArgumentNotNull(ip, "ip"); string geoCityPath = Settings.GetSetting(ModuleName + ".DatabaseLocation.GeoLiteCity", "~/app_data/GeoLiteCity.dat"); string vLogging = Settings.GetSetting(ModuleName + ".VerboseLogging", "false"); bool vLoggingResult = false; bool verboseLogging = bool.TryParse(vLogging, out vLoggingResult); if (!vLoggingResult) { verboseLogging = false; } try { if (verboseLogging) { Log.Info(ModuleName + ": Lookup Initialized", this); Log.Info(ModuleName + ": IP Address: " + ip, this); Log.Info(ModuleName + ": geoLitePath: " + geoCityPath, this); Log.Info(ModuleName + ": full path: " + HostingEnvironment.MapPath(geoCityPath), this); } var lookUpService = new LookupService(HostingEnvironment.MapPath(geoCityPath), LookupService.GEOIP_STANDARD); var location = lookUpService.getLocation(ip); if (location != null) { information.Country = location.countryCode ?? string.Empty; if (verboseLogging) { Log.Info(ModuleName + ": information.Country = " + information.Country, this); } information.Region = location.regionName ?? string.Empty; if (verboseLogging) { Log.Info(ModuleName + ": information.Region = " + information.Region, this); } information.City = location.city ?? string.Empty; if (verboseLogging) { Log.Info(ModuleName + ": information.City = " + information.City, this); } information.PostalCode = location.postalCode ?? string.Empty; if (verboseLogging) { Log.Info(ModuleName + ": information.PostalCode = " + information.PostalCode, this); } information.Latitude = (location.latitude == 0) ? string.Empty : location.latitude.ToString(); if (verboseLogging) { Log.Info(ModuleName + ": information.Latitude = " + ((location.latitude == 0) ? string.Empty : location.latitude.ToString()), this); } information.Longitude = (location.longitude == 0) ? string.Empty : location.longitude.ToString(); if (verboseLogging) { Log.Info(ModuleName + ": information.Longitude = " + ((location.longitude == 0) ? string.Empty : location.longitude.ToString()), this); } information.MetroCode = (location.metro_code <= 0) ? string.Empty : location.metro_code.ToString(); if (verboseLogging) { Log.Info(ModuleName + ": information.MetroCode = " + ((location.metro_code <= 0) ? string.Empty : location.metro_code.ToString()), this); } information.AreaCode = (location.area_code <= 0) ? string.Empty : location.area_code.ToString(); if (verboseLogging) { Log.Info(ModuleName + ": information.AreaCode = " + ((location.area_code <= 0) ? string.Empty : location.area_code.ToString()), this); } } else { Log.Info(ModuleName + ": IP location cannot be determined. IP Address: " + ip, this); information.BusinessName = Settings.GetSetting(ModuleName + ".NoLocationText", "Not Available"); } if (verboseLogging) { Log.Info(ModuleName + ": IP Lookup Complete", this); } return information; } catch (Exception ex) { Log.Error(ModuleName + ": Exception occurred. Exception: " + ex.Message, this); } return null; }
/// <summary> /// Fill WhoIsInfomation Property /// /// Please refer following url about key and value /// http://ip-api.com/docs/api:returned_values /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="who"></param> protected virtual void FillWhoIsInformation(string key, string value, WhoIsInformation who) { Assert.ArgumentNotNull(key, "key"); Assert.ArgumentNotNull(value, "value"); Assert.ArgumentNotNull(who, "who"); if (string.IsNullOrWhiteSpace(value)) { return; } key = key.ToLowerInvariant(); switch (key) { case C.Country: // not used break; case C.CountryCode: who.Country = value; break; case C.Region: who.AreaCode = value; break; case C.RegionName: who.Region = value; break; case C.City: who.City = value; break; case C.Zip: who.PostalCode = value; break; case C.Lat: who.Latitude = value; break; case C.Lon: who.Longitude = value; break; case C.TimeZone: // not used break; case C.Isp: who.Isp = value; break; case C.Org: who.BusinessName = value; break; case C.AS: // not used break; case C.Reverse: who.Dns = value; break; case C.Query: // not used break; case C.Status: case C.Message: // not used here break; default: Log.Info("Unknown Key " + key, this); break; } }
protected virtual long GetDataLength(WhoIsInformation whoIsInformation) { int num = TypeUtil.SizeOfString(whoIsInformation.AreaCode) + TypeUtil.SizeOfString(whoIsInformation.BusinessName) + TypeUtil.SizeOfString(whoIsInformation.City) + TypeUtil.SizeOfString(whoIsInformation.Country) + TypeUtil.SizeOfString(whoIsInformation.Dns) + TypeUtil.SizeOfString(whoIsInformation.Isp) + TypeUtil.SizeOfString(whoIsInformation.MetroCode) + TypeUtil.SizeOfString(whoIsInformation.PostalCode) + TypeUtil.SizeOfString(whoIsInformation.Region) + TypeUtil.SizeOfString(whoIsInformation.Url) + 16 + 1; return((long)num); }
/// <summary> /// Get a random city by country /// </summary> /// <param name="country">The country name</param> /// <returns>A city name</returns> private static WhoIsInformation GetWhoIs(string country) { var id = new Random(Guid.NewGuid().GetHashCode()); var randomId = id.NextDouble(); var whois = new WhoIsInformation(); switch (country) { case "United Kingdom": if (randomId <= 0.2) { whois.Country = country; whois.City = "London"; whois.Region = "London"; } else if (randomId > 0.2 && randomId <= 0.4) { whois.Country = country; whois.City = "Liverpool"; whois.Region = "North West England"; } else if (randomId > 0.4 && randomId <= 0.6) { whois.Country = country; whois.City = "Bristol"; whois.Region = "South West"; } else if (randomId > 0.6 && randomId <= 0.8) { whois.Country = country; whois.City = "Manchester"; whois.Region = "North West England"; } else { whois.Country = country; whois.City = "Leeds"; whois.Region = "Yorkshire and the Humber"; } break; //case "Netherlands": // if (randomId <= 0.2) // { // city = "Amsterdam"; // } // else if (randomId > 0.2 && randomId <= 0.4) // { // city = "Groningen"; // } // else if (randomId > 0.4 && randomId <= 0.6) // { // city = "Leeuwarden"; // } // else if (randomId > 0.6 && randomId <= 0.8) // { // city = "Rotterdam"; // } // else // { // city = "Den Haag"; // } // break; case "Germany": if (randomId <= 0.2) { whois.Country = country; whois.City = "Stuttgart"; whois.Region = "Baden-Württemberg"; } else if (randomId > 0.2 && randomId <= 0.4) { whois.Country = country; whois.City = "Berlin"; whois.Region = "Berlin"; } else if (randomId > 0.4 && randomId <= 0.6) { whois.Country = country; whois.City = "Düsseldorf"; whois.Region = "North Rhine-Westphalia"; } else if (randomId > 0.6 && randomId <= 0.8) { whois.Country = country; whois.City = "Koblenz"; whois.Region = "Rhineland-Palatinate"; } else { whois.Country = country; whois.City = "Dresden"; whois.Region = "Saxony"; } break; case "Denmark": if (randomId <= 0.2) { whois.Country = country; whois.City = "Copenhagen"; whois.Region = "Capital of Denmark"; } else if (randomId > 0.2 && randomId <= 0.4) { whois.Country = country; whois.City = "Aarhus"; whois.Region = "Central Denmark"; } else if (randomId > 0.4 && randomId <= 0.6) { whois.Country = country; whois.City = "Odense"; whois.Region = "Southern Denmark"; } else if (randomId > 0.6 && randomId <= 0.8) { whois.Country = country; whois.City = "Aalborg"; whois.Region = "North Denmark"; } else { whois.Country = country; whois.City = "Frederiksberg"; whois.Region = "Capital of Denmark"; } break; case "France": if (randomId <= 0.2) { whois.Country = country; whois.City = "Paris"; whois.Region = "Île-de-France"; } else if (randomId > 0.2 && randomId <= 0.4) { whois.Country = country; whois.City = "Dijon"; whois.Region = "Burgundy"; } else if (randomId > 0.4 && randomId <= 0.6) { whois.Country = country; whois.City = "Strasbourg"; whois.Region = "Alsace"; } else if (randomId > 0.6 && randomId <= 0.8) { whois.Country = country; whois.City = "Bordeaux"; whois.Region = "Aquitaine"; } else { whois.Country = country; whois.City = "Montpellier"; whois.Region = "Languedoc-Roussillon"; } break; case "Japan": if (randomId <= 0.2) { whois.Country = country; whois.City = "Tokyo"; whois.Region = "Kantō"; } else if (randomId > 0.2 && randomId <= 0.4) { whois.Country = country; whois.City = "Sendai"; whois.Region = "Tōhoku"; } else if (randomId > 0.4 && randomId <= 0.6) { whois.Country = country; whois.City = "Sapporo"; whois.Region = "Hokkaidō"; } else if (randomId > 0.6 && randomId <= 0.8) { whois.Country = country; whois.City = "Osaka"; whois.Region = "Kansai"; } else { whois.Country = country; whois.City = "Matsuyama"; whois.Region = "Shikoku"; } break; } return whois; }
public static void GenerateHandlerEvent(string hostName, Guid contactId, MessageItem messageItem, EventType eventType, DateTime dateTime, string userAgent, WhoIsInformation geoData, string link) { string eventHandlerPath; switch (eventType) { case EventType.Open: eventHandlerPath = GetEventHandlePath(EventType.Open); break; case EventType.Unsubscribe: eventHandlerPath = GetEventHandlePath(EventType.Unsubscribe); link = "/sitecore modules/Web/EXM/Unsubscribe.aspx"; break; case EventType.UnsubscribeFromAll: eventHandlerPath = GetEventHandlePath(EventType.UnsubscribeFromAll); link = "/sitecore modules/Web/EXM/UnsubscribeFromAll.aspx"; break; case EventType.Click: eventHandlerPath = GetEventHandlePath(EventType.Click); break; case EventType.Bounce: GenerateBounce(hostName, contactId, messageItem, dateTime); return; case EventType.SpamComplaint: GenerateSpam(hostName, contactId, messageItem, dateTime); return; default: throw new InvalidEnumArgumentException("No such event in ExmEvents"); } var queryStrings = GetQueryParameters(contactId, messageItem, link); var encryptedQueryString = QueryStringEncryption.GetDefaultInstance().Encrypt(queryStrings); var parameters = encryptedQueryString.ToQueryString(true); var url = $"{hostName}{eventHandlerPath}{parameters}"; var fakeData = new RequestHeaderInfo { UserAgent = userAgent, RequestTime = dateTime, GeoData = geoData }; var response = RequestUrl(url, fakeData); if (!response.IsSuccessful) { Errors++; } if (response.IsSuccessful && eventType == EventType.Click) { EndSession(hostName, response); } }
public void GetCurrent_NullLongitude_ReturnNull(double?latitude, ITracker tracker, CurrentInteraction interaction, WhoIsInformation whoIsInformation) { //Arrange whoIsInformation.Latitude = latitude; whoIsInformation.Longitude = null; interaction.HasGeoIpData.Returns(true); interaction.GeoData.Returns(new ContactLocation(() => whoIsInformation)); tracker.Interaction.Returns(interaction); var locationRepository = new LocationRepository(); using (new TrackerSwitcher(tracker)) { //Act var location = locationRepository.GetCurrent(); //Assert location.Should().BeNull(); } }
protected virtual void FillWhoIsInformation(string key, string value, WhoIsInformation who) { Assert.ArgumentNotNull(key, "key"); Assert.ArgumentNotNull(value, "value"); Assert.ArgumentNotNull(who, "who"); if (string.IsNullOrWhiteSpace(value)) { return; } key = key.ToLowerInvariant(); switch (key) { case C.Ip: break; case C.ContinentCode: break; case C.CountryCode: who.Country = value; break; case C.CountryAName: break; case C.CountryJName: break; case C.PrefCode: who.AreaCode = value; break; case C.RegionCode: break; case C.PrefAName: who.Region = value; break; case C.PrefJName: break; case C.PrefLatitude: if (string.IsNullOrWhiteSpace(who.Latitude)) { who.Latitude = value; } break; case C.PrefLongtude: if (string.IsNullOrWhiteSpace(who.Longitude)) { who.Longitude = value; } break; case C.PrefCF: break; case C.CityCode: who.MetroCode = value; break; case C.CityAName: who.City = value; break; case C.CityJName: break; case C.CityLatitude: who.Latitude = value; break; case C.CityLongtude: who.Longitude = value; break; case C.CityCF: break; case C.BCFlag: break; case C.OrgCode: break; case C.OrgOfficeCode: break; case C.OrgIndependentCode: break; case C.OrgName: who.BusinessName = value; break; case C.OrgPrefCode: break; case C.OrgCityCode: break; case C.OrgZipCode: who.PostalCode = value; break; case C.OrgAliress: break; case C.OrgTel: break; case C.OrgFax: break; case C.OrgIpoType: break; case C.OrgDate: break; case C.OrgCapitalCode: break; case C.OrgEmployeesCode: break; case C.OrgGrossCode: break; case C.OrgPresclassent: break; case C.OrgIndustrialCategoryL: break; case C.OrgIndustrialCategoryM: break; case C.OrgIndustrialCategoryS: break; case C.OrgIndustrialCategoryT: break; case C.OrgDomainName: break; case C.OrgDomainType: break; case C.LineCode: break; case C.LineJName: who.Isp = value; break; case C.LineCF: break; case C.TimeZone: break; case C.TelCode: break; case C.StockTickerNumber: break; case C.DomainName: who.Dns = value; break; case C.DomainType: break; default: Log.Info("Unknown Key " + key, this); break; } }