Exemple #1
0
        private static Element _GetItemContainer(Document doc, MenuViewModel MenuViewModel)
        {
            // find the item container.
            if (!string.IsNullOrEmpty(MenuViewModel.ItemContainer))
            {
                var itemcontainer = DomService.GetElementByKoobooId(doc, MenuViewModel.ItemContainer) as Element;
                if (itemcontainer != null)
                {
                    return(itemcontainer);
                }
            }

            List <Element> containerlist = new List <Element>();

            foreach (var item in MenuViewModel.children)
            {
                if (!string.IsNullOrEmpty(item.ContainerElement))
                {
                    var element = DomService.GetElementByKoobooId(doc, item.ContainerElement) as Element;
                    if (element != null)
                    {
                        containerlist.Add(element);
                    }
                }
            }

            if (containerlist.Count == 0)
            {
                foreach (var item in MenuViewModel.children)
                {
                    var element = DomService.GetElementByKoobooId(doc, item.LinkElement) as Element;
                    if (element != null)
                    {
                        containerlist.Add(element);
                    }
                }
            }
            if (containerlist.Count > 1)
            {
                var element = DomService.FindParent(containerlist);
                if (element != null)
                {
                    MenuViewModel.ItemContainer = DomService.GetKoobooId(element);
                }
                return(element);
            }
            return(null);
        }
Exemple #2
0
        public static string DetectKoobooId(Document dom, List <string> SubLinks)
        {
            var  allinks         = dom.getElementsByTagName("a").item;
            var  GroupbyLinks    = MenuService.SimpleGroupBy(allinks);
            bool match           = true;
            bool onetimedismatch = false;

            foreach (var item in GroupbyLinks)
            {
                var allgrouplinks = item.Select(o => o.getAttribute("href"));

                match = false;
                foreach (var link in SubLinks)
                {
                    if (allgrouplinks.Any(o => IsSameUrl(o, link)))
                    {
                        match = true;
                    }
                    else
                    {
                        if (!onetimedismatch)
                        {
                            onetimedismatch = true;
                        }
                        else
                        {
                            match = false;
                            break;
                        }
                    }
                }

                if (match)
                {
                    var commoneparent = DomService.FindParent(item);
                    if (commoneparent != null)
                    {
                        return(DomService.GetKoobooId(commoneparent));
                    }
                }
            }

            return(null);
        }