예제 #1
0
        private SongViewModel LookupSong(SongModel song)
        {
            if (song == null)
            {
                return(null);
            }

            if (SongLookupMap.ContainsKey(song.SongId))
            {
                return(SongLookupMap[song.SongId]);
            }
            else
            {
                ArtistViewModel artist = LookupArtistById(song.ArtistId);

                AlbumViewModel album = LookupAlbumById(song.AlbumId);

                SongViewModel newSongViewModel = new SongViewModel(song, artist, album);

                SongLookupMap.Add(newSongViewModel.SongId, newSongViewModel);
                SongCollection.Add(newSongViewModel, newSongViewModel.SortName);
                FlatSongCollection.Add(newSongViewModel);

                if (LibraryLoaded)
                {
                    NotifyPropertyChanged(Properties.IsEmpty);
                }

                return(newSongViewModel);
            }
        }
예제 #2
0
        private void HandleAllSongsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                foreach (SongViewModel oldSongViewModel in FlatSongCollection)
                {
                    oldSongViewModel.Album.Songs.Remove(oldSongViewModel);
                    oldSongViewModel.Artist.Songs.Remove(oldSongViewModel);

                    SongCollection.Remove(oldSongViewModel, oldSongViewModel.SortName);
                    FlatSongCollection.Remove(oldSongViewModel);
                    SongLookupMap.Remove(oldSongViewModel.SongId);
                }
            }
            else
            {
                if (e.OldItems != null)
                {
                    foreach (SongModel oldSong in e.OldItems)
                    {
                        SongViewModel oldSongViewModel = LookupSong(oldSong);

                        SongCollection.Remove(oldSongViewModel, oldSongViewModel.SortName);
                        FlatSongCollection.Remove(oldSongViewModel);
                        SongLookupMap.Remove(oldSongViewModel.SongId);

                        oldSongViewModel.Album.Songs.Remove(oldSongViewModel);
                        oldSongViewModel.Artist.Songs.Remove(oldSongViewModel);
                    }
                }

                if (e.NewItems != null)
                {
                    foreach (SongModel newSong in e.NewItems)
                    {
                        LookupSong(newSong);
                    }
                }
            }

            if (LibraryLoaded)
            {
                NotifyPropertyChanged(Properties.IsEmpty);
                ShuffleAllSongs.RaiseExecuteChanged();
            }
        }