示例#1
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            SmartUri smartUri = obj as SmartUri;

            if (smartUri != null)
            {
                if (this.HostNameType == UriHostNameType.Unknown || this.HostNameType != smartUri.HostNameType)
                {
                    return(false);
                }
                if (this.HostNameType == UriHostNameType.Dns)
                {
                    return(this.Host.Equals(smartUri.Host, StringComparison.OrdinalIgnoreCase));
                }
                return(this.IPEndPoint.Equals((object)smartUri.IPEndPoint));
            }
            IPEndPoint ipEndPoint = obj as IPEndPoint;

            if (ipEndPoint != null && this.IPEndPoint != null)
            {
                return(this.IPEndPoint.Equals((object)ipEndPoint));
            }
            return(false);
        }
示例#2
0
        public static SmartUri ParseOrDefault(string value, int defaultPort)
        {
            SmartUri uri;

            SmartUri.TryParse(value, defaultPort, out uri);
            return(uri);
        }
示例#3
0
        public static SmartUri Parse(string value, int defaultPort)
        {
            SmartUri uri;

            if (!SmartUri.TryParse(value, defaultPort, out uri))
            {
                throw new FormatException("The string could not be parsed as a URI.");
            }
            return(uri);
        }
示例#4
0
 public bool HostEquals(SmartUri hostUri)
 {
     if (hostUri == null || this.HostNameType == UriHostNameType.Unknown || this.HostNameType != hostUri.HostNameType)
     {
         return(false);
     }
     if (this.HostNameType == UriHostNameType.Dns)
     {
         return(this.Host.Equals(hostUri.Host, StringComparison.OrdinalIgnoreCase));
     }
     return(this.IPEndPoint.Address.Equals((object)hostUri.IPEndPoint.Address));
 }
示例#5
0
        public SmartUri(IPEndPoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }
            this.HostNameType = SmartUri.GetHostNameType(endpoint.Address);
            this.Host         = endpoint.Address.ToString();
            string str;

            if (this.HostNameType != UriHostNameType.IPv6)
            {
                str = this.Host;
            }
            else
            {
                str = this.Host.Trim('[', ']');
            }
            this.DnsFriendlyHost = str;
            this.Port            = endpoint.Port;
            this.IPEndPoint      = endpoint;
        }
示例#6
0
        public static bool TryParse(string value, int defaultPort, out SmartUri uri)
        {
            uri = new SmartUri();
            if (string.IsNullOrEmpty(value))
            {
                return(false);
            }
            int startIndex1 = value.IndexOf('[');
            int startIndex2 = 0;
            int length1     = value.Length;
            int num;

            if (startIndex1 >= 0)
            {
                startIndex2 = startIndex1;
                int startIndex3 = value.IndexOf(']', startIndex1);
                if (startIndex3 < 0)
                {
                    return(false);
                }
                length1 = startIndex3 - startIndex1 + 1;
                num     = value.IndexOf(':', startIndex3);
                if (num > 0 && startIndex3 + 1 != num)
                {
                    return(false);
                }
            }
            else
            {
                num = value.LastIndexOf(':');
                if (num >= 0)
                {
                    if (value.IndexOf(':') == num)
                    {
                        length1 = num - startIndex2;
                    }
                    else
                    {
                        num = -1;
                    }
                }
            }
            string    ipString = value.Substring(startIndex2, length1);
            IPAddress address;

            IPAddress.TryParse(ipString, out address);
            int result;

            if (num >= 0)
            {
                int startIndex3 = num + 1;
                int length2     = value.Length - startIndex3;
                if (!int.TryParse(value.Substring(startIndex3, length2), out result))
                {
                    return(false);
                }
            }
            else
            {
                result = defaultPort;
            }
            UriHostNameType hostNameType = SmartUri.GetHostNameType(address);


            SmartUri local     = @uri;
            SmartUri smartUri1 = new SmartUri();

            smartUri1.HostNameType = hostNameType;
            smartUri1.Host         = ipString;
            SmartUri smartUri2 = smartUri1;
            string   str;

            if (hostNameType != UriHostNameType.IPv6)
            {
                str = ipString;
            }
            else
            {
                str = ipString.Trim('[', ']');
            }
            smartUri2.DnsFriendlyHost = str;
            smartUri1.Port            = result;
            smartUri1.IPEndPoint      = address != null ? new IPEndPoint(address, result) : (IPEndPoint)null;
            SmartUri smartUri3 = smartUri1;

            local = smartUri3;
            return(true);
        }