private void _btnAddHost_Click(object sender, EventArgs e) { IPScanHostState host = (IPScanHostState)_lvAliveHosts.SelectedItems[0].Tag; HostPinger pinger = new HostPinger(host.HostName, host.Address); ((PingForm)Owner).AddNewHost(pinger); }
private void _btnTrace_Click(object sender, EventArgs e) { IPScanHostState host = (IPScanHostState)_lvAliveHosts.SelectedItems[0].Tag; IPTraceForm form = new IPTraceForm(); form.Target = host.Address.ToString(); form.ShowDialog(this); }
private ListViewItem FindListViewItem(IPScanHostState host) { foreach (ListViewItem item in _lvAliveHosts.Items) { if (item.Tag == host) { return(item); } } return(null); }
void host_OnHostNameAvailable(IPScanHostState host) { if (InvokeRequired) { BeginInvoke(new IPScanHostState.HostNameAvailableDelegate(host_OnHostNameAvailable), host); return; } ListViewItem item = FindListViewItem(host); if (item != null) { item.SubItems[4].Text = host.HostName; } }
private void _scanner_OnAliveHostFound(IPScanner scanner, IPScanHostState host) { if (InvokeRequired) { BeginInvoke(new IPScanner.AliveHostFoundDelegate(_scanner_OnAliveHostFound), scanner, host); return; } ListViewItem item = new ListViewItem(); item.Tag = host; item.BackColor = Color.GreenYellow; item.SubItems.Add(host.Address.ToString()); item.SubItems.Add(""); item.SubItems.Add(""); item.SubItems.Add(""); _lvAliveHosts.Items.Add(item); _lvAliveHosts.Sort(); host.OnHostNameAvailable += new IPScanHostState.HostNameAvailableDelegate(host_OnHostNameAvailable); host.OnStateChange += new IPScanHostState.StateChangeDelegate(host_OnStateChange); if (!host.IsTesting()) { item.ImageIndex = (int)host.QualityCategory; item.SubItems[2].Text = host.AvgResponseTime.ToString("F02") + " ms"; item.SubItems[3].Text = ((float)(host.LossCount) / host.PingsCount).ToString("P"); item.SubItems[4].Text = host.HostName; } AddLogEntry("Host [" + host.Address.ToString() + "] is alive."); Timer newTimer = new Timer(); newTimer.Tag = item; newTimer.Interval = 2000; newTimer.Tick += new EventHandler(newTimer_Tick); newTimer.Enabled = true; }
private void host_OnStateChange(IPScanHostState host, IPScanHostState.State oldState) { if (InvokeRequired) { BeginInvoke(new IPScanHostState.StateChangeDelegate(host_OnStateChange), host, oldState); return; } if (!host.IsTesting()) { ListViewItem item = FindListViewItem(host); if (item != null) { if (host.IsAlive()) { item.ImageIndex = (int)host.QualityCategory; item.SubItems[2].Text = host.AvgResponseTime.ToString("F02") + " ms"; item.SubItems[3].Text = ((float)(host.LossCount) / host.PingsCount).ToString("P"); } else { AddLogEntry("Host [" + host.Address.ToString() + "] died."); host.OnStateChange -= host_OnStateChange; host.OnHostNameAvailable -= host_OnHostNameAvailable; item.BackColor = Color.IndianRed; Timer removeTimer = new Timer(); removeTimer.Tag = item; removeTimer.Interval = 2000; removeTimer.Tick += new EventHandler(removeTimer_Tick); removeTimer.Enabled = true; } } } }