public void Insert_SingleRow() { var playlists = new Playlists(); var inserted = playlists.Insert(new { Name = "MassivePlaylist" }); Assert.IsTrue(inserted.PlaylistId > 0); }
public async Task <Playlist> CreatePlaylistAsync(string name) { if (Playlists.Count(p => p.Name == name) > 0) { throw new ArgumentException(name); } var playlist = new Playlist { Name = name }; await _sqlService.InsertAsync(playlist); Playlists.Insert(0, playlist); return(playlist); }
/// <inheritdoc/> public async Task AddPlaylist(string title, string description) { try { var newPlaylist = new Google.Apis.YouTube.v3.Data.Playlist(); newPlaylist.Snippet = new PlaylistSnippet(); newPlaylist.Snippet.Title = title; newPlaylist.Snippet.Description = description; newPlaylist.Status = new PlaylistStatus(); newPlaylist.Status.PrivacyStatus = "private"; await m_YouTubeService !.Playlists.Insert(newPlaylist, "snippet,status").ExecuteAsync(); } catch { // エラーが発生した場合は何もしない } }
private void ChangePlaylistName(object obj) { var activePlaylist = SelectedPlaylist; var dialog = new TextBoxWindow(); if (dialog.ShowDialog() == true) { activePlaylist.Name = dialog.ResponseText; } int index = Playlists.IndexOf(activePlaylist); SelectedPlaylist = null; Playlists.Remove(activePlaylist); Playlists.Insert(index, activePlaylist); SelectedPlaylist = activePlaylist; }
protected override void InitializeCommands() { base.InitializeCommands(); //place other commands here AddPlaylistCommand = new DelegateCommand(async() => { var newPlaylist = (IPlaylist)await PopupControl.Show <EditPlaylistView>(); if (newPlaylist != null) { Playlists.Insert(0, newPlaylist); } }); GoToPlaylistCommand = new DelegateCommand <PlaylistVk>(playlist => { NavigationService.Navigate(typeof(PlaylistView), new Dictionary <string, object> { ["playlist"] = playlist }); }); ShuffleAllCommand = new DelegateCommand(() => { List <IAudio> tracks = null; switch (_tabIndex) { case 0: tracks = Tracks.ToList(); break; case 1: tracks = _news?.SelectMany(p => p.Tracks).ToList(); break; case 2: tracks = _wallPosts?.SelectMany(p => p.Tracks).ToList(); break; } if (tracks.IsNullOrEmpty()) { return; } tracks.Shuffle(); AudioService.Instance.PlayAudio(tracks.First(), tracks); }); PlayAllCommand = new DelegateCommand(() => { List <IAudio> tracks = null; if (_tabIndex == 1) { tracks = _news?.SelectMany(p => p.Tracks).ToList(); } else if (_tabIndex == 2) { tracks = _wallPosts?.SelectMany(p => p.Tracks).ToList(); } if (tracks.IsNullOrEmpty()) { return; } AudioService.Instance.PlayAudio(tracks.First(), tracks); }); }
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 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)); } } }