Esempio n. 1
0
        public async Task <List <Product> > GetPartialProductsFromSubchapterAsync(string url, int prefixId,
                                                                                  int pageMax = int.MaxValue)
        {
            var firstPageProducts = await _skladchikApiClient.CallAsync(url + $"?prefix_id={prefixId}").ConfigureAwait(false);

            if (string.IsNullOrEmpty(firstPageProducts))
            {
                return(null);
            }

            var doc = new HtmlDocument();

            doc.LoadHtml(firstPageProducts);

            var pageCount     = Convert.ToInt32(GetNodeValue(doc, XPaths["PageCount"]) ?? "0");
            var lastPageIndex = pageCount >= pageMax ? pageMax : pageCount;

            if (lastPageIndex <= 0)
            {
                lastPageIndex = 1;
            }
            var links = new List <string>();

            for (var i = 1; i <= lastPageIndex; i++)
            {
                _skladchikApiClient.ThrowIfCancellationRequested();
                var productListUrl = url + $"/page-{i}?prefix_id={prefixId}";
                links.Add(productListUrl);
            }

            var products = await ParseProductFromPage(links).ConfigureAwait(false);

            return(products);
        }
Esempio n. 2
0
        /// <summary>
        /// Получение складчины.
        /// </summary>
        /// <param name="id">Id складчины.</param>
        /// <param name="dateUpdate">Дата последнего события.</param>
        /// <param name="viewCount">Количество просмотров.</param>
        /// <param name="important">Закреплена ли в разделе.</param>
        public async Task <Product> GetByIdAsync(int id, DateTime dateUpdate = default(DateTime), int viewCount = 0,
                                                 bool important = false)
        {
            var product = new Product
            {
                Id         = id,
                ViewCount  = viewCount,
                Important  = important,
                DateUpdate = dateUpdate
            };
            var source = await _skladchikApiClient.CallAsync($"{SkladchikApiClient.Domain}threads/{product.Id}").ConfigureAwait(false);

            if (string.IsNullOrEmpty(source))
            {
                return(null);
            }

            SetProductFields(source, product);

            return(product);
        }