private void AddArtist(object sender, MouseButtonEventArgs e) { player.stop(); currentSong = null; player_changeState(); song_change(); artist Artist = ((artist)((TreeViewItem)sender).DataContext); playlist.Clear(); playlist.AddRange(Artist.Songs); NotifyPropertyChanged("Playlist"); }
void parseList(string list, BackgroundWorker worker) { worker.WorkerReportsProgress = true; worker.ReportProgress(20); if (list != null && !string.IsNullOrWhiteSpace(list)) { artists = new ObservableCollection <artist>(); string[] temp = null; temp = list.Split('\n'); List <string> SongList = new List <string>(temp); int SongCount = SongList.Count; if (SongCount > 0) { int i = 0; foreach (string title in SongList) { temp = new string[] { "::" }; string[] splitLine = title.Split(temp, StringSplitOptions.None); i++; worker.ReportProgress((i / SongCount) * 100); if (splitLine.Length != 7) { continue; } var temp1 = artists.Where(x => x.Name == splitLine[1]); artist currentArtist = null; // artist handling if (temp1 != null && temp1.Count() > 0) { // artist exits currentArtist = temp1.First(); } else { // artirst not exits currentArtist = new artist(splitLine[1]); artists.Add(currentArtist); } // album handling var temp2 = currentArtist.Albums.Where(x => x.Name == splitLine[2]); album currentAlbum = null; if (temp2 != null && temp2.Count() > 0) { // album exits currentAlbum = temp2.First(); } else { // album not exits currentAlbum = new album(splitLine[2]); Albums.Add(currentAlbum); currentArtist.Albums.Add(currentAlbum); } // song handling var temp3 = currentAlbum.Songs.Where(x => x.Name == splitLine[3]); song currentSong = null; if (temp3 != null && temp3.Count() > 0) { // song exits currentSong = temp3.First(); } else { // song not exits int sec = -1; int.TryParse(splitLine[6], out sec); currentSong = new song(splitLine[4], splitLine[5], splitLine[0], sec); currentAlbum.Songs.Add(currentSong); Songs.Add(currentSong.UID, currentSong); } } } NotifyPropertyChanged("Artists"); } }