protected override void LoadRules (Category c) { // load xml file from smokey resources using (Stream ruleInfo = SmokeyRunner.Smokey.GetManifestResourceStream (c.Id + ".xml")) { using (XmlTextReader reader = new XmlTextReader (ruleInfo)) { reader.WhitespaceHandling = WhitespaceHandling.None; // we need to know all rule ids, names and descriptions while (reader.Read ()) { reader.ReadToFollowing ("Violation"); string ruleId = reader.GetAttribute ("checkID"); // id do { if (reader.EOF) break; reader.ReadToFollowing ("Translation"); } while (reader.GetAttribute ("lang") != "en"); if (reader.EOF) break; string ruleName = reader.GetAttribute ("typeName"); // name reader.ReadToFollowing ("Description"); string ruleDescription = reader.ReadElementContentAsString (); // description SmokeyRule rule = new SmokeyRule (ruleId, ruleName, ruleDescription); SmokeyRuleCache.Add (rule); base.AddRule (c, rule); } } } }
public IEnumerable<IRule> GetRules (Category category) { EnsureLoaded (); if (!categorizedRules.ContainsKey (category)) throw new ArgumentOutOfRangeException ("category", category, AddinCatalog.GetString ("Category '{0}' does not exist.", category)); return categorizedRules [category]; }
protected override void LoadRules (Category c) { string rulesFile = GetRulesAssemblyFileName (c.Id); if (!File.Exists (rulesFile)) throw new ArgumentException (AddinCatalog.GetString ("Could not find '{0}' rules assembly in '{1}'.", c.Id, gendarmeDirectory)); Assembly rulesAssembly = Assembly.LoadFile (Path.GetFullPath (rulesFile)); foreach (Type t in rulesAssembly.GetTypes ()) { if (t.IsAbstract || t.IsInterface) continue; if (Utilities.IsGendarmeRule (t)) base.AddRule (c, GendarmeRuleCache.CreateOrGetProxy (t)); } }
/// <summary> /// Adds a category to internal dictionary. /// </summary> protected void RegisterCategory (string id) { Category c = new Category (id, id); // TODO: make id and name different? categorizedRules.Add (c, new List<IRule> ()); }
/// <summary> /// Loads rules of specified category. /// </summary> protected abstract void LoadRules (Category c);
/// <summary> /// Adds a rule to the specified category (one should exist). /// </summary> protected void AddRule (Category c, IRule r) { categorizedRules [c].Add (r); }