Ejemplo n.º 1
0
        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}次运行计划后结束");
        }
Ejemplo n.º 2
0
 public LatestTask(ICrawlerBatchBook crawlerBatchData,
                   ICrawlerBook crawlerBook,
                   DouBanBookService douBanBookRepository)
 {
     _DetailCrawler        = crawlerBook;
     _DouBanBookRepository = douBanBookRepository;
     _LatestCrawler        = crawlerBatchData;
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 public PlanFromTagsTask(ICrawlerTag crawlerTag,
                         ICrawlerBatchBook crawlerTagList,
                         ICrawlerBook crawlerBook,
                         DouBanBookService douBanBookRepository)
 {
     _DouBanBookRepository = douBanBookRepository;
     _TagsCrawler          = crawlerTag;
     _DetailCrawler        = crawlerBook;
     _TagListCrawler       = crawlerTagList;
 }
Ejemplo n.º 5
0
        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);
            }
        }