Ejemplo n.º 1
0
        public async Task Load(List <string> files, LoadListener listener, CancellationToken cancelToken)
        {
            this.listener    = listener;
            this.cancelToken = cancelToken;
            lock (songs)
            {
                songs.Clear();
            }

            try
            {
                await Task.Run(() =>
                {
                    splits = 0;
                    listener.NotifyLoadInitiated(files.Count);
                    SplitAndLoad(files);
                }, cancelToken);
            }
            catch (Exception e)
            {
                Messenger.Log("Canceled!");
            }

            lock (songs)
            {
                Messenger.Log("Collected songs: " + songs.Count);
                listener.NotifyCompleted(songs);
            }
        }
Ejemplo n.º 2
0
        public void DeleteSongs(IList <Song> songs, LoadListener progressTracker)
        {
            progressTracker.NotifyNewLoad();
            progressTracker.NotifyLoadInitiated(songs.Count);

            foreach (var s in songs)
            {
                library.RemoveById(s.ID);
                Messenger.Post("Deleted song: " + s.Name);
                progressTracker.NotifyProgress(1);
            }

            progressTracker.NotifyCompleted(songs);
            library.InitialiseParts();
            NotifyUpdated();
        }
Ejemplo n.º 3
0
        public void DeleteAlbum(string album, LoadListener listener)
        {
            var songsToDelete = library.GetSongsByAlbum(album);

            listener.NotifyNewLoad();
            listener.NotifyLoadInitiated(songsToDelete.Count);
            foreach (var song in songsToDelete)
            {
                library.RemoveById(song.ID);
                listener.NotifyProgress(1);
            }

            library.InitialiseParts();
            listener.NotifyCompleted(new List <Song>());
            NotifyUpdated();
        }
Ejemplo n.º 4
0
        public void DeleteArtist(string artist, LoadListener progressTracker)
        {
            var songs = library.GetSongsByArtist(artist);

            progressTracker.NotifyNewLoad();
            progressTracker.NotifyLoadInitiated(songs.Count + 1);
            foreach (var song in songs)
            {
                library.RemoveById(song.ID);
                progressTracker.NotifyProgress(1);
            }

            library.InitialiseParts();
            progressTracker.NotifyProgress(1);
            progressTracker.NotifyCompleted(new List <Song>());
            NotifyUpdated();
        }
Ejemplo n.º 5
0
        private IList <Song> LoadFromXml(LoadListener listener)
        {
            if (!File.Exists(filename))
            {
                throw new Exception(filename + " not found!");
            }

            listener.NotifyNewLoad();

            List <PersistedSong> songs = null;

            using (var reader = XmlReader.Create(filename))
            {
                songs = new List <PersistedSong>((PersistedSong[])serializerInstance.Deserialize(reader));
            }

            Messenger.Post("Library reloaded from " + filename);
            var convertedSongs = new SongConverter().ConvertPersistedSongs(songs);

            Messenger.Log("Persisted songs converted");
            listener.NotifyLoadInitiated(convertedSongs.Count);
            listener.NotifyCompleted(convertedSongs);
            return(convertedSongs);
        }
Ejemplo n.º 6
0
 public void NotifyLoadInitiated(int capacity)
 {
     attachedListener?.NotifyLoadInitiated(capacity);
     LoadInitiated?.Invoke(this, capacity);
 }
Ejemplo n.º 7
0
 public void Initiate()
 {
     IsInitiated = true;
     listener?.NotifyLoadInitiated(list.Count);
 }