コード例 #1
0
        public async Task StepByStep()
        {
            BaiduRestService.GetService(this.Client.RestClient).Responsed += BaiduSongListServiceTest_Responsed;
            SongListContent songlistContent = await BaiduSongListService.GetService(this.Client).GedanAsync(1);

            foreach (var songlist in songlistContent.SongLists)
            {
                SongListInfoContent songlistInfoContent = await BaiduSongListService.GetService(this.Client).GedanInfoAsync(songlist.ListId);

                foreach (var song in songlistInfoContent.Songs)
                {
                    SongInfoContent songInfoContent = await BaiduSongService.GetService(this.Client).GetInfoAsync(song.SongId);

                    song.CopyFrom(songInfoContent.Item);
                }
            }
            BaiduRestService.GetService(this.Client.RestClient).Responsed -= BaiduSongListServiceTest_Responsed;
        }
コード例 #2
0
ファイル: BaiduRestClient.cs プロジェクト: ruo2012/OpenMusic
        /// <summary>
        /// Execute request.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <BaiduRestResponse> SendAsync([NotNull] BaiduRestRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            BaiduRestResponse response = null;

            BaiduRestService.GetService(this).SendRequest(request);
            try
            {
                HttpResponseMessage httpResponseMessage = await GetHttpResponseMessage(request, cancellationToken).ConfigureAwait(false);

                string content = await GetResponseContent(httpResponseMessage).ConfigureAwait(false);

                response = new BaiduRestResponse(request, httpResponseMessage, content);
            }
            catch (Exception ex)
            {
                response = new BaiduRestResponse(request, new HttpResponseMessage(HttpStatusCode.BadRequest), ex);
            }
            finally
            {
                BaiduRestService.GetService(this).SendResponse(response);
            }
            return(response);
        }