public static Playlist Deserialize(XElement xml) { Playlist playlist = null; Guid id; var idElement = xml.Descendants("Id").FirstOrDefault(); var nameElement = xml.Descendants("Name").FirstOrDefault(); var tracksElement = xml.Descendants("Tracks").FirstOrDefault(); if (null != nameElement && null != idElement && Guid.TryParse(idElement.Value, out id) && null != tracksElement) { playlist = new Playlist() { Name = nameElement.Value, Id = id }; foreach(var trackElement in tracksElement.Descendants("Track")) { playlist.Tracks.Add(Track.Deserialize(trackElement)); } } else { Debug.WriteLine("Playlist: Invalid track XML"); } return playlist; }
public async Task<Guid> StartNewPlaylist(string name, List<Track> tracks, bool persist) { await this.saveCurrentPlaylistToFile(); var newPlaylist = new Playlist(name, Guid.NewGuid()); newPlaylist.Tracks = new ObservableCollection<Track>(tracks); this.CurrentPlaylist = newPlaylist; await this.saveCurrentPlaylistToFile(); return newPlaylist.Id; }
private async Task<Playlist> loadPlaylistFromFile(Guid playlistId) { Playlist playlist = null; var fileName = playlistId.ToString() + ".playlist"; var folder = Windows.Storage.ApplicationData.Current.LocalFolder; try { var playlistFile = await folder.GetFileAsync(fileName); var xmlString = await FileIO.ReadTextAsync(playlistFile); var xml = XElement.Parse(xmlString); playlist = Playlist.Deserialize(xml); } catch(FileNotFoundException) { Debug.WriteLine("RadioLocalPresetManager: Playlist file not found - " + fileName); } catch(XmlException) { Debug.WriteLine("RadioLocalPresetManager: Playlist file was corrupt, deleting - " + fileName); File.Delete(fileName); } return playlist; }