public static void AddRule(Rule rule, IPSecuritySection section)
        {
            if (rule == null)
            {
                throw new ArgumentNullException("rule");
            }
            if (rule.IpAddress == null)
            {
                throw new ArgumentNullException("rule.IpAddress");
            }

            IPAddressFilterCollection collection = section.IpAddressFilters;

            int dummy;

            if (ExistsAddressFilter(collection, rule.DomainName, rule.IpAddress, rule.SubnetMask, out dummy))
            {
                throw new AlreadyExistsException("rule");
            }

            try {
                Rule element = collection.Add(rule);
                element.Allowed = rule.Allowed;
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }
        }
        public static void DeleteRule(Rule rule, IPSecuritySection section)
        {
            IPAddressFilterCollection collection = section.IpAddressFilters;

            int dummy;

            if (ExistsAddressFilter(collection, rule.DomainName, rule.IpAddress, rule.SubnetMask, out dummy))
            {
                try {
                    collection.RemoveAt(dummy);
                }
                catch (FileLoadException e) {
                    throw new LockedException(section.SectionPath, e);
                }
                catch (DirectoryNotFoundException e) {
                    throw new ConfigScopeNotFoundException(e);
                }
            }
        }
        private static bool ExistsAddressFilter(IPAddressFilterCollection collection,
                                                string domainName, IPAddress address, string subnetMask,
                                                out int index)
        {
            // NOTE: Normalize things for the config system
            if (domainName == null)
            {
                domainName = String.Empty;
            }

            index = -1;

            Rule element = collection.Find(domainName, address, subnetMask);

            if (element != null)
            {
                index = collection.IndexOf(element);

                return(true);
            }

            return(false);
        }