示例#1
0
        public virtual void Write(IList <Song> songs)
        {
            Messenger.Post("Writing " + songs.Count + " songs");
            var persisted = new List <PersistedSong>();

            foreach (var song in songs)
            {
                persisted.Add(new PersistedSong(song));
            }

            var stream = new StreamWriter(filename, false);

            try
            {
                serializer.Serialize(stream, persisted);
                stream.Flush();
            }
            catch (Exception e)
            {
                Messenger.Post("Error occured! " + e.Message);
            }
            finally
            {
                stream.Close();
                stream.Dispose();
            }
        }
示例#2
0
文件: Helpers.cs 项目: yongjan/Espera
        public static string GenerateSaveFile()
        {
            using (var stream = new MemoryStream())
            {
                LibrarySerializer.Serialize(new[] { LocalSong1, LocalSong2 }, new[] { Playlist1, Playlist2 }, SongSourcePath, stream);

                return(Encoding.UTF8.GetString(stream.ToArray()));
            }
        }
示例#3
0
            public void SmokeTest()
            {
                using (Stream targetStream = new MemoryStream())
                {
                    var songs = new[] { Helpers.LocalSong1, Helpers.LocalSong2 };

                    var playlists = new[] { Helpers.Playlist1, Helpers.Playlist2 };

                    LibrarySerializer.Serialize(songs, playlists, Helpers.SongSourcePath, targetStream);

                    string expected = Helpers.GenerateSaveFile();
                    string actual   = Helpers.StreamToString(targetStream).Replace("\r\n", String.Empty);

                    Assert.Equal(expected, actual);
                }
            }