Ejemplo n.º 1
0
        public async Task ImportTracks(IEnumerable<FileInfo> files, UserPlaylist playlist)
        {
            if (_isEnabled)
                throw new InvalidOperationException("The TrackImporter is already running");
            _isEnabled = true;

            var extensions = _musicDataManager.MusicManager.AudioEngine.SupportedExtensions;
            var filesToImport = files.Where(fileInfo => fileInfo.Exists && !string.IsNullOrEmpty(fileInfo.Extension)).ToList();
            var allFilesCount = (double)filesToImport.Count;

            for (int i = 0; i < filesToImport.Count; i++)
            {
                var fileInfo = filesToImport[i];
                ProgressMessageChanged?.Invoke(this, $"\"{fileInfo.Name}\"");
                ProgressChanged?.Invoke(this, i / allFilesCount);

                var track = await GetTrack(fileInfo, extensions);

                if (track != null && playlist != null && !playlist.Tracks.Contains(track))
                    playlist.AddTrack(track);

                if (_cancel)
                    break;
            }
            Finished?.Invoke(this, EventArgs.Empty);
            _isEnabled = false;
            _cancel = false;
        }
Ejemplo n.º 2
0
 private void PlaylistProvider_PlaylistRemoved(object sender, UserPlaylist e)
 {
     foreach (var viewItem in ViewItems)
     {
         var playlistView = viewItem as PlaylistView;
         if (playlistView == null)
             continue;
         if (playlistView.Playlist == e)
         {
             ViewItems.Remove(viewItem);
             break;
         }
     }
 }
Ejemplo n.º 3
0
        public async Task Load(SQLiteConnection connection)
        {
            using (var command = new SQLiteCommand("SELECT * FROM `Playlists`", connection))
            {
                var reader = await command.ExecuteReaderAsync();
                while (await reader.ReadAsync())
                {
                    var playlist = new UserPlaylist {Name = reader.GetString(0), Id = reader.GetGuid(1)};
                    using (var trackCommando = new SQLiteCommand("SELECT * FROM `PlaylistTracks` WHERE PlaylistId=@guid", connection ))
                    {
                        trackCommando.Parameters.AddGuid("@guid", playlist.Id);
                        var trackReader = trackCommando.ExecuteReader();
                        while (await trackReader.ReadAsync())
                            playlist.Tracks.Add(_trackProvider.Collection[trackReader.GetGuid(1)]);
                    }
                    playlist.TrackAdded += Playlist_TrackAdded;
                    playlist.TrackRemoved += Playlist_TrackRemoved;

                    Playlists.Add(playlist);
                }
            }

            _connection = connection;
        }
Ejemplo n.º 4
0
        public async Task RemovePlaylist(UserPlaylist playlist)
        {
            Playlists.Remove(playlist);
            PlaylistRemoved?.Invoke(this, playlist);

            using (
                var command =
                    new SQLiteCommand(
                        "DELETE FROM `Playlists` WHERE Guid=@guid", _connection))
            {
                command.Parameters.AddGuid("@guid", playlist.Id);

                await command.ExecuteNonQueryAsync();
            }

            using (
                var command =
                    new SQLiteCommand(
                        "DELETE FROM `PlaylistTracks` WHERE PlaylistId=@guid", _connection))
            {
                command.Parameters.AddGuid("@guid", playlist.Id);

                await command.ExecuteNonQueryAsync();
            }
        }
Ejemplo n.º 5
0
        public Task AddPlaylist(UserPlaylist playlist)
        {
            Playlists.Add(playlist);
            PlaylistAdded?.Invoke(this, playlist);

            using (
                var command =
                    new SQLiteCommand(
                        "INSERT INTO `Playlists` (Name, Guid) VALUES (@name, @guid)", _connection))
            {
                command.Parameters.AddWithValue("@name", playlist.Name);
                command.Parameters.AddGuid("@guid", playlist.Id);

                return command.ExecuteNonQueryAsync();
            }
        }
Ejemplo n.º 6
0
 public Task ImportDirectory(DirectoryInfo directoryInfo, bool goDeep, UserPlaylist playlist)
 {
     return ImportTracks(directoryInfo.GetFiles("*.*",
         goDeep ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly), playlist);
 }
Ejemplo n.º 7
0
 public PlaylistView(UserPlaylist playlist)
 {
     Playlist = playlist;
     Icon = (Geometry)Application.Current.Resources["VectorPlaylist"];
 }
Ejemplo n.º 8
0
 private void PlaylistProvider_PlaylistAdded(object sender, UserPlaylist e)
 {
     ViewItems.Insert(ViewItems.Count -1, new PlaylistView(e));
 }