private static void RunPlan() { int tryNum = 1; while (tryNum < 3) { try { _DouBanBookRepository = _ServiceProvider.GetService <DouBanBookService>(); var list = _ServiceProvider.GetService <IEnumerable <ICrawlerBatchBook> >(); _TagList = list.FirstOrDefault(a => a.GetType().Name == "TagListCrawler"); _DetailBook = _ServiceProvider.GetService <ICrawlerBook>(); _CrawlerTag = _ServiceProvider.GetService <ICrawlerTag>(); PlanFromTagsTask planFromTagsTask = new PlanFromTagsTask( _CrawlerTag, _TagList, _DetailBook, _DouBanBookRepository); planFromTagsTask.run(); } catch (ExceptionProxyConnect epc) { NLogUtil.ErrorTxt($"代理连接错误:{epc.Message}"); NLogUtil.InfoTxt($"开始尝试第{tryNum++}次运行计划"); } } NLogUtil.InfoTxt($"第{tryNum}次运行计划后结束"); }
public LatestTask(ICrawlerBatchBook crawlerBatchData, ICrawlerBook crawlerBook, DouBanBookService douBanBookRepository) { _DetailCrawler = crawlerBook; _DouBanBookRepository = douBanBookRepository; _LatestCrawler = crawlerBatchData; }
public DouBanController(IEnumerable <ICrawlerBatchBook> crawlerServices, ICrawlerBook crawlerData, ICrawlerSearchBook crawlerSearchBook, DouBanBookService douBanBookRepository) { _DouBanBookRepository = douBanBookRepository; _CrawlerLatest = crawlerServices.FirstOrDefault(a => a.GetType().Name == "BookLatestCrawler"); _CrawlerDetail = crawlerData; _CrawlerSearchBook = crawlerSearchBook; }
public PlanFromTagsTask(ICrawlerTag crawlerTag, ICrawlerBatchBook crawlerTagList, ICrawlerBook crawlerBook, DouBanBookService douBanBookRepository) { _DouBanBookRepository = douBanBookRepository; _TagsCrawler = crawlerTag; _DetailCrawler = crawlerBook; _TagListCrawler = crawlerTagList; }
private static void InitSystem() { try { dynamic type = (new Program()).GetType(); _CurrentDirectory = Path.GetDirectoryName(type.Assembly.Location); _configuration = Configuration.SetBasePath(_CurrentDirectory) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSqlSugarSetup(_configuration); serviceCollection.AddCrawlers(_configuration); serviceCollection.AddRepository(_configuration); serviceCollection.AddInitDbSeed(_configuration); serviceCollection.AddMemoryCache(); // serviceCollection.AddScoped<IConfiguration>(_configuration); // _ServiceProvider = serviceCollection.BuildServiceProvider(); _DouBanBookRepository = _ServiceProvider.GetService <DouBanBookService>(); _Db = _ServiceProvider.GetService <SqlSugarClient>(); var list = _ServiceProvider.GetService <IEnumerable <ICrawlerBatchBook> >(); _LatestBatchBook = list.FirstOrDefault(a => a.GetType().Name == "BookLatestCrawler"); _TagList = list.FirstOrDefault(a => a.GetType().Name == "TagListCrawler"); _DetailBook = _ServiceProvider.GetService <ICrawlerBook>(); _CrawlerTag = _ServiceProvider.GetService <ICrawlerTag>(); _DaReTouCrawler = _ServiceProvider.GetService <DaReTouCrawler>(); } catch (Exception ex) { NLogUtil.ErrorTxt($"Init Error:{ex.Message}", true); } }
public SinglgTask(ICrawlerBook crawlerDetail, DouBanBookService douBanBookRepository) { _DouBanBookRepository = douBanBookRepository; _DetailCrawler = crawlerDetail; }
public static void InitData(DouBanBookService db, bool needsection = false) { db.InitData(needsection); }