Ejemplo n.º 1
0
        private async Task <IList <Album> > GetSbwrAlbumsAsync()
        {
            var albums = new List <Album>();

            var feedPage = 1;

            while (feedPage < SbwrMaxFeedPageCount && albums.Count < NumberOfAlbums)
            {
                foreach (var genre in _sbwrConfiguration.Genres)
                {
                    var feedItems = await _sbwrFeedItemService.GetFeedItemsByGenreAsync(genre, feedPage);
                    await GetFeedItemsAlbumsAsync(feedItems, albums);

                    if (albums.Count == NumberOfAlbums)
                    {
                        break;
                    }
                    feedPage++;
                }
            }

            return(albums);
        }
Ejemplo n.º 2
0
        private async Task <Albums> GetAlbumsAsync(FeedItemSource source, string genre, int page)
        {
            FeedItemsResult feedItemsResult;

            if (source == FeedItemSource.Boomkat)
            {
                feedItemsResult = (genre != "0")
                    ? await _boomkatBoomkatFeedItemService.GetFeedItemsByGenreAsync(genre, page)
                    : await _boomkatBoomkatFeedItemService.GetFeedItemsAsync(page);
            }
            else
            {
                feedItemsResult = await _sbwrFeedItemService.GetFeedItemsByGenreAsync(genre, page);
            }

            var albums = new Albums {
                Items = new List <Album>(),
                Pages = feedItemsResult.Pages.Select(
                    x => (x != "...")
                        ? new Page {
                    Text = x, Value = int.Parse(x), IsCurrent = int.Parse(x) == page
                }
                        : new Page {
                    Text = x, Value = 0, IsDisabled = true
                }).ToList()
            };

            if (page > 1)
            {
                albums.Pages.Insert(0, new Page {
                    Text = "‹ previous", Value = page - 1
                });
            }

            if (albums.Pages[albums.Pages.Count - 1].Text == "..." || albums.Pages[albums.Pages.Count - 1].Value != page)
            {
                albums.Pages.Add(new Page {
                    Text = "next ›", Value = page + 1
                });
            }

            foreach (var feedItem in feedItemsResult.Items)
            {
                var album = (Album)null;

                try {
                    album = await _spotifyService.FindArtistAlbumAsync(feedItem.Artist, feedItem.Album);
                }
                catch (SpotifyServiceException ssex) {
                    _newRelicTransactionManager.NoticeError(ssex);
                }

                if (album == null)
                {
                    continue;
                }

                album.ImageUrl = album.ImageUrl;
                if (!albums.Items.Contains(album, new AlbumComparer()))
                {
                    albums.Items.Add(album);
                }
            }

            return(albums);
        }