Exemplo n.º 1
0
        /// <summary>
        /// Compares the InternetUrl with another InternetUrl object. The comparison
        /// is done based on the Url property.
        /// </summary>
        /// <param name="obj">The InternetUrl object to be compared to this one</param>
        /// <returns>An integer indicating difference between the two objects</returns>
        public int CompareTo(object obj)
        {
            if (!(obj is InternetUrl))
            {
                throw new ArgumentException("InternetUrl can only be compared to InternetUrl objects.");
            }
            InternetUrl toCompare = (InternetUrl)obj;

            return(String.Compare(url.ToString(), toCompare.Url));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Returns the host name of an <see cref="InternetUrl"/>
 /// </summary>
 /// <param name="url">The <see cref="InternetUrl"/> to examine</param>
 /// <returns>A string containing the Url's host name or IP Address.</returns>
 public static string HostName(InternetUrl url)
 {
     try
     {
         Uri uri = new Uri(url.Url);
         return(uri.Host);
     }
     catch
     {
         return(String.Empty);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Compares an existing <see cref="InternetUrl"/> instance with the Url of the object for equality.
        /// </summary>
        /// <param name="obj">The object to compare with the current instance</param>
        /// <returns>true if obj represents the same Url as the Url contained in this <see cref="InternetUrl"/> instance; otherwise, false.</returns>
        /// <remarks>This method must not throw any exceptions. The method automatically uses
        /// the <see cref="Object.GetType"/> method to determine if the runtime types of the
        /// objects being compared are equivalent, therefore it is not necessary to check
        /// whether the obj parameter is a <see cref="InternetUrl"/> instance.
        /// </remarks>
        public override bool Equals(object obj)
        {
            //does not check the ID member
            InternetUrl ToCompare = (InternetUrl)obj;

            for (int i = 0; i < 16; i++)
            {
                if ((urlMD5[i] != ToCompare.MD5[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Checks if at least 30 seconds have passed since the last request to a given host
 /// was made, in order not to slammer it with simultaneous or frequent requests.
 /// </summary>
 /// <param name="targetUrl">
 /// A <see cref="InternetUrl"/> that is served by a host we wish to check.
 /// </param>
 /// <returns>
 /// An integer containing the number of milliseconds a crawler thread must wait
 /// before visiting this host.
 /// </returns>
 public int FilterUrl(ref InternetUrl targetUrl)
 {
     string hostName = InternetUtils.HostName(targetUrl);
     return FilterHost(ref hostName);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Constructs a new <see cref="InternetUrl"/> object from an existing <see cref="InternetUrl"/> object.
 /// </summary>
 /// <param name="IUrl">The existing <see cref="InternetUrl"/> object</param>
 public InternetUrl(InternetUrl IUrl)
 {
     urlID = IUrl.ID;
     url = IUrl.Url;
     urlMD5 = IUrl.MD5;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Constructs a new <see cref="InternetUrl"/> object from an existing <see cref="InternetUrl"/> object.
 /// </summary>
 /// <param name="IUrl">The existing <see cref="InternetUrl"/> object</param>
 public InternetUrl(InternetUrl IUrl)
 {
     urlID  = IUrl.ID;
     url    = IUrl.Url;
     urlMD5 = IUrl.MD5;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Returns the host name of an <see cref="InternetUrl"/>
 /// </summary>
 /// <param name="url">The <see cref="InternetUrl"/> to examine</param>
 /// <returns>A string containing the Url's host name or IP Address.</returns>
 public static string HostName(InternetUrl url)
 {
     try
     {
         Uri uri = new Uri(url.Url);
         return uri.Host;
     }
     catch
     {
         return String.Empty;
     }
 }