public override void RefreshDisplayData() { try { System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; lvwEntries.BeginUpdate(); foreach (ListViewItem itmX in lvwEntries.Items) { PingCollectorHostEntry host = (PingCollectorHostEntry)itmX.Tag; try { PingCollectorResult pingResult = host.Ping(); CollectorState result = host.GetState(pingResult); if (pingResult.Success) { itmX.SubItems[1].Text = pingResult.PingTime.ToString() + " ms"; itmX.SubItems[2].Text = pingResult.ResponseDetails; if (result == CollectorState.Good) { itmX.ImageIndex = 0; itmX.BackColor = SystemColors.Window; } else if (result == CollectorState.Warning) { itmX.ImageIndex = 1; itmX.BackColor = Color.SandyBrown; } else { itmX.ImageIndex = 2; itmX.BackColor = Color.Salmon; } } else { itmX.ImageIndex = 2; itmX.BackColor = Color.Salmon; if (pingResult.PingTime < 0) { itmX.SubItems[1].Text = "Err"; } itmX.SubItems[2].Text = pingResult.ResponseDetails; } } catch (Exception ex) { itmX.ImageIndex = 2; itmX.SubItems[1].Text = "Err"; itmX.SubItems[2].Text = ex.Message; itmX.BackColor = Color.Salmon; } } lvwEntries.EndUpdate(); System.Windows.Forms.Cursor.Current = Cursors.Default; toolStripStatusLabelDetails.Text = "Last updated " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } finally { } }
private PingCollectorResult RunPingTest() { PingCollectorResult result; PingCollectorHostEntry tmpPingCollectorHostEntry = new PingCollectorHostEntry(); if (cboPingType.SelectedIndex == 1) { tmpPingCollectorHostEntry.PingType = PingCollectorType.HTTP; if (!txtAddress.Text.ToUpper().StartsWith("HTTP")) { txtAddress.Text = "http://" + txtAddress.Text; } } else if (cboPingType.SelectedIndex == 2) { tmpPingCollectorHostEntry.PingType = PingCollectorType.Socket; } else { tmpPingCollectorHostEntry.PingType = PingCollectorType.Ping; } tmpPingCollectorHostEntry.Address = txtAddress.Text; tmpPingCollectorHostEntry.DescriptionLocal = txtDescription.Text; tmpPingCollectorHostEntry.MaxTimeMS = Convert.ToInt32(nudExpextedTime.Value); tmpPingCollectorHostEntry.TimeOutMS = Convert.ToInt32(nudTimeOut.Value); tmpPingCollectorHostEntry.HttpHeaderUserName = txtHTTPHeaderUsername.Text; tmpPingCollectorHostEntry.HttpHeaderPassword = txtHTTPHeaderPassword.Text; tmpPingCollectorHostEntry.HttpProxyServer = txtHttpProxy.Text; tmpPingCollectorHostEntry.HttpProxyUserName = txtProxyUsername.Text; tmpPingCollectorHostEntry.HttpProxyPassword = txtProxyPassword.Text; tmpPingCollectorHostEntry.HTMLContentContain = txtHTMLContent.Text; tmpPingCollectorHostEntry.IgnoreInvalidHTTPSCerts = chkIgnoreInvalidHTTPSCerts.Checked; tmpPingCollectorHostEntry.SocketPort = (int)nudPortNumber.Value; tmpPingCollectorHostEntry.ReceiveTimeOutMS = (int)nudReceiveTimeout.Value; tmpPingCollectorHostEntry.SendTimeOutMS = (int)nudSendTimeout.Value; tmpPingCollectorHostEntry.UseTelnetLogin = chkUseTelNetLogin.Checked; tmpPingCollectorHostEntry.TelnetUserName = txtUserName.Text; tmpPingCollectorHostEntry.TelnetPassword = txtPassword.Text; result = tmpPingCollectorHostEntry.Ping(); result.Success = tmpPingCollectorHostEntry.GetState(result) == CollectorState.Good; return(result); }