Example #1
0
        private void ProcessCategoryListPage(ProcessQueueItem pqi)
        {
            if (cancel)
            {
                return;
            }

            var html = PageRetriever.ReadFromServer(pqi.URL);
            var doc  = CreateDoc(html);

            pqi.Processed = true;

            var categories = doc.DocumentNode.SelectNodes("//ul[@class='category-list']/li/ul/li");

            if (categories == null)
            {
                Log.Error(categories, new NullReferenceException());
                return;
            }

            foreach (var category in categories)
            {
                var a    = category.SelectSingleNode(".//a[@href]");
                var name = a.InnerTextOrNull();

                if (string.IsNullOrWhiteSpace(name))
                {
                    Log.Warn(category, new NullReferenceException());
                    continue;
                }

                var wi = new ExtWareInfo
                {
                    Category = name
                };
                var url = a.AttributeOrNull("href");

                lock (this)
                {
                    lstProcessQueue.Add(new ProcessQueueItem
                    {
                        Item     = wi,
                        ItemType = ProcessLevels.SubCategory,
                        URL      = Url + url,
                        Name     = name
                    });
                }
            }

            OnItemLoaded(null);
            pqi.Processed = true;

            MessagePrinter.PrintMessage("Category list processed");
            StartOrPushPropertiesThread();
        }
Example #2
0
        private void ProcessDetailsPage(ProcessQueueItem pqi)
        {
            if (cancel)
            {
                return;
            }

            var wi   = (ExtWareInfo)pqi.Item;
            var html = PageRetriever.ReadFromServer(pqi.URL);
            var doc  = CreateDoc(html);

            pqi.Processed = true;

            var details = doc.DocumentNode.SelectSingleNode("//div[@class='BlockContent']");

            if (details == null)
            {
                Log.Error(details, new NullReferenceException());
                return;
            }

            var images = details.SelectNodes("//div[@class='ProductTinyImageList']/ul/li/div[@class='TinyOuterDiv']/div/a[@rel]")
                         .Select(s => JsonConvert.DeserializeObject <ImageObject>(s.AttributeOrNull("rel")));
            var item = new ExtWareInfo
            {
                Category    = wi.Category,
                SubCategory = wi.SubCategory,
                Page        = wi.Page,
                Url         = wi.Url,
                Title       = details.SelectSingleNode("//h1").InnerTextOrNull(),
                Description = details.SelectSingleNode("//div[@class='ProductDescriptionContainer']").InnerTextOrNull(),
                Price       = ParsePrice(details.SelectSingleNode("//em[@class='ProductPrice VariationProductPrice']").InnerTextOrNull()),
                Weight      = ParseDouble(details.SelectSingleNode("//span[@class='VariationProductWeight']").InnerTextOrNull()),
                Images      = String.Join(";", images.Select(s => s.largeimage))
            };

            AddWareInfo(item);

            OnItemLoaded(null);
            MessagePrinter.PrintMessage("Product '" + item.Title + "' details processed");
            StartOrPushPropertiesThread();
        }