/* 1. Ping the gateway and server if ok * 2. send request for test data (list of ip adresses and dns servers * 3. Receive data from server parse it, fill data structures * 4. ping hosts * 5. Check DNS * 6. Measure speed * 7. Send results to server * 8. display results on the screen * */ public Client(String tech_name, String service_request_num) { local_hosts2Ping = new List<IPAddress>(); remote_hosts2Ping = new List<IPAddress>(); dns_servers = new List<IPAddress>(); results = new Results(); this.set_tech_name(tech_name); this.set_service_request_number(service_request_num); }
public String json_encode() { Client client = new Client("Ivanov", "123"); Results results = new Results(); for (int i = 0; i < 20; i++) { String num = Convert.ToString(i); String rem = Convert.ToString(i + 100); results.localhosts_results.Add(num, num); results.remotehosts_results.Add(num, num); } results.SomeInt = 9999; results.someString = "HuivRot!"; String result = client.json_encode(results); Console.WriteLine(results); return result; }
public main_test_form(String tech_name, String service_request_num) { InitializeComponent(); //TODO //wait disable main form client = new Client(tech_name, service_request_num); results = new Results(); results.TechName = tech_name; results.RequestNum = service_request_num; //SEND REQUEST TO A SERVER VIA JSON SERIALIZER //IF SERVER DOES NOT RESPOND - PING GATEWAY //DISPLAY RESULTS TO A USER //TODO GET RESPOND FROM A SERVER WITH PARAMETERS, PARSE THEM }
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<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; }
public List<String> CheckSpeed(Results results) { ClassSpeedTest test = new ClassSpeedTest(); List<string> result = test.runSpeedTest(); try { results.DownloadSpeed = result[0]; } catch (Exception ex) { Console.WriteLine("Didn't get the result. Error: " + ex); } //const string tempfile = "tempfile.tmp"; //System.Net.WebClient webClient = new System.Net.WebClient(); //Console.WriteLine("Downloading file...."); //System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew(); //webClient.DownloadFile("http://mirror.internode.on.net/pub/test/10meg.test", tempfile); //sw.Stop(); //long speed; //double result; //FileInfo fileInfo = new FileInfo(tempfile); //if (sw.Elapsed.Seconds != 0){ // speed = (fileInfo.Length / sw.Elapsed.Seconds); // result = (double)speed * 0.000008; //} //else // result = 0; //Console.WriteLine("Download duration: {0}", sw.Elapsed); //Console.WriteLine("File size: {0} bytes", fileInfo.Length.ToString("N0")); //try //{ // FileInfo currentFile = new FileInfo(tempfile); // currentFile.Delete(); //} //catch (Exception ex) //{ // Debug.WriteLine("Error on file: {0}\r\n {1}", tempfile, ex.Message); //} return result; }