public ContentResult RunDiagnostics() { var diag = new StringBuilder(); try { Debug.WriteLine("RunDiagnostics(): START"); string currentIP = IpHelper.GetIPAddress(HttpContext.Request); string testingIP = "13.82.179.176"; Debug.WriteLine("RunDiagnostics(): Current IP: " + currentIP); Debug.WriteLine("RunDiagnostics(): Testing IP: " + testingIP); diag.AppendLine("Current IP: " + currentIP); diag.AppendLine("Testing IP: " + testingIP); var locTesting = GeoLocationHelper.GetLocationFromIp(IPAddress.Parse(testingIP)); // Geolocation not configured or not working if (locTesting == null) { diag.AppendLine("GeoLocation: Not working! Please configure Maxmind or another GeoIP provider"); return(Content(diag.ToString(), "text/plain")); } else { var locCurrent = GeoLocationHelper.GetLocationFromIp(IPAddress.Parse(currentIP)); string psCurrent = HttpHelper.GetSegmentList(GeoLocationHelper.GetCoordinatesFromIp(IPAddress.Parse(currentIP))); Debug.WriteLine("RunDiagnostics(): GeoLocation (current IP): {0} - {1}", locCurrent.CountryCode, locCurrent.Region); Debug.WriteLine("RunDiagnostics(): Segments (current IP): " + psCurrent); diag.AppendLine("GeoLocation (current IP): " + locCurrent.CountryCode + " - " + locCurrent.Region); diag.AppendLine("Segments (current IP): " + psCurrent); string psTesting = HttpHelper.GetSegmentList(GeoLocationHelper.GetCoordinatesFromIp(IPAddress.Parse(testingIP))); Debug.WriteLine("RunDiagnostics(): GeoLocation (testing IP): {0} - {1}", locTesting.CountryCode, locTesting.Region); Debug.WriteLine("RunDiagnostics(): Segments (testing IP): " + psTesting); diag.AppendLine("GeoLocation (testing IP): " + locTesting.CountryCode + " - " + locTesting.Region); diag.AppendLine("Segments (testing IP): " + psTesting); Debug.WriteLine("RunDiagnostics(): END"); return(Content(diag.ToString(), "text/plain")); } } catch (Exception ex) { Debug.WriteLine("RunDiagnostics(): Error: " + ex.Message); diag.AppendLine("Error while running diagnostics" + ex.Message); return(Content(diag.ToString(), "text/plain")); } }
private void PulseSessionStartHandler(object sender, CriterionEventArgs e) { var locker = LockingSingleton.GetInstance(); if (Monitor.TryEnter(locker.lockObj)) { try { if (!locker.isLocked) { locker.isLocked = true; Debug.WriteLine("PulseSessionStartHandler(): START"); string ip = IpHelper.GetIPAddress(new HttpRequestWrapper(HttpContext.Current.Request)); Debug.WriteLine("PulseSessionStartHandler(): IP:" + ip); CoordinatesModel coordinates = GeoLocationHelper.GetCoordinatesFromIp(IPAddress.Parse(ip)); if (coordinates == null) { e.HttpContext.Session["pulse_segments"] = new string[0]; locker.isLocked = false; return; } QueryPulse(coordinates, e.HttpContext.Session, locker); Debug.WriteLine("PulseSessionStartHandler(): END"); } else { Debug.WriteLine("PulseSessionStartHandler(): Another thread already started"); } } finally { // Ensure that the lock is released. Monitor.Exit(locker.lockObj); Debug.WriteLine("PulseSessionStartHandler(): Lock released"); } } }