public override void Parse(XElement element) { var pairs = element.Descendants("series_work"); if (pairs.Any()) { var dict = new Dictionary <long, SeriesResource>(); foreach (var pair in pairs) { var series = new SeriesResource(); series.Parse(pair.Element("series")); if (!dict.TryGetValue(series.Id, out var cached)) { dict[series.Id] = series; cached = series; } var work = new WorkResource(); work.Parse(pair.Element("work")); work.SetSeriesInfo(pair); cached.Works.Add(work); } List = dict.Values.ToList(); } else { List = new List <SeriesResource>(); } }
// TODO: parse series information once I get a better sense // of what series are from the other API calls. //// public List<Series> Series { get; private set; } public override void Parse(XElement element) { Id = element.ElementAsLong("id"); Title = element.ElementAsString("title"); TitleWithoutSeries = element.ElementAsString("title_without_series"); Isbn = element.ElementAsString("isbn"); Isbn13 = element.ElementAsString("isbn13"); Asin = element.ElementAsString("asin"); KindleAsin = element.ElementAsString("kindle_asin"); MarketplaceId = element.ElementAsString("marketplace_id"); CountryCode = element.ElementAsString("country_code"); ImageUrl = element.ElementAsString("large_image_url") ?? element.ElementAsString("image_url") ?? element.ElementAsString("small_image_url"); PublicationDate = element.ElementAsMultiDateField("publication"); Publisher = element.ElementAsString("publisher"); LanguageCode = element.ElementAsString("language_code"); IsEbook = element.ElementAsBool("is_ebook"); Description = element.ElementAsString("description"); AverageRating = element.ElementAsDecimal("average_rating"); Pages = element.ElementAsInt("num_pages"); Format = element.ElementAsString("format"); EditionInformation = element.ElementAsString("edition_information"); RatingsCount = element.ElementAsInt("ratings_count"); TextReviewsCount = element.ElementAsInt("text_reviews_count"); Url = element.ElementAsString("link"); EditionsUrl = element.ElementAsString("editions_url"); ReviewsWidget = element.ElementAsString("reviews_widget"); var workElement = element.Element("work"); if (workElement != null) { Work = new WorkResource(); Work.Parse(workElement); } Authors = element.ParseChildren <AuthorSummaryResource>("authors", "author"); SimilarBooks = element.ParseChildren <BookSummaryResource>("similar_books", "book"); var bookLinks = element.ParseChildren <BookLinkResource>("book_links", "book_link"); if (bookLinks != null) { bookLinks.ForEach(x => x.FixBookLink(Id)); BookLinks = bookLinks; } var buyLinks = element.ParseChildren <BookLinkResource>("buy_links", "buy_link"); if (buyLinks != null) { buyLinks.ForEach(x => x.FixBookLink(Id)); BuyLinks = buyLinks; } var shelves = element.ParseChildren( "popular_shelves", "shelf", (shelfElement) => { var shelfName = shelfElement?.Attribute("name")?.Value; var shelfCountValue = shelfElement?.Attribute("count")?.Value; int shelfCount = 0; int.TryParse(shelfCountValue, out shelfCount); return(new KeyValuePair <string, int>(shelfName, shelfCount)); }); if (shelves != null) { PopularShelves = shelves.GroupBy(obj => obj.Key).ToDictionary(shelf => shelf.Key, shelf => shelf.Sum(x => x.Value)); } }