private void Save_Click(object sender, RoutedEventArgs e) { string title = TitleBox.Text; string description = DescriptionBox.Text; string regex = RegexBox.Text; List<string> extensions = new List<string>(ExtensionBox.Text.Split(',')); List<string> guidance = new List<string>(Regex.Split(GuidanceBox.Text, "\r\n")); newRule = new Rule(title, description, regex, extensions, guidance); this.Close(); }
public static List<Rule> GetRulesFromFile(string file) { List<Rule> rules = new List<Rule>(); if (File.Exists(file)) { XmlTextReader reader = new XmlTextReader(file); while (reader.Read()) { if ("Rule" == reader.Name) { Rule r = new Rule(); while(!(XmlNodeType.EndElement == reader.NodeType && "Rule" == reader.Name)) { reader.Read(); switch (reader.Name) { case "Title": r.Title = ReadElement(reader, "Title"); break; case "Severity": r.Severity = ReadElement(reader, "Severity"); break; case "Type": r.Type = ReadElement(reader, "Type"); break; case "RegularExpressionPattern": r.RegexSearchPattern = ReadElement(reader, "RegularExpressionPattern"); break; case "Extensions": r.AddExtensionList(ReadList(reader, "Extensions", "Extension")); break; case "Guidance": r.AddGuidanceList(ReadList(reader, "Guidance", "Url")); break; case "Description": r.Description = ReadElement(reader, "Description"); break; } } r.Selected = true; rules.Add(r); } } reader.Close(); } return rules; }
public static void AddRule(Rule r) { StreamReader InRules = new StreamReader(Settings.Default.RulesDirectory); string[] lines = Regex.Split(InRules.ReadToEnd(), "\r\n"); InRules.Close(); StreamWriter OutRules = new StreamWriter(Settings.Default.RulesDirectory); foreach(string line in lines) { if(!line.Contains("</Rules>")) OutRules.WriteLine(line); else { OutRules.Write(r.GenerateXMLSnippet()); } } OutRules.WriteLine("</Rules>"); OutRules.Close(); }
public static void RemoveRule(Rule r) { }