public async Task ObserveAsync(string productName, string productUrl) { try { ISiteParser parser = _parserFactory.GetInstance(productUrl); ProductPriceFetchResult price = parser.Parse(productName, productUrl); if (price.Price <= 0) { throw new Exception("Price is negative or zero"); } await _priceStore.StoreAsync(price); } catch (Exception e) { var id = Guid.NewGuid().ToString("N"); _logger.LogError(e, $"{id} Could not observe prices on site {productUrl}"); var price = new ProductPriceFetchResult(e.Message, id, productName, productUrl); await _priceStore.StoreAsync(price); } }
internal static async Task <IEnumerable <byte[]> > GetPreviewsImpl(ISiteParser parser, IManga manga) { var links = new List <Uri>(); var client = await ConfigStorage.Plugins.Single(p => p.MangaType == manga.GetType()).GetCookieClient(true).ConfigureAwait(false); try { var document = new HtmlDocument(); var content = (await client.GetPage(manga.Uri).ConfigureAwait(false)).Content; document.LoadHtml(content); var chapterNodes = document.DocumentNode.SelectNodes("//img[@id='cover']"); if (chapterNodes != null) { foreach (var node in chapterNodes.SelectMany(n => n.Attributes).Where(a => a.Name == "src" && !string.IsNullOrWhiteSpace(a.Value))) { var src = node.Value; Uri link; if (Uri.IsWellFormedUriString(src, UriKind.Relative)) { link = new Uri(manga.Setting.MainUri, src); } else { link = new Uri(src); } links.Add(link); } } } catch (NullReferenceException ex) { Log.Exception(ex, $"Возможно, требуется регистрация для доступа к {manga.Uri}"); } var images = new List <byte[]>(); foreach (var link in links) { byte[] image = null; try { image = await client.GetData(link).ConfigureAwait(false); } catch (Exception e) { Log.Exception(e); } if (image != null) { images.Add(image); } } return(images); }
public SiteChecker(ISiteReader reader = null, ISiteParser parser = null) { _siteReader = reader ?? new SiteReader(); _siteParser = parser ?? new SiteParser(); }
public SiteParser(ISiteParser parser, ISiteRequests requests) { this.parser = parser; this.requests = requests; }
public StoreController(ISiteParser siteParser, PredictionEnginePool <ModelInput, ModelOutput> predictionEnginePool) { _siteParser = siteParser; _predictionEnginePool = predictionEnginePool; }
public SiteParserHostedService(ISiteParser siteParser, IApplicationLifetime applicationLifetime) { _siteParser = siteParser; _applicationLifetime = applicationLifetime; }
public HomeController(ISiteParser parser) { _siteParser = parser; }