Example #1
0
        protected virtual async Task <bool> AddPlaylistItem(Playlist playlist, PlaylistWriter writer, string fileName)
        {
            try
            {
                if (!this.PlaybackManager.IsSupported(fileName))
                {
                    Logger.Write(this, LogLevel.Debug, "File is not supported: {0}", fileName);
                    return(false);
                }
                Logger.Write(this, LogLevel.Trace, "Adding file to playlist: {0}", fileName);
                var playlistItem = new PlaylistItem()
                {
                    Playlist_Id   = playlist.Id,
                    DirectoryName = Path.GetDirectoryName(fileName),
                    FileName      = fileName,
                    Sequence      = this.Sequence,
                    Status        = PlaylistItemStatus.Import
                };
                await writer.Write(playlistItem).ConfigureAwait(false);

                this.Offset++;
                return(true);
            }
            catch (Exception e)
            {
                Logger.Write(this, LogLevel.Debug, "Failed to add file \"{0}\" to playlist: {0}", fileName, e.Message);
                return(false);
            }
        }
Example #2
0
        public async Task Populate(Playlist playlist, IEnumerable <string> paths, CancellationToken cancellationToken)
        {
            if (this.ReportProgress)
            {
                this.Timer.Interval = FAST_INTERVAL;
                this.Timer.Start();
            }

            using (var writer = new PlaylistWriter(this.Database, this.Transaction))
            {
                foreach (var path in paths.OrderBy())
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }
                    if (Directory.Exists(path))
                    {
                        var fileNames = FileSystemHelper.EnumerateFiles(
                            path,
                            "*.*",
                            FileSystemHelper.SearchOption.Recursive | FileSystemHelper.SearchOption.Sort
                            );
                        foreach (var fileName in fileNames)
                        {
                            if (cancellationToken.IsCancellationRequested)
                            {
                                return;
                            }
                            Logger.Write(this, LogLevel.Debug, "Adding file to playlist: {0}", fileName);
                            var success = await this.AddPlaylistItem(playlist, writer, fileName).ConfigureAwait(false);

                            if (success && this.ReportProgress)
                            {
                                this.Current = fileName;
                            }
                        }
                    }
                    else if (File.Exists(path))
                    {
                        Logger.Write(this, LogLevel.Debug, "Adding file to playlist: {0}", path);
                        var success = await this.AddPlaylistItem(playlist, writer, path).ConfigureAwait(false);

                        if (success && this.ReportProgress)
                        {
                            this.Current = path;
                        }
                    }
                }
            }
        }
Example #3
0
        protected virtual async Task <bool> AddPlaylistItem(PlaylistWriter writer, string fileName)
        {
            if (!this.PlaybackManager.IsSupported(fileName))
            {
                Logger.Write(this, LogLevel.Debug, "File is not supported: {0}", fileName);
                return(false);
            }
            Logger.Write(this, LogLevel.Trace, "Adding file to playlist: {0}", fileName);
            var playlistItem = new PlaylistItem()
            {
                DirectoryName = Path.GetDirectoryName(fileName),
                FileName      = fileName,
                Sequence      = this.Sequence
            };
            await writer.Write(playlistItem).ConfigureAwait(false);

            this.Offset++;
            return(true);
        }
Example #4
0
            private async Task AddPlaylistItems()
            {
                await this.SetName("Getting track list").ConfigureAwait(false);

                await this.SetIsIndeterminate(true).ConfigureAwait(false);

                var info = default(CDInfo);

                BassUtils.OK(BassCd.GetInfo(this.Drive, out info));
                var id            = BassCd.GetID(this.Drive, CDID.CDPlayer);
                var directoryName = string.Format("{0}:\\", info.DriveLetter);

                using (var transaction = this.Database.BeginTransaction(this.Database.PreferredIsolationLevel))
                {
                    using (var writer = new PlaylistWriter(this.Database, transaction))
                    {
                        for (int a = 0, b = BassCd.GetTracks(this.Drive); a < b; a++)
                        {
                            if (BassCd.GetTrackLength(this.Drive, a) == -1)
                            {
                                //Not a music track.
                                continue;
                            }
                            var fileName = BassCdStreamProvider.CreateUrl(this.Drive, id, a);
                            fileName += string.Format("/{0}", await this.GetFileName(fileName, a));
                            Logger.Write(this, LogLevel.Debug, "Adding file to playlist: {0}", fileName);
                            var playlistItem = new PlaylistItem()
                            {
                                DirectoryName = directoryName,
                                FileName      = fileName,
                                Sequence      = this.Sequence + a
                            };
                            await writer.Write(playlistItem).ConfigureAwait(false);

                            this.Offset++;
                        }
                    }
                    transaction.Commit();
                }
            }