Пример #1
0
        public static bool TryParse(string address, out RoutingHost routinghost)
        {
            routinghost = null;
            if (string.IsNullOrEmpty(address))
            {
                return(false);
            }
            address = address.Trim();
            RoutingHost routingHost = new RoutingHost();
            int         length      = address.Length;

            if (address[0] == '[' && address[length - 1] == ']')
            {
                address = address.Substring(1, length - 2);
            }
            if (IPAddress.TryParse(address, out routingHost.ipAddress))
            {
                if (routingHost.ipAddress.Equals(IPAddress.Any))
                {
                    return(false);
                }
            }
            else
            {
                if (!RoutingHostName.TryParse(address, out routingHost.domain))
                {
                    return(false);
                }
                routingHost.ipAddress = IPAddress.Any;
            }
            routinghost = routingHost;
            return(true);
        }
Пример #2
0
        public RoutingHost(string address)
        {
            if (string.IsNullOrEmpty(address))
            {
                throw new ArgumentException("A null or empty routing host name was specified");
            }
            address = address.Trim();
            int length = address.Length;

            if (address[0] == '[' && address[length - 1] == ']')
            {
                address = address.Substring(1, length - 2);
            }
            if (IPAddress.TryParse(address, out this.ipAddress))
            {
                if (this.ipAddress.Equals(IPAddress.Any) || this.ipAddress.Equals(IPAddress.IPv6Any))
                {
                    throw new ArgumentException(string.Format("The specified IP address '{0}' isn't valid as a routing host", this.ipAddress));
                }
                return;
            }
            else
            {
                this.ipAddress = IPAddress.Any;
                if (!RoutingHostName.TryParse(address, out this.domain))
                {
                    throw new ArgumentException(string.Format("The specified routing host name '{0}' isn't valid", address));
                }
                return;
            }
        }
Пример #3
0
 public RoutingHostName(string address)
 {
     if (!RoutingHostName.IsValidName(address))
     {
         throw new ArgumentException(string.Format("The specified host name '{0}' isn't valid", address));
     }
     this.hostnamestring = address;
 }
Пример #4
0
 public bool Equals(RoutingHostName rhs)
 {
     if (this.hostnamestring != null)
     {
         return(this.hostnamestring.Equals(rhs.hostnamestring, StringComparison.OrdinalIgnoreCase));
     }
     return(rhs.hostnamestring == null);
 }
Пример #5
0
 public static bool TryParse(string address, out RoutingHostName hostname)
 {
     hostname = RoutingHostName.Empty;
     if (string.IsNullOrEmpty(address))
     {
         return(false);
     }
     if (!RoutingHostName.IsValidName(address))
     {
         return(false);
     }
     hostname = new RoutingHostName(address);
     return(true);
 }
Пример #6
0
 internal static bool IsValidName(string name)
 {
     return(RoutingHostName.ValidateName(DNSNameFormat.Domain, name) == DNSNameStatus.Valid);
 }