public async Task AddNew(StopOperationToken stopToken) { List <StorageFolder> folders = await GetStorageFolders(); List <IPlaylist> adds = new List <IPlaylist>(); foreach (StorageFolder folder in folders.OrderBy(f => f.Path)) { if (stopToken.IsStopped) { return; } if (Playlists.Any(p => p.AbsolutePath == folder.Path)) { continue; } IPlaylist playlist = new Playlist(folder.Path); playlist.Parent = Playlists; await playlist.Reset(stopToken); if (playlist.Songs.Count > 0) { adds.Add(playlist); } } if (stopToken.IsStopped) { return; } Playlists.Change(null, adds); }
public void AddPlaylist(Model.Playlist newPlaylist) { if (Playlists.Any(cus => cus.Name == newPlaylist.Name) == false) { XML.PlaylistXML playlistXML = new XML.PlaylistXML(); playlistXML.Load("playlists.xml"); if (!playlistXML.HasPlaylist(newPlaylist.Name)) { playlistXML.AddPlaylist(newPlaylist.Name); playlistXML.WriteInFile("playlists.xml"); Playlists.Add(newPlaylist); } } }
public void RemovePlaylist(Model.Playlist selectedPlaylist) { if (Playlists.Any(cus => cus.Name == selectedPlaylist.Name) == true) { XML.PlaylistXML playlistXML = new XML.PlaylistXML(); playlistXML.Load("playlists.xml"); if (playlistXML.HasPlaylist(selectedPlaylist.Name)) { playlistXML.RemovePlaylist(selectedPlaylist.Name); playlistXML.WriteInFile("playlists.xml"); Playlists.Remove(selectedPlaylist); } } }
public virtual void AddPlaylist(Playlist playlist) { // Client might not set the sequence number. if (playlist.Sequence < 0) { if (Playlists.Any()) { playlist.Sequence = Playlists.OrderBy(i => i.Sequence).Last().Sequence + 10000; } else { playlist.Sequence = 10000; } } playlist.User = this; Playlists.Add(playlist); }
public void Button_Save_Click(object sender, RoutedEventArgs e) { string name = textboxListName.Text.Trim(); if (!string.IsNullOrEmpty(name)) { PlaylistModel model = new PlaylistModel { Name = name, UserId = CurrentUser.Id }; SaveNewPlayList(model); if (!Playlists.Any(x => x.Id == model.Id)) { Playlists.Add(model); } var p = (MainWindow)((FrameworkElement)((FrameworkElement)((FrameworkElement)((FrameworkElement)((FrameworkElement)((FrameworkElement)((FrameworkElement)this.Parent).Parent).Parent).Parent).Parent).Parent).Parent).Parent; p.ShowPlaylist(); PlayListGrid.Children.Clear(); //PlayListGrid.Children.Add(new Playlist()); } }
/// <summary> /// Removes the playlist with the specified name from the library. /// </summary> /// <param name="playlistName">The name of the playlist to remove.</param> /// <exception cref="InvalidOperationException">No playlist exists, or no playlist with the specified name exists.</exception> public void RemovePlaylist(string playlistName) { if (playlistName == null) { Throw.ArgumentNullException(() => playlistName); } if (!Playlists.Any()) { throw new InvalidOperationException("There are no playlists."); } Playlist playlist = GetPlaylistByName(playlistName); if (playlist == null) { throw new InvalidOperationException("No playlist with the specified name exists."); } _playlists.Remove(playlist); }
public async Task RefreshPlayLists() { PlayListsAreLoaded = false; if (Playlists == null) { Playlists = new ObservableCollection <PlaylistEx>(); } if (Playlists.Any()) { Playlists.Clear(); } var pl = await GetPlaylists(); foreach (var playlist in pl) { Playlists.Add(new PlaylistEx { Playlist = playlist, Subscription = Channel }); } PlayListsAreLoaded = true; }
public Config(byte[] rom) { const string configFile = "MP2K.yaml"; using (StreamReader fileStream = File.OpenText(Util.Utils.CombineWithBaseDirectory(configFile))) { string gcv = string.Empty; try { ROM = rom; Reader = new EndianBinaryReader(new MemoryStream(rom)); GameCode = Reader.ReadString(4, 0xAC); Version = Reader.ReadByte(0xBC); gcv = $"{GameCode}_{Version:X2}"; var yaml = new YamlStream(); yaml.Load(fileStream); var mapping = (YamlMappingNode)yaml.Documents[0].RootNode; YamlMappingNode game; try { game = (YamlMappingNode)mapping.Children.GetValue(gcv); } catch (BetterKeyNotFoundException) { throw new Exception(string.Format(Strings.ErrorParseConfig, configFile, Environment.NewLine + string.Format(Strings.ErrorAlphaDreamMP2KMissingGameCode, gcv))); } YamlNode nameNode = null, songTableOffsetsNode = null, songTableSizesNode = null, sampleRateNode = null, reverbTypeNode = null, reverbNode = null, volumeNode = null, hasGoldenSunSynthsNode = null, hasPokemonCompression = null; void Load(YamlMappingNode gameToLoad) { if (gameToLoad.Children.TryGetValue("Copy", out YamlNode node)) { YamlMappingNode copyGame; try { copyGame = (YamlMappingNode)mapping.Children.GetValue(node); } catch (BetterKeyNotFoundException ex) { throw new Exception(string.Format(Strings.ErrorAlphaDreamMP2KParseGameCode, gcv, configFile, Environment.NewLine + string.Format(Strings.ErrorAlphaDreamMP2KCopyInvalidGameCode, ex.Key))); } Load(copyGame); } if (gameToLoad.Children.TryGetValue(nameof(Name), out node)) { nameNode = node; } if (gameToLoad.Children.TryGetValue(nameof(SongTableOffsets), out node)) { songTableOffsetsNode = node; } if (gameToLoad.Children.TryGetValue(nameof(SongTableSizes), out node)) { songTableSizesNode = node; } if (gameToLoad.Children.TryGetValue(nameof(SampleRate), out node)) { sampleRateNode = node; } if (gameToLoad.Children.TryGetValue(nameof(ReverbType), out node)) { reverbTypeNode = node; } if (gameToLoad.Children.TryGetValue(nameof(Reverb), out node)) { reverbNode = node; } if (gameToLoad.Children.TryGetValue(nameof(Volume), out node)) { volumeNode = node; } if (gameToLoad.Children.TryGetValue(nameof(HasGoldenSunSynths), out node)) { hasGoldenSunSynthsNode = node; } if (gameToLoad.Children.TryGetValue(nameof(HasPokemonCompression), out node)) { hasPokemonCompression = node; } if (gameToLoad.Children.TryGetValue(nameof(Playlists), out node)) { var playlists = (YamlMappingNode)node; foreach (KeyValuePair <YamlNode, YamlNode> kvp in playlists) { string name = kvp.Key.ToString(); var songs = new List <Song>(); foreach (KeyValuePair <YamlNode, YamlNode> song in (YamlMappingNode)kvp.Value) { long songIndex = Util.Utils.ParseValue(string.Format(Strings.ConfigKeySubkey, nameof(Playlists)), song.Key.ToString(), 0, long.MaxValue); if (songs.Any(s => s.Index == songIndex)) { throw new Exception(string.Format(Strings.ErrorAlphaDreamMP2KParseGameCode, gcv, configFile, Environment.NewLine + string.Format(Strings.ErrorAlphaDreamMP2KSongRepeated, name, songIndex))); } songs.Add(new Song(songIndex, song.Value.ToString())); } Playlists.Add(new Playlist(name, songs)); } } } Load(game); if (nameNode == null) { throw new BetterKeyNotFoundException(nameof(Name), null); } Name = nameNode.ToString(); if (songTableOffsetsNode == null) { throw new BetterKeyNotFoundException(nameof(SongTableOffsets), null); } string[] songTables = songTableOffsetsNode.ToString().SplitSpace(StringSplitOptions.RemoveEmptyEntries); int numSongTables = songTables.Length; if (numSongTables == 0) { throw new Exception(string.Format(Strings.ErrorAlphaDreamMP2KParseGameCode, gcv, configFile, Environment.NewLine + string.Format(Strings.ErrorConfigKeyNoEntries, nameof(SongTableOffsets)))); } if (songTableSizesNode == null) { throw new BetterKeyNotFoundException(nameof(SongTableSizes), null); } string[] sizes = songTableSizesNode.ToString().SplitSpace(StringSplitOptions.RemoveEmptyEntries); if (sizes.Length != numSongTables) { throw new Exception(string.Format(Strings.ErrorAlphaDreamMP2KParseGameCode, gcv, configFile, Environment.NewLine + string.Format(Strings.ErrorAlphaDreamMP2KSongTableCounts, nameof(SongTableSizes), nameof(SongTableOffsets)))); } SongTableOffsets = new int[numSongTables]; SongTableSizes = new long[numSongTables]; int maxOffset = rom.Length - 1; for (int i = 0; i < numSongTables; i++) { SongTableSizes[i] = Util.Utils.ParseValue(nameof(SongTableSizes), sizes[i], 1, maxOffset); SongTableOffsets[i] = (int)Util.Utils.ParseValue(nameof(SongTableOffsets), songTables[i], 0, maxOffset); } if (sampleRateNode == null) { throw new BetterKeyNotFoundException(nameof(SampleRate), null); } SampleRate = (int)Util.Utils.ParseValue(nameof(SampleRate), sampleRateNode.ToString(), 0, Utils.FrequencyTable.Length - 1); if (reverbTypeNode == null) { throw new BetterKeyNotFoundException(nameof(ReverbType), null); } ReverbType = Util.Utils.ParseEnum <ReverbType>(nameof(ReverbType), reverbTypeNode.ToString()); if (reverbNode == null) { throw new BetterKeyNotFoundException(nameof(Reverb), null); } Reverb = (byte)Util.Utils.ParseValue(nameof(Reverb), reverbNode.ToString(), byte.MinValue, byte.MaxValue); if (volumeNode == null) { throw new BetterKeyNotFoundException(nameof(Volume), null); } Volume = (byte)Util.Utils.ParseValue(nameof(Volume), volumeNode.ToString(), 0, 15); if (hasGoldenSunSynthsNode == null) { throw new BetterKeyNotFoundException(nameof(HasGoldenSunSynths), null); } HasGoldenSunSynths = Util.Utils.ParseBoolean(nameof(HasGoldenSunSynths), hasGoldenSunSynthsNode.ToString()); if (hasPokemonCompression == null) { throw new BetterKeyNotFoundException(nameof(HasPokemonCompression), null); } HasPokemonCompression = Util.Utils.ParseBoolean(nameof(HasPokemonCompression), hasPokemonCompression.ToString()); // The complete playlist if (!Playlists.Any(p => p.Name == "Music")) { Playlists.Insert(0, new Playlist(Strings.PlaylistMusic, Playlists.SelectMany(p => p.Songs).Distinct().OrderBy(s => s.Index))); } } catch (BetterKeyNotFoundException ex) { throw new Exception(string.Format(Strings.ErrorAlphaDreamMP2KParseGameCode, gcv, configFile, Environment.NewLine + string.Format(Strings.ErrorConfigKeyMissing, ex.Key))); } catch (InvalidValueException ex) { throw new Exception(string.Format(Strings.ErrorAlphaDreamMP2KParseGameCode, gcv, configFile, Environment.NewLine + ex.Message)); } catch (YamlDotNet.Core.YamlException ex) { throw new Exception(string.Format(Strings.ErrorParseConfig, configFile, Environment.NewLine + ex.Message)); } } }
public NamingError CheckPlaylistNamingError(string newName) { if (string.IsNullOrEmpty(newName) || string.IsNullOrWhiteSpace(newName)) { return(NamingError.EmptyOrWhiteSpace); } if (newName == MenuFlyoutHelper.NowPlaying || newName == MenuFlyoutHelper.MyFavorites || Playlists.Any(p => p.Name == newName)) { return(NamingError.Used); } if (newName.Contains(TileHelper.StringConcatenationFlag) || newName.Contains("{0}")) { return(NamingError.Special); } if (newName.Length > PlaylistNameMaxLength) { return(NamingError.TooLong); } return(NamingError.Good); }
public Config(byte[] rom) { const string configFile = "MLSS.yaml"; using (StreamReader fileStream = File.OpenText(configFile)) { string gcv = string.Empty; try { ROM = rom; Reader = new EndianBinaryReader(new MemoryStream(rom)); GameCode = Reader.ReadString(4, 0xAC); Version = Reader.ReadByte(0xBC); gcv = $"{GameCode}_{Version:X2}"; var yaml = new YamlStream(); yaml.Load(fileStream); var mapping = (YamlMappingNode)yaml.Documents[0].RootNode; YamlMappingNode game; try { game = (YamlMappingNode)mapping.Children.GetValue(gcv); } catch (BetterKeyNotFoundException) { throw new Exception(string.Format(Strings.ErrorParseConfig, configFile, Environment.NewLine + string.Format(Strings.ErrorMLSSMP2KMissingGameCode, gcv))); } Name = game.Children.GetValue(nameof(Name)).ToString(); string[] songTables = game.Children.GetValue(nameof(SongTableOffsets)).ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (songTables.Length == 0) { throw new Exception(string.Format(Strings.ErrorMLSSMP2KParseGameCode, gcv, configFile, Environment.NewLine + string.Format(Strings.ErrorConfigKeyNoEntries, nameof(SongTableOffsets)))); } VoiceTableOffset = (int)game.GetValidValue(nameof(VoiceTableOffset), 0, rom.Length - 1); SampleTableOffset = (int)game.GetValidValue(nameof(SampleTableOffset), 0, rom.Length - 1); if (game.Children.TryGetValue("Copy", out YamlNode copy)) { try { game = (YamlMappingNode)mapping.Children.GetValue(copy); } catch (BetterKeyNotFoundException ex) { throw new Exception(string.Format(Strings.ErrorMLSSMP2KParseGameCode, gcv, configFile, Environment.NewLine + string.Format(Strings.ErrorMLSSMP2KCopyInvalidGameCode, ex.Key))); } } string[] sizes = game.Children.GetValue(nameof(SongTableSizes)).ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (sizes.Length != songTables.Length) { throw new Exception(string.Format(Strings.ErrorMLSSMP2KParseGameCode, gcv, configFile, Environment.NewLine + string.Format(Strings.ErrorMLSSMP2KSongTableCounts, nameof(SongTableSizes), nameof(SongTableOffsets)))); } SongTableOffsets = new int[songTables.Length]; SongTableSizes = new long[songTables.Length]; for (int i = 0; i < songTables.Length; i++) { SongTableOffsets[i] = (int)Util.Utils.ParseValue(nameof(SongTableOffsets), songTables[i], 0, rom.Length - 1); SongTableSizes[i] = Util.Utils.ParseValue(nameof(SongTableSizes), sizes[i], 1, rom.Length - 1); } SampleTableSize = game.GetValidValue(nameof(SampleTableSize), 0, rom.Length - 1); if (game.Children.TryGetValue(nameof(Remap), out YamlNode remap)) { Remap = remap.ToString(); } if (game.Children.TryGetValue(nameof(Playlists), out YamlNode _playlists)) { var playlists = (YamlMappingNode)_playlists; foreach (KeyValuePair <YamlNode, YamlNode> kvp in playlists) { string name = kvp.Key.ToString(); var songs = new List <Song>(); foreach (KeyValuePair <YamlNode, YamlNode> song in (YamlMappingNode)kvp.Value) { long songIndex = Util.Utils.ParseValue(string.Format(Strings.ConfigKeySubkey, nameof(Playlists)), song.Key.ToString(), 0, long.MaxValue); if (songs.Any(s => s.Index == songIndex)) { throw new Exception(string.Format(Strings.ErrorMLSSMP2KParseGameCode, gcv, configFile, Environment.NewLine + string.Format(Strings.ErrorMLSSMP2KSongRepeated, name, songIndex))); } songs.Add(new Song(songIndex, song.Value.ToString())); } Playlists.Add(new Playlist(name, songs)); } } // The complete playlist if (!Playlists.Any(p => p.Name == "Music")) { Playlists.Insert(0, new Playlist(Strings.PlaylistMusic, Playlists.SelectMany(p => p.Songs).Distinct().OrderBy(s => s.Index))); } } catch (BetterKeyNotFoundException ex) { throw new Exception(string.Format(Strings.ErrorMLSSMP2KParseGameCode, gcv, configFile, Environment.NewLine + string.Format(Strings.ErrorConfigKeyMissing, ex.Key))); } catch (InvalidValueException ex) { throw new Exception(string.Format(Strings.ErrorMLSSMP2KParseGameCode, gcv, configFile, Environment.NewLine + ex.Message)); } catch (YamlDotNet.Core.YamlException ex) { throw new Exception(string.Format(Strings.ErrorParseConfig, configFile, Environment.NewLine + ex.Message)); } } }