// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider provider, IApplicationLifetime appLifetime) { loggerFactory.AddConsole(); // loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } var olxUaConfig = new OlxConfig( OlxType.Ua, "http://olx.ua/sitemap.xml", "https://ssl.olx.ua/i2/obyavlenie/?json=1&id={0}&version=2.3.2", "https://ssl.olx.ua/i2/ajax/ad/getcontact/?type=phone&json=1&id={0}&version=2.3.2" ); var sitemapManager = provider.GetService <ISitemapManager>(); var sitemapGrabber = new OlxSitemapGrabber(olxUaConfig, new PlainHttpClient()); sitemapManager.AddGrabber(SourceType.OlxUa.ToString(), sitemapGrabber, isEnabled: true); sitemapManager.Run(appLifetime.ApplicationStopping); var nadproxy = provider.GetService <SimpleNadproxy>(); nadproxy.AddProxy(new Proxy { Host = "127.0.0.1", Port = 3128 }); nadproxy.AddProxy(new Proxy { Host = "127.0.0.1", Port = 3128 }); nadproxy.AddProxy(new Proxy { Host = "46.101.22.147", Port = 8118 }); var adManager = provider.GetService <IAdvertManager>(); var grabber = new OlxAdvertGrabber(olxUaConfig, nadproxy); adManager.AddGrabber(SourceType.OlxUa.ToString(), grabber); adManager.Run(appLifetime.ApplicationStopping); //app.Run(async (context) => { await context.Response.WriteAsync("Hello World!"); }); app.UseDeveloperExceptionPage(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}"); }); }
private static void TestWithConfig(OlxConfig config) { var sitemapGrabber = new OlxSitemapGrabber(config, new SimpleGrabberHttpClient()); var sitemapIndex = sitemapGrabber.GrabIndex().Result; Assert.NotEmpty(sitemapIndex); Assert.IsType(typeof(SitemapEntry), sitemapIndex.First()); Assert.False(sitemapGrabber.HasSitemapsToGrab(new List <SitemapEntry>())); Assert.True(sitemapGrabber.HasSitemapsToGrab(sitemapIndex)); var sitemapResult = sitemapGrabber.GrabNextSitemap(sitemapIndex).Result; Assert.NotEmpty(sitemapResult.AdIds); Assert.Contains(sitemapResult.SitemapEntry, sitemapIndex); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider provider) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); var olxUaConfig = new OlxConfig( OlxType.Ua, "http://olx.ua/sitemap.xml", "https://ssl.olx.ua/i2/obyavlenie/?json=1&id={0}&version=2.3.2", "https://ssl.olx.ua/i2/ajax/ad/getcontact/?type=phone&json=1&id={0}&version=2.3.2" ); var sitemapManager = provider.GetService <ISitemapGrabberManager>(); var sitemapGrabber = new OlxSitemapGrabber(olxUaConfig, new GrabberHttpClient()); sitemapManager.AddGrabber("olx_ua", sitemapGrabber, isEnabled: true); var adManager = provider.GetService <AdGrabberManager>(); var adGrabber = new OlxAdGrabber(olxUaConfig, new GrabberHttpClient()); adManager.AddGrabber("olx_ua", adGrabber); sitemapManager.Run(CancellationToken.None); adManager.Run(CancellationToken.None); }