/// <summary> /// Updates the playlist Url. /// </summary> private async Task UpdatePlaylistUrl() { if (_playlistUrlChanged) { Workspace.SetPlaylistUrl(PlaylistUrl); Tracks.Clear(); } if (string.IsNullOrEmpty(Workspace.PlaylistId)) { return; } await Task.Run(() => { foreach (var track in Tracks) { track.CheckForTrack(); } }); PlaylistFetchProgress = 0; FetchingPlaylist = true; var retreiver = new PlaylistItemsRetriever(Settings.Default.PlaylistReceiveMaximum); retreiver.PlaylistItemsRetrieverProgressChanged += delegate(object sender, PlaylistItemRetreiverProgressChangedEventArgs args) { PlaylistFetchProgress = args.Progress; }; retreiver.PlaylistItemsRetrieverCompleted += (sender, args) => { if (args.Cancelled) { Messenger.Default.Send( new ShowMessageDialogMessage(Resources.MainWindow_CurrentWorkspace_PlaylistLoadError_Title, Resources.MainWindow_CurrentWorkspace_PlaylistLoadError_Content)); FetchingPlaylist = false; return; } Workspace.Settings.Items = new HashSet <PlaylistItem>(List.Sync(Workspace.Settings.Items.ToList(), args.Result)); UpdateTracks(); FetchingPlaylist = false; if (_playlistUrlChanged) { _playlistUrlChanged = false; CleanupWorkspaceFolder(); } }; await Task.Run(() => { retreiver.GetPlaylistItems(Workspace.PlaylistId); }); }
/// <summary> /// Updates the playlist Url. /// </summary> private async Task UpdatePlaylistUrl() { if (_playlistUrlChanged) { Workspace.SetPlaylistUrl(PlaylistUrl); Tracks.Clear(); } await Task.Run(() => { foreach (var track in Tracks) { track.CheckForTrack(); } }); PlaylistFetchProgress = 0; FetchingPlaylist = true; var retreiver = new PlaylistItemsRetriever(Settings.Default.PlaylistReceiveMaximum); retreiver.PlaylistItemsRetrieverProgressChanged += delegate(object sender, PlaylistItemRetreiverProgressChangedEventArgs args) { PlaylistFetchProgress = args.Progress; }; retreiver.PlaylistItemsRetrieverCompleted += (sender, args) => { if (args.Cancelled) { Messenger.Default.Send(new ShowMessageDialogMessage("Error loading your playlist", "There was an error loading your playlist.\nThis could be due to a missing internet connection, an invalid playlist id or if the playlist is listed as \"Private\".")); FetchingPlaylist = false; return; } Workspace.Settings.Items = new HashSet <PlaylistItem>(Enumerable.Sync(Workspace.Settings.Items.ToList(), args.Result)); UpdateTracks(); FetchingPlaylist = false; if (_playlistUrlChanged) { _playlistUrlChanged = false; CleanupWorkspaceFolder(); } }; try { await Task.Run(() => retreiver.GetPlaylistItems(Workspace.PlaylistId)); } catch (Exception ex) { Messenger.Default.Send(new ShowMessageDialogMessage("Failed to load playlist", "It was not possible to load the content of the specified playlist.\nPlease check your internet connection. If this error persists please report this issue.")); Logger.Warn(ex, "Failed to retreive playlist items for workspace {0}", Workspace); FetchingPlaylist = false; } }