private Author SetPropertiesAndValidate(Author newAuthor) { var path = newAuthor.Path; if (string.IsNullOrWhiteSpace(path)) { var folderName = _fileNameBuilder.GetAuthorFolder(newAuthor); path = Path.Combine(newAuthor.RootFolderPath, folderName); } // Disambiguate author path if it exists already if (_authorService.AuthorPathExists(path)) { if (newAuthor.Metadata.Value.Disambiguation.IsNotNullOrWhiteSpace()) { path += $" ({newAuthor.Metadata.Value.Disambiguation})"; } if (_authorService.AuthorPathExists(path)) { var basepath = path; int i = 0; do { i++; path = basepath + $" ({i})"; }while (_authorService.AuthorPathExists(path)); } } newAuthor.Path = path; newAuthor.CleanName = newAuthor.Metadata.Value.Name.CleanAuthorName(); newAuthor.SortName = Parser.Parser.NormalizeTitle(newAuthor.Metadata.Value.Name).ToLower(); newAuthor.Added = DateTime.UtcNow; if (newAuthor.AddOptions != null && newAuthor.AddOptions.Monitor == MonitorTypes.None) { newAuthor.Monitored = false; } var validationResult = _addAuthorValidator.Validate(newAuthor); if (!validationResult.IsValid) { throw new ValidationException(validationResult.Errors); } return(newAuthor); }
public string BuildPath(Author author, bool useExistingRelativeFolder) { if (author.RootFolderPath.IsNullOrWhiteSpace()) { throw new ArgumentException("Root folder was not provided", nameof(author)); } if (useExistingRelativeFolder && author.Path.IsNotNullOrWhiteSpace()) { var relativePath = GetExistingRelativePath(author); return(Path.Combine(author.RootFolderPath, relativePath)); } return(Path.Combine(author.RootFolderPath, _fileNameBuilder.GetAuthorFolder(author))); }
public void Execute(BulkMoveAuthorCommand message) { var authorToMove = message.Author; var destinationRootFolder = message.DestinationRootFolder; _logger.ProgressInfo("Moving {0} author to '{1}'", authorToMove.Count, destinationRootFolder); for (var index = 0; index < authorToMove.Count; index++) { var s = authorToMove[index]; var author = _authorService.GetAuthor(s.AuthorId); var destinationPath = Path.Combine(destinationRootFolder, _filenameBuilder.GetAuthorFolder(author)); MoveSingleAuthor(author, s.SourcePath, destinationPath, index, authorToMove.Count); } _logger.ProgressInfo("Finished moving {0} author to '{1}'", authorToMove.Count, destinationRootFolder); }
public string GetAuthorFolderSample(NamingConfig nameSpec) { return(_buildFileNames.GetAuthorFolder(_standardAuthor, nameSpec)); }