Ejemplo n.º 1
0
        public void Init()
        {
            pacSetting = new PacSetting();
//			URLPattern up = new URLPattern("http://.*.baidu.com/.*");
//			//up.NecessaryKeyword.Add("百度");
//			up.ForbiddenKeywords.Add("五星体育");
//			up.NeedValidation = true;
//			pacSetting.LoadURLPattern(up);
//			PacSettingParser.ReadConfig("./Config/pac.xml",pacSetting);

            dnsCache = new DNSCache();

            targetConnectionPool               = new TargetConnectionPool();
            targetResponseValidator            = new TargetResponseValidator();
            targetResponseValidator.PacSetting = pacSetting;



            //targetConnectionPool.StartDaemon();


            proxyManager = new ProxyManager();
//			var 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})"
//			                    });
//			proxyManager.ProxyProviders.Add(wppp);

            proxyManager.ProxyValidator = new ProxyValidator();
            //load validate conditions
//			var vc = new ProxyValidateCondition();
//			vc.Url = "http://www.baidu.com";
//			vc.Keywords.Add("百度");
//			vc.Keywords.Add("html");
//			proxyManager.ProxyValidator.ValidateConditions.Add(vc);

//			proxyValidator.ValidateConditions.AddRange(ProxyValidateConditionParser.ReadConfig("./Config/validate.xml"));

            selectiveProxyGuide              = new SelectiveProxyGuide();
            selectiveProxyGuide.DnsCache     = dnsCache;
            selectiveProxyGuide.PacSetting   = pacSetting;
            selectiveProxyGuide.ProxyManager = proxyManager;

            listener = new Listener();
            listener.TargetConnectionPool    = targetConnectionPool;
            listener.TargetConnctionGuide    = selectiveProxyGuide;
            listener.TargetResponseValidator = targetResponseValidator;


            proxyManager.OnValidateCompleted += new RunWorkerCompletedEventHandler(DoValidateCompleted);

            IEProxySetter = new IEProxySetter();
            pacFilePath   = Path.GetFullPath("my.pac");
        }