Ejemplo n.º 1
0
        /// <summary>
        /// Adds the song that are contained in the specified directory recursively to the library.
        /// </summary>
        /// <param name="path">The path of the directory to search.</param>
        private void AddLocalSongs(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(Reflector.GetMemberName(() => path));
            }

            if (!Directory.Exists(path))
            {
                throw new ArgumentException("The directory doesn't exist.", Reflector.GetMemberName(() => path));
            }

            var finder = new LocalSongFinder(path);

            finder.SongFound += (sender, e) =>
            {
                bool added;

                lock (this.songLocker)
                {
                    added = this.songs.Add(e.Song);
                }

                if (added)
                {
                    this.SongAdded.RaiseSafe(this, new LibraryFillEventArgs(e.Song, finder.TagsProcessed, finder.CurrentTotalSongs));
                }
            };

            finder.Start();
        }
Ejemplo n.º 2
0
        public async Task FileSystemExceptionsAreHandledGracefully()
        {
            var fileSystem = Substitute.For<IFileSystem>();
            fileSystem.Directory.GetDirectories(Arg.Any<string>()).Returns(x => { throw new Exception(); });
            fileSystem.Directory.GetFiles(Arg.Any<string>()).Returns(x => { throw new Exception(); });

            var songFinder = new LocalSongFinder("C:\\", fileSystem);

            Assert.True(await songFinder.GetSongsAsync().IsEmpty());
        }
Ejemplo n.º 3
0
        public async Task FileSystemExceptionsAreHandledGracefully()
        {
            var fileSystem = Substitute.For <IFileSystem>();

            fileSystem.Directory.GetDirectories(Arg.Any <string>()).Returns(x => { throw new Exception(); });
            fileSystem.Directory.GetFiles(Arg.Any <string>()).Returns(x => { throw new Exception(); });

            var songFinder = new LocalSongFinder("C:\\", fileSystem);

            Assert.True(await songFinder.GetSongsAsync().IsEmpty());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds the song that are contained in the specified directory recursively to the library.
        /// </summary>
        /// <param name="path">The path of the directory to search.</param>
        private void AddLocalSongs(string path)
        {
            if (path == null)
            {
                Throw.ArgumentNullException(() => path);
            }

            if (!Directory.Exists(path))
            {
                Throw.ArgumentException("The directory doesn't exist.", () => path);
            }

            var finder = new LocalSongFinder(path);

            finder.SongFound += (sender, e) =>
            {
                if (this.abortSongAdding)
                {
                    finder.Abort();
                    return;
                }

                bool added;

                lock (this.songLock)
                {
                    lock (this.disposeLock)
                    {
                        added = this.songs.Add(e.Song);
                    }
                }

                if (added)
                {
                    this.SongAdded.RaiseSafe(this, new LibraryFillEventArgs(e.Song, finder.TagsProcessed, finder.CurrentTotalSongs));
                }
            };

            finder.Start();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Adds the song that are contained in the specified directory recursively to the library.
        /// </summary>
        /// <param name="path">The path of the directory to search.</param>
        private void AddLocalSongs(string path)
        {
            if (path == null)
                Throw.ArgumentNullException(() => path);

            if (!Directory.Exists(path))
                Throw.ArgumentException("The directory doesn't exist.", () => path);

            var finder = new LocalSongFinder(path);

            finder.SongFound += (sender, e) =>
            {
                if (this.abortSongAdding)
                {
                    finder.Abort();
                    return;
                }

                bool added;

                lock (this.songLock)
                {
                    lock (this.disposeLock)
                    {
                        added = this.songs.Add(e.Song);
                    }
                }

                if (added)
                {
                    this.SongAdded.RaiseSafe(this, new LibraryFillEventArgs(e.Song, finder.TagsProcessed, finder.CurrentTotalSongs));
                }
            };

            finder.Start();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds the song that are contained in the specified directory recursively to the library.
        /// </summary>
        /// <param name="path">The path of the directory to search.</param>
        private void AddLocalSongs(string path)
        {
            if (path == null)
                throw new ArgumentNullException(Reflector.GetMemberName(() => path));

            if (!Directory.Exists(path))
                throw new ArgumentException("The directory doesn't exist.", Reflector.GetMemberName(() => path));

            var finder = new LocalSongFinder(path);

            finder.SongFound += (sender, e) =>
            {
                bool added;

                lock (this.songLocker)
                {
                    added = this.songs.Add(e.Song);
                }

                if (added)
                {
                    this.SongAdded.RaiseSafe(this, new LibraryFillEventArgs(e.Song, finder.TagsProcessed, finder.CurrentTotalSongs));
                }
            };

            finder.Start();
        }