コード例 #1
0
        private StackPanel GenerateUL(IHtmlUnorderedListElement node)
        {
            var verticalStackPanel = new StackPanel();

            foreach (var child in node.ChildNodes)
            {
                if (String.IsNullOrWhiteSpace(child.TextContent))
                {
                    continue;
                }

                var horizontalStackPanel = new StackPanel()
                {
                    Orientation = Orientation.Horizontal, Margin = new Thickness(0, 3, 0, 3)
                };
                horizontalStackPanel.Children.Add(new TextBlock()
                {
                    Text = "•", Margin = new Thickness(9.5, 0, 9.5, 0)
                });

                var richTextBlock = new RichTextBlock();
                var paragraph     = new Paragraph();

                AddInlineChildren(child, paragraph.Inlines);

                richTextBlock.Blocks.Add(paragraph);
                horizontalStackPanel.Children.Add(richTextBlock);
                verticalStackPanel.Children.Add(horizontalStackPanel);
            }

            return(verticalStackPanel);
        }
コード例 #2
0
        List Render(IHtmlUnorderedListElement element)
        {
            var list = new List {
                MarkerStyle = TextMarkerStyle.Circle
            };

            RenderList(element.Children, list);
            return(list);
        }
コード例 #3
0
        private Block GenerateUL(IHtmlUnorderedListElement node)
        {
            var ulParagraph = new Paragraph()
            {
                LineHeight = 3,
                Margin     = new Thickness(0, 3, 0, 3)
            };

            foreach (var child in node.ChildNodes)
            {
                if (String.IsNullOrWhiteSpace(child.TextContent))
                {
                    continue;
                }

                var liInlineContainer = new InlineUIContainer();
                var dot = new TextBlock()
                {
                    Text = "•", Margin = new Thickness(9.5, 0, 9.5, 0)
                };
                liInlineContainer.Child = dot;
                ulParagraph.Inlines.Add(liInlineContainer); //添加"•"

                //var horizontalStackPanel = new StackPanel() { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 3, 0, 3) };
                //horizontalStackPanel.Children.Add(new TextBlock() { Text = "•", Margin = new Thickness(9.5, 0, 9.5, 0) });

                //var richTextBlock = new RichTextBlock();

                AddInlineChildren(child, ulParagraph.Inlines);

                //richTextBlock.Blocks.Add(paragraph);
                //horizontalStackPanel.Children.Add(richTextBlock);
                //ulParagraph.Children.Add(horizontalStackPanel);
                ulParagraph.Inlines.Add(new LineBreak());
            }
            ulParagraph.Inlines.RemoveAt(ulParagraph.Inlines.Count - 1); //Delete Last LineBreak (Because this is a block, means next content will start in another line anyway, so one more LineBreak makes one more line spacing.)
            return(ulParagraph);
        }
コード例 #4
0
        /// <summary>
        /// Заполнение данных о товаре с сайта поставщика
        /// </summary>
        public async Task <bool> FillByUrl()
        {
            bool res = false;

            if (await Loader.LoadPageAsync(Url))
            {
                // Получение наименования товара
                IHtmlHeadingElement pageHeader = (IHtmlHeadingElement)Loader.Document.QuerySelectorAll("h1")
                                                 .Where(item => item.TextContent.Trim().Length > 0)
                                                 .FirstOrDefault();
                if (pageHeader != null)
                {
                    Name = pageHeader.TextContent.Trim();
                }

                // Получение цены товара
                IHtmlSpanElement mainPrice = (IHtmlSpanElement)Loader.Document.QuerySelectorAll("span")
                                             .Where(item => item.Id != null &&
                                                    item.Id.Trim() == @"main-price")
                                             .FirstOrDefault();
                if (mainPrice != null)
                {
                    int mainPriceValue = 0;
                    if (int.TryParse(mainPrice.TextContent.Trim().Replace(" ", string.Empty), out mainPriceValue))
                    {
                        Price = mainPriceValue;
                    }
                }

                // Получение старой цены товара
                IHtmlDivElement oldPriceElement = (IHtmlDivElement)Loader.Document.QuerySelectorAll("div")
                                                  .Where(item => item.ClassName != null &&
                                                         item.ClassName.Contains(@"old-price"))
                                                  .FirstOrDefault();
                if (oldPriceElement != null)
                {
                    Regex rgOldPrice = new Regex(@"^(?<value>\d+)");
                    Match mtOldPrice = rgOldPrice.Match(oldPriceElement.TextContent.Trim().Replace(" ", string.Empty));
                    if (mtOldPrice.Success)
                    {
                        int oldPriceValue = 0;
                        if (int.TryParse(mtOldPrice.Groups["value"].ToString(), out oldPriceValue))
                        {
                            OldPrice = oldPriceValue;
                        }
                    }
                }

                // Загрузка списка технических характеристик
                IHtmlElement techSpecSection = (IHtmlElement)Loader.Document.QuerySelectorAll("section")
                                               .Where(item => item.ClassName != null &&
                                                      item.ClassName.Contains(@"tech-specs"))
                                               .FirstOrDefault();
                if (techSpecSection != null)
                {
                    var techSpecRowsCollection = techSpecSection.QuerySelectorAll("div")
                                                 .Where(item => item.ClassName != null &&
                                                        item.ClassName.Contains(@"row"));
                    foreach (IHtmlDivElement techSpecRow in techSpecRowsCollection)
                    {
                        IHtmlSpanElement techSpecName = (IHtmlSpanElement)techSpecRow.QuerySelectorAll("span")
                                                        .FirstOrDefault();
                        IHtmlParagraphElement techSpecValue = (IHtmlParagraphElement)techSpecRow.QuerySelectorAll("p")
                                                              .Where(item => item.ClassName != null &&
                                                                     item.ClassName.Contains(@"p-style2"))
                                                              .FirstOrDefault();
                        if (techSpecName != null &&
                            techSpecValue != null &&
                            techSpecName.TextContent.Trim().Length > 0 &&
                            techSpecValue.TextContent.Trim().Length > 0)
                        {
                            Options.Add(new InventItemOption(techSpecName.TextContent.Trim(), techSpecValue.TextContent.Trim()));
                        }
                    }
                }

                // Загрузка описания товара
                IHtmlDivElement descrElement = (IHtmlDivElement)Loader.Document.QuerySelectorAll("div")
                                               .Where(item => item.Id != null &&
                                                      item.Id.Trim() == @"descr")
                                               .FirstOrDefault();
                if (descrElement != null)
                {
                    Descr = descrElement.TextContent.Trim();
                }

                // Формирование списка изображений товара
                IHtmlUnorderedListElement imagesListElement = (IHtmlUnorderedListElement)Loader.Document.QuerySelectorAll("ul")
                                                              .Where(item => item.ClassName != null &&
                                                                     item.ClassName.Contains(@"pagination"))
                                                              .FirstOrDefault();
                if (imagesListElement != null)
                {
                    var imagesListCallection = imagesListElement.QuerySelectorAll("img");
                    foreach (IHtmlImageElement imageItem in imagesListCallection)
                    {
                        if (imageItem.Source != null && imageItem.Source.Length > 0)
                        {
                            Images.Add(Site.PrepareUrl(imageItem.Source));
                        }
                    }
                }

                res = true;
            }

            RegisterInventItem();

            return(res);
        }