public void loadAllRules(string filepath) { foreach(string line in File.ReadLines(filepath)) { XpathItem item = XpathItem.fromLine(line); AddItem(item); } }
public void AddItem(XpathItem item) { if (item != null) { if (!DomainEndpointItems.ContainsKey(item.domainPattern)) DomainEndpointItems.Add(item.domainPattern, new Dictionary<string, List<XpathItem>>()); if (!DomainEndpointItems[item.domainPattern].ContainsKey(item.epPattern)) DomainEndpointItems[item.domainPattern].Add(item.epPattern, new List<XpathItem>()); DomainEndpointItems[item.domainPattern][item.epPattern].Add(item); } }
public static XpathItem fromLine(string line) { XpathItem result = new XpathItem(); int[] indexes = { -1, -1, -1 }; try { line = line.Trim(new[] { '\r', '\n', ' ' }); result.parentCount = int.Parse(getSubstring(line, ' ', 0, out indexes[0])); result.domainPattern = getSubstring(line, ' ', indexes[0], out indexes[1]); result.epPattern = getSubstring(line, ' ', indexes[1], out indexes[2]); result.xpath = line.Substring(indexes[2]); int errorNum = indexes.Min(); if (errorNum < 0) result = null; } catch (Exception ex) { result = null; } return result; }