Ejemplo n.º 1
0
        public void Add(IPRange range, T value)
        {
            if (range == null)
            {
                throw new ArgumentNullException("range");
            }

            Add(range.From, range.To, value);
        }
Ejemplo n.º 2
0
        private static IPRange ReadRangeElement(XmlReader reader)
        {
            if (reader == null) throw new ArgumentNullException("reader");

            string network = null;
            string from = null;
            string to = null;
            while (reader.MoveToNextAttribute())
            {
                var attrName = reader.Name.ToLowerInvariant();
                switch (attrName)
                {
                    case "network":
                    case "subnet":
                        network = reader.Value.Trim(); break;

                    case "from":
                    case "fromip":
                        from = reader.Value.Trim(); break;

                    case "to":
                    case "toip":
                        to = reader.Value.Trim(); break;
                }
            }

            IPRange range = null;
            IPAddress fromIp = null;
            IPAddress toIp = null;

            if (!String.IsNullOrEmpty(network)) range = IPRange.Parse(network);
            if (!String.IsNullOrEmpty(from))
            {
                if (!IPAddress.TryParse(from, out fromIp))
                    throw new FormatException(String.Format("An invalid from IP address was specified ('{0}').", from));
                if (range != null && !fromIp.Equals(range.From))
                    throw new InvalidDataException(String.Format("From IP in range does not match calculated value, data seems to be inconsistent ({0} != {1})", fromIp, range.From));
            }
            if (!String.IsNullOrEmpty(to))
            {
                if (!IPAddress.TryParse(to, out toIp))
                    throw new FormatException(String.Format("An invalid to IP address was specified ('{0}').", to));
                if (range != null && !toIp.Equals(range.To))
                    throw new InvalidDataException(String.Format("To IP in range does not match calculated value, data seems to be inconsistent ({0} != {1})", toIp, range.To));
            }

            if (range == null)
            {
                if (fromIp == null) throw new InvalidDataException("Missing 'from' or 'network' attribute for range");
                if (toIp == null) throw new InvalidDataException("Missing 'to' or 'network' attribute for range");
                range = new IPRange(fromIp, toIp);
            }
            reader.MoveToContent();
            return range;
        }
Ejemplo n.º 3
0
        private static IPRange ReadRangeElement(XmlReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            string network = null;
            string from    = null;
            string to      = null;

            while (reader.MoveToNextAttribute())
            {
                var attrName = reader.Name.ToLowerInvariant();
                switch (attrName)
                {
                case "network":
                case "subnet":
                    network = reader.Value.Trim(); break;

                case "from":
                case "fromip":
                    from = reader.Value.Trim(); break;

                case "to":
                case "toip":
                    to = reader.Value.Trim(); break;
                }
            }

            IPRange   range  = null;
            IPAddress fromIp = null;
            IPAddress toIp   = null;

            if (!String.IsNullOrEmpty(network))
            {
                range = IPRange.Parse(network);
            }
            if (!String.IsNullOrEmpty(from))
            {
                if (!IPAddress.TryParse(from, out fromIp))
                {
                    throw new FormatException(String.Format("An invalid from IP address was specified ('{0}').", from));
                }
                if (range != null && !fromIp.Equals(range.From))
                {
                    throw new InvalidDataException(String.Format("From IP in range does not match calculated value, data seems to be inconsistent ({0} != {1})", fromIp, range.From));
                }
            }
            if (!String.IsNullOrEmpty(to))
            {
                if (!IPAddress.TryParse(to, out toIp))
                {
                    throw new FormatException(String.Format("An invalid to IP address was specified ('{0}').", to));
                }
                if (range != null && !toIp.Equals(range.To))
                {
                    throw new InvalidDataException(String.Format("To IP in range does not match calculated value, data seems to be inconsistent ({0} != {1})", toIp, range.To));
                }
            }

            if (range == null)
            {
                if (fromIp == null)
                {
                    throw new InvalidDataException("Missing 'from' or 'network' attribute for range");
                }
                if (toIp == null)
                {
                    throw new InvalidDataException("Missing 'to' or 'network' attribute for range");
                }
                range = new IPRange(fromIp, toIp);
            }
            reader.MoveToContent();
            return(range);
        }