示例#1
0
        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();
        }
示例#2
0
        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;
        }
示例#3
0
        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();
        }
示例#4
0
 public static void RemoveRule(Rule r)
 {
 }