Ejemplo n.º 1
0
        private void dataGrid_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                int currentMouseOverRow = dataGrid.HitTest(e.X, e.Y).RowIndex;
                if (currentMouseOverRow >= 0)
                {
                    Dota2Server server = (Dota2Server)dataGrid.Rows[currentMouseOverRow].DataBoundItem;

                    ContextMenu m = new ContextMenu();

                    MenuItem itemRefresh = new MenuItem(string.Format("Refresh ping"));
                    itemRefresh.Click += (sender2, e2) => ContextMenuItemRefresh(server);
                    m.MenuItems.Add(itemRefresh);
                    MenuItem itemDetail = new MenuItem(string.Format("Detail Refresh ping"));
                    itemDetail.Click += (sender2, e2) => ContextMenuItemDetailRefresh(server);
                    m.MenuItems.Add(itemDetail);
                    m.Show(dataGrid, new Point(e.X, e.Y));
                }
            }
        }
Ejemplo n.º 2
0
        internal void RefreshPing(Dota2Server server, bool isDetailed)
        {
            try
            {
                lock (_lock)
                {
                    ResetStats();
                    int tries = isDetailed ? DetailTries : NormalTries;

                    Ping pingSender = new Ping();
                    for (int i = 0; i < tries; i++)
                    {
                        _totalPacketsSent++;
                        PingReply reply = pingSender.Send(server.Address, Timeout);

                        if (reply != null && reply.Status == IPStatus.Success)
                        {
                            _totalPacketsReceived++;
                            _totalRoundTripTime += reply.RoundtripTime;
                        }
                    }
                    if (_totalPacketsReceived > 0)
                    {
                        _ping = (_totalRoundTripTime / _totalPacketsReceived);
                    }
                    else
                    {
                        _ping = int.MaxValue;
                    }
                    if (_totalPacketsSent > 0)
                    {
                        _packetLoss = CalculatePacketLoss();
                    }
                    else
                    {
                        _packetLoss = 100;
                    }
                    if (isDetailed)
                    {
                        MessageBox.Show("Server Name \t\t = " + server.Name + "\r\n"
                                        + "Total Packets sent \t\t = " + _totalPacketsSent + " packets \r\n"
                                        + "Total Packets Received \t = " + _totalPacketsReceived + " packets \r\n"
                                        + "Total Time taken \t\t = " + _totalRoundTripTime + " mili-Seconds \r\n"
                                        + "Average Ping \t\t = " + _ping + " mili-Seconds \r\n"
                                        + "Packet Loss \t\t = " + _packetLoss + " % \r\n"
                                        , "Detail Ping Results", MessageBoxButtons.OK);
                    }
                    ConsoleWrite("Request ping " + server.Name + " Completed.", Color.Lime);
                }
            }
            catch (Exception e)
            {
                _ping       = int.MaxValue;
                _packetLoss = 100;
                if (ConfigurationSettings.AppSettings["IsErrorEnabled"] == "true")
                {
                    ConsoleWrite("Error occured while requesting ping " + server.Name + " " + e, Color.Red);
                }
                else
                {
                    ConsoleWrite("Error occured while requesting ping " + server.Name + " " + e.Message, Color.Red);
                }
            }
            ResetStats();
            UpdateData();
        }
Ejemplo n.º 3
0
        internal void RefreshPing(Dota2Server server, bool isDetailed)
        {
            try
            {
                lock (_lock)
                {
                    ResetStats();
                    int tries = isDetailed ? DetailTries : NormalTries;

                    Ping pingSender = new Ping();
                    for (int i = 0; i < tries; i++)
                    {
                        _totalPacketsSent++;
                        PingReply reply = pingSender.Send(server.Address, Timeout);

                        if (reply != null && reply.Status == IPStatus.Success)
                        {
                            _totalPacketsReceived++;
                            _totalRoundTripTime += reply.RoundtripTime;
                        }
                    }
                    if (_totalPacketsReceived > 0)
                    {
                        _ping = (_totalRoundTripTime / _totalPacketsReceived);
                    }
                    else
                    {
                        _ping = int.MaxValue;
                    }
                    if (_totalPacketsSent > 0)
                    {
                        _packetLoss = CalculatePacketLoss();
                    }
                    else
                    {
                        _packetLoss = 100;
                    }
                    if (isDetailed)
                    {
                        MessageBox.Show("Server Name \t\t = " + server.Name + "\r\n"
                                        + "Total Packets sent \t\t = " + _totalPacketsSent + " packets \r\n"
                                        + "Total Packets Received \t = " + _totalPacketsReceived + " packets \r\n"
                                        + "Total Time taken \t\t = " + _totalRoundTripTime + " mili-Seconds \r\n"
                                        + "Average Ping \t\t = " + _ping + " mili-Seconds \r\n"
                                        + "Packet Loss \t\t = " + _packetLoss + " % \r\n"
                            , "Detail Ping Results", MessageBoxButtons.OK);
                    }
                    ConsoleWrite("Request ping " + server.Name + " Completed.", Color.Lime);
                }
            }
            catch (Exception e)
            {
                _ping = int.MaxValue;
                _packetLoss = 100;
                if (ConfigurationSettings.AppSettings["IsErrorEnabled"] == "true")
                    ConsoleWrite("Error occured while requesting ping " + server.Name + " " + e, Color.Red);
                else
                    ConsoleWrite("Error occured while requesting ping " + server.Name + " " + e.Message, Color.Red);
            }
            ResetStats();
            UpdateData();
        }
Ejemplo n.º 4
0
 private void ContextMenuItemDetailRefresh(Dota2Server server)
 {
     ConsoleWrite("Requesting ping " + server.Name, Color.Lime);
     Application.UseWaitCursor = true;
     server.RefreshPing(true);
 }
Ejemplo n.º 5
0
 private void ContextMenuItemDetailRefresh(Dota2Server server)
 {
     ConsoleWrite("Requesting ping " + server.Name, Color.Lime);
     Application.UseWaitCursor = true;
     server.RefreshPing(true);
 }