Esempio n. 1
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);
            }
        }
Esempio n. 2
0
 public DaReTouTask(DaReTouCrawler crawler)
 {
     _crawler = crawler;
 }