Example #1
0
        void hp_OnStopPinging(HostPinger host)
        {
            if (InvokeRequired)
            {
                Invoke(new OnPingDelegate(OnHostPing), new object[] { host });
                return;
            }

            lock (_table)
            {
                ListViewItem item = (ListViewItem)_table[host.ID];
                if (item != null)
                {
                    item.BackColor = Color.White;
                    item.ForeColor = Color.Black;

                    if (_selectedPinger == host)
                    {
                        _tbStartHost.Enabled  = true;
                        _tbRemoveHost.Enabled = true;
                        _tbStopHost.Enabled   = false;
                    }
                }
            }
        }
Example #2
0

        
Example #3
0

        
Example #4
0

        
Example #5
0
        public void Log(HostPinger host, string message)
        {
            PingForm.NotifyMessage(host, message);

            lock (this)
            {
                _fileWriter.WriteLine(LOG_ROW_FORMAT, DateTime.Now, host.HostIP, host.HostName, message);
                _fileWriter.Flush();
            }
        }
Example #6
0
        public DataSeriesNameParser(string namePattern, DataSeries series, HostPinger host, SeriesDataSources dataSource)
        {
            _series     = series;
            _host       = host;
            _dataSource = dataSource;

            _seriesNamePattern = namePattern;
            _series.Name       = Parse(_seriesNamePattern);

            _host.OnHostNameChanged += new OnHostNameChangedDelegate(_host_OnHostNameChanged);
        }
Example #7
0
 public static void NotifyMessage(HostPinger host, string message)
 {
     if (Application.OpenForms.Count > 0)
     {
         PingForm frm = ((PingForm)Application.OpenForms[0]);
         if (frm != null)
         {
             frm._notifyIcon.ShowBalloonTip(10000, host.HostName + "(" + host.HostIP.ToString() + ")",
                                            message, ToolTipIcon.Info);
         }
     }
 }
Example #8
0
        public DialogResult ShowDialog(IWin32Window owner, HostPinger host)
        {
            _host = host;

            DialogResult res = ShowDialog(owner);

            if (res == DialogResult.OK)
            {
                if (_host == null)
                {
                    bool ne = string.IsNullOrEmpty(_tbHostName.Text);
                    bool ae = string.IsNullOrEmpty(_tbHostIp.Text);
                    try
                    {
                        if (!ne && ae)
                        {
                            _host = new HostPinger(_tbHostName.Text);
                        }
                        else if (ne && !ae)
                        {
                            _host = new HostPinger(IPAddress.Parse(_tbHostIp.Text));
                        }
                        else if (!ne && !ae)
                        {
                            _host = new HostPinger(_tbHostName.Text, IPAddress.Parse(_tbHostIp.Text));
                        }

                        if (_host != null)
                        {
                            _host.Logger = DefaultLogger.Instance;
                        }
                    }
                    catch
                    {
                        _host = null;
                        return(DialogResult.Cancel);
                    }
                }

                _host.HostName          = _tbHostName.Text;
                _host.HostDescription   = _tbDescription.Text;
                _host.Timeout           = (int)_spTimeout.Value;
                _host.PingInterval      = (int)_spInterval.Value;
                _host.DnsQueryInterval  = (int)_spDnsInterval.Value;
                _host.PingsBeforeDead   = (int)_spPingsBeforeDeath.Value;
                _host.RecentHisoryDepth = (int)_spRecentDepth.Value;
                _host.BufferSize        = (int)_spBufferSize.Value;
                _host.TTL          = (int)_spTtl.Value;
                _host.DontFragment = _chkbDontFragent.Checked;
            }

            return(res);
        }
Example #9
0
        public void AddNewHost(HostPinger host)
        {
            HostOptions dlg = new HostOptions();

            if (dlg.ShowDialog(this, host) == DialogResult.OK)
            {
                bool exists = false;
                lock (_hosts)
                {
                    foreach (HostPinger hp in _hosts)
                    {
                        if (hp.HostIP != null && hp.HostIP == dlg.Host.HostIP)
                        {
                            exists = true;
                            break;
                        }
                    }
                }

                if (exists)
                {
                    MessageBox.Show("Host already exists.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                dlg.Host.Logger          = DefaultLogger.Instance;
                dlg.Host.OnPing         += new OnPingDelegate(OnHostPing);
                dlg.Host.OnStopPinging  += new OnHostPingerCommandDelegate(hp_OnStopPinging);
                dlg.Host.OnStartPinging += new OnHostPingerCommandDelegate(hp_OnStartPinging);

                lock (_hosts)
                {
                    _hosts.Add(dlg.Host);

                    HostDataSeries series = new HostDataSeries(this, dlg.Host);
                    _dataSeries.Add(dlg.Host, series);
                    //	_graphManager.RegisterSeries(series);
                }

                _hostListChanged = true;

                if (MessageBox.Show("Start pinging of the host?", "Start", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    dlg.Host.Start();
                }
            }
        }
Example #10
0
        private void _lvHosts_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_lvHosts.SelectedItems != null && _lvHosts.SelectedItems.Count > 0)
            {
                _selectedPinger = (HostPinger)_lvHosts.SelectedItems[0].Tag;
            }
            else
            {
                _selectedPinger = null;
            }

            _tbStartHost.Enabled  = _selectedPinger != null && !_selectedPinger.IsRunning;
            _tbRemoveHost.Enabled = _selectedPinger != null && !_selectedPinger.IsRunning;
            _tbStopHost.Enabled   = _selectedPinger != null && _selectedPinger.IsRunning;

            _tbHostOptions.Enabled = _selectedPinger != null;
        }
Example #11
0
        public void LogStatusChange(HostPinger host, HostStatus oldStatus, HostStatus newStatus)
        {
            switch (newStatus)
            {
            case HostStatus.Alive:
                Log(host, "Host is now alive!");
                break;

            case HostStatus.Dead:
                Log(host, "Host died!");
                break;

            case HostStatus.DnsError:
                Log(host, "Host name couldn't be resolved (DNS error)!");
                break;
            }
        }
Example #12
0
        public DialogResult ShowDialog(IWin32Window owner, HostPinger host)
        {
            _host = host;

            DialogResult res = ShowDialog(owner);

            if (res == DialogResult.OK)
            {
                if (_host == null)
                {
                    bool ne = string.IsNullOrEmpty(_tbHostName.Text);
                    bool ae = string.IsNullOrEmpty(_tbHostIp.Text);
                    try
                    {
                        if (!ne && ae)
                        {
                            _host = new HostPinger(_tbHostName.Text);
                        }
                        else if (ne && !ae)
                        {
                            _host = new HostPinger(IPAddress.Parse(_tbHostIp.Text));
                        }
                        else if (!ne && !ae)
                        {
                            _host = new HostPinger(_tbHostName.Text, IPAddress.Parse(_tbHostIp.Text));
                        }
                    }
                    catch
                    {
                        _host = null;
                        return(DialogResult.Cancel);
                    }
                }
                else
                {
                    _host.Timeout         = (int)_spTimeout.Value;
                    _host.PingInterval    = (int)_spInterval.Value;
                    _host.PingsBeforeDead = (int)_spPingsBeforeDeath.Value;
                    _host.BufferSize      = (int)_spBufferSize.Value;
                    _host.TTL             = (int)_spTtl.Value;
                    _host.DontFragment    = _chkbDontFragent.Checked;
                }
            }

            return(res);
        }
Example #13
0
        void hp_OnStartPinging(HostPinger host)
        {
            if (InvokeRequired)
            {
                Invoke(new OnPingDelegate(OnHostPing), new object[] { host });
                return;
            }

            lock (_table)
            {
                if ((ListViewItem)_table[host.ID] != null && _selectedPinger == host)
                {
                    _tbStartHost.Enabled  = false;
                    _tbRemoveHost.Enabled = false;
                    _tbStopHost.Enabled   = true;
                }
            }
        }
Example #14
0
        public PingForm()
        {
            InitializeComponent();

            XmlDocument config = new XmlDocument();

            config.Load("hosts.cfg");
            XmlNode hostsNode = config.ChildNodes[0];

            foreach (XmlNode node in hostsNode.ChildNodes)
            {
                try
                {
                    HostPinger hp = new HostPinger(node);
                    hp.OnPing += new PingDelegate(OnHostPing);
                    _hosts.Add(hp);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #15
0
        void OnHostPing(HostPinger host)
        {
            if (InvokeRequired)
            {
                Invoke(new OnPingDelegate(OnHostPing), new object[] { host });
                return;
            }

            lock (_table)
            {
                ListViewItem item = (ListViewItem)_table[host.ID];
                if (item != null)
                {
                    item.SubItems[0].Text = host.HostIP.ToString();
                    item.SubItems[1].Text = host.HostName;
                    item.SubItems[2].Text = host.HostDescription;

                    item.SubItems[3].Text = host.StatusName;

                    item.SubItems[4].Text = host.SentPackets.ToString();

                    item.SubItems[5].Text = host.ReceivedPackets.ToString();
                    item.SubItems[6].Text = PercentToString(host.ReceivedPacketsPercent);

                    item.SubItems[7].Text = host.LostPackets.ToString();
                    item.SubItems[8].Text = PercentToString(host.LostPacketsPercent);

                    item.SubItems[9].Text = host.LastPacketLost ? "Yes" : "No";

                    item.SubItems[10].Text = host.ConsecutivePacketsLost.ToString();
                    item.SubItems[11].Text = host.MaxConsecutivePacketsLost.ToString();

                    item.SubItems[12].Text = host.RecentlyReceivedPackets.ToString();
                    item.SubItems[13].Text = PercentToString(host.RecentlyReceivedPacketsPercent);

                    item.SubItems[14].Text = host.RecentlyLostPackets.ToString();
                    item.SubItems[15].Text = PercentToString(host.RecentlyLostPacketsPercent);

                    item.SubItems[16].Text = host.CurrentResponseTime.ToString();
                    item.SubItems[17].Text = host.AverageResponseTime.ToString("F");

                    item.SubItems[18].Text = host.MinResponseTime.ToString();
                    item.SubItems[19].Text = host.MaxResponseTime.ToString();

                    item.SubItems[20].Text = DurationToString(host.CurrentStatusDuration);

                    item.SubItems[21].Text = DurationToString(host.GetStatusDuration(HostStatus.Alive));
                    item.SubItems[22].Text = DurationToString(host.GetStatusDuration(HostStatus.Dead));
                    item.SubItems[23].Text = DurationToString(host.GetStatusDuration(HostStatus.DnsError));
                    item.SubItems[24].Text = DurationToString(host.GetStatusDuration(HostStatus.Unknown));

                    item.SubItems[25].Text = PercentToString(host.HostAvailability);

                    item.SubItems[26].Text = DurationToString(host.TotalTestDuration);
                    item.SubItems[27].Text = DurationToString(host.CurrentTestDuration);
                }
                else
                {
                    item = new ListViewItem(new string[]
                    {
                        host.HostIP.ToString(), host.HostName, host.HostDescription,
                        host.StatusName,
                        host.SentPackets.ToString(),
                        host.ReceivedPackets.ToString(), PercentToString(host.ReceivedPacketsPercent),
                        host.LostPackets.ToString(), PercentToString(host.LostPacketsPercent),
                        host.LastPacketLost ? "Yes" : "No",
                        host.ConsecutivePacketsLost.ToString(), host.MaxConsecutivePacketsLost.ToString(),
                        host.RecentlyReceivedPackets.ToString(), PercentToString(host.RecentlyReceivedPacketsPercent),
                        host.RecentlyLostPackets.ToString(), PercentToString(host.RecentlyLostPacketsPercent),
                        host.CurrentResponseTime.ToString(), host.AverageResponseTime.ToString("F"),
                        host.MinResponseTime.ToString(), host.MaxResponseTime.ToString(),
                        DurationToString(host.CurrentStatusDuration),
                        DurationToString(host.GetStatusDuration(HostStatus.Alive)),
                        DurationToString(host.GetStatusDuration(HostStatus.Dead)),
                        DurationToString(host.GetStatusDuration(HostStatus.DnsError)),
                        DurationToString(host.GetStatusDuration(HostStatus.Unknown)),
                        PercentToString(host.HostAvailability),
                        DurationToString(host.TotalTestDuration),
                        DurationToString(host.CurrentTestDuration)
                    });

                    _table.Add(host.ID, item);
                    item.Tag = host;
                    _lvHosts.Items.Insert(0, item);
                }

                switch (host.Status)
                {
                case HostStatus.Dead:
                    item.BackColor = Color.Red;
                    item.ForeColor = Color.White;
                    break;

                case HostStatus.DnsError:
                    item.BackColor = Color.OrangeRed;
                    item.ForeColor = Color.White;
                    break;

                case HostStatus.Alive:
                    item.BackColor = Color.LightGreen;
                    item.ForeColor = Color.Black;
                    break;

                case HostStatus.Unknown:
                    item.BackColor = Color.Yellow;
                    item.ForeColor = Color.Black;
                    break;
                }

                if (host == _selectedPinger)
                {
                    _tbStartHost.Enabled  = !_selectedPinger.IsRunning;
                    _tbRemoveHost.Enabled = !_selectedPinger.IsRunning;
                    _tbStopHost.Enabled   = _selectedPinger.IsRunning;
                }
            }
        }
Example #16
0
 public void LogStart(HostPinger host)
 {
     Log(host, "Pinging started");
 }
Example #17
0
 private void _host_OnHostNameChanged(HostPinger host)
 {
     _series.Name = Parse(_seriesNamePattern);
 }
Example #18
0
 public void LogStop(HostPinger host)
 {
     Log(host, "Pinging stopped");
 }
Example #19
0
 public void LogStart(HostPinger host)
 {
     Log(host, "Pinging ...");
 }
Example #20
0
        void OnHostPing(HostPinger host)
        {
            if (InvokeRequired)
            {
                Invoke(new PingDelegate(OnHostPing), new object[] { host });
                return;
            }

            lock (_table)
            {
                ListViewItem item = (ListViewItem)_table[host.HostIP];
                if (item != null)
                {
                    item.SubItems[0].Text = host.HostIP.ToString();
                    item.SubItems[1].Text = host.HostName;
                    item.SubItems[2].Text = host.Status.ToString();
                    item.SubItems[3].Text = DurationToString(host.StatusDuration);

                    item.SubItems[4].Text = host.SentPackets.ToString();
                    item.SubItems[5].Text = host.LostPackets.ToString();
                    item.SubItems[6].Text = String.Format("{0:P}", host.LostPacketsPercent / 100);
                    item.SubItems[7].Text = host.CurrentResponseTime.ToString();
                    item.SubItems[8].Text = host.AvargeResponseTime.ToString("F");
                    item.SubItems[9].Text = DurationToString(host.TestDuration);
                }
                else
                {
                    item = new ListViewItem(new string[]
                    {
                        host.HostIP.ToString(), host.HostName, host.Status.ToString(), DurationToString(host.StatusDuration),
                        host.SentPackets.ToString(), host.LostPackets.ToString(), String.Format("{0:P}", host.LostPacketsPercent / 100),
                        host.CurrentResponseTime.ToString(), host.AvargeResponseTime.ToString("F"), DurationToString(host.TestDuration)
                    });

                    _table.Add(host.HostIP, item);
                    item.Tag = host;
                    _lvHosts.Items.Insert(0, item);
                }

                switch (host.Status)
                {
                case HostStatus.Dead:
                    item.BackColor = Color.Red;
                    item.ForeColor = Color.White;
                    break;

                case HostStatus.Alive:
                    item.BackColor = Color.LightGreen;
                    item.ForeColor = Color.Black;
                    break;

                case HostStatus.Unknown:
                    item.BackColor = Color.Yellow;
                    item.ForeColor = Color.Black;
                    break;
                }

                if (host == _selectedPinger)
                {
                    _tbStartHost.Enabled  = !_selectedPinger.IsRunning;
                    _tbRemoveHost.Enabled = !_selectedPinger.IsRunning;
                    _tbStopHost.Enabled   = _selectedPinger.IsRunning;
                }
            }
        }
Example #21
0
 public DataSeriesNameParser(DataSeries series, HostPinger host, SeriesDataSources dataSource) : this(DEFAULT_NAME_PATTERN, series, host, dataSource)
 {
 }