Пример #1
0
        /// <summary>
        /// Gets the available routes.
        /// </summary>
        /// <returns></returns>
        private IEnumerable <Route> GetRoutes()
        {
            var testTargetUri = TestTargetUri;

            // if remote is optional, whenever we have a remote proxy configured or not,
            // the short route (local only) is returned
            if (OptionalRemoteProxy)
            {
                var shortRoute = ProxyClient.CreateRoute(LocalProxy);
                if (testTargetUri != null)
                {
                    ProxyValidator.Validate(shortRoute, testTargetUri);
                }
                yield return(shortRoute);
            }
            // then, if there is a remote proxy or it is not optional
            // (in which case we skipped the first step above)
            // the full route is returned
            if (!OptionalRemoteProxy || RemoteProxy != null)
            {
                var fullRoute = ProxyClient.CreateRoute(LocalProxy, RemoteProxy);
                if (testTargetUri != null)
                {
                    ProxyValidator.Validate(fullRoute, testTargetUri);
                }
                yield return(fullRoute);
            }
        }
Пример #2
0
        static void v5()
        {
            WebPageProxyProvider wppp = new WebPageProxyProvider();

            wppp.Sources.Add(new WebPageProxySource
            {
                URL     = "http://proxy.ipcn.org/proxylist.html",
                Pattern = @"(?<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s*):(?<port>\s*\d{1,5})"
            });

            ProxyValidator         pv = new ProxyValidator();
            ProxyValidateCondition vc = new ProxyValidateCondition();

            vc.Url = "http://www.baidu.com";
            vc.Keywords.Add("百度");
            vc.Keywords.Add("html");
            pv.ValidateConditions.Add(vc);

            pm = new ProxyManager();
            pm.ProxyProviders.Add(wppp);
            pm.ProxyValidator = pv;
            pm.ProxyValidator.ValidateConditions.Add(vc);

            pm.StartDownloadProxies(false);
            Thread.Sleep(10000);
            pm.CancelValidation();
        }
        public bool IsAvailable(WebProxy proxy)
        {
            var timeout       = TimeSpan.FromSeconds(1d);
            var validator     = new ProxyValidator(proxy);
            var targetAddress = new Uri(_targetUrl);

            return(validator.Validate(targetAddress, timeout) == HttpStatusCode.OK);
        }
Пример #4
0
 public CacheBuilder As <TInterface>()
 {
     if (typeof(TInterface).IsClass)
     {
         ProxyValidator.Validate(_details);
     }
     addToCachedMethods(typeof(TInterface));
     return(_cacheBuilder);
 }
Пример #5
0
 public FluentBuilder(CacheBuilder cacheBuilder,
                      IDictionary <Type, ConfigurationForType> cachedMethods,
                      ConfigurationForType details,
                      ProxyValidator proxyValidator)
 {
     _cacheBuilder   = cacheBuilder;
     _cachedMethods  = cachedMethods;
     _details        = details;
     _proxyValidator = proxyValidator;
 }
 public ProxyProvider(IProxyConfiguration configuration, bool isValid)
 {
     _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     _collection    = new ProxyCollection();
     _generator     = new ProxyTypeGenerator(configuration);
     if (isValid)
     {
         _validator = new ProxyValidator();
     }
 }
Пример #7
0
        private void button2_Click(object sender, EventArgs e)
        {
            button2.Enabled = false;
            var watch = Stopwatch.StartNew();

            ProxyValidator.BeginValidate();
            MessageBox.Show(string.Format("proxy validate: 耗时{0}秒", watch.Elapsed.TotalSeconds));
            ProxyValidator.Save();
            button2.Enabled = true;
        }
Пример #8
0
 public CacheBuilder(IProxyFactory proxyFactory)
 {
     _configuredTypes = new Dictionary <Type, ConfigurationForType>();
     _details         = new List <ConfigurationForType>();
     _proxyFactory    = proxyFactory;
     _proxyValidator  = new ProxyValidator(_proxyFactory);
     _eventListeners  = new List <IEventListener>();
     if (LogEventListener.IsLoggingEnabled())
     {
         _eventListeners.Add(new LogEventListener());
     }
 }
Пример #9
0
        static void v8()
        {
            ManualResetEvent mre = new ManualResetEvent(false);

            l = new Listener();
            SelectiveProxyGuide spg = new SelectiveProxyGuide();

            spg.DnsCache   = new DNSCache();
            spg.PacSetting = new PacSetting();
//			spg.PacSetting.AddURLPattern(@"http://.*\.baidu\.com");

            pm = new ProxyManager();
            WebPageProxyProvider wppp = new WebPageProxyProvider();

            wppp.Sources.Add(new WebPageProxySource
            {
                URL     = "http://proxy.ipcn.org/proxylist.html",
                Pattern = @"(?<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s*):(?<port>\s*\d{1,5})"
            });

            pm.ProxyProviders.Add(wppp);

            ProxyValidator         pv = new ProxyValidator();
            ProxyValidateCondition vc = new ProxyValidateCondition();

            vc.Url = "http://www.baidu.com";
            vc.Keywords.Add("百度");
            vc.Keywords.Add("html");
            pv.ValidateConditions.Add(vc);

            pm.ProxyValidator = pv;

            spg.ProxyManager       = pm;
            l.TargetConnctionGuide = spg;

            pm.StartDownloadProxies(false);

            l.StartListener();
            mre.WaitOne();
        }
Пример #10
0
 public CacheBuilder AsImplemented()
 {
     ProxyValidator.Validate(_details);
     addToCachedMethods(_details.ComponentType.ConcreteType);
     return(_cacheBuilder);
 }