Example #1
0
 protected Url(SerializationInfo info,StreamingContext context)
 {
     this.uri = info.GetValue("uri", typeof(Uri)) as Uri;
     this.uriEscape = info.GetBoolean("escape");
     this.checkSum = info.GetUInt32("checkSum");
     this.hostCheckSum = info.GetUInt32("hostCheckSum");
     this.checkSumAlgorith = info.GetValue("checkSumAlgorith", typeof(IUrlCheckSum)) as IUrlCheckSum;
     this.httpMethod = info.GetString("httpMethod");
     this.appendParams = info.GetValue("appendParams", typeof(NameValueCollection)) as NameValueCollection;
     this.ignoreParams = info.GetValue("ignoreParams", typeof(NameValueCollection)) as NameValueCollection;
     this.maxTryTimes = info.GetInt32("maxTryTimes");
     this.hasTriedTimes = info.GetInt32("hasTriedTimes");
     this.hasError = info.GetBoolean("hasError");
     this.errorMsg = info.GetString("errorMsg");
     this.contentHandlers = info.GetValue("contentHandlers", typeof(ContentHandlerCollection)) as ContentHandlerCollection;
     this.text = info.GetString("text");
     this.domainSuffixProvider = info.GetValue("domainSuffixProvider", typeof(IDomainSuffixPrivoder)) as IDomainSuffixPrivoder;
     this.allowExtractUrl = info.GetBoolean("allowExtractUrl");
 }
Example #2
0
        /// <summary>
        /// 构造函数
        /// </summary>
        private Url()
        {
            this.uri = null;
            this.uriEscape = true;
            this.checkSum = UInt32.MinValue;
            this.hostCheckSum = UInt32.MinValue;
            this.checkSumAlgorith = new GeneralUrlCheckSum(true);
            this.httpMethod = "GET";
            this.appendParams = null;
            this.maxTryTimes = 1;
            this.hasTriedTimes = 0;
            this.hasError = false;
            this.errorMsg = "";
            this.text = "";

            this.contentHandlers = new ContentHandlerCollection();

            this.domain = null;
            this.domainSuffixProvider = Core.DomainSuffixProvider.Default;

            this.allowExtractUrl = true;
        }
Example #3
0
        /// <summary>
        /// 获取URL的域部分,如www.urbly.com的域部分为urbly.com,www2.test.urbly.com.cn的域部分为urbly.com.cn.
        /// </summary>
        /// <returns>string,无法获取时返回空字符串</returns>
        public static string GetUrlDomain(Url url, IDomainSuffixPrivoder provider)
        {
            if (null == url || null == provider)
            {
                return "";
            }

            string host = url.Uri.Host;
            string[] suffixes = provider.GetSuffixes();
            if (null == suffixes)
            {
                return "";
            }

            string pattern = String.Join("|", suffixes).Replace(".", "\\.");
            pattern = "\\.(?<D>[\\w-]+)(?:" + pattern + ")$";

            Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
            Match m = r.Match(host);
            if (m.Success)
            {
                return host.Substring(m.Groups["D"].Index);
            }
            return "";
        }