private void button1_Click(object sender, EventArgs e) { //check server // Thread checkServer = new Thread(check_server_connection); if (this.login_text_box.Text.Equals(this.login) && this.password_text_box.Text.Equals(this.password)) { // invoke main test form //RADIUS LOGIN this.Hide(); // send request to a server ask for test parameters! main_test_form MainTest = new main_test_form(this.technician_full_name.Text, this.service_request_num.Text); MainTest.Closed += (s, args) => this.Close(); MainTest.Show(); } else { DialogResult dialogResult = MessageBox.Show("Имя или паполь введены неверно!", "Отказ", MessageBoxButtons.OK); } }
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); } }
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; }
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; }
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; }
public async Task<Object> ASUO_request(main_test_form form, Results results, String server){ //TODO 1 // Serialize results and prepare HTTP message var message = results.serializeRezults(); var httpWebRequest = (HttpWebRequest)WebRequest.Create(server); httpWebRequest.ContentType = "text/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { streamWriter.Write(message); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); //Get test results back and display it on the output console using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { JObject result = JObject.Parse(streamReader.ReadToEnd()); //{"Port speed":"auto","Port errors":"Error","Link status":"down"} results.PortSpeed = (String)result["Port speed"]; results.PortErrors = (String)result["Port errors"]; results.LinkStatus1 = (String)result["Link status"]; } return null; }