コード例 #1
0
            static TimeSpan LoopWhileNoConnection(DateTime disconnectionStartTime, ICMConfiguration conf)
            {
                var      disconnected          = true;
                TimeSpan durationDisconnection = TimeSpan.Zero;

                while (disconnected)
                {
                    var nowDisconnected = DateTime.Now.ToLocalTime();
                    durationDisconnection = nowDisconnected - disconnectionStartTime;

                    var pingsResults = ICM.pingServers(conf.servers);
                    disconnected = !pingsResults.AtLeastOneServerReachable;

                    OutputNoConnection(nowDisconnected, durationDisconnection, conf);

                    LetWaitFewSeconds(conf);
                }

                return(durationDisconnection);
            }
コード例 #2
0
        public static Task Main(string[] args)
        {
            ICM.pingServersResult pingsResults;
            ICMConfiguration      conf = LoadConfiguration(args);

            while (true)
            {
                var now = DateTime.Now.ToLocalTime();
                pingsResults = ICM.pingServers(conf.servers);
                if (pingsResults.AtLeastOneServerReachable)
                {
                    OutputOkPingsResults(pingsResults, now, conf);
                }
                else
                {
                    var disconnectionDuration = LoopWhileNoConnection(now, conf);
                    OutputReconnection(now, disconnectionDuration, conf);
                }

                LetWaitFewSeconds(conf);
            }