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; }
/// <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); }