示例#1
0
        public async Task PingResultTest()
        {
            IPingable target = new CheckTarget(1, "www.baidu.com", "80", "百度");

            Assert.NotNull(target);

            string result = await CheckTargetService.PingRemoteTargetAsync(target, 1000, 4);

            Assert.NotNull(result);
            Assert.IsNotEmpty(result);

            // Console.WriteLine(result);
        }
示例#2
0
        /// <summary>
        /// 尝试异步ping目标地址
        /// </summary>
        /// <param name="timeout">超时时间</param>
        /// <param name="tryCount">ping的次数</param>
        /// <returns></returns>
        public Task TryPingAsync(int timeout, int tryCount)
        {
            return(Task.Run(async() =>
            {
                string pingResult = await CheckTargetService.PingRemoteTargetAsync(this, timeout, tryCount);

                Console.WriteLine(pingResult);

                //NLogMgr.DebugLog(_programLog, $"TryPingAsync=>{this.Remarks}调用结束{Environment.NewLine}");
                Console.WriteLine($"TryPingAsync=>{this.Remarks}调用结束{Environment.NewLine}");

                ////返回空串证明地址ping出了异常
                //if (string.IsNullOrWhiteSpace(pingResult))
                //{
                //    //既然已经异常了,就退出当前任务执行,可以考虑统计同一个地址出错次数,一定时间内冻结任务,避免过多的访问不正常的地址
                //    return;
                //}

                CheckReesultInfo checkReesultInfo = await CheckResultService.UnscramblePingResultAsync(IpAddresV4, TargetPort, Remarks, TimeMgr.GetLoaclDateTime(), pingResult);



                NLogMgr.DebugLog(_programLog, checkReesultInfo.GetResultInfoString());
                if (PingResultStatus.Pass == checkReesultInfo.Status)
                {
                    //NLogMgr.CheckMsgLog(_checkLog, LogLevel.Debug, checkReesultInfo.GetResultInfoString(), pingResult, $"[{this.IpAddresV4}]{this.Remarks}", checkReesultInfo.ResultReceiveTime);
                    return;
                }

                //todo:将非正常结果推送到消息队列(考虑开发时间问题,目前先直接写入日志)

                NLogMgr.CheckMsgLog(_checkLog, LogLevel.Error, checkReesultInfo.GetResultInfoString(), pingResult, $"[{this.IpAddresV4}]{this.Remarks}", checkReesultInfo.ResultReceiveTime);


                //Console.Clear();
            }));
        }
示例#3
0
        public void Setup()
        {
            var moqRepository = new Moq.Mock <ICheckTargetRepository>();

            this.checkTargetService = new CheckTargetService(moqRepository.Object);
        }