private void SetRuleForItem(IssueTableItem item, Rule.Action ruleAction) { var descriptor = item.ProblemDescriptor; var callingMethod = ""; Rule rule; if (item.hasChildren) { rule = m_ProjectAuditor.config.GetRule(descriptor); } else { callingMethod = item.ProjectIssue.callingMethod; rule = m_ProjectAuditor.config.GetRule(descriptor, callingMethod); } if (rule == null) { m_ProjectAuditor.config.AddRule(new Rule { id = descriptor.id, filter = callingMethod, action = ruleAction }); } else { rule.action = ruleAction; } }
public bool ReadRules(string directoryPath) { if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); return(false); } foreach (var xmlfile in Directory.EnumerateFiles(directoryPath, "*.xml")) { Globals.ThisAddIn.GetLogger().Log($"Loading rules from: {xmlfile}"); XmlDocument doc = new XmlDocument(); try { doc.Load(xmlfile); } catch (System.Exception ex) { Globals.ThisAddIn.GetLogger().Log($"Malformed xml: {xmlfile} - {ex.ToString()}"); return(false); } foreach (XmlNode rule_node in doc.DocumentElement.SelectNodes("/rule")) { // <rule> Rule rule = new Rule(rule_node.SelectSingleNode("final") != null); var match = rule_node.SelectSingleNode("match"); var regexes = match.SelectNodes("regex"); if (regexes.Count == 0) { // this matches everything, okaaaaaaay, can be useful for *ding* } foreach (XmlNode regex in regexes) { if (!rule.AddRegex(regex.InnerText)) { // bad regex return(false); } } var actions = rule_node.SelectSingleNode("actions"); foreach (XmlNode action in actions.SelectNodes("action")) { var run = action.SelectSingleNode("run"); // store it Rule.Action ruleAction = new Rule.Action(); if (!ruleAction.SetRun(run.InnerText)) { // bad executable return(false); } ruleAction.SetHide(action.SelectSingleNode("hide") != null); ruleAction.SetShellExecute(action.SelectSingleNode("shellexecute") != null); ruleAction.SetMinimize(action.SelectSingleNode("minimize") != null); var args_node = action.SelectSingleNode("args"); if (args_node != null) { foreach (XmlNode arg in args_node.SelectNodes("arg")) { if (!ruleAction.AddArg(arg.InnerText)) { // bad args return(false); } } } rule.AddAction(ruleAction); } rules.Add(rule); } } Globals.ThisAddIn.GetLogger().Log($"Got {rules.Count}"); return(true); }