예제 #1
0
        public Task AddArtist(Artist artist)
        {
            ArtistDictionary.Add(artist.Guid, artist);

            _imageProvider.AddImage(artist.SmallImage);
            _imageProvider.AddImage(artist.MediumImage);
            _imageProvider.AddImage(artist.LargeImage);

            using (
                var command =
                    new SQLiteCommand(
                        "INSERT INTO `Artists` (Name, MusicBrainzId, Url, Guid, SmallImage, MediumImage, LargeImage) VALUES (@name, @musicBrainzId, @url, @guid, @smallImage, @mediumImage, @largeImage)",
                        _connection))
            {
                command.Parameters.AddWithValue("@name", artist.Name);
                command.Parameters.AddWithValue("@musicBrainzId", artist.MusicBrainzId);
                command.Parameters.AddWithValue("@url", artist.Url);
                command.Parameters.AddGuid("@guid", artist.Guid);
                command.Parameters.AddGuid("@smallImage", artist.SmallImage?.Guid);
                command.Parameters.AddGuid("@mediumImage", artist.MediumImage?.Guid);
                command.Parameters.AddGuid("@largeImage", artist.LargeImage?.Guid);

                return(command.ExecuteNonQueryAsync());
            }
        }
예제 #2
0
        public Task AddTrack(PlayableBase track)
        {
            track.Guid = Guid.NewGuid();
            Collection.Add(track.Guid, track);
            Tracks.Add(track);
            _imageProvider.AddImage(track.Cover);

            using (
                var command =
                    new SQLiteCommand(
                        "INSERT INTO `Tracks` (Title, ArtistGuid, AlbumGuid, Guid, LastTimePlayed, MusicBrainzId, Duration, Cover, XmlData) VALUES (@title, @artistGuid, @albumGuid, @guid, @lastTimePlayed, @musicBrainzId, @duration, @cover, @xmlData)",
                        _connection))
            {
                command.Parameters.AddWithValue("@title", track.Title);
                command.Parameters.AddGuid("@artistGuid", track.Artist.Guid);
                command.Parameters.AddGuid("@albumGuid", track.Album?.Guid);
                command.Parameters.AddGuid("@guid", track.Guid);
                command.Parameters.AddWithValue("@lastTimePlayed", track.LastTimePlayed.ToString("yyyy-MM-dd HH:mm:ss"));
                command.Parameters.AddWithValue("@musicBrainzId", track.MusicBrainzId);
                command.Parameters.AddWithValue("@duration", XmlConvert.ToString(track.Duration));
                command.Parameters.AddGuid("@cover", track.Cover?.Guid);
                using (var stringWriter = new StringWriter())
                {
                    _serializer.Serialize(stringWriter, track);
                    command.Parameters.AddWithValue("@xmlData", stringWriter.ToString());
                }

                return(command.ExecuteNonQueryAsync());
            }
        }