コード例 #1
0
ファイル: ApiService.cs プロジェクト: arcsinw/ofo
        /// <summary>
        /// 获取频道列表
        /// </summary>
        /// <returns></returns>
        public async Task <List <Channel> > GetChannelList()
        {
            string filename = "channelList.json";

            ResultDataTemplate <List <Channel> > channelResult = new ResultDataTemplate <List <Channel> >();

            channelResult.Result = await FileHelper.Current.ReadObjectAsync <List <Channel> >(filename);


            if (channelResult.Result == null)
            {
                PostDataTemplate <AllChannelListRequest> postData = new PostDataTemplate <AllChannelListRequest>()
                {
                    deviceId = DeviceInformationHelper.GetDeviceId(),
                    request  = new AllChannelListRequest()
                    {
                        type = "0"
                    }
                };

                channelResult = await PostJson <PostDataTemplate <AllChannelListRequest>, ResultDataTemplate <List <Channel> > >(ServiceUri.AllChannel, postData);

                if (channelResult != null && channelResult.Result != null)
                {
                    await FileHelper.Current.WriteObjectAsync(channelResult.Result, filename);
                }
            }

            channelResult.Result.Insert(0, new Channel {
                IsTop = "False", NodeId = 0, NodeName = "头条"
            });
            return(channelResult.Result);
        }
コード例 #2
0
ファイル: ApiService.cs プロジェクト: arcsinw/ofo
        /// <summary>
        /// 获取新闻列表
        /// </summary>
        /// <param name="nodeId">频道ID</param>
        /// <param name="pageIndex">页码</param>
        /// <returns></returns>
        public async Task <List <Essay> > GetEssayList(int nodeId, int pageIndex)
        {
            string filename = "essayList_" + nodeId + "_" + pageIndex + ".json";
            ResultDataTemplate <List <Essay> > essayResult = new ResultDataTemplate <List <Essay> >();

            if (!ConnectionHelper.IsInternetAvailable) //无网络
            {
                essayResult.Result = await FileHelper.Current.ReadObjectAsync <List <Essay> >(filename);
            }
            else
            {
                PostDataTemplate <AllChannelListRequest> postData = new PostDataTemplate <AllChannelListRequest>()
                {
                    deviceId = DeviceInformationHelper.GetDeviceId(),
                    request  = new AllChannelListRequest()
                    {
                        elementsCountPerPage = 20,
                        nodeIds      = nodeId,
                        pageIndex    = pageIndex,
                        parentNodeId = "news",
                        type         = "null",
                    }
                };

                essayResult = await PostJson <PostDataTemplate <AllChannelListRequest>, ResultDataTemplate <List <Essay> > >(ServiceUri.AllChannelList, postData);

                if (essayResult != null && essayResult.Result != null)
                {
                    await FileHelper.Current.WriteObjectAsync(essayResult.Result, filename);
                }
            }

            return(essayResult?.Result);
        }
コード例 #3
0
ファイル: ApiService.cs プロジェクト: arcsinw/ofo
        /// <summary>
        /// 阅读文章
        /// 适用于新闻 和 攻略
        /// </summary>
        /// <param name="contentId">文章Id</param>
        /// <returns></returns>
        public async Task <News> GetEssay(string contentId)
        {
            string filename = "news_" + contentId + ".json";
            ResultDataTemplate <News> newsResult = new ResultDataTemplate <News>();

            if (!ConnectionHelper.IsInternetAvailable)  //无网络
            {
                newsResult.Result = await FileHelper.Current.ReadObjectAsync <News>(filename);
            }
            else
            {
                PostDataTemplate <AllChannelListRequest> postData = new PostDataTemplate <AllChannelListRequest>()
                {
                    request = new AllChannelListRequest
                    {
                        contentId = contentId,
                        pageIndex = 1
                    },
                    deviceId = DeviceInformationHelper.GetDeviceId()
                };

                newsResult = await PostJson <PostDataTemplate <AllChannelListRequest>, ResultDataTemplate <News> >(ServiceUri.TwoArticle, postData);

                if (newsResult != null && newsResult.Result != null)
                {
                    await FileHelper.Current.WriteObjectAsync <News>(newsResult.Result, filename);
                }
            }

            return(newsResult?.Result);
        }