Example #1
0
        public static Connection Parse(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            string[] parts = value.Split(' ');

            if (parts.Length != 3)
            {
                throw new FormatException("Value do not contain 3 parts as needed.");
            }

            if (parts[0] != "IN")
            {
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Net type {0} not suported", parts[0]));
            }

            switch (parts[1])
            {
            case "IP4":
                return(ConnectionIP4.Parse(parts[2]));

            case "IP6":
                return(ConnectionIP6.Parse(parts[2]));

            default:
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Address type {1} not suported", parts[1]));
            }
        }
Example #2
0
        internal static new ConnectionIP4 Parse(string ipAddress)
        {
            string[] parts = ipAddress.Split('/');

            if (parts.Length > 3)
                throw new FormatException("Too much address subpart in " + ipAddress);

            ConnectionIP4 result = new ConnectionIP4();

            result.Host = parts[0];

            int ttl;
            if (parts.Length > 1)
            {
                if (!int.TryParse(parts[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out ttl))
                    throw new FormatException("Invalid TTL format : " + parts[1]);
                result.Ttl = ttl;
            }
            int numberOfAddress;
            if (parts.Length > 2)
            {
                if (!int.TryParse(parts[2], NumberStyles.Integer, CultureInfo.InvariantCulture, out numberOfAddress))
                    throw new FormatException("Invalid number of address : " + parts[2]);
                result.NumberOfAddress = numberOfAddress;
            }

            return result;
        }
Example #3
0
        internal new static ConnectionIP4 Parse(string ipAddress)
        {
            string[] parts = ipAddress.Split('/');

            if (parts.Length > 3)
            {
                throw new FormatException("Too much address subpart in " + ipAddress);
            }

            ConnectionIP4 result = new ConnectionIP4();

            result.Host = parts[0];

            int ttl;

            if (parts.Length > 1)
            {
                if (!int.TryParse(parts[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out ttl))
                {
                    throw new FormatException("Invalid TTL format : " + parts[1]);
                }
                result.Ttl = ttl;
            }
            int numberOfAddress;

            if (parts.Length > 2)
            {
                if (!int.TryParse(parts[2], NumberStyles.Integer, CultureInfo.InvariantCulture, out numberOfAddress))
                {
                    throw new FormatException("Invalid number of address : " + parts[2]);
                }
                result.NumberOfAddress = numberOfAddress;
            }

            return(result);
        }