/// <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 ProcessFirstArgForFile(string arg)
        {
            if (File.Exists(arg))
            {
                var tablatureFileProcessor = new TabsterFileProcessor<TablatureFile>(Constants.TablatureFileVersion);
                var file = tablatureFileProcessor.Load(arg);

                if (file != null)
                {
                    _queuedTablatureFile = file;
                    _queuedFileInfo = new FileInfo(arg);
                }
            }
        }
        /// <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 ProcessFirstArgForFile(string arg)
        {
            if (File.Exists(arg))
            {
                var tablatureFileProcessor = new TabsterFileProcessor <TablatureFile>(Constants.TablatureFileVersion);
                var file = tablatureFileProcessor.Load(arg);

                if (file != null)
                {
                    _queuedTablatureFile = file;
                    _queuedFileInfo      = new FileInfo(arg);
                }
            }
        }
        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);
                            }
                        }
                    }
                }
            }
        }
Exemple #6
0
        public void Load(bool useFileSystem)
        {
            if (useFileSystem)
            {
                LoadTablatureFiles();
            }

            else
            {
                using (var cmd = new SQLiteCommand(string.Format("SELECT * FROM {0}", TabsterDatabaseHelper.TableLibraryItems), _databaseHelper.GetConnection()))
                {
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var id       = long.Parse(reader["id"].ToString());
                            var filename = reader["filename"].ToString();
                            var favorite = bool.Parse(reader["favorite"].ToString());
                            var views    = int.Parse(reader["views"].ToString());
                            var rating   = TablatureRatingUtilities.FromString(reader["rating"].ToString());

                            var file = _fileProcessor.Load(filename);

                            if (file != null)
                            {
                                var fileInfo = new FileInfo(filename);
                                var item     = new TablatureLibraryItem <TablatureFile>(file, fileInfo)
                                {
                                    Id        = id,
                                    Favorited = favorite,
                                    Views     = views,
                                    Rating    = rating
                                };

                                base.Add(item);
                            }
                        }
                    }
                }
            }
        }
        public void Load()
        {
            _items.Clear();

            using (var cmd = new SQLiteCommand(string.Format("SELECT * FROM {0} ORDER BY id DESC", TabsterDatabaseHelper.TableRecentFiles), _databaseHelper.GetConnection()))
            {
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var filename = reader["filename"].ToString();

                        var file = _fileProcessor.Load(filename);

                        if (file != null)
                        {
                            var r = new RecentFile(file, new FileInfo(filename));
                            _items.Add(r);
                        }
                    }
                }
            }
        }