private void AddDefaultProfile(string name, List <PrimaryAlbumType> primAllowed, List <SecondaryAlbumType> secAllowed, List <ReleaseStatus> relAllowed) { var primaryTypes = PrimaryAlbumType.All .OrderByDescending(l => l.Name) .Select(v => new ProfilePrimaryAlbumTypeItem { PrimaryAlbumType = v, Allowed = primAllowed.Contains(v) }) .ToList(); var secondaryTypes = SecondaryAlbumType.All .OrderByDescending(l => l.Name) .Select(v => new ProfileSecondaryAlbumTypeItem { SecondaryAlbumType = v, Allowed = secAllowed.Contains(v) }) .ToList(); var releaseStatues = ReleaseStatus.All .OrderByDescending(l => l.Name) .Select(v => new ProfileReleaseStatusItem { ReleaseStatus = v, Allowed = relAllowed.Contains(v) }) .ToList(); var profile = new MetadataProfile { Name = name, PrimaryAlbumTypes = primaryTypes, SecondaryAlbumTypes = secondaryTypes, ReleaseStatuses = releaseStatues }; Add(profile); }
public void Update(MetadataProfile profile) { if (profile.Name == NONE_PROFILE_NAME) { throw new InvalidOperationException("Not permitted to alter None metadata profile"); } _profileRepository.Update(profile); }
private bool BookAllowedByRating(Book b, MetadataProfile p) { // hack for the 'none' metadata profile if (p.MinPopularity == NONE_PROFILE_MIN_POPULARITY) { return(false); } return((b.Ratings.Popularity >= p.MinPopularity) || b.ReleaseDate > DateTime.UtcNow); }
public MetadataProfile Add(MetadataProfile profile) { return(_profileRepository.Insert(profile)); }
private void FilterByPredicate <T>(HashSet <T> remoteItems, Func <T, string> getId, HashSet <string> localItems, MetadataProfile profile, Func <T, MetadataProfile, bool> bookAllowed, string message) { var filtered = new HashSet <T>(remoteItems.Where(x => !bookAllowed(x, profile) && !localItems.Contains(getId(x)))); if (filtered.Any()) { _logger.Trace($"Skipping {filtered.Count} {typeof(T).Name} because {message}:\n{filtered.ConcatToString(x => x.ToString(), "\n")}"); remoteItems.RemoveWhere(x => filtered.Contains(x)); } }
private List <Edition> FilterEditions(IEnumerable <Edition> editions, List <Edition> localEditions, List <BookFile> localFiles, MetadataProfile profile) { var allowedLanguages = profile.AllowedLanguages.IsNotNullOrWhiteSpace() ? new HashSet <string>(profile.AllowedLanguages.Split(',').Select(x => x.Trim().ToLower())) : new HashSet <string>(); var hash = new HashSet <Edition>(editions); var localHash = new HashSet <string>(localEditions.Where(x => x.ManualAdd).Select(x => x.ForeignEditionId)); localHash.UnionWith(localFiles.Select(x => x.Edition.Value.ForeignEditionId)); FilterByPredicate(hash, x => x.ForeignEditionId, localHash, profile, (x, p) => !allowedLanguages.Any() || allowedLanguages.Contains(x.Language?.ToLower() ?? "null"), "edition language not allowed"); FilterByPredicate(hash, x => x.ForeignEditionId, localHash, profile, (x, p) => !p.SkipMissingIsbn || x.Isbn13.IsNotNullOrWhiteSpace() || x.Asin.IsNotNullOrWhiteSpace(), "isbn and asin is missing"); return(hash.ToList()); }
public void Update(MetadataProfile profile) { _profileRepository.Update(profile); }