private async void beginTest_Click(object sender, EventArgs e) { Console.WriteLine("About to send data!"); this.progressBar1.Value = 0; try { if (!dataReceived) { await this.client.get_test_data(this, "http://localhost:8080/target", "message"); dataReceived = true; } this.begin_test.Enabled = false; await client.beginTest(this, results); await client.ASUO_request(this, results, "http://localhost:8080/getASUOdata"); client.displayFinalResults(this, results); } catch (Exception ex) { updateConsole n = new updateConsole(this.outputToConsole); n(System.Drawing.Color.Red, "Не удалось соединиться с сервером.", true); Console.WriteLine(ex.ToString()); Console.WriteLine("Something went wrong"); return; } }
internal void displayFinalResults(main_test_form form, Results results) { updateConsole n = new updateConsole(form.outputToConsole); n(System.Drawing.Color.Black, "\r\nРезультаты из АСУО:\r\n\r\n", true); n(System.Drawing.Color.Black, "\r\nТарифный план: "+results.TariffPlanCheck, true); n(System.Drawing.Color.Black, "\r\nСкорость Порта: ", true); n(System.Drawing.Color.Green, results.PortSpeed, false); if (results.LinkStatus1.Contains("up")) { n(System.Drawing.Color.Black, "\r\nСтатус линка: ", true); n(System.Drawing.Color.Green, results.LinkStatus1, false); } else { n(System.Drawing.Color.Black, "\r\nСтатус линка: ", true); n(System.Drawing.Color.Red, results.LinkStatus1, false); } if (results.PortErrors.Contains("Error")) { n(System.Drawing.Color.Black, "\r\nОшибки порта: ", true); n(System.Drawing.Color.Red, results.PortErrors, false); } else { n(System.Drawing.Color.Black, "\r\nОшибки порта: ", true); n(System.Drawing.Color.Green, results.PortErrors, false); } try { int cableLength = int.Parse(results.CableLength); if (cableLength <= 180) { n(System.Drawing.Color.Black, "\r\nДлина кабеля: ", true); n(System.Drawing.Color.Green, "ОК", false); } else throw new Exception(); } catch { n(System.Drawing.Color.Black, "\r\nДлина кабеля: ", true); if (results.CableLength.Contains("Нет")) n(System.Drawing.Color.Red, results.CableLength, false); else n(System.Drawing.Color.Red, "Error", false); } }
internal async Task<int> beginTest(main_test_form form, Results results) { updateConsole n = new updateConsole(form.outputToConsole); n(System.Drawing.Color.Red, "Внимание!!! Процедура должна занять некоторое время.\r\nПожалуйста дождитесь окончания процедуры.", true); n(System.Drawing.Color.Black, "\r\nТестируем...\r\n\r\n", true); n(System.Drawing.Color.Black, "Проверяем локальные хосты...\r\n", true); await pingLocalHostsMain(form, results); n(System.Drawing.Color.Black, "\r\n\r\nПроверяем внешние хосты...\r\n", true); await pingRemotelHostsMain(form, results); n(System.Drawing.Color.Black, "\r\n\r\nПроверяем скорость...\r\n", true); List<String> response = this.CheckSpeed(results); n(System.Drawing.Color.Black, "Скорость закачки: ", true); n(System.Drawing.Color.Green, response[0] + " Мб/с", false); n(System.Drawing.Color.Black, "Скорость выкачки: ", true); n(System.Drawing.Color.Green, response[1] + " Мб/с", false); updateProgressBar g = new updateProgressBar(form.fillProgressBar); g(10); return 0; }
private async Task<int> pingLocalHostsMain(main_test_form form, Results results) { for (int i = 0; i < this.parameters.localhostsR1.Count(); i++) { int fraction; try { fraction = 15 / this.parameters.localhostsR1.Count(); } catch (Exception e) { fraction = 15; } updateProgressBar g = new updateProgressBar(form.fillProgressBar); g(fraction); String host = this.parameters.localhostsR1[i].ToString(); results.localhosts_results.Add(host, new Dictionary<String, String>()); long roundTrip = 0; int count = 0; int failures = 0; for (int j = 0; j < 5; j++) { PingReply reply = await ping_test(this.parameters.localhostsR1[i]); if (reply.Status == IPStatus.Success) { roundTrip += reply.RoundtripTime; count++; } else { failures++; } Thread.Sleep(500); } //Updating results results.localhosts_results[host].Add("Sent packets", count.ToString()); results.localhosts_results[host].Add("Errors", failures.ToString()); results.localhosts_results[host].Add("Average response time", ((roundTrip * 1.0) / count).ToString()); //Updating console updateConsole n = new updateConsole(form.outputToConsole); n(System.Drawing.Color.Black, " ", true); n(System.Drawing.Color.Black, "Хост: " + host, true); n(System.Drawing.Color.Red, "Ошибок: " + failures + " || ", true); if (count > 0) n(System.Drawing.Color.Green, "Среднее время отклика: " + ((roundTrip * 1.0) / count) + "мс", false); else n(System.Drawing.Color.Red, "Хост не ответил ни разу.", false); } return 0; }
public async Task<int> get_test_data(main_test_form form, String server, String message) { var HTTPmessage = new Dictionary<String, String>{ {"parameters","parameters"} }; var content = new FormUrlEncodedContent(HTTPmessage); HttpClient client = new HttpClient(); HttpResponseMessage response = await client.PostAsync(server, content); if (response.IsSuccessStatusCode) { this.paramData = await response.Content.ReadAsStringAsync(); Console.WriteLine("Success!\r\n" + this.paramData); this.parameters.parseJsonData(paramData); } else { updateConsole n = new updateConsole(form.outputToConsole); n(System.Drawing.Color.Red, "\r\n\r\nНе получилось соединиться с сервером.", true); Console.WriteLine("Something went wrong..."); return -1; } return 0; }