Beispiel #1
0
        }                                           // graph

        internal void RebuildIndex()
        {
            CachedIndex.Clear();
            foreach (var item in items)
            {
                CachedIndex.Add(item.XPath, item);
            }
            ;

            ContentGraph = NodeGraph.Build(items); // BuildGraph();
            if (ContentGraph != null)
            {
                var allChildren = ContentGraph.getAllChildren();

                foreach (graphWrapNode <LeafNodeDictionaryEntry> child in allChildren)
                {
                    if (!child.name.isNullOrEmpty())
                    {
                        String tag = child.name.Trim(ContentGraph.pathSeparator.ToCharArray());
                        var    m   = TagSelectorRegex.Match(tag);
                        if (m.Success)
                        {
                            tag = m.Groups[m.Groups.Count - 1].Value;
                        }
                        NodeTagCounter.Count(tag);
                    }
                }
            }

            foreach (var item in items)
            {
                TagCounter.Count(item.node.Name);
            }
        }
Beispiel #2
0
 public void RemoveEntriesByXPath(List <String> XPathList)
 {
     foreach (String XPath in XPathList)
     {
         if (CachedIndex.ContainsKey(XPath))
         {
             items.Remove(CachedIndex[XPath]);
             CachedIndex.Remove(XPath);
         }
     }
 }
Beispiel #3
0
        public LeafNodeDictionaryEntry GetEntry(String xpath)
        {
            if (CachedIndex.ContainsKey(xpath))
            {
                return(CachedIndex[xpath]);
            }

            var entry = items.FirstOrDefault(x => x.XPath == xpath);

            if (entry != null)
            {
                return(entry);
            }
            return(null);
        }
        public void CacheIndex(IEnumerable <string> filesToCache, IDictionary <string, IDictionary <string, int> > index)
        {
            if (!fs.Directory.Exists(CacheFolderName))
            {
                fs.Directory.CreateDirectory(CacheFolderName);
            }
            string cacheFileName = string.Concat(CacheFolderName, "\\", "cache.json");
            var    indexToCache  = new CachedIndex()
            {
                Meta  = filesToCache.ToDictionary(file => file, file => fs.File.GetLastWriteTime(file)),
                Value = index
            };

            fs.File.WriteAllText(cacheFileName, JsonConvert.SerializeObject(indexToCache));
        }
        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);
        }