예제 #1
0
        public void AddAndStartOperation(int configurationId)
        {
            var scrappingConfiguration =
                _context.ScrappingConfigurations.Include(item => item.ScrappingResult).Include(item => item.UrlLibrary).Single(item => item.ScrappingConfigurationId == configurationId);
            var scope          = _scopeFactory.CreateScope();
            var taskContext    = scope.ServiceProvider.GetService <ScrapperContext>();
            var bodyComparer   = new BodyComparer(taskContext);
            var scrapperClient = new BaseScrapperClient(taskContext, bodyComparer,
                                                        scrappingConfiguration.UrlLibrary.Url, scrappingConfiguration.ScrappingResult.ScrappingResultId,
                                                        scrappingConfiguration.Interval, scrappingConfiguration.ScrappingConfigurationId);

            if (scrappingConfiguration.ScrappingEnabled)
            {
                scrapperClient.StartScrapping();
            }
            _scrappingTask.Add(scrapperClient);
        }
예제 #2
0
        public void Initialize()
        {
            var toDoList = _context.ScrappingConfigurations.Include(item => item.ScrappingResult)
                           .Include(item => item.UrlLibrary);

            _scrappingTask = new List <BaseScrapperClient>();
            foreach (var scrappingConfiguration in toDoList)
            {
                //Resolving a new context
                var scope          = _scopeFactory.CreateScope();
                var taskContext    = scope.ServiceProvider.GetService <ScrapperContext>();
                var bodyComparer   = new BodyComparer(taskContext);
                var scrapperClient = new BaseScrapperClient(taskContext, bodyComparer,
                                                            scrappingConfiguration.UrlLibrary.Url, scrappingConfiguration.ScrappingResult.ScrappingResultId,
                                                            scrappingConfiguration.Interval, scrappingConfiguration.ScrappingConfigurationId);
                if (scrappingConfiguration.ScrappingEnabled)
                {
                    scrapperClient.StartScrapping();
                }
                _scrappingTask.Add(scrapperClient);
            }
        }