Exemple #1
0
        /// <summary>
        /// Fetches the tracklist of the clicked release and displays it.
        /// </summary>
        /// <param name="sender">Clicked release as <see cref="LastAlbum"/>.</param>
        /// <param name="e">Ignored.</param>
        public async void ReleaseClicked(object sender, EventArgs e)
        {
            if (EnableControls)
            {
                EnableControls = false;

                try
                {
                    var release = sender as Release;

                    OnStatusUpdated("Trying to fetch tracklist from '" + release.Name + "'");

                    LastResponse <LastAlbum> detailedRelease = null;
                    if (release.Mbid != null && release.Mbid != "")
                    {
                        detailedRelease = await _lastfmAlbumAPI.GetInfoByMbidAsync(release.Mbid);
                    }
                    else
                    {
                        detailedRelease = await _lastfmAlbumAPI.GetInfoAsync(release.ArtistName, release.Name);
                    }

                    if (detailedRelease.Success)
                    {
                        FetchedTracks.Clear();
                        foreach (var t in detailedRelease.Content.Tracks)
                        {
                            FetchedTrackViewModel vm = new FetchedTrackViewModel(new ScrobbleBase(t.Name, t.ArtistName, t.AlbumName, "", t.Duration), release.Image);
                            vm.ToScrobbleChanged += ToScrobbleChanged;
                            FetchedTracks.Add(vm);
                        }

                        if (FetchedTracks.Count != 0)
                        {
                            CurrentView = _trackResultView;
                            OnStatusUpdated("Successfully fetched tracklist from '" + release.Name + "'");
                        }
                        else
                        {
                            OnStatusUpdated("'" + release.Name + "' has no tracks");
                        }
                    }
                    else
                    {
                        OnStatusUpdated("Error while fetching tracklist from '" + release.Name + "'");
                    }
                }
                catch (Exception ex)
                {
                    OnStatusUpdated("Fatal error while fetching tracklist from release: " + ex.Message);
                }
                finally
                {
                    EnableControls = true;
                }
            }
        }
        /// <summary>
        /// Fetches the tracklist of the clicked release and displays it.
        /// </summary>
        /// <param name="sender">Clicked release as <see cref="LastAlbum"/>.</param>
        /// <param name="e">Ignored.</param>
        public async void ReleaseClicked(object sender, EventArgs e)
        {
            if (EnableControls)
            {
                EnableControls = false;

                try
                {
                    var release = sender as Release;
                    OnStatusUpdated(string.Format("Trying to fetch tracklist from release '{0}'", release.Name));

                    LastResponse <LastAlbum> response = null;
                    if (!string.IsNullOrEmpty(release.Mbid))
                    {
                        response = await _lastfmAlbumAPI.GetInfoByMbidAsync(release.Mbid);
                    }
                    else
                    {
                        response = await _lastfmAlbumAPI.GetInfoAsync(release.ArtistName, release.Name);
                    }

                    if (response.Success && response.Status == LastResponseStatus.Successful)
                    {
                        FetchedTracks.Clear();
                        foreach (var t in response.Content.Tracks)
                        {
                            FetchedTrackViewModel vm = new FetchedTrackViewModel(new ScrobbleBase(t.Name, t.ArtistName, t.AlbumName, "", t.Duration), release.Image);
                            vm.ToScrobbleChanged += ToScrobbleChanged;
                            FetchedTracks.Add(vm);
                        }

                        if (FetchedTracks.Count != 0)
                        {
                            CurrentView = _trackResultView;
                            OnStatusUpdated(string.Format("Successfully fetched tracklist from release '{0}'", release.Name));
                        }
                        else
                        {
                            OnStatusUpdated(string.Format("Release '{0}' has no tracks", release.Name));
                        }
                    }
                    else
                    {
                        OnStatusUpdated(string.Format("Error while fetching tracklist from release '{0}': {1}", release.Name, response.Status));
                    }
                }
                catch (Exception ex)
                {
                    OnStatusUpdated(string.Format("Fatal error while fetching tracklist from release: {0}", ex.Message));
                }
                finally
                {
                    EnableControls = true;
                }
            }
        }