public static IEnumerable <TreeNodeViewModel> SelectFrom(IEnumerable <Node> nodes)
        {
            foreach (var node in nodes)
            {
                TreeNodeViewModel element = Create(node);

                if (element != null)
                {
                    yield return(element);
                }
            }
        }
Beispiel #2
0
        protected override async Task Use(Uri url, HTMLDocument document, CancellationToken cancel)
        {
            nodes.Clear();
            Status = "Constructing tree ...";
            var elements = TreeNodeViewModel.SelectFrom(document.ChildNodes);

            foreach (var element in elements)
            {
                element.Parent = nodes;
                nodes.Add(element);
            }

            await Task.Yield();
        }
        static TreeNodeViewModel Create(Element node)
        {
            var vm = new TreeNodeViewModel {
                Value = OpenTag(node)
            };

            foreach (var element in SelectFrom(node.ChildNodes))
            {
                element.parent = vm.children;
                vm.children.Add(element);
            }

            if (vm.children.Count != 0)
            {
                vm.expansionElement = new TreeNodeViewModel {
                    Value = CloseTag(node)
                }
            }
            ;

            return(vm);
        }
        static TreeNodeViewModel Create(Element node)
        {
            var vm = new TreeNodeViewModel { Value = OpenTag(node) };

            foreach (var element in SelectFrom(node.ChildNodes))
            {
                element.parent = vm.children;
                vm.children.Add(element);
            }

            if (vm.children.Count != 0)
                vm.expansionElement = new TreeNodeViewModel { Value = CloseTag(node) };

            return vm;
        }