private void RefreshList() { System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; lvwHosts.BeginUpdate(); foreach (ListViewItem itmX in lvwHosts.Items) { SocketPingEntry httpPingEntry = (SocketPingEntry)itmX.Tag; try { int pingTime = httpPingEntry.Ping(); itmX.SubItems[1].Text = pingTime.ToString(); if (pingTime > httpPingEntry.PingTimeOutMS) { itmX.ImageIndex = 2; itmX.BackColor = Color.Salmon; itmX.SubItems[1].Text = "Time-out (" + pingTime.ToString() + ")"; } else { itmX.ImageIndex = 0; itmX.BackColor = SystemColors.Window; } } catch (Exception ex) { itmX.SubItems[1].Text = ex.Message; itmX.ImageIndex = 2; itmX.BackColor = Color.Salmon; } } lvwHosts.EndUpdate(); System.Windows.Forms.Cursor.Current = Cursors.Default; toolStripStatusLabel1.Text = "Last updated " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); }
private void cmdTestAddress_Click(object sender, EventArgs e) { SocketPingEntry tmpSocketPingEntry = new SocketPingEntry(); tmpSocketPingEntry.HostName = txtAddress.Text; tmpSocketPingEntry.PortNumber = (int)nudPortNumber.Value; tmpSocketPingEntry.PingTimeOutMS = (int)nudTimeOut.Value; tmpSocketPingEntry.ReceiveTimeoutMS = (int)nudReceiveTimeout.Value; tmpSocketPingEntry.SendTimeoutMS = (int)nudSendTimeout.Value; tmpSocketPingEntry.UseTelnetLogin = chkUseTelNetLogin.Checked; tmpSocketPingEntry.UserName = txtUserName.Text; tmpSocketPingEntry.Password = txtPassword.Text; try { int pingTime = tmpSocketPingEntry.Ping(); if (pingTime == int.MaxValue) { throw new Exception("An error occured while trying to ping the URL\r\n" + tmpSocketPingEntry.LastError); } MessageBox.Show(string.Format("Test success!\r\nTime: {0}ms", pingTime), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void cmdOK_Click(object sender, EventArgs e) { if (CheckOKButtonEnable()) { SelectedSocketPingConfig.Entries.Clear(); foreach (ListViewItem lvi in lvwEntries.Items) { SocketPingEntry socketPingEntry = (SocketPingEntry)lvi.Tag; SelectedSocketPingConfig.Entries.Add(socketPingEntry); } DialogResult = System.Windows.Forms.DialogResult.OK; Close(); } }
private void cmdOK_Click(object sender, EventArgs e) { if (CheckOKButtonEnable()) { SelectedSocketPingEntry = new SocketPingEntry(); SelectedSocketPingEntry.HostName = txtAddress.Text; SelectedSocketPingEntry.PortNumber = (int)nudPortNumber.Value; SelectedSocketPingEntry.PingTimeOutMS = (int)nudTimeOut.Value; SelectedSocketPingEntry.ReceiveTimeoutMS = (int)nudReceiveTimeout.Value; SelectedSocketPingEntry.SendTimeoutMS = (int)nudSendTimeout.Value; SelectedSocketPingEntry.UseTelnetLogin = chkUseTelNetLogin.Checked; SelectedSocketPingEntry.UserName = txtUserName.Text; SelectedSocketPingEntry.Password = txtPassword.Text; DialogResult = System.Windows.Forms.DialogResult.OK; Close(); } }
public void ReadConfiguration(XmlDocument config) { XmlElement root = config.DocumentElement; Entries.Clear(); foreach (XmlElement addressNode in root.SelectNodes("hosts/host")) { SocketPingEntry socketPingEntry = new SocketPingEntry(); socketPingEntry.HostName = addressNode.ReadXmlElementAttr("name", ""); socketPingEntry.PortNumber = int.Parse(addressNode.ReadXmlElementAttr("port", "23")); socketPingEntry.ReceiveTimeoutMS = int.Parse(addressNode.ReadXmlElementAttr("receiveTimeoutMS", "30000")); socketPingEntry.SendTimeoutMS = int.Parse(addressNode.ReadXmlElementAttr("sendTimeoutMS", "30000")); socketPingEntry.UseTelnetLogin = bool.Parse(addressNode.ReadXmlElementAttr("useTelnetLogin", "false")); socketPingEntry.UserName = addressNode.ReadXmlElementAttr("userName", ""); socketPingEntry.Password = addressNode.ReadXmlElementAttr("password", ""); socketPingEntry.PingTimeOutMS = int.Parse(addressNode.ReadXmlElementAttr("pingTimeOutMS", "5000")); Entries.Add(socketPingEntry); } }