Пример #1
0
 public static async void SavePlayListAsync(IEnumerable files) {
   await Task.Factory.StartNew(() => {
                                 var pl = new PlayList { Files = files.OfType<MediaFile>().ToList() };
                                 var playListAsJson = JsonConvert.SerializeObject(pl, Formatting.None);
                                 File.WriteAllText(PlayListFileName, playListAsJson);
                               });
 }
Пример #2
0
        private static void SavePlayList(IEnumerable files)
        {
            var pl = new PlayList {
                Files = files.OfType <MediaFile>().ToList()
            };

            using (var fs = File.Open(PlayListFileName, FileMode.OpenOrCreate))
            {
                using (var sw = new StreamWriter(fs))
                {
                    using (var jw = new JsonTextWriter(sw))
                    {
                        jw.Formatting = Formatting.None;
                        var serializer = new JsonSerializer();
                        serializer.Serialize(jw, pl);
                    }
                }
            }
        }
 public async void SavePlayListAsync(IEnumerable<IMediaFile> files) {
   var pl = new PlayList();
   pl.Files = files.OfType<MediaFileViewModel>().ToList();
   var playListAsJson = await JsonConvert.SerializeObjectAsync(pl, Formatting.None);
   await Task.Factory.StartNew(() => File.WriteAllText(PlayList.PlayListFileName, playListAsJson));
 }