예제 #1
0
        private void 处理Ping结果(string __地址, Ping __Ping, M链路状态 __状态, bool __通, int?__延时 = null)
        {
            __状态.延时 = __延时;
            __状态.缓存.Enqueue(__通);
            var __旧 = __状态.通;

            if (__状态.缓存.Count > 10)
            {
                var __移除 = __状态.缓存.Dequeue();
                if (__移除 != __通)
                {
                    __状态.通 = __状态.缓存.Count(q => q) >= 配置.阈值;
                }
            }
            else
            {
                __状态.通 = __通;
            }
            if (__状态.通 != __旧)
            {
                On连接变化(__地址, __旧, __状态.通);
            }
            __Ping.PingCompleted -= PingCompletedCallback;
            __Ping.Dispose();
        }
예제 #2
0
 public B链路监控(M链路监控配置 __配置)
 {
     配置 = __配置;
     Task.Factory.StartNew(() =>
     {
         while (true)
         {
             var temp = new Dictionary <string, string>(配置.IP列表);
             foreach (var __kv in temp)
             {
                 var __地址   = __kv.Key;
                 M链路状态 __状态 = null;
                 if (_缓存.ContainsKey(__地址))
                 {
                     __状态 = _缓存[__地址];
                 }
                 else
                 {
                     __状态 = new M链路状态 {
                         地址 = __地址, 通 = true, 描述 = __kv.Value
                     };
                     _缓存[__地址] = __状态;
                 }
                 var __Ping            = new Ping();
                 __Ping.PingCompleted += PingCompletedCallback;
                 try
                 {
                     if (Program.IsWindows)
                     {
                         __Ping.SendAsync(__地址, 配置.超时, new Tuple <string, Ping, M链路状态>(__地址, __Ping, __状态));
                     }
                     else
                     {
                         __Ping.SendAsync(Dns.GetHostAddresses(__地址)[0], 配置.超时, new Tuple <string, Ping, M链路状态>(__地址, __Ping, __状态));
                     }
                 }
                 catch (Exception)
                 {
                     处理Ping结果(__地址, __Ping, __状态, false);
                 }
             }
             Thread.Sleep(配置.频率);
         }
     });
 }