public static SongDataColl ImportPlaylist(string path) { SongDataColl cll = null; // Deserialize an instance of the class // from an XML file. First create an instance of the // XmlDictionaryReader. try { FileStream fs = new FileStream(path, FileMode.OpenOrCreate); XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas()); // Create the DataContractSerializer instance. DataContractSerializer ser = new DataContractSerializer(typeof(SongDataColl)); // Deserialize the data and read it from the instance. cll = (SongDataColl)ser.ReadObject(reader); fs.Close(); } catch (Exception ex) { cll = new SongDataColl(); } return cll; }
/// <summary> /// Default constructor /// </summary> public PlayListBuilder() { InitializeComponent(); _songCollection = LoadPlaylist(@"c:\playlist.xml"); InitializeBindings(); }
/// <summary> /// Method that will filter the current playlist and return the songs that are acording to the correct BPM Interval /// </summary> /// <param name="bpmInterval"> Interval of BPM's allowed in the playlist</param> /// <returns>Playlist of songs with the beats per minute acording to the passed interval</returns> private SongDataColl GetSongsWithBPM(BPMInterval bpmInterval) { SongDataColl playlist = new SongDataColl(); foreach (var song in _songCollection) { if( song.BPM <= bpmInterval.MaxBPM && song.BPM >= bpmInterval.MinBPM ) playlist.Add(song); } return playlist; }