Exemplo n.º 1
0
        /// <summary>
        /// 初始化url信息
        /// </summary>
        private void GatherInitUrls()
        {
            //域名
            string strPagePre = this.txtDomainUrl.Text.Trim();

            if (strPagePre.EndsWith("/"))
            {
                strPagePre = strPagePre.Remove(strPagePre.Length - 1);
            }

            //相对路径,分页参数需用占位符替换
            string strPagePost = this.txtRelativeUrl.Text.Trim();

            if (!strPagePost.StartsWith("/"))
            {
                strPagePost = "/" + strPagePost;
            }

            //拼接成完整的请求url
            string strPage = string.Concat(strPagePre, strPagePost);

            //请求开始的页码
            int startPageIndex = 1;
            //请求结束的页码
            int endPageIndex = 1;

            if (!string.IsNullOrEmpty(this.txtStartPageIndex.Text.Trim()))
            {
                int.TryParse(this.txtStartPageIndex.Text.Trim(), out startPageIndex);
            }

            if (!string.IsNullOrEmpty(this.txtEndPageIndex.Text.Trim()))
            {
                int.TryParse(this.txtEndPageIndex.Text.Trim(), out endPageIndex);
            }

            int articleCategoryId = Convert.ToInt32(this.cobArticleCategory.SelectedValue);

            //初始化下载器
            downloader = new WebDownloader(AppHelper.RequestTimeSpan, articleCategoryId);

            string preUrl = "";

            for (int i = startPageIndex; i <= endPageIndex; i++)
            {
                //添加到下载队列
                string strUrl = string.Format(strPage, i);
                if (string.IsNullOrEmpty(preUrl))
                {
                    downloader.AddUrlQueue(strUrl, strUrl);
                }
                else
                {
                    downloader.AddUrlQueue(strUrl, preUrl);
                }

                preUrl = strUrl;
            }
        }