Exemplo n.º 1
0
        protected bool VerifyProxy(Proxy p)
        {
            if (p == null || string.IsNullOrWhiteSpace(p.Adress) || p.Port == 0)
            {
                return(false);
            }
            var state = ProxyVerify.IsAvailable(p);

            if (state.IsAvailable)
            {
                p.LastVerifyDate = DateTime.Now;
                p.Speed          = state.Speed;
            }
            return(state.IsAvailable);
        }
Exemplo n.º 2
0
        public void Verify()
        {
            var pageSize = 100;
            var page     = 1;
            int count    = 0;
            var service  = new ProxyService();

            do
            {
                try
                {
                    var lstProxy = service.GetList(page, pageSize);
                    count = lstProxy.Count;
                    var availableList = new List <Proxy>();
                    var deleteList    = new List <Proxy>();
                    Parallel.ForEach(lstProxy, proxy =>
                    {
                        var state = ProxyVerify.IsAvailable(proxy);
                        if (state.IsAvailable)
                        {
                            //对于可用的,修改最后验证日期
                            proxy.Speed          = state.Speed;
                            proxy.LastVerifyDate = DateTime.Now;
                            availableList.Add(proxy);
                        }
                        else
                        {
                            deleteList.Add(proxy);
                        }
                    });
                    //更新可用的
                    service.Update(availableList);
                    //删除不可用的
                    service.Delete(deleteList);
                }
                catch (Exception ex)
                {
                    LogHelper.LogError("验证代理时出错:" + ex);
                }
            } while (count >= pageSize);
        }