public void CreateNewQuestion() { this.ForeColor = null; this.BackColor = null; this.currentElementIndex = randCol.GetRandomIndex(); this.currentElement = allQuestions[currentElementIndex]; StringBuilder questionBuilder = new StringBuilder(); if (currentElement.TestType == NetTestType.Pattern) { if (this.WithCalculations && currentElement.Answer.Length > 1) { CalculationType type = GetCalculationType(currentElement.Answer); string testName = ConvertToString(type); if (!string.IsNullOrEmpty(testName)) { questionBuilder.AppendLine(testName); } this.rightAnswer = GenerateAnswer(currentElement.Answer, out this.answerText, type); } else { this.answerText = this.rightAnswer = currentElement.Answer; } questionBuilder.Append(currentElement.Question); } else if (currentElement.TestType == NetTestType.Number) { questionBuilder.Append(currentElement.Question); this.answerText = this.rightAnswer = currentElement.Answer; } if (!oneNet) { questionBuilder.AppendLine(); questionBuilder.Append(currentElement.BaseUnit.NetName); } this.questionText = questionBuilder.ToString(); if (currentElement.QuestionColor.HasValue) { if (currentElement.TestType == NetTestType.Pattern) { this.questionText = string.Empty; this.BackColor = currentElement.QuestionColor.Value; } else if (currentElement.TestType == NetTestType.Number) { this.ForeColor = currentElement.QuestionColor.Value; } } }
public void TCPingTest() { var ipv4 = IPAddress.Loopback; var ipv6 = IPAddress.IPv6Loopback; Assert.IsNull(NetTest.TCPing(ipv4)); Assert.IsNotNull(NetTest.TCPing(ipv4, 3389)); Assert.IsNotNull(NetTest.TCPing(ipv6, 3389)); }
private void PingOne(int index) { if (mainTable[index].Endpoint == string.Empty) { var ip = NetTest.GetIP(mainTable[index].HostsName); if (ip != null) { mainTable[index].Endpoint = ip.AddressFamily == AddressFamily.InterNetwork ? $@"{ip}:{rawTable[index].Port}" : $@"[{ip}]:{rawTable[index].Port}"; } else { return; } } var ipe = IPFormatter.ToIPEndPoint(mainTable[index].Endpoint); double?latency = null; var res = Timeout; var time = DateTime.Now; try { latency = NetTest.TCPing(ipe.Address, ipe.Port, Timeout); } catch { // ignored } if (latency != null) { res = Convert.ToInt32(Math.Round(latency.Value)); } else { //notifyIcon1.ShowBalloonTip(1000, time.ToString(CultureInfo.CurrentCulture), $"{mainTable[index].HostsName}\n{ipe}", ToolTipIcon.Error); } var log = new DateTable { Date = time, Latency = res }; mainTable[index].AddNewLog(log); if (MainList.SelectedRows.Count == 1) { var i = MainList.SelectedRows[0].Cells[0].Value as int?; if (i == index && DateList.Visible) { DateList.Invoke(() => { LoadLogs(log); }); } } }
public MobiledgeXIntegration() { // Set the platform specific way to get SIM carrier information. pIntegration = new PlatformIntegration(); // Platform integration needs to initialize first: me = new MatchingEngine(pIntegration.CarrierInfo, pIntegration.NetInterface, pIntegration.UniqueID); // Optional NetTesting. netTest = new NetTest(me); }
public void TCPingAsyncTest() { var ipv4 = IPAddress.Loopback; var ipv6 = IPAddress.IPv6Loopback; var latency = NetTest.TCPingAsync(ipv4).Result; Assert.IsNull(latency); latency = NetTest.TCPingAsync(ipv4, 3389).Result; Assert.IsNotNull(latency); latency = NetTest.TCPingAsync(ipv6, 3389).Result; Assert.IsNotNull(latency); }
private void FirstPing() { var t = new Task(() => { Parallel.For(0, mainTable.Count, (i, state) => { if (cts_PingTask.IsCancellationRequested) { state.Stop(); return; } if (IPFormatter.IsIPAddress(mainTable[i].HostsName)) //反查DNS { PingOne(i); if (cts_PingTask.IsCancellationRequested) { state.Stop(); return; } mainTable[i].HostsName = NetTest.GetHostName(IPAddress.Parse(mainTable[i].HostsName), ReverseDNSTimeout); } else { var ip = NetTest.GetIP(mainTable[i].HostsName); if (cts_PingTask.IsCancellationRequested) { state.Stop(); return; } if (ip != null) { mainTable[i].Endpoint = ip.AddressFamily == AddressFamily.InterNetwork ? $@"{ip}:{rawTable[i].Port}" : $@"[{ip}]:{rawTable[i].Port}"; } PingOne(i); } if (cts_PingTask.IsCancellationRequested) { state.Stop(); } }); //notifyIcon1.ShowBalloonTip(1000, ExeName, @"载入完毕", ToolTipIcon.Info); }); PingTasks.Add(t); t.Start(); }
public async void MobiledgeXAPICalls() { gameManager.clog("RegisterClient NOT IMPLEMENTED"); return; gameManager.clog("FindCloudlet NOT IMPLEMENTED"); return; gameManager.clog("GetAppPort NOT IMPLEMENTED"); return; gameManager.clog("GetUrl NOT IMPLEMENTED"); return; // NetTest netTest = new NetTest(integration.matchingEngine); foreach (AppPort ap in integration.FindCloudletReply.ports) { gameManager.clog("Port: proto: " + ap.proto + ", prefix: " + ap.fqdn_prefix + ", path_prefix: " + ap.path_prefix + ", port: " + ap.public_port); NetTest.Site site; // We're looking for one of the TCP app ports: if (ap.proto == LProto.L_PROTO_TCP) { // Add to test targets. if (ap.path_prefix == "") { site = new NetTest.Site { host = integration.GetHost(ap), port = integration.GetPort(ap) }; site.testType = NetTest.TestType.CONNECT; } else { site = new NetTest.Site { L7Path = integration.GetUrl("", ap) }; site.testType = NetTest.TestType.CONNECT; } if (useAltServer) { site.host = host; } l7Path = site.L7Path; netTest.sites.Enqueue(site); } } netTest.doTest(true); }
public MobiledgeXIntegration() { // Set the platform specific way to get SIM carrier information. pIntegration = new PlatformIntegration(); // The following is to allow Get{TCP, TLS, UDP}Connection APIs to return the configured // edge network path to your MobiledgeX AppInsts. Other connections will use the system // default network route. NetInterface netInterface = new SimpleNetInterface(pIntegration.NetworkInterfaceName); // Platform integration needs to initialize first: me = new MatchingEngine(pIntegration, netInterface); // Optional NetTesting. netTest = new NetTest(me); }
// Basic utility funtion to connect and disconnect from any TCP port. public async void RunNetTest() { NetTest nt = new NetTest(); while (shouldPing) { foreach (HostAndPort site in sites) { UnityEngine.Debug.Log("Pinging: " + site.host + ", port: " + site.port); double elapsed = nt.ConnectAndDisconnect(site.host, site.port); site.lastPingMs = elapsed; UnityEngine.Debug.Log("Round(-ish) trip to host: " + site.host + ", port: " + site.port + ", elapsed: " + elapsed); } await Task.Delay(5000); } }
public async void MobiledgeXAPICalls() { integration.UseWifiOnly(true); // RegisterAndFindCloudlet and VerifyLocation: FindCloudletReply findCloudletReply; try { gameManager.uiConsole.text = "Registering to DME: "; bool registeredAndFoundCloudlet = await integration.RegisterAndFindCloudlet(); if (!registeredAndFoundCloudlet) { gameManager.clog("Unable to register and find cloudlet"); return; } stopWatch.Start(); findCloudletReply = integration.FindCloudletReply; gameManager.clog("FindCloudletReply: status: " + findCloudletReply.status + ", fqdn: " + findCloudletReply.fqdn); // This might be inside a thread update loop. Re-register client and check periodically. // VerifyLocation will fail if verification is unavailable at the carrier. bool verifiedLocation = await integration.VerifyLocation(); // Decide what to do with location status. gameManager.clog("VerifiedLocation: " + verifiedLocation); } catch (RegisterClientException rce) { gameManager.clog("RegisterClientException: " + rce.Message + ". Make sure OrgName, AppName, and AppVers are correct."); return; } catch (FindCloudletException fce) { gameManager.clog("FindCloudletException: " + fce.Message + ". Make sure you have an app instance deployed to your region and carrier network"); return; } catch (DmeDnsException de) { // This app should fallback to public cloud, as the DME doesn't exist for your // SIM card + carrier. gameManager.clog("Cannot register to DME host: " + de.Message + ", Stack: " + de.StackTrace); if (de.InnerException != null) { gameManager.clog("Original Exception: " + de.InnerException.Message); } // Handle fallback to public cloud application server. return; } catch (Exception e) { gameManager.clog("Unexpected Exception: " + e.StackTrace); return; } // GetAppPort AppPort appPort; try { appPort = integration.GetAppPort(LProto.L_PROTO_TCP); } catch (AppPortException ape) { gameManager.clog("Unabled to get AppPort. AppPortException: " + ape.Message); return; } if (appPort == null) { gameManager.clog("GetAppPort returned null"); return; } // GetUrl try { edgeCloudletStr = integration.GetUrl("ws"); gameManager.clog("Found Cloudlet from DME result: [" + edgeCloudletStr + "]"); } catch (GetConnectionException gce) { gameManager.clog("Unabled to get url. GetConnectionException " + gce.Message); return; } // NetTest netTest = new NetTest(integration.matchingEngine); foreach (AppPort ap in findCloudletReply.ports) { gameManager.clog("Port: proto: " + ap.proto + ", prefix: " + ap.fqdn_prefix + ", path_prefix: " + ap.path_prefix + ", port: " + ap.public_port); NetTest.Site site; // We're looking for one of the TCP app ports: if (ap.proto == LProto.L_PROTO_TCP) { // Add to test targets. if (ap.path_prefix == "") { site = new NetTest.Site { host = integration.GetHost(ap), port = integration.GetPort(ap) }; site.testType = NetTest.TestType.CONNECT; } else { site = new NetTest.Site { L7Path = integration.GetUrl("", ap) }; site.testType = NetTest.TestType.CONNECT; } if (useAltServer) { site.host = host; } l7Path = site.L7Path; netTest.sites.Enqueue(site); } } netTest.doTest(true); }
private void FirstPing() { var t = new Task(() => { Parallel.For(0, mainTable.Count, (i, state) => { try { cts_PingTask.Token.ThrowIfCancellationRequested(); } catch (OperationCanceledException) { state.Stop(); return; } if (IPFormatter.IsIPv4Address(mainTable[i].HostsName)) //反查DNS { PingOne(i); try { cts_PingTask.Token.ThrowIfCancellationRequested(); } catch (OperationCanceledException) { state.Stop(); return; } mainTable[i].HostsName = NetTest.GetHostName(IPAddress.Parse(mainTable[i].HostsName), ReverseDNSTimeout); } else { var ip = NetTest.GetIP(mainTable[i].HostsName); try { cts_PingTask.Token.ThrowIfCancellationRequested(); } catch (OperationCanceledException) { state.Stop(); return; } if (ip != null) { mainTable[i].Endpoint = $@"{ip}:{rawTable[i].Port}"; } PingOne(i); } try { cts_PingTask.Token.ThrowIfCancellationRequested(); } catch (OperationCanceledException) { state.Stop(); } }); //notifyIcon1.ShowBalloonTip(1000, ExeName, @"载入完毕", ToolTipIcon.Info); }); PingTasks.Add(t); t.Start(); }