public ProxyBackgroundService(
     IProxyService pool, ILogger <ProxyService> logger, IServiceProvider serviceProvider,
     IOptions <SpiderOptions> options)
 {
     _proxySupplier = serviceProvider.GetService(typeof(IProxySupplier)) as IProxySupplier;
     _pool          = pool;
     _logger        = logger;
     _options       = options.Value;
 }
Beispiel #2
0
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="supplier">代理提供接口</param>
        /// <param name="reuseInterval">代理不被再次使用的间隔</param>
        public HttpProxyPool(IProxySupplier supplier, int reuseInterval = 500)
        {
            _supplier = supplier ?? throw new SpiderException($"{nameof(supplier)} is null.");

            _reuseInterval = reuseInterval;
            if (ProxyValidator != null)
            {
                ThreadPool.QueueUserWorkItem(RefreshProxies);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="supplier">代理提供接口</param>
        /// <param name="reuseInterval">代理不被再次使用的间隔</param>
        public HttpProxyPool(IProxySupplier supplier, int reuseInterval = 500)
        {
            _supplier = supplier ?? throw new SpiderException("IProxySupplier should not be null");

            _reuseInterval = reuseInterval;

            Task.Factory.StartNew(() =>
            {
                while (!_isDispose)
                {
                    if (_proxyQueue.Count < 50)
                    {
                        RefreshProxies();
                    }
                    Thread.Sleep(30000);
                }
            });
        }
Beispiel #4
0
        public HttpProxyPool(IProxySupplier supplier, int reuseInterval = 500)
        {
            _supplier = supplier ?? throw new SpiderException("IProxySupplier should not be null.");

            _reuseInterval = reuseInterval;

            Task.Factory.StartNew(() =>
            {
                for (long i = 0; i < long.MaxValue; i++)
                {
                    if (_proxyQueue.Count < 50)
                    {
                        UpdateProxy();
                    }
                    Thread.Sleep(30000);
                }
            });
        }
Beispiel #5
0
        public HttpProxyPool(IProxySupplier supplier, int reuseInterval = 500)
        {
            if (supplier == null)
            {
                throw new SpiderException("IProxySupplier should not be null.");
            }
            _supplier = supplier;
            Logger    = LogManager.GetCurrentClassLogger();

            _reuseInterval = reuseInterval;

            var timer = new Timer((a) =>
            {
                if (_proxyQueue.Count < 50)
                {
                    UpdateProxy();
                }
            }, null, 1, 30000);
        }