コード例 #1
0
        /// <summary>
        /// Builds graph with chunk root nodes
        /// </summary>
        /// <returns></returns>
        public NodeGraph BuildChunkRootsGraph()
        {
            List <LeafNodeDictionaryEntry> rootEntries = new List <LeafNodeDictionaryEntry>();
            Dictionary <LeafNodeDictionaryEntry, ContentChunk> EntryChunkDictionary = new Dictionary <LeafNodeDictionaryEntry, ContentChunk>();

            foreach (var chunk in items)
            {
                LeafNodeDictionaryEntry entry = null;
                if (chunk.RootNode != null)
                {
                    entry = new LeafNodeDictionaryEntry(chunk.RootNode);
                }
                else
                {
                    entry = new LeafNodeDictionaryEntry()
                    {
                        XPath = chunk.XPathRoot
                    };
                }

                EntryChunkDictionary.Add(entry, chunk);
                rootEntries.Add(entry);
            }

            NodeGraph graph = NodeGraph.Build(rootEntries);

            foreach (var pair in EntryChunkDictionary)
            {
                NodeGraph chunkChild = graph.GetChildAtPath <NodeGraph>(pair.Key.XPath);
                chunkChild.SetMetaData(pair.Value);
            }

            return(graph);
        }
コード例 #2
0
 public void Add(LeafNodeDictionaryEntry entry)
 {
     if (entry != null)
     {
         items.Add(entry);
         CachedIndex.Add(entry.XPath, entry);
     }
 }
コード例 #3
0
 public virtual LeafNodeDictionaryEntry Add(HtmlNode item)
 {
     if (item != null)
     {
         LeafNodeDictionaryEntry entry = new LeafNodeDictionaryEntry(item);
         items.Add(entry);
         CachedIndex.Add(entry.XPath, entry);
         return(entry);
     }
     return(null);
 }
コード例 #4
0
        public List <LeafNodeDictionaryEntry> AddRange(IEnumerable <HtmlNode> nodes)
        {
            List <LeafNodeDictionaryEntry> output = new List <LeafNodeDictionaryEntry>();

            foreach (var item in nodes)
            {
                LeafNodeDictionaryEntry entry = new LeafNodeDictionaryEntry(item);
                items.Add(entry);
                CachedIndex.Add(entry.XPath, entry);
                output.Add(entry);
            }
            return(output);
        }
コード例 #5
0
        protected LeafNodeDictionaryEntry ProcessLabelNode(HtmlNode n)
        {
            LeafNodeDictionaryEntry entry = AddOrGet(n);

            if (entry.MetaData == null)
            {
                LabelNodeDefinition labelNodeDefinition = new LabelNodeDefinition(n, entry);
                if (!labelNodeDefinition.for_attribute.isNullOrEmpty())
                {
                    var ind = InputNodes.FirstOrDefault(x => x.id.Equals(labelNodeDefinition.for_attribute));
                    if (ind != null)
                    {
                        ind.Label = labelNodeDefinition;
                    }
                    LabelNodes.Add(labelNodeDefinition);
                }
            }
            return(entry);
        }
コード例 #6
0
        protected LeafNodeDictionaryEntry ProcessInputNode(HtmlNode n)
        {
            var input_types_toWatch = InputTypesToWatch.or(DefaultInputTypesToWatch);

            LeafNodeDictionaryEntry entry = AddOrGet(n);

            if (entry.MetaData == null)
            {
                var formParentNode      = n.GetFirstParent(x => x.Name.Equals("form", StringComparison.InvariantCultureIgnoreCase));
                InputFormDefinition inf = null;
                if (formParentNode != null)
                {
                    if (!FormNodes.Any(x => x.entry.XPath == formParentNode.XPath))
                    {
                        LeafNodeDictionaryEntry form_entry = Add(formParentNode);
                        inf = new InputFormDefinition(form_entry, formParentNode);
                        FormNodes.Add(inf);
                    }
                    else
                    {
                        inf = FormNodes.FirstOrDefault(x => x.entry.XPath == formParentNode.XPath);
                    }
                }


                InputNodeDefinition ind = new InputNodeDefinition(entry, n);

                if (input_types_toWatch.Contains(ind.type))
                {
                    ind.DoWatch = true;
                }

                if (!InputNodes.Any(x => x.xkey == ind.xkey))
                {
                    InputNodes.Add(ind);
                    if (inf != null)
                    {
                        inf.Add(ind);
                    }
                }
            }
            return(entry);
        }
コード例 #7
0
        public DocumentNodeChanges Compare(HtmlNode node)
        {
            DocumentNodeChanges output = new DocumentNodeChanges();

            var input_nodes = node.selectNodes(".//input");

            if (input_nodes == null)
            {
                return(null);
            }

            foreach (HtmlNode n in input_nodes)
            {
                LeafNodeDictionaryEntry entry = null;
                if (CachedIndex.ContainsKey(n.XPath))
                {
                    entry = CachedIndex[n.XPath];
                }

                InputNodeDefinition ind = new InputNodeDefinition(entry, n);
                if (InputNodes.Any(x => x.xkey == ind.xkey))
                {
                    InputNodeDefinition o_ind = InputNodes.FirstOrDefault(x => x.xkey == ind.xkey);

                    if (!o_ind.value.Equals(ind.value))
                    {
                        InputNodeChange change = new InputNodeChange()
                        {
                            oldValue       = o_ind.value,
                            newValue       = ind.value,
                            NodeDefinition = o_ind,
                            name           = o_ind.xkey
                        };
                        output.InputChanges.Add(change);
                    }
                }
            }

            return(output);
        }
コード例 #8
0
 public LabelNodeDefinition(HtmlNode _node, LeafNodeDictionaryEntry _entry)
 {
     entry          = _entry;
     entry.MetaData = this;
     Deploy(_node);
 }
コード例 #9
0
 public InputNodeDefinition(LeafNodeDictionaryEntry _entry, HtmlNode _node)
 {
     entry          = _entry;
     entry.MetaData = this;
     Deploy(_node);
 }