コード例 #1
0
        public BookFile MoveBookFile(BookFile bookFile, Author author)
        {
            var edition     = _editionService.GetEdition(bookFile.EditionId);
            var newFileName = _buildFileNames.BuildBookFileName(author, edition, bookFile);
            var filePath    = _buildFileNames.BuildBookFilePath(author, edition, newFileName, Path.GetExtension(bookFile.Path));

            EnsureBookFolder(bookFile, author, edition.Book.Value, filePath);

            _logger.Debug("Renaming book file: {0} to {1}", bookFile, filePath);

            return(TransferFile(bookFile, author, bookFile.Edition.Value.Book.Value, filePath, TransferMode.Move));
        }
コード例 #2
0
        private IEnumerable <RenameBookFilePreview> GetPreviews(Author author, List <BookFile> files)
        {
            foreach (var f in files)
            {
                var file         = f;
                var book         = file.Edition.Value;
                var bookFilePath = file.Path;

                if (book == null)
                {
                    _logger.Warn("File ({0}) is not linked to a book", bookFilePath);
                    continue;
                }

                var newName = _filenameBuilder.BuildBookFileName(author, book, file);

                _logger.Trace($"got name {newName}");

                var newPath = _filenameBuilder.BuildBookFilePath(author, book, newName, Path.GetExtension(bookFilePath));

                _logger.Trace($"got path {newPath}");

                if (!bookFilePath.PathEquals(newPath, StringComparison.Ordinal))
                {
                    yield return(new RenameBookFilePreview
                    {
                        AuthorId = author.Id,
                        BookId = book.Id,
                        BookFileId = file.Id,
                        ExistingPath = file.Path,
                        NewPath = newPath
                    });
                }
            }
        }
コード例 #3
0
 private string BuildTrackSample(Author author, BookFile bookFile, NamingConfig nameSpec)
 {
     try
     {
         return(_buildFileNames.BuildBookFileName(author, bookFile.Edition.Value, bookFile, nameSpec, _preferredWords));
     }
     catch (NamingFormatException)
     {
         return(string.Empty);
     }
 }
コード例 #4
0
        private IEnumerable <RenameBookFilePreview> GetPreviews(Author author, List <BookFile> files)
        {
            var counts = files.GroupBy(x => x.EditionId).ToDictionary(g => g.Key, g => g.Count());

            // Don't rename Calibre files
            foreach (var f in files.Where(x => x.CalibreId == 0))
            {
                var file = f;
                file.PartCount = counts[file.EditionId];

                var book         = file.Edition.Value;
                var bookFilePath = file.Path;

                if (book == null)
                {
                    _logger.Warn("File ({0}) is not linked to a book", bookFilePath);
                    continue;
                }

                var newName = _filenameBuilder.BuildBookFileName(author, book, file);

                _logger.Trace($"got name {newName}");

                var newPath = _filenameBuilder.BuildBookFilePath(author, book, newName, Path.GetExtension(bookFilePath));

                _logger.Trace($"got path {newPath}");

                if (!bookFilePath.PathEquals(newPath, StringComparison.Ordinal))
                {
                    yield return(new RenameBookFilePreview
                    {
                        AuthorId = author.Id,
                        BookId = book.Id,
                        BookFileId = file.Id,
                        ExistingPath = file.Path,
                        NewPath = newPath
                    });
                }
            }
        }