void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { // Local variables string ip = "-"; string status = "-"; StatusCode newStatus = StatusCode.Online; int imageIndex = 0; if (e.Error == null) // String downloaded successfully { // Remove line breaks from the IP address ip = e.Result.Replace("\r", "").Replace("\n", ""); StatusText = "Logging connection at: " + Global.ConvertTime(DateTime.Now); // Begin downloading the data, passing the IP to the DownloadDataCompleted event if (AppSettings.AutoDownload) { string url = string.Empty; long maximumSpeed = 0; foreach (ListViewItem item in Global.ConnectionLog) { long speed = item.SpeedByte; if (speed > maximumSpeed) { maximumSpeed = speed; } } // Auto-select URL based on maximum download speed if (maximumSpeed < 1024000) { // Download 0.6 MB file url = "http://81.169.245.14/~0.6MBfile.zip"; } else if (maximumSpeed < 1024000 * 2) { // Download 1.5 MB file url = "http://81.169.245.14/~1.5MBfile.zip"; } else if (maximumSpeed < 1024000 * 3) { // Download 3 MB file url = "http://81.169.245.14/~3MBfile.zip"; } else if (maximumSpeed < 1024000 * 5) { // Download 6 MB file url = "http://81.169.245.14/~6MBfile.zip"; } else { // Download 12 MB file url = "http://81.169.245.14/~12MBfile.zip"; } webClient.DownloadDataAsync(new Uri(url), ip); } else { webClient.DownloadDataAsync(new Uri(AppSettings.DownloadURL), ip); } } else // An error occured downloading the string { StatusText = "Unable to log connection: " + Global.ConvertTime(DateTime.Now); // Set status to Offline newStatus = StatusCode.Offline; imageIndex = 2; ip = "-"; if (!p_CurrentIP.Equals(ip)) { status = "IP Changed"; imageIndex = 1; p_CurrentIP = ip; } if (!p_CurrentStatus.Equals(newStatus)) { status = "Offline"; imageIndex = 2; p_CurrentStatus = newStatus; } // Create a new ListViewItem object ListViewItem item = new ListViewItem(DateTime.Now, 0); item.SubItems.Add(Global.ConvertBytes(0) + "/s"); item.SubItems.Add(p_CurrentIP); item.SubItems.Add("Offline"); item.SubItems.Add(status); item.ImageIndex = imageIndex; // Add the ListViewItem to the log AddItem(item); } }