public override async Task RunAsync() { var conf = DbConfigManager.Default.GetConfig("SqlServerTest", true); if (conf == null) { throw new DbConfigNotFoundException(); } var proxyAgent = ProxyAgent <SqlServerProxyDbContext> .CreateInstance(conf, c => new SqlServerProxyDbContext(c)); DefaultProxyUriLoader proxyUriLoader = new DefaultProxyUriLoader() { Days = 360, Condition = p => p.Id > 0, ProxyAgent = proxyAgent }; DefaultWebProxyValidator webProxyValidator = new DefaultWebProxyValidator(CreateWebClient, ValidateWebProxy, new WebProxyValidatorConfig() { UseThresold = 1, VerifyPauseThresold = 2 }); DefaultWebProxySelector proxySelector = new DefaultWebProxySelector(new Uri("http://www.baidu.com"), proxyUriLoader, webProxyValidator); proxySelector.Initialize(); string rspText = await HttpConsole.GetResponseTextByProxyAsync(HomePageUri, proxySelector, GetResponseTextAsync); ShowLogInfo(rspText); }
protected virtual IProxyUriLoader CreateProxyUriLoader() { var proxyAgent = ProxyAgent <SqlServerProxyDbContext> .CreateInstance("SqlServerTest", true, c => new SqlServerProxyDbContext(c)); DefaultProxyUriLoader loader = new DefaultProxyUriLoader() { Days = 360, Condition = e => e.Category == 1 && e.AnonymityDegree == 3 }; return(loader); }
public override async Task RunAsync() { string caseName = ClassName; var pa = ProxyAgent <SqlServerProxyDbContext> .CreateInstance("SqlServerTest", true, c => new SqlServerProxyDbContext(c)); var urls = ApiProvider.GetRequestUrls(); using (SpiderHttpClient webClient = ApiProvider.CreateWebClient()) { var entities = await GetProxyEntitiesAsync(webClient, HttpMethod.Get, urls, urls.Count * 10); if (entities.Count < 1) { return; } entities.ForEach(e => e.Source = caseName); ShowLogInfo("CollectCount: " + entities.Count.ToString()); int insertCount = pa.InsertProxyEntities(entities); ShowLogInfo("InsertCount: " + insertCount.ToString()); } }