public void Update(TablaturePlaylist playlist) { using (var cmd = new SQLiteCommand(_databaseHelper.GetConnection())) { cmd.CommandType = CommandType.Text; cmd.CommandText = string.Format(@"INSERT OR REPLACE INTO {0} (id, name, created) VALUES (@id, @name, @created)", TabsterDatabaseHelper.TablePlaylists); cmd.Parameters.Add(new SQLiteParameter("@id", playlist.Id)); cmd.Parameters.Add(new SQLiteParameter("@name", playlist.Name)); cmd.Parameters.Add(new SQLiteParameter("@created", TabsterDatabaseHelper.GetUnixTimestamp(playlist.Created.Value))); cmd.ExecuteNonQuery(); } playlist.Id = _databaseHelper.GetConnection().LastInsertRowId; RemovePlaylistItems(playlist); foreach (var item in playlist) { using (var cmd = new SQLiteCommand(_databaseHelper.GetConnection())) { cmd.CommandType = CommandType.Text; cmd.CommandText = string.Format(@"INSERT INTO {0} (filename, playlist_id) VALUES (@filename, @playlist_id)", TabsterDatabaseHelper.TablePlaylistItems); cmd.Parameters.Add(new SQLiteParameter("@filename", item.FileInfo.FullName)); cmd.Parameters.Add(new SQLiteParameter("@playlist_id", playlist.Id)); cmd.ExecuteNonQuery(); } } _playlists.Add(playlist); }
private void AddPlaylistNode(TablaturePlaylist playlist, bool select = false) { var playlistRootNode = sidemenu.Nodes["node_playlists"]; //check if tablaturePlaylist node already exists var node = playlistRootNode.Nodes.Cast <TreeNode>().FirstOrDefault(n => n.Tag.Equals(playlist)); if (node == null) { node = new TreeNode(playlist.Name) { NodeFont = sidemenu.FirstNode.FirstNode.NodeFont, Tag = playlist }; playlistRootNode.Nodes.Add(node); if (!playlistRootNode.IsExpanded) { playlistRootNode.ExpandAll(); } } if (select) { sidemenu.SelectedNode = node; } }
public PlaylistDetailsDialog(TablaturePlaylist playlist) { InitializeComponent(); _playlist = playlist; LoadData(); }
private void RemovePlaylistItems(TablaturePlaylist playlist) { using (var cmd = new SQLiteCommand(_databaseHelper.GetConnection())) { cmd.CommandType = CommandType.Text; cmd.CommandText = string.Format(@"DELETE FROM {0} WHERE playlist_id=@playlist_id", TabsterDatabaseHelper.TablePlaylistItems); cmd.Parameters.Add(new SQLiteParameter("@playlist_id", playlist.Id)); cmd.ExecuteNonQuery(); } }
/// <summary> /// Convert Xml-based files to binary. /// </summary> public static void ConvertXmlFiles(PlaylistManager playlistManager, LibraryManager libraryManager) { var playlistsDirectory = Path.Combine(TabsterEnvironment.GetEnvironmentDirectoryPath(TabsterEnvironmentDirectory.UserData), "Playlists"); // playlists are no longer stored as files, but are now stored in database if (Directory.Exists(playlistsDirectory)) { #pragma warning disable 612 var playlistProcessor = new TabsterFileProcessor <TablaturePlaylistDocument>(TablaturePlaylistDocument.FileVersion); #pragma warning restore 612 foreach (var file in Directory.GetFiles(playlistsDirectory, string.Format("*{0}", Constants.TablaturePlaylistFileExtension), SearchOption.AllDirectories)) { var playlistFile = playlistProcessor.Load(file); if (playlistFile != null) { var playlist = new TablaturePlaylist(playlistFile.Name) { Created = playlistFile.FileAttributes.Created }; foreach (var item in playlistFile) { playlist.Add(item); } playlistManager.Update(playlist); try { File.Delete(file); } catch (Exception ex) { Logging.GetLogger().Error(string.Format("Error occured during playlist conversion: {0}", file), ex); } } } } if (Directory.Exists(libraryManager.TablatureDirectory)) { foreach (var file in Directory.GetFiles(libraryManager.TablatureDirectory, string.Format("*{0}", Constants.TablatureFileExtension), SearchOption.AllDirectories)) { var tablatureFile = TabsterXmlFileConverter.ConvertTablatureDocument(file); if (tablatureFile != null) { tablatureFile.Save(file); } } } }
private void RemovePlaylistNode(TablaturePlaylist playlist) { foreach (TreeNode node in sidemenu.Nodes["node_playlists"].Nodes) { if (node.Tag.Equals(playlist)) { sidemenu.Nodes.Remove(node); break; } } }
/// <summary> /// Convert Xml-based files to binary. /// </summary> public static void ConvertXmlFiles(PlaylistManager playlistManager, LibraryManager libraryManager) { var playlistsDirectory = Path.Combine(TabsterEnvironment.GetEnvironmentDirectoryPath(TabsterEnvironmentDirectory.UserData), "Playlists"); // playlists are no longer stored as files, but are now stored in database if (Directory.Exists(playlistsDirectory)) { #pragma warning disable 612 var playlistProcessor = new TabsterFileProcessor<TablaturePlaylistDocument>(TablaturePlaylistDocument.FileVersion); #pragma warning restore 612 foreach (var file in Directory.GetFiles(playlistsDirectory, string.Format("*{0}", Constants.TablaturePlaylistFileExtension), SearchOption.AllDirectories)) { var playlistFile = playlistProcessor.Load(file); if (playlistFile != null) { var playlist = new TablaturePlaylist(playlistFile.Name) {Created = playlistFile.FileAttributes.Created}; foreach (var item in playlistFile) { playlist.Add(item); } playlistManager.Update(playlist); try { File.Delete(file); } catch(Exception ex) { Logging.GetLogger().Error(string.Format("Error occured during playlist conversion: {0}", file), ex); } } } } if (Directory.Exists(libraryManager.TablatureDirectory)) { foreach (var file in Directory.GetFiles(libraryManager.TablatureDirectory, string.Format("*{0}", Constants.TablatureFileExtension), SearchOption.AllDirectories)) { var tablatureFile = TabsterXmlFileConverter.ConvertTablatureDocument(file); if (tablatureFile != null) tablatureFile.Save(file); } } }
public void Load() { _playlists.Clear(); using (var cmd = new SQLiteCommand(string.Format("SELECT * FROM {0}", TabsterDatabaseHelper.TablePlaylists), _databaseHelper.GetConnection())) { using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var id = long.Parse(reader["id"].ToString()); var name = reader["name"].ToString(); var created = reader["created"].ToString(); var playlist = new TablaturePlaylist(name) { Id = id, Created = TabsterDatabaseHelper.UnixTimestampToDateTime(int.Parse(created)) }; _playlists.Add(playlist); } } } foreach (var playlist in _playlists) { using (var cmd = new SQLiteCommand(string.Format("SELECT * FROM {0} WHERE playlist_id=@playlist_id", TabsterDatabaseHelper.TablePlaylistItems), _databaseHelper.GetConnection())) { cmd.Parameters.Add(new SQLiteParameter("@playlist_id", playlist.Id)); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var id = long.Parse(reader["id"].ToString()); var filename = reader["filename"].ToString(); var file = _fileProcessor.Load(filename); if (file != null) { var fileInfo = new FileInfo(filename); var item = new TablaturePlaylistItem(file, fileInfo); playlist.Add(item); } } } } } }
public void Load() { _playlists.Clear(); using (var cmd = new SQLiteCommand(string.Format("SELECT * FROM {0}", TabsterDatabaseHelper.TablePlaylists), _databaseHelper.GetConnection())) { using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var id = long.Parse(reader["id"].ToString()); var name = reader["name"].ToString(); var created = reader["created"].ToString(); var playlist = new TablaturePlaylist(name) {Id = id, Created = TabsterDatabaseHelper.UnixTimestampToDateTime(int.Parse(created))}; _playlists.Add(playlist); } } } foreach (var playlist in _playlists) { using (var cmd = new SQLiteCommand(string.Format("SELECT * FROM {0} WHERE playlist_id=@playlist_id", TabsterDatabaseHelper.TablePlaylistItems), _databaseHelper.GetConnection())) { cmd.Parameters.Add(new SQLiteParameter("@playlist_id", playlist.Id)); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var id = long.Parse(reader["id"].ToString()); var filename = reader["filename"].ToString(); var file = _fileProcessor.Load(filename); if (file != null) { var fileInfo = new FileInfo(filename); var item = new TablaturePlaylistItem(file, fileInfo); playlist.Add(item); } } } } } }
private void AddPlaylistNode(TablaturePlaylist playlist, bool select = false) { var playlistRootNode = sidemenu.Nodes["node_playlists"]; //check if tablaturePlaylist node already exists var node = playlistRootNode.Nodes.Cast<TreeNode>().FirstOrDefault(n => n.Tag.Equals(playlist)); if (node == null) { node = new TreeNode(playlist.Name) {NodeFont = sidemenu.FirstNode.FirstNode.NodeFont, Tag = playlist}; playlistRootNode.Nodes.Add(node); if (!playlistRootNode.IsExpanded) playlistRootNode.ExpandAll(); } if (select) sidemenu.SelectedNode = node; }
private void NewPlaylist(object sender, EventArgs e) { using (var p = new NewPlaylistDialog()) { if (p.ShowDialog() == DialogResult.OK) { if (string.IsNullOrEmpty(p.PlaylistName)) { MessageBox.Show(Resources.InvalidNameDialogText, Resources.InvalidNameDialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var playlist = new TablaturePlaylist(p.PlaylistName) { Created = DateTime.UtcNow }; var item = GetSelectedLibraryItem(); // new playlist if (sender == newPlaylistToolStripMenuItem) { // 'add to' new playlist if (item != null) { playlist.Add(new TablaturePlaylistItem(item.File, item.FileInfo)); } } _playlistManager.Update(playlist); AddPlaylistNode(playlist); PopulatePlaylistMenu(); UpdateDetails(); } } }
private void NewPlaylist(object sender, EventArgs e) { using (var p = new NewPlaylistDialog()) { if (p.ShowDialog() == DialogResult.OK) { if (string.IsNullOrEmpty(p.PlaylistName)) { MessageBox.Show(Resources.InvalidNameDialogText, Resources.InvalidNameDialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var playlist = new TablaturePlaylist(p.PlaylistName) {Created = DateTime.UtcNow}; var item = GetSelectedLibraryItem(); // new playlist if (sender == newPlaylistToolStripMenuItem) { // 'add to' new playlist if (item != null) { playlist.Add(new TablaturePlaylistItem(item.File, item.FileInfo)); } } _playlistManager.Update(playlist); AddPlaylistNode(playlist); PopulatePlaylistMenu(); UpdateDetails(); } } }
public void Remove(TablaturePlaylist playlist) { using (var cmd = new SQLiteCommand(_databaseHelper.GetConnection())) { cmd.CommandType = CommandType.Text; cmd.CommandText = string.Format(@"DELETE FROM {0} WHERE id=@id", TabsterDatabaseHelper.TablePlaylists); cmd.Parameters.Add(new SQLiteParameter("@id", playlist.Id)); cmd.ExecuteNonQuery(); } RemovePlaylistItems(playlist); }