private async Task SetList(PlayList pl, bool random = true) { CurrentList = pl; FileList = await Task.Run(() => new ObservableCollection<ListFiles>(pl.ListFiles.Where(lf => lf.IsChecked))); if (random) miRandom_Click(null, null); }
public static async Task<int> ReloadPlayList(PlayList pl) { return await Task.Run(() => { int count = 0; var newLines = ImportListFile(pl.Source, ListType.M3U8); if (newLines == null) return 0; var dict = pl.ListFiles.ToDictionary(lf => lf.MusicFile.FullName); var oldLines = dict.Keys.AsEnumerable(); var del = oldLines.Except(newLines).Select(ol => dict[ol]); var add = newLines.Except(oldLines).Select(nl => MDModel.Model.MusicFile.SingleOrDefault(m => m.FullName == nl)); foreach (var di in del) pl.ListFiles.Remove(di); count += MDModel.Model.SaveChanges(); foreach (var ai in add) { if (ai == null) continue; var lf = new ListFiles() { FileId = ai.FileId, IsChecked = true, ListId = pl.ListId, }; pl.ListFiles.Add(lf); } count += MDModel.Model.SaveChanges(); return count; }); }