예제 #1
0
        public OlxAdsService()
        {
            var configuration = new OlxConfiguration();

            _reader = new OlxAdsReader(configuration);
            _notificationService = new NotificationService();
        }
예제 #2
0
        private static ServiceProvider RegisterDependencyInjection()
        {
            var serviceCollection = new ServiceCollection();

            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json", true, true)
                                .Build();

            var olxConfig = new OlxConfiguration();

            configuration.Bind(olxConfig);
            serviceCollection.AddSingleton(olxConfig);

            var telegramConfig = new TelegramApiConfiguration();

            configuration.Bind(telegramConfig);
            serviceCollection.AddSingleton(telegramConfig);

            serviceCollection.AddHttpClient <TelegramClient>();

            serviceCollection.AddTransient <IProcessor, Processor>();

            serviceCollection.AddTransient <IScraper, Scraper.Adapters.Scraper>();
            serviceCollection.Decorate <IScraper, ScraperWithRetry>();

            return(serviceCollection.BuildServiceProvider());
        }
예제 #3
0
        public Scraper(OlxConfiguration config)
        {
            Config = config ?? throw new System.ArgumentNullException(nameof(config));

            titleRegex = new Regex(Config.TitleRegex);
            priceRegex = new Regex(Config.PriceRegex);
            dateRegex  = new Regex(Config.DateRegex);
            urlRegex   = new Regex(Config.UrlRegex);
        }
예제 #4
0
 public OlxAdExtractor(OlxConfiguration configuration)
 {
     _olxDateParser = new OlxDateParser(configuration);
 }
예제 #5
0
 public OlxAdsReader(OlxConfiguration configuration)
 {
     _adUrl          = configuration.Url;
     _httpClient     = new HttpClient();
     _olxAdExtractor = new OlxAdExtractor(configuration);
 }
예제 #6
0
 public OlxDateParser(OlxConfiguration configuration)
 {
     _todayPrefix     = configuration.TodayPrefix;
     _yesterdayPrefix = configuration.YesterdayPrefix;
     _dateTimeCulture = CultureInfo.CreateSpecificCulture(configuration.CultureCode);
 }