void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { var playlistString = e.Result; try { var json = JObject.Parse(playlistString); var currentTrackFragment = json["now_playing"]; var currentTrack = JsonConvert.DeserializeObject<Song>(currentTrackFragment.ToString()); var recentlyPlayedFragment = json["recently_played"]; var recentlyPlayed = JsonConvert.DeserializeObject<List<Song>>(recentlyPlayedFragment.ToString()); var args = new RequestCompletedEventArgs() { CurrentTrack = currentTrack, PreviousTracks = recentlyPlayed }; if (RequestCompleted != null) { RequestCompleted(this, args); } } catch (Exception ex) { throw new Exception(ex.ToString()); } } else { if(RequestCompleted != null) { RequestCompleted(this, new RequestCompletedEventArgs() { Error = e.Error.Message }); } else { throw new Exception("Unable to retrieve playlist"); } } }
void requestHelper_RequestCompleted(object sender, RequestCompletedEventArgs args) { if (String.IsNullOrEmpty(args.Error) == false) { MessageBox.Show("Can't connect to the internet. Make sure you have a network connection and try again"); timer.Stop(); return; } timer.Start(); _viewModel.CurrentTrack = args.CurrentTrack; _viewModel.RecentTracks.Clear(); //if (BackgroundAudioPlayer.Instance.Track != null) //{ // BackgroundAudioPlayer.Instance.Track.BeginEdit(); // BackgroundAudioPlayer.Instance.Track.Title = "asdf"; // BackgroundAudioPlayer.Instance.Track.EndEdit(); //} foreach (var t in args.PreviousTracks) { _viewModel.RecentTracks.Add(t); } }