/// <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); } } } }
/// <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 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(); } } }