コード例 #1
0
        public static bool IsConnected(string ipAddress)
        {
            bool isConnected = true;

            try
            {
                cnblogs.Jackson0714.RetryScope.RetryScope.BeginRetry(retryInterval);
                do
                {
                    try
                    {
                        try
                        {
                            if (!PingUtil.Ping(ipAddress))
                            {
                                throw new Exception(string.Format("{0} Disconnected", ipAddress), new Exception("Disconnected"));
                            }
                        }
                        finally
                        {
                        }

                        break;
                    }
                    catch (Exception ex)
                    {
                        if (!cnblogs.Jackson0714.RetryScope.RetryScope.HandleException(ex))
                        {
                            throw;
                        }
                    }
                } while (cnblogs.Jackson0714.RetryScope.RetryScope.Continue);
            }
            catch (Exception cex)
            {
                isConnected = false;
            }

            finally
            {
                cnblogs.Jackson0714.RetryScope.RetryScope.EndRetry(retryInterval);
            }
            return(isConnected);
        }
コード例 #2
0
        public static void TestTargetIP2Disconnected()
        {
            while (true)
            {
                if (targetIP2lastStatus != NetworkStatus.Offline && !PingUtil.IsConnected(targetIP2))
                {
                    timePoints2.Add(new TimePoint(DateTime.Now, NetworkStatus.Offline));

                    pingTarget2Count = 0;
                    targetIP2GroupCount++;

                    targetIP2lastStatus     = NetworkStatus.Offline;
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine(FormatDisconnectedConsoleLog(targetIP2, targetIP2GroupCount));
                    Console.ForegroundColor = ConsoleColor.White;
                    log2.Info(FormatDisconnectedFileLog(targetIP2, targetIP2GroupCount));
                }
                Thread.Sleep(sleepTime);
            }
        }
コード例 #3
0
 public static void TestTargetIP2Connecting()
 {
     while (true)
     {
         if (targetIP2lastStatus != NetworkStatus.Online)
         {
             pingTarget2Count++;
             if (PingUtil.IsConnected(targetIP2))
             {
                 timePoints2.Add(new TimePoint(DateTime.Now, NetworkStatus.Online));
                 targetIP2lastStatus     = NetworkStatus.Online;
                 Console.ForegroundColor = ConsoleColor.Cyan;
                 Console.WriteLine(FormatConnectingConsoleLog(targetIP2, pingTarget2Count));
                 Console.ForegroundColor = ConsoleColor.White;
                 log2.Info(FormatConnectingFileLog(targetIP2, pingTarget2Count));
             }
         }
         Thread.Sleep(sleepTime);
     }
 }