public static void AddRule(Rule rule, RequestFilteringSection section) { if (rule == null) { throw new ArgumentNullException("rule"); } if (rule.Name == null) { throw new ArgumentNullException("rule.Name"); } FilteringRuleCollection collection = section.FilteringRules; if (collection.Any(r => r.Name.Equals(rule.Name))) { throw new AlreadyExistsException("rule"); } try { collection.Add(rule); } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } }
public static void DeleteRule(Rule rule, RequestFilteringSection section) { if (rule == null) { return; } FilteringRuleCollection collection = section.FilteringRules; // To utilize the remove functionality we must pull the element directly from the collection rule = collection.FirstOrDefault(r => r.Name.Equals(rule.Name)); if (rule != null) { try { collection.Remove(rule); } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } } }