/// <summary>
        /// Adds a new <see cref="FetchedArtistViewModel"/> to the <see cref="FetchedArtists"/>.
        /// </summary>
        /// <param name="name">Name of the artist.</param>
        /// <param name="mbid">Mbid of the artist.</param>
        /// <param name="image">Image of the artist.</param>
        private void AddArtistViewModel(string name, string mbid, Uri image)
        {
            FetchedArtistViewModel vm = new FetchedArtistViewModel(new Artist(name, mbid, image));

            vm.ArtistClicked += ArtistClicked;
            FetchedArtists.Add(vm);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Searches for artists with the <see cref="SearchText"/>.
        /// </summary>
        /// <returns>Task.</returns>
        private async Task SearchArtists()
        {
            EnableControls = false;

            try
            {
                OnStatusUpdated(string.Format("Searching for artist '{0}'", SearchText));
                ArtistSearchResult asr = null;
                await Task.Run(() => asr = _setlistFMClient.FindArtists(new ArtistSearchOptions()
                {
                    Name = SearchText, Page = ArtistResultPage
                }));

                if (asr != null)
                {
                    ObservableCollection <FetchedArtistViewModel> vms = new ObservableCollection <FetchedArtistViewModel>();
                    foreach (var artist in asr.Artists)
                    {
                        Uri imgUri   = null;
                        var response = await MainViewModel.Client.Artist.GetInfoAsync(artist.Name);

                        if (response.Success)
                        {
                            imgUri = response.Content.MainImage.ExtraLarge;
                        }

                        FetchedArtistViewModel vm = new FetchedArtistViewModel(new Models.Artist(artist.Name, artist.MbId, imgUri));
                        vm.ArtistClicked += ArtistClicked;
                        vms.Add(vm);
                    }

                    if (vms.Count > 0)
                    {
                        FetchedArtists = new ObservableCollection <FetchedArtistViewModel>(vms);
                        CurrentView    = _artistResultView;
                        OnStatusUpdated("Successfully fetched artists");
                    }
                    else
                    {
                        OnStatusUpdated("Found no artists");
                    }
                }
                else
                {
                    OnStatusUpdated("Found no artists");
                }
            }
            catch (Exception ex)
            {
                OnStatusUpdated("Fatal error while searching for artist: " + ex.Message);
            }
            finally
            {
                EnableControls = true;
            }
        }