/// <summary> /// 继续加载博客列表 /// </summary> public void listBoxHelper_ReloadDelegate( ) { if (this.listBoxHelper.isLoading == true) { return; } Dictionary <string, string> parameters = new Dictionary <string, string> { { "authoruid", authoruid.ToString() }, { "pageIndex", (this.listBoxHelper.allCount / 20).ToString() }, { "pageSize", "20" }, { "uid", Config.UID.ToString() }, }; WebClient client = Tool.SendWebClient(Config.api_userblog_list, parameters); this.listBoxHelper.isLoading = true; client.DownloadStringCompleted += (s, e) => { this.listBoxHelper.isLoading = false; if (e.Error != null) { System.Diagnostics.Debug.WriteLine("获取 UserBlogList 网络错误: {0}", e.Error.Message); return; } int pageSize; BlogUnit[] newBlogs = Tool.GetUserBlogList(e.Result, out pageSize); if (newBlogs == null) { newBlogs = new BlogUnit[] { }; } if (newBlogs != null) { this.listBoxHelper.allCount += pageSize; this.listBoxHelper.isLoadOver = pageSize < 20; //筛选 int[] ids = Tool.GetIDS_ID <BlogUnit>(this.listBoxHelper.datas); newBlogs = newBlogs.Where(n => ids.Contains(n.id) == false).ToArray( ); if (newBlogs.Length > 0) { if (this.listBoxHelper.datas.Count > 0) { this.listBoxHelper.datas[this.listBoxHelper.datas.Count - 1] = newBlogs[0]; for (int i = 1; i < newBlogs.Length; i++) { this.listBoxHelper.datas.Add(newBlogs[i]); } } else { newBlogs.ForAll(n => this.listBoxHelper.datas.Add(n)); } } //添加最后的提示文字 LoadNextTip tip = this.listBoxHelper.GetLoadTip; this.listBoxHelper.datas.Add(tip); } }; }
/// <summary> /// 继续加载评论列表 /// </summary> public void listBoxHelper_ReloadDelegate( ) { if (this.listBoxHelper == null) { return; } if (this.listBoxHelper.isLoading == true) { return; } Dictionary <string, string> parameters = new Dictionary <string, string> { { "pageIndex", (this.listBoxHelper.allCount / 20).ToString() }, { "pageSize", "20" }, { "id", this.id.ToString( ) }, { "guid", Guid.NewGuid().ToString() }, }; if (catalog != 5) { parameters.Add("catalog", this.catalog.ToString( )); } WebClient client = Tool.SendWebClient(catalog != 5 ? Config.api_comment_list : Config.api_blogcomment_list, parameters); this.listBoxHelper.isLoading = true; client.DownloadStringCompleted += (s, e) => { this.listBoxHelper.isLoading = false; if (e.Error != null) { System.Diagnostics.Debug.WriteLine("获取 {0} 网络错误: {1}", catalog == 5 ? "BlogCommentList" : "CommentList", e.Error.Message); return; } int pageSize; CommentUnit[] newComments = Tool.GetCommentList(e.Result, out pageSize); if (newComments != null) { this.listBoxHelper.allCount += this.catalog != 5 ? pageSize : newComments.Length; this.listBoxHelper.isLoadOver = this.catalog != 5 ? pageSize < 20 : newComments.Length < 20; //筛选 int[] ids = Tool.GetIDS_ID <CommentUnit>(this.listBoxHelper.datas); newComments = newComments.Where(c => ids.Contains(c.id) == false).ToArray( ); if (newComments.Length > 0) { if (this.listBoxHelper.datas.Count > 0) { this.listBoxHelper.datas[this.listBoxHelper.datas.Count - 1] = newComments[0]; for (int i = 1; i < newComments.Length; i++) { this.listBoxHelper.datas.Add(newComments[i]); } } else { newComments.ForAll(n => this.listBoxHelper.datas.Add(n)); } } else { //去除最后项 if (this.listBoxHelper.datas.Count > 0) { this.listBoxHelper.datas.RemoveAt(this.listBoxHelper.datas.Count - 1); } } //添加最后的提示文字 if (this.listBoxHelper.isLoadOver == false || this.listBoxHelper.datas.Count <= 0) { LoadNextTip tip = this.listBoxHelper.GetLoadTip; tip.Foreground = new SolidColorBrush(Colors.Black); this.listBoxHelper.datas.Add(tip); } } }; }
/// <summary> /// 继续加载新闻列表 /// </summary> private void listBoxHelper_ReloadDelegate() { if (this.listBoxHelper.isLoading == true) { return; } Dictionary <string, string> parameters = new Dictionary <string, string> { { "pageIndex", (this.listBoxHelper.allCount / 20).ToString() }, { "pageSize", "20" }, }; switch (this.newsType) { case NewsType.News: parameters.Add("catalog", "1"); break; case NewsType.Blogs: parameters.Add("type", "latest"); break; case NewsType.RecommendBlogs: parameters.Add("type", "recommend"); break; } WebClient client = Tool.SendWebClient(NewsType == Controls.NewsType.News ? Config.api_news_list : Config.api_blog_list, parameters); this.listBoxHelper.isLoading = true; client.DownloadStringCompleted += (s, e) => { this.listBoxHelper.isLoading = false; if (e.Error != null) { System.Diagnostics.Debug.WriteLine("获取 NewsList 网络错误: {0}", e.Error.Message); return; } int pageSize; #region 获取新闻 if (this.NewsType == Controls.NewsType.News) { NewsUnit[] newNews = Tool.GetNewsList(e.Result, out pageSize); if (newNews != null) { this.listBoxHelper.allCount += pageSize; this.listBoxHelper.isLoadOver = pageSize < 20; //如果是刷新则提示有数据 注意必须在筛选前就处理好 //筛选 int[] ids = Tool.GetIDS_ID <NewsUnit>(this.listBoxHelper.datas); newNews = newNews.Where(n => ids.Contains(n.id) == false).ToArray( ); if (newNews.Length > 0) { if (this.listBoxHelper.datas.Count > 0) { this.listBoxHelper.datas[this.listBoxHelper.datas.Count - 1] = newNews[0]; for (int i = 1; i < newNews.Length; i++) { this.listBoxHelper.datas.Add(newNews[i]); } } else { newNews.ForAll(n => this.listBoxHelper.datas.Add(n)); } } //添加最后的提示文字 if (this.listBoxHelper.isLoadOver == false) { LoadNextTip tip = this.listBoxHelper.GetLoadTip; tip.Foreground = new SolidColorBrush(Colors.White); this.listBoxHelper.datas.Add(tip); } } } #endregion #region 博客 else { BlogUnit[] newBlogs = Tool.GetUserBlogList(e.Result, out pageSize); if (newBlogs != null) { this.listBoxHelper.allCount += pageSize; this.listBoxHelper.isLoadOver = pageSize < 20; //如果是刷新则提示有数据 注意必须在筛选前就处理好 //筛选 int[] ids = Tool.GetIDS_ID <BlogUnit>(this.listBoxHelper.datas); newBlogs = newBlogs.Where(n => ids.Contains(n.id) == false).ToArray( ); if (newBlogs.Length > 0) { if (this.listBoxHelper.datas.Count > 0) { this.listBoxHelper.datas[this.listBoxHelper.datas.Count - 1] = newBlogs[0]; for (int i = 1; i < newBlogs.Length; i++) { this.listBoxHelper.datas.Add(newBlogs[i]); } } else { newBlogs.ForAll(n => this.listBoxHelper.datas.Add(n)); } } //添加最后的提示文字 if (this.listBoxHelper.isLoadOver == false) { LoadNextTip tip = this.listBoxHelper.GetLoadTip; tip.Foreground = new SolidColorBrush(Colors.White); this.listBoxHelper.datas.Add(tip); } } } #endregion }; }