Пример #1
0
        private async Task GetFeedItemsAlbumsAsync(FeedItemsResult feedItems, IList <Album> albums)
        {
            foreach (var feedItem in feedItems.Items)
            {
                var album = (Album)null;

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

                if (album == null)
                {
                    continue;
                }
                if (
                    albums.FirstOrDefault(
                        a => a.Href.Equals(album.Href, StringComparison.InvariantCultureIgnoreCase)) != null)
                {
                    continue;
                }

                album.ImageUrl = album.ImageUrl;
                albums.Add(album);

                if (albums.Count == NumberOfAlbums)
                {
                    break;
                }
            }
        }
Пример #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);
        }