public async Task AddNew(StopOperationToken stopToken) { List <StorageFolder> folders = await GetStorageFolders(); List <IPlaylist> adds = new List <IPlaylist>(); foreach (StorageFolder folder in folders.OrderBy(f => f.Path)) { if (stopToken.IsStopped) { return; } if (Playlists.Any(p => p.AbsolutePath == folder.Path)) { continue; } IPlaylist playlist = new Playlist(folder.Path); playlist.Parent = Playlists; await playlist.Reset(stopToken); if (playlist.Songs.Count > 0) { adds.Add(playlist); } } if (stopToken.IsStopped) { return; } Playlists.Change(null, adds); }
public void Load(IEnumerable <IPlaylist> playlists) { if (IsLoaded || playlists == null) { return; } string currentSongPath = CurrentPlaylist?.CurrentSong?.Path; double currentSongPosition = CurrentPlaylist?.CurrentSongPosition ?? 0; List <IPlaylist> remainingPlaylists = Playlists.ToList(); List <IPlaylist> addPlaylists = new List <IPlaylist>(); foreach (IPlaylist setPlaylist in playlists) { IPlaylist existingPlaylist = remainingPlaylists.FirstOrDefault(p => p.AbsolutePath == setPlaylist.AbsolutePath); if (existingPlaylist == null) { addPlaylists.Add(setPlaylist); } else { existingPlaylist.Songs = setPlaylist.Songs; remainingPlaylists.Remove(existingPlaylist); } } Playlists.Change(remainingPlaylists, addPlaylists); SetCurrentPlaylistAndCurrentSong(currentSongPath, currentSongPosition); //AutoSaveLoad.CheckLibrary(this, "LoadedComplete"); IsLoaded = true; Loaded?.Invoke(this, System.EventArgs.Empty); }