コード例 #1
0
        public async Task GetServiceBlog(int pageIndex, int pageSize, int position)
        {
            string url = string.Empty;

            //开放平台上请求数据
            if (position < 2)
            {
                if (position == 0)
                {
                    url = string.Format(Constant.BLOG_HOME_LIST, pageIndex, pageSize);
                }
                else
                {
                    url = string.Format(Constant.BLOG_PICKED_LIST, pageIndex, pageSize);
                }
                await HttpClientUtil.GetAsync <List <BlogModel> >(url, null,
                                                                  async (list) =>
                {
                    blogView.GetServiceBlogSuccess(list);
                    BlogCategoryModel model        = MyApplication.blogCategoryList.Where(f => f.Position == position).FirstOrDefault();
                    list.ForEach(f => f.CategoryId = model.CategoryId);
                    await SqliteDatabase.Instance().UpdateBlogList(list);
                },
                                                                  (error) =>
                {
                    blogView.GetServiceBlogFail(error);
                });
            }
            //从网页总抓取数据
            else
            {
                url = string.Format(Constant.BLOG_CATEGORY_LIST, pageIndex, pageSize);
                BlogCategoryModel model = MyApplication.blogCategoryList.Where(f => f.Position == position).FirstOrDefault();
                model.PageIndex = pageIndex;
                await HttpClientUtil.PostBlogCategoryAsync(url, model,
                                                           async (list) => {
                    blogView.GetServiceBlogSuccess(list);
                    list.ForEach(f => f.CategoryId = model.CategoryId);
                    await SqliteDatabase.Instance().UpdateBlogList(list);
                },
                                                           (error) => {
                    blogView.GetServiceBlogFail(error);
                });
            }
        }
コード例 #2
0
ファイル: BlogPresenter.cs プロジェクト: zhangzhg0508/Cnblogs
        public async Task GetServiceBlog(AccessToken token, string blogApp)
        {
            try
            {
                var result = await OkHttpUtils.Instance(token).GetAsyn(string.Format(ApiUtils.BlogApp, blogApp));

                if (result.IsError)
                {
                    blogView.GetServiceBlogFail(result.Message);
                }
                else
                {
                    var blog = JsonConvert.DeserializeObject <BlogModel>(result.Message);
                    blog.BlogApp = blogApp;
                    await SQLiteUtils.Instance().UpdateBlog(blog);

                    blogView.GetServiceBlogSuccess(blog);
                }
            }
            catch (Exception ex)
            {
                blogView.GetServiceBlogFail(ex.Message);
            }
        }