From 3eb4091808735858b01855d298226d239be464af Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 3 Nov 2016 02:37:52 -0400 Subject: move additional classes to new server lib --- .../Library/Validators/ArtistsPostScanTask.cs | 44 ++++++ .../Library/Validators/ArtistsValidator.cs | 84 ++++++++++ .../Library/Validators/GameGenresPostScanTask.cs | 45 ++++++ .../Library/Validators/GameGenresValidator.cs | 74 +++++++++ .../Library/Validators/GenresPostScanTask.cs | 42 +++++ .../Library/Validators/GenresValidator.cs | 75 +++++++++ .../Library/Validators/MusicGenresPostScanTask.cs | 45 ++++++ .../Library/Validators/MusicGenresValidator.cs | 75 +++++++++ .../Library/Validators/PeopleValidator.cs | 172 +++++++++++++++++++++ .../Library/Validators/StudiosPostScanTask.cs | 45 ++++++ .../Library/Validators/StudiosValidator.cs | 74 +++++++++ .../Library/Validators/YearsPostScanTask.cs | 55 +++++++ 12 files changed, 830 insertions(+) create mode 100644 Emby.Server.Implementations/Library/Validators/ArtistsPostScanTask.cs create mode 100644 Emby.Server.Implementations/Library/Validators/ArtistsValidator.cs create mode 100644 Emby.Server.Implementations/Library/Validators/GameGenresPostScanTask.cs create mode 100644 Emby.Server.Implementations/Library/Validators/GameGenresValidator.cs create mode 100644 Emby.Server.Implementations/Library/Validators/GenresPostScanTask.cs create mode 100644 Emby.Server.Implementations/Library/Validators/GenresValidator.cs create mode 100644 Emby.Server.Implementations/Library/Validators/MusicGenresPostScanTask.cs create mode 100644 Emby.Server.Implementations/Library/Validators/MusicGenresValidator.cs create mode 100644 Emby.Server.Implementations/Library/Validators/PeopleValidator.cs create mode 100644 Emby.Server.Implementations/Library/Validators/StudiosPostScanTask.cs create mode 100644 Emby.Server.Implementations/Library/Validators/StudiosValidator.cs create mode 100644 Emby.Server.Implementations/Library/Validators/YearsPostScanTask.cs (limited to 'Emby.Server.Implementations/Library/Validators') diff --git a/Emby.Server.Implementations/Library/Validators/ArtistsPostScanTask.cs b/Emby.Server.Implementations/Library/Validators/ArtistsPostScanTask.cs new file mode 100644 index 000000000..4d718dbee --- /dev/null +++ b/Emby.Server.Implementations/Library/Validators/ArtistsPostScanTask.cs @@ -0,0 +1,44 @@ +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Logging; +using System; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Persistence; + +namespace Emby.Server.Implementations.Library.Validators +{ + /// + /// Class ArtistsPostScanTask + /// + public class ArtistsPostScanTask : ILibraryPostScanTask + { + /// + /// The _library manager + /// + private readonly ILibraryManager _libraryManager; + private readonly ILogger _logger; + private readonly IItemRepository _itemRepo; + + /// + /// Initializes a new instance of the class. + /// + /// The library manager. + public ArtistsPostScanTask(ILibraryManager libraryManager, ILogger logger, IItemRepository itemRepo) + { + _libraryManager = libraryManager; + _logger = logger; + _itemRepo = itemRepo; + } + + /// + /// Runs the specified progress. + /// + /// The progress. + /// The cancellation token. + /// Task. + public Task Run(IProgress progress, CancellationToken cancellationToken) + { + return new ArtistsValidator(_libraryManager, _logger, _itemRepo).Run(progress, cancellationToken); + } + } +} diff --git a/Emby.Server.Implementations/Library/Validators/ArtistsValidator.cs b/Emby.Server.Implementations/Library/Validators/ArtistsValidator.cs new file mode 100644 index 000000000..643c5970e --- /dev/null +++ b/Emby.Server.Implementations/Library/Validators/ArtistsValidator.cs @@ -0,0 +1,84 @@ +using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Logging; +using System; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Persistence; + +namespace Emby.Server.Implementations.Library.Validators +{ + /// + /// Class ArtistsValidator + /// + public class ArtistsValidator + { + /// + /// The _library manager + /// + private readonly ILibraryManager _libraryManager; + + /// + /// The _logger + /// + private readonly ILogger _logger; + private readonly IItemRepository _itemRepo; + + /// + /// Initializes a new instance of the class. + /// + /// The library manager. + /// The logger. + public ArtistsValidator(ILibraryManager libraryManager, ILogger logger, IItemRepository itemRepo) + { + _libraryManager = libraryManager; + _logger = logger; + _itemRepo = itemRepo; + } + + /// + /// Runs the specified progress. + /// + /// The progress. + /// The cancellation token. + /// Task. + public async Task Run(IProgress progress, CancellationToken cancellationToken) + { + var names = _itemRepo.GetAllArtistNames(); + + var numComplete = 0; + var count = names.Count; + + foreach (var name in names) + { + try + { + var item = _libraryManager.GetArtist(name); + + await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); + } + catch (OperationCanceledException) + { + // Don't clutter the log + break; + } + catch (Exception ex) + { + _logger.ErrorException("Error refreshing {0}", ex, name); + } + + numComplete++; + double percent = numComplete; + percent /= count; + percent *= 100; + + progress.Report(percent); + } + + progress.Report(100); + } + } +} diff --git a/Emby.Server.Implementations/Library/Validators/GameGenresPostScanTask.cs b/Emby.Server.Implementations/Library/Validators/GameGenresPostScanTask.cs new file mode 100644 index 000000000..ee6c4461c --- /dev/null +++ b/Emby.Server.Implementations/Library/Validators/GameGenresPostScanTask.cs @@ -0,0 +1,45 @@ +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Logging; +using System; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Persistence; + +namespace Emby.Server.Implementations.Library.Validators +{ + /// + /// Class GameGenresPostScanTask + /// + public class GameGenresPostScanTask : ILibraryPostScanTask + { + /// + /// The _library manager + /// + private readonly ILibraryManager _libraryManager; + private readonly ILogger _logger; + private readonly IItemRepository _itemRepo; + + /// + /// Initializes a new instance of the class. + /// + /// The library manager. + /// The logger. + public GameGenresPostScanTask(ILibraryManager libraryManager, ILogger logger, IItemRepository itemRepo) + { + _libraryManager = libraryManager; + _logger = logger; + _itemRepo = itemRepo; + } + + /// + /// Runs the specified progress. + /// + /// The progress. + /// The cancellation token. + /// Task. + public Task Run(IProgress progress, CancellationToken cancellationToken) + { + return new GameGenresValidator(_libraryManager, _logger, _itemRepo).Run(progress, cancellationToken); + } + } +} diff --git a/Emby.Server.Implementations/Library/Validators/GameGenresValidator.cs b/Emby.Server.Implementations/Library/Validators/GameGenresValidator.cs new file mode 100644 index 000000000..b1820bb91 --- /dev/null +++ b/Emby.Server.Implementations/Library/Validators/GameGenresValidator.cs @@ -0,0 +1,74 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Logging; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Persistence; + +namespace Emby.Server.Implementations.Library.Validators +{ + class GameGenresValidator + { + /// + /// The _library manager + /// + private readonly ILibraryManager _libraryManager; + + /// + /// The _logger + /// + private readonly ILogger _logger; + private readonly IItemRepository _itemRepo; + + public GameGenresValidator(ILibraryManager libraryManager, ILogger logger, IItemRepository itemRepo) + { + _libraryManager = libraryManager; + _logger = logger; + _itemRepo = itemRepo; + } + + /// + /// Runs the specified progress. + /// + /// The progress. + /// The cancellation token. + /// Task. + public async Task Run(IProgress progress, CancellationToken cancellationToken) + { + var names = _itemRepo.GetGameGenreNames(); + + var numComplete = 0; + var count = names.Count; + + foreach (var name in names) + { + try + { + var item = _libraryManager.GetGameGenre(name); + + await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); + } + catch (OperationCanceledException) + { + // Don't clutter the log + break; + } + catch (Exception ex) + { + _logger.ErrorException("Error refreshing {0}", ex, name); + } + + numComplete++; + double percent = numComplete; + percent /= count; + percent *= 100; + + progress.Report(percent); + } + + progress.Report(100); + } + } +} diff --git a/Emby.Server.Implementations/Library/Validators/GenresPostScanTask.cs b/Emby.Server.Implementations/Library/Validators/GenresPostScanTask.cs new file mode 100644 index 000000000..be46decfb --- /dev/null +++ b/Emby.Server.Implementations/Library/Validators/GenresPostScanTask.cs @@ -0,0 +1,42 @@ +using MediaBrowser.Controller.Library; +using System; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Persistence; +using MediaBrowser.Model.Logging; + +namespace Emby.Server.Implementations.Library.Validators +{ + public class GenresPostScanTask : ILibraryPostScanTask + { + /// + /// The _library manager + /// + private readonly ILibraryManager _libraryManager; + private readonly ILogger _logger; + private readonly IItemRepository _itemRepo; + + /// + /// Initializes a new instance of the class. + /// + /// The library manager. + /// The logger. + public GenresPostScanTask(ILibraryManager libraryManager, ILogger logger, IItemRepository itemRepo) + { + _libraryManager = libraryManager; + _logger = logger; + _itemRepo = itemRepo; + } + + /// + /// Runs the specified progress. + /// + /// The progress. + /// The cancellation token. + /// Task. + public Task Run(IProgress progress, CancellationToken cancellationToken) + { + return new GenresValidator(_libraryManager, _logger, _itemRepo).Run(progress, cancellationToken); + } + } +} diff --git a/Emby.Server.Implementations/Library/Validators/GenresValidator.cs b/Emby.Server.Implementations/Library/Validators/GenresValidator.cs new file mode 100644 index 000000000..d8956f78a --- /dev/null +++ b/Emby.Server.Implementations/Library/Validators/GenresValidator.cs @@ -0,0 +1,75 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Logging; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Persistence; + +namespace Emby.Server.Implementations.Library.Validators +{ + class GenresValidator + { + /// + /// The _library manager + /// + private readonly ILibraryManager _libraryManager; + private readonly IItemRepository _itemRepo; + + /// + /// The _logger + /// + private readonly ILogger _logger; + + public GenresValidator(ILibraryManager libraryManager, ILogger logger, IItemRepository itemRepo) + { + _libraryManager = libraryManager; + _logger = logger; + _itemRepo = itemRepo; + } + + /// + /// Runs the specified progress. + /// + /// The progress. + /// The cancellation token. + /// Task. + public async Task Run(IProgress progress, CancellationToken cancellationToken) + { + var names = _itemRepo.GetGenreNames(); + + var numComplete = 0; + var count = names.Count; + + foreach (var name in names) + { + try + { + var item = _libraryManager.GetGenre(name); + + await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); + } + catch (OperationCanceledException) + { + // Don't clutter the log + break; + } + catch (Exception ex) + { + _logger.ErrorException("Error refreshing {0}", ex, name); + } + + numComplete++; + double percent = numComplete; + percent /= count; + percent *= 100; + + progress.Report(percent); + } + + progress.Report(100); + } + } +} diff --git a/Emby.Server.Implementations/Library/Validators/MusicGenresPostScanTask.cs b/Emby.Server.Implementations/Library/Validators/MusicGenresPostScanTask.cs new file mode 100644 index 000000000..cd4021548 --- /dev/null +++ b/Emby.Server.Implementations/Library/Validators/MusicGenresPostScanTask.cs @@ -0,0 +1,45 @@ +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Logging; +using System; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Persistence; + +namespace Emby.Server.Implementations.Library.Validators +{ + /// + /// Class MusicGenresPostScanTask + /// + public class MusicGenresPostScanTask : ILibraryPostScanTask + { + /// + /// The _library manager + /// + private readonly ILibraryManager _libraryManager; + private readonly ILogger _logger; + private readonly IItemRepository _itemRepo; + + /// + /// Initializes a new instance of the class. + /// + /// The library manager. + /// The logger. + public MusicGenresPostScanTask(ILibraryManager libraryManager, ILogger logger, IItemRepository itemRepo) + { + _libraryManager = libraryManager; + _logger = logger; + _itemRepo = itemRepo; + } + + /// + /// Runs the specified progress. + /// + /// The progress. + /// The cancellation token. + /// Task. + public Task Run(IProgress progress, CancellationToken cancellationToken) + { + return new MusicGenresValidator(_libraryManager, _logger, _itemRepo).Run(progress, cancellationToken); + } + } +} diff --git a/Emby.Server.Implementations/Library/Validators/MusicGenresValidator.cs b/Emby.Server.Implementations/Library/Validators/MusicGenresValidator.cs new file mode 100644 index 000000000..983c881b7 --- /dev/null +++ b/Emby.Server.Implementations/Library/Validators/MusicGenresValidator.cs @@ -0,0 +1,75 @@ +using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Logging; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Persistence; + +namespace Emby.Server.Implementations.Library.Validators +{ + class MusicGenresValidator + { + /// + /// The _library manager + /// + private readonly ILibraryManager _libraryManager; + + /// + /// The _logger + /// + private readonly ILogger _logger; + private readonly IItemRepository _itemRepo; + + public MusicGenresValidator(ILibraryManager libraryManager, ILogger logger, IItemRepository itemRepo) + { + _libraryManager = libraryManager; + _logger = logger; + _itemRepo = itemRepo; + } + + /// + /// Runs the specified progress. + /// + /// The progress. + /// The cancellation token. + /// Task. + public async Task Run(IProgress progress, CancellationToken cancellationToken) + { + var names = _itemRepo.GetMusicGenreNames(); + + var numComplete = 0; + var count = names.Count; + + foreach (var name in names) + { + try + { + var item = _libraryManager.GetMusicGenre(name); + + await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); + } + catch (OperationCanceledException) + { + // Don't clutter the log + break; + } + catch (Exception ex) + { + _logger.ErrorException("Error refreshing {0}", ex, name); + } + + numComplete++; + double percent = numComplete; + percent /= count; + percent *= 100; + + progress.Report(percent); + } + + progress.Report(100); + } + } +} diff --git a/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs b/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs new file mode 100644 index 000000000..813f07fff --- /dev/null +++ b/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs @@ -0,0 +1,172 @@ +using MediaBrowser.Common.Progress; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Common.IO; +using MediaBrowser.Controller.IO; +using MediaBrowser.Model.IO; + +namespace Emby.Server.Implementations.Library.Validators +{ + /// + /// Class PeopleValidator + /// + public class PeopleValidator + { + /// + /// The _library manager + /// + private readonly ILibraryManager _libraryManager; + /// + /// The _logger + /// + private readonly ILogger _logger; + + private readonly IServerConfigurationManager _config; + private readonly IFileSystem _fileSystem; + + /// + /// Initializes a new instance of the class. + /// + /// The library manager. + /// The logger. + public PeopleValidator(ILibraryManager libraryManager, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem) + { + _libraryManager = libraryManager; + _logger = logger; + _config = config; + _fileSystem = fileSystem; + } + + private bool DownloadMetadata(PersonInfo i, PeopleMetadataOptions options) + { + if (i.IsType(PersonType.Actor)) + { + return options.DownloadActorMetadata; + } + if (i.IsType(PersonType.Director)) + { + return options.DownloadDirectorMetadata; + } + if (i.IsType(PersonType.Composer)) + { + return options.DownloadComposerMetadata; + } + if (i.IsType(PersonType.Writer)) + { + return options.DownloadWriterMetadata; + } + if (i.IsType(PersonType.Producer)) + { + return options.DownloadProducerMetadata; + } + if (i.IsType(PersonType.GuestStar)) + { + return options.DownloadGuestStarMetadata; + } + + return options.DownloadOtherPeopleMetadata; + } + + /// + /// Validates the people. + /// + /// The cancellation token. + /// The progress. + /// Task. + public async Task ValidatePeople(CancellationToken cancellationToken, IProgress progress) + { + var innerProgress = new ActionableProgress(); + + innerProgress.RegisterAction(pct => progress.Report(pct * .15)); + + var peopleOptions = _config.Configuration.PeopleMetadataOptions; + + var people = _libraryManager.GetPeople(new InternalPeopleQuery()); + + var dict = new Dictionary(StringComparer.OrdinalIgnoreCase); + + foreach (var person in people) + { + var isMetadataEnabled = DownloadMetadata(person, peopleOptions); + + bool currentValue; + if (dict.TryGetValue(person.Name, out currentValue)) + { + if (!currentValue && isMetadataEnabled) + { + dict[person.Name] = true; + } + } + else + { + dict[person.Name] = isMetadataEnabled; + } + } + + var numComplete = 0; + + _logger.Debug("Will refresh {0} people", dict.Count); + + var numPeople = dict.Count; + + foreach (var person in dict) + { + cancellationToken.ThrowIfCancellationRequested(); + + try + { + var item = _libraryManager.GetPerson(person.Key); + + var hasMetdata = !string.IsNullOrWhiteSpace(item.Overview); + var performFullRefresh = !hasMetdata && (DateTime.UtcNow - item.DateLastRefreshed).TotalDays >= 30; + + var defaultMetadataRefreshMode = performFullRefresh + ? MetadataRefreshMode.FullRefresh + : MetadataRefreshMode.Default; + + var imageRefreshMode = performFullRefresh + ? ImageRefreshMode.FullRefresh + : ImageRefreshMode.Default; + + var options = new MetadataRefreshOptions(_fileSystem) + { + MetadataRefreshMode = person.Value ? defaultMetadataRefreshMode : MetadataRefreshMode.ValidationOnly, + ImageRefreshMode = person.Value ? imageRefreshMode : ImageRefreshMode.ValidationOnly, + ForceSave = performFullRefresh + }; + + await item.RefreshMetadata(options, cancellationToken).ConfigureAwait(false); + } + catch (OperationCanceledException) + { + throw; + } + catch (Exception ex) + { + _logger.ErrorException("Error validating IBN entry {0}", ex, person); + } + + // Update progress + numComplete++; + double percent = numComplete; + percent /= numPeople; + + progress.Report(100 * percent); + } + + progress.Report(100); + + _logger.Info("People validation complete"); + } + } +} diff --git a/Emby.Server.Implementations/Library/Validators/StudiosPostScanTask.cs b/Emby.Server.Implementations/Library/Validators/StudiosPostScanTask.cs new file mode 100644 index 000000000..d23efb6d3 --- /dev/null +++ b/Emby.Server.Implementations/Library/Validators/StudiosPostScanTask.cs @@ -0,0 +1,45 @@ +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Logging; +using System; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Persistence; + +namespace Emby.Server.Implementations.Library.Validators +{ + /// + /// Class MusicGenresPostScanTask + /// + public class StudiosPostScanTask : ILibraryPostScanTask + { + /// + /// The _library manager + /// + private readonly ILibraryManager _libraryManager; + + private readonly ILogger _logger; + private readonly IItemRepository _itemRepo; + + /// + /// Initializes a new instance of the class. + /// + /// The library manager. + public StudiosPostScanTask(ILibraryManager libraryManager, ILogger logger, IItemRepository itemRepo) + { + _libraryManager = libraryManager; + _logger = logger; + _itemRepo = itemRepo; + } + + /// + /// Runs the specified progress. + /// + /// The progress. + /// The cancellation token. + /// Task. + public Task Run(IProgress progress, CancellationToken cancellationToken) + { + return new StudiosValidator(_libraryManager, _logger, _itemRepo).Run(progress, cancellationToken); + } + } +} diff --git a/Emby.Server.Implementations/Library/Validators/StudiosValidator.cs b/Emby.Server.Implementations/Library/Validators/StudiosValidator.cs new file mode 100644 index 000000000..6faab7bb9 --- /dev/null +++ b/Emby.Server.Implementations/Library/Validators/StudiosValidator.cs @@ -0,0 +1,74 @@ +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Logging; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Persistence; + +namespace Emby.Server.Implementations.Library.Validators +{ + class StudiosValidator + { + /// + /// The _library manager + /// + private readonly ILibraryManager _libraryManager; + + private readonly IItemRepository _itemRepo; + /// + /// The _logger + /// + private readonly ILogger _logger; + + public StudiosValidator(ILibraryManager libraryManager, ILogger logger, IItemRepository itemRepo) + { + _libraryManager = libraryManager; + _logger = logger; + _itemRepo = itemRepo; + } + + /// + /// Runs the specified progress. + /// + /// The progress. + /// The cancellation token. + /// Task. + public async Task Run(IProgress progress, CancellationToken cancellationToken) + { + var names = _itemRepo.GetStudioNames(); + + var numComplete = 0; + var count = names.Count; + + foreach (var name in names) + { + try + { + var item = _libraryManager.GetStudio(name); + + await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); + } + catch (OperationCanceledException) + { + // Don't clutter the log + break; + } + catch (Exception ex) + { + _logger.ErrorException("Error refreshing {0}", ex, name); + } + + numComplete++; + double percent = numComplete; + percent /= count; + percent *= 100; + + progress.Report(percent); + } + + progress.Report(100); + } + } +} diff --git a/Emby.Server.Implementations/Library/Validators/YearsPostScanTask.cs b/Emby.Server.Implementations/Library/Validators/YearsPostScanTask.cs new file mode 100644 index 000000000..ae43c77f0 --- /dev/null +++ b/Emby.Server.Implementations/Library/Validators/YearsPostScanTask.cs @@ -0,0 +1,55 @@ +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Logging; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Emby.Server.Implementations.Library.Validators +{ + public class YearsPostScanTask : ILibraryPostScanTask + { + private readonly ILibraryManager _libraryManager; + private readonly ILogger _logger; + + public YearsPostScanTask(ILibraryManager libraryManager, ILogger logger) + { + _libraryManager = libraryManager; + _logger = logger; + } + + public async Task Run(IProgress progress, CancellationToken cancellationToken) + { + var yearNumber = 1900; + var maxYear = DateTime.UtcNow.Year + 3; + var count = maxYear - yearNumber + 1; + var numComplete = 0; + + while (yearNumber < maxYear) + { + try + { + var year = _libraryManager.GetYear(yearNumber); + + await year.RefreshMetadata(cancellationToken).ConfigureAwait(false); + } + catch (OperationCanceledException) + { + // Don't clutter the log + break; + } + catch (Exception ex) + { + _logger.ErrorException("Error refreshing year {0}", ex, yearNumber); + } + + numComplete++; + double percent = numComplete; + percent /= count; + percent *= 100; + + progress.Report(percent); + yearNumber++; + } + } + } +} -- cgit v1.2.3