Esempio n. 1
0
        public static Commons.PingInformation PingInformation(string targetAddress, string gatewayAddress)
        {
            Commons.PingInformation information = new Commons.PingInformation();

            string targetQuery  = @"SELECT AVG(RoundTripTime), SUM(CASE WHEN PingStatus = 'TimedOut' THEN 1 ELSE 0 END) FROM Outside WHERE IP = '" + targetAddress + "';";
            string gatewayQuery = @"SELECT AVG(RoundTripTime), SUM(CASE WHEN PingStatus = 'TimedOut' THEN 1 ELSE 0 END) FROM Gateway WHERE IP = '" + gatewayAddress + "';";

            using (SqlConnection con = new SqlConnection(sqlConnectionString))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand(targetQuery, con))
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            information.TargetPing     = Convert.ToInt32(reader[0]);
                            information.TargetTimeouts = Convert.ToInt32(reader[1]);
                        }
                    }
                using (SqlCommand cmd = new SqlCommand(gatewayQuery, con))
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            information.GatewayPing     = Convert.ToInt32(reader[0]);
                            information.GatewayTimeouts = Convert.ToInt32(reader[1]);
                        }
                    }
                con.Close();
            }
            return(information);
        }
Esempio n. 2
0
 public static void UpdateMainWindow()
 {
     Commons.PingInformation info = DbConnection.PingInformation(m_targetAddress.ToString(), m_GatewayAddress.ToString());
     System.Windows.Application.Current.Dispatcher.Invoke(() => m_TbAvgPingGateway.Text  = info.GatewayPing.ToString());
     System.Windows.Application.Current.Dispatcher.Invoke(() => m_TbTimeOutsGateway.Text = info.GatewayTimeouts.ToString());
     System.Windows.Application.Current.Dispatcher.Invoke(() => m_TbAvgPingOut.Text      = info.TargetPing.ToString());
     System.Windows.Application.Current.Dispatcher.Invoke(() => m_TbTimeOutsOut.Text     = info.TargetTimeouts.ToString());
 }