private void RefreshMusicAlbumsLibrary()
        {
            Logger.Instance().Log("Yatse2","Start Refresh : MusicAlbums");
            var res = _remote.AudioLibrary.GetAlbums();
            Logger.Instance().Log("Yatse2","Remote MusicAlbums : " + res.Count);
            var oldData = _database.GetAudioAlbumFavorites(_remoteInfo.Id);

            _database.SetBulkInsert(true);
            _database.BeginTransaction();
            _database.DeleteRemoteAudioAlbum(_remoteInfo.Id);
            foreach (var apiMusicAlbum in res)
            {
                long oldFavorite = 0;
                foreach (var oalbum in oldData)
                {
                    if (oalbum.IdAlbum == apiMusicAlbum.IdAlbum)
                        oldFavorite = oalbum.IsFavorite;
                }
                var musicAlbum = new Yatse2AudioAlbum(apiMusicAlbum) { IdRemote = _remoteInfo.Id, IsFavorite = oldFavorite };
                _database.InsertAudioAlbum(musicAlbum);
            }
            _database.CommitTransaction();
            _database.SetBulkInsert(false);
            Logger.Instance().Log("Yatse2","End Refresh : MusicAlbums");
        }
Example #2
0
        private Collection<Yatse2AudioAlbum> QueryAudioAlbum(SQLiteCommand query)
        {
            var audioalbums = new Collection<Yatse2AudioAlbum>();
            if (!_connected) return audioalbums;

            try
            {
                LogQuery(query);
                var sqldReader = query.ExecuteReader();
                while (sqldReader.Read())
                {
                    var audioAlbum = new Yatse2AudioAlbum
                    {
                        Id = GetLong(sqldReader, "Id"),
                        IdRemote = GetLong(sqldReader, "IdRemote"),
                        Title = GetString(sqldReader, "Title"),
                        IdAlbum = GetLong(sqldReader, "IdAlbum"),
                        IdArtist = GetLong(sqldReader, "IdArtist"),
                        Artist = GetString(sqldReader, "Artist"),
                        Genre = GetString(sqldReader, "Genre"),
                        IdGenre = GetLong(sqldReader, "IdGenre"),
                        Year = GetLong(sqldReader, "Year"),
                        Thumb = GetString(sqldReader, "Thumb"),
                        Fanart = GetString(sqldReader, "Fanart"),
                        Hash = GetString(sqldReader, "Hash"),
                        IsFavorite = GetLong(sqldReader, "IsFavorite")
                    };
                    audioalbums.Add(audioAlbum);
                }
                sqldReader.Dispose();
                query.Dispose();
            }
            catch (SQLiteException e)
            {
                Log(e.Message);
            }
            return audioalbums;
        }
Example #3
0
        public long InsertAudioAlbum(Yatse2AudioAlbum audioAlbum)
        {
            if (audioAlbum == null)
                return 0;
            var sqlCmd = _dbConnection.CreateCommand();
            sqlCmd.CommandText =
                @"INSERT INTO `AudioAlbums` ( IdRemote ,Title,IdAlbum,IdArtist,Artist,Genre,IdGenre,Year,Thumb,Fanart,Hash,IsFavorite )
                  VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?);";
            sqlCmd.Parameters.AddWithValue("a1", audioAlbum.IdRemote);
            sqlCmd.Parameters.AddWithValue("a2", audioAlbum.Title);
            sqlCmd.Parameters.AddWithValue("a3", audioAlbum.IdAlbum);
            sqlCmd.Parameters.AddWithValue("a4", audioAlbum.IdArtist);
            sqlCmd.Parameters.AddWithValue("a5", audioAlbum.Artist);
            sqlCmd.Parameters.AddWithValue("a6", audioAlbum.Genre);
            sqlCmd.Parameters.AddWithValue("a7", audioAlbum.IdGenre);
            sqlCmd.Parameters.AddWithValue("a8", audioAlbum.Year);
            sqlCmd.Parameters.AddWithValue("a9", audioAlbum.Thumb);
            sqlCmd.Parameters.AddWithValue("a10", audioAlbum.Fanart);
            sqlCmd.Parameters.AddWithValue("a11", audioAlbum.Hash);
            sqlCmd.Parameters.AddWithValue("a12", audioAlbum.IsFavorite);

            return QueryInsert(sqlCmd);
        }
Example #4
0
        public bool UpdateAudioAlbum(Yatse2AudioAlbum audioAlbum)
        {
            if (audioAlbum == null)
                return false;
            var sqlCmd = _dbConnection.CreateCommand();
            sqlCmd.CommandText =
                @"UPDATE `AudioAlbums` SET IdRemote = ? ,Title = ? ,IdAlbum = ? ,IdArtist = ? ,Artist = ? ,Genre = ? ,IdGenre = ? ,Year = ? ,Thumb = ? ,Fanart = ? ,Hash = ? ,IsFavorite = ? WHERE Id = @Id;";
            sqlCmd.Parameters.AddWithValue("a1", audioAlbum.IdRemote);
            sqlCmd.Parameters.AddWithValue("a2", audioAlbum.Title);
            sqlCmd.Parameters.AddWithValue("a3", audioAlbum.IdAlbum);
            sqlCmd.Parameters.AddWithValue("a4", audioAlbum.IdArtist);
            sqlCmd.Parameters.AddWithValue("a5", audioAlbum.Artist);
            sqlCmd.Parameters.AddWithValue("a6", audioAlbum.Genre);
            sqlCmd.Parameters.AddWithValue("a7", audioAlbum.IdGenre);
            sqlCmd.Parameters.AddWithValue("a8", audioAlbum.Year);
            sqlCmd.Parameters.AddWithValue("a9", audioAlbum.Thumb);
            sqlCmd.Parameters.AddWithValue("a10", audioAlbum.Fanart);
            sqlCmd.Parameters.AddWithValue("a11", audioAlbum.Hash);
            sqlCmd.Parameters.AddWithValue("a12", audioAlbum.IsFavorite);
            sqlCmd.Parameters.AddWithValue("@Id", audioAlbum.Id);

            return Query(sqlCmd);
        }