public Album(DirectoryInfo sourceDirectory, IProgress progress, CancellationToken cancellationToken, Session session, Context context) : this(session, context) { var discDirectories = new List<DirectoryInfo>(); discDirectories.Add(sourceDirectory); discDirectories.AddRange(sourceDirectory.GetDirectories()); progress.Begin(discDirectories.Sum(directory => directory.GetFiles("*.mp3").Length)); foreach (var directory in discDirectories) { var disc = new Disc(this, _session, _context); foreach (var file in directory.GetFiles("*.mp3")) { cancellationToken.ThrowIfCancellationRequested(); progress.Advance(file.Name); var track = new Track(file, disc, _session, _context); disc.Tracks.Add(track); } if (disc.Tracks.Count > 0) Discs.Add(disc); } SourceDirectory = sourceDirectory; }
public void SaveTo(DirectoryInfo destinationDirectory, IProgress progress, CancellationToken cancellationToken) { progress.Begin(Discs.Sum(disc => disc.Tracks.Count)); if (!destinationDirectory.Exists) destinationDirectory.Create(); var artistDirectory = destinationDirectory.CreateSubdirectory(ArtistDirectoryName); if (artistDirectory.GetDirectories(AlbumDirectoryName).Length != 0) throw new Exception("Album directory exists!"); var albumDirectory = artistDirectory.CreateSubdirectory(AlbumDirectoryName); foreach (var disc in Discs) disc.SaveTo(albumDirectory, progress, cancellationToken); GeneratePlaylist(albumDirectory); AlbumDirectory = albumDirectory; }
public IEnumerable<Issue> DetectIssues(IProgress progress, CancellationToken cancellationToken) { progress.Begin(2 + Discs.Sum(disc => disc.Tracks.Count + 1)); // Artist Name + Album Name + (Disk Name + Track Count)* progress.Advance(string.Format("Artist: {0}", ArtistName)); foreach (var validator in _context.GetArtistValidators(this)) { cancellationToken.ThrowIfCancellationRequested(); foreach (var issue in validator.Validate()) yield return issue; } progress.Advance(string.Format("Album: {0}", Name)); foreach (var validator in _context.GetAlbumValidators(this)) { cancellationToken.ThrowIfCancellationRequested(); foreach (var issue in validator.Validate()) yield return issue; } foreach (var disc in Discs) { progress.Advance(string.Format("Disc {0} Name: {1}", disc.Index, Name)); foreach (var validator in _context.GetDiscValidators(disc)) { cancellationToken.ThrowIfCancellationRequested(); foreach (var issue in validator.Validate()) yield return issue; } foreach (var track in disc.Tracks) { progress.Advance(string.Format(@"Disc {0}\Track {1}: {2}", disc.Index, track.Index, Name)); foreach (var validator in _context.GetTrackValidators(track)) { cancellationToken.ThrowIfCancellationRequested(); foreach (var issue in validator.Validate()) yield return issue; } } } }