Example #1
0
 protected void OnFetchPostCompleted(FetchTitleCompletedEventArgs e)
 {
     if (this.FetchPostCompleted != null)
     {
         this.FetchPostCompleted(this, e);
     }
 }
Example #2
0
        void tlf_FetchPostCompleted(object sender, FetchTitleCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                //如果是1.说明是第一次请求,用于初始化总页数
                if (e.UserState.ToString().IndexOf("init") > -1)
                {
                    if (e.TotalPageCount > 0)
                    {
                        projects[0].TotalPageCount = e.TotalPageCount;
                        projects[0].CurrentPageId = e.TotalPageCount;
                        projects[0].PostList = new List<PostInfo>();
                    }
                    else
                    {
                        //获取页数出错,重试
                        this.tlf.FetchListAnsy("init" + Guid.NewGuid().ToString());
                        this.PostFetchInfoChanged(
                            "初次获取页数出错",
                            "初次获取页数出错,重试ing",
                            "",
                            null
                            );

                        return;
                    }
                }
                else
                {
                    //添加到project对象的属性中
                    foreach (PostInfo pi in e.Posts)
                    {
                        //todo : 需要用lb表达式判断,contains是无法获得结果的
                        if (!projects[0].PostList.Contains(pi))
                        {
                            projects[0].PostList.Add(pi);
                        }
                        else
                        {
                            string message = "重复Url获得 : " + pi.Url;
                            this.PostFetchInfoChanged(message, message, "", null);
                            System.Diagnostics.Debug.WriteLine(message);
                        }
                    }

                    //发送事件
                    this.PostFetchPostsProgressChanged(
                        projects[0].TotalPageCount - projects[0].CurrentPageId + 1,
                        projects[0].TotalPageCount
                        );

                    //计算下次获取页数
                    if (e.TotalPageCount > 0)
                    {
                        //如果页数不变,继续递减pageid
                        if (e.TotalPageCount > projects[0].TotalPageCount)
                        {
                            projects[0].CurrentPageId += e.TotalPageCount - projects[0].TotalPageCount;
                            projects[0].TotalPageCount = e.TotalPageCount;
                        }
                        else
                        {
                            projects[0].CurrentPageId--;
                        }

                    }
                    else
                    {
                        //获取页数出错,重试
                        this.tlf.FetchListAnsy("continue" + projects[0].CurrentPageId.ToString());
                        this.PostFetchInfoChanged(
                            "获取页数出错",
                            "获取页数出错,重试ing:" + projects[0].CurrentPageId.ToString(),
                            "",
                            null
                            );

                        return;
                    }
                }


                //获取全部完成?
                if (projects[0].CurrentPageId == 0)
                {
                    this.PostFetchInfoChanged(
                        "获取Post完成",
                        string.Format("获取{0}Post完成", projects[0].PostList.Count),
                        "",
                        null
                        );

                    this.FetchFiles();
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("===> fetch:" + projects[0].CurrentPageId.ToString());
                    this.tlf.Url = projects[0].Url.Replace("[*]", projects[0].CurrentPageId.ToString());
                    this.tlf.FetchListAnsy("continue" + projects[0].CurrentPageId.ToString() + Guid.NewGuid().ToString());
                }
            }
            else
            {
                this.PostFetchPostsAndFilesComplted(this.projects, e.Error);
            }
        }