示例#1
0
        public async Task ReadChapterAsync()
        {
            Console.WriteLine(nameof(ReadChapterAsync));
            var chapters = await _client.GetAllAsync(_urlService.BooksApi);

            Guid        id      = chapters.First().Id;
            BookChapter chapter = await _client.GetAsync(_urlService.BooksApi + id);

            Console.WriteLine($"{chapter.Number} {chapter.Title}");
            Console.WriteLine();
        }
        /// <summary>
        /// 如果章节的标识符不存在,就调用
        /// </summary>
        /// <returns></returns>
        public async Task ReadNotExistingChapterAsync()
        {
            Console.WriteLine(nameof(ReadNotExistingChapterAsync));
            string requestedIdentifier = Guid.NewGuid().ToString();

            try
            {
                BookChapter chapter = await _client.GetAsync(_urlService.BooksApi + requestedIdentifier.ToString());

                Console.WriteLine($"{chapter.Number} {chapter.Title}");
            }
            catch (HttpRequestException ex) when(ex.Message.Contains("404"))
            {
                Console.WriteLine($"没有找到章节识别码: {requestedIdentifier}");
            }
        }
        public async Task ReadNotExistingChapterAsync()
        {
            Console.WriteLine(nameof(ReadNotExistingChapterAsync));
            Guid requestedIdentifier = Guid.NewGuid();

            try
            {
                var chapter = await _bookChapterClientService.GetAsync(_urlService.BookApi + requestedIdentifier);

                Console.WriteLine($"{chapter.Id} {chapter.Title}");
            }
            catch (HttpRequestException ex) when(ex.Message.Contains("404"))
            {
                Console.WriteLine($"book chapter with the identifier {requestedIdentifier} not found.");
            }
        }