private void ProcessPing(string targetNameOrAddress) { string resolvedTargetName; IPAddress targetAddress; if (!InitProcessPing(targetNameOrAddress, out resolvedTargetName, out targetAddress)) { return; } if (!Continues.IsPresent) { WritePingHeader(resolvedTargetName, targetAddress.ToString()); } bool quietResult = true; byte[] buffer = GetSendBuffer(BufferSize); Ping sender = new Ping(); PingReply reply; PingOptions pingOptions = new PingOptions(MaxHops, DontFragment.IsPresent); PingReport pingReport = new PingReport(Source, resolvedTargetName); int timeout = TimeoutSeconds * 1000; int delay = Delay * 1000; for (int i = 1; i <= Count; i++) { try { reply = sender.Send(targetAddress, timeout, buffer, pingOptions); } catch (PingException ex) { string message = StringUtil.Format(TestConnectionResources.NoPingResult, resolvedTargetName, ex.Message); Exception pingException = new PingException(message, ex.InnerException); ErrorRecord errorRecord = new ErrorRecord( pingException, TestConnectionExceptionId, ErrorCategory.ResourceUnavailable, resolvedTargetName); WriteError(errorRecord); quietResult = false; continue; } if (Continues.IsPresent) { WriteObject(reply); } else { if (Quiet.IsPresent) { // Return 'true' only if all pings have completed successfully. quietResult &= reply.Status == IPStatus.Success; } else { pingReport.Replies.Add(reply); } WritePingProgress(reply); } // Delay between ping but not after last ping. if (i < Count && Delay > 0) { Thread.Sleep(delay); } } if (!Continues.IsPresent) { WritePingFooter(); } if (Quiet.IsPresent) { WriteObject(quietResult); } else { WriteObject(pingReport); } }
public void Verify_PingReport_Json_Output() { var endpoints = new Dictionary <string, IEnumerable <IEndpointDiagnostics> > { { "fts", new List <EndpointDiagnostics> { new EndpointDiagnostics { Id = "0x1415F11", Latency = 877909, Local = "127.0.0.1:54669", Remote = "centos7-lx1.home.somewhere.org:8094", State = ServiceState.Ok } } }, { "kv", new List <EndpointDiagnostics> { new EndpointDiagnostics { Id = "0x1415F12", Latency = 1182000, Local = "127.0.0.1:54670", Remote = "centos7-lx1.home.somewhere.org:11210", State = ServiceState.Ok, Scope = "bucketname" } } }, { "n1ql", new List <EndpointDiagnostics> { new EndpointDiagnostics { Id = "0x1415F13", Latency = 6217, Local = "127.0.0.1:54671", Remote = "centos7-lx1.home.somewhere.org:8093", State = ServiceState.Ok }, new EndpointDiagnostics { Id = "0x1415F14", Latency = 2213, Local = "127.0.0.1:54682", Remote = "centos7-lx2.home.somewhere.org:8095", State = ServiceState.Timeout } } }, { "cbas", new List <EndpointDiagnostics> { new EndpointDiagnostics { Id = "0x1415F15", Latency = 2213, Local = "127.0.0.1:54675", Remote = "centos7-lx1.home.somewhere.org:8095", State = ServiceState.Error } } }, { "view", new List <EndpointDiagnostics> { new EndpointDiagnostics { Id = "0x1415F16", Latency = 45585, Local = "127.0.0.1:54672", Remote = "centos7-lx1.home.somewhere.org:8092", State = ServiceState.Ok } } } }; var report = new PingReport("0xdeadbeef", 53, endpoints); var expected = JsonConvert.SerializeObject( JsonConvert.DeserializeObject(ResourceHelper.ReadResource(@"Data\ping_report.json")), Formatting.None ).Replace("[[sdk_version]]", ClientIdentifier.GetClientDescription()); Assert.AreEqual(expected, report.ToString()); }