2013-10-18 21:08:48 +02:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2016-11-03 07:37:52 +01:00
|
|
|
|
namespace Emby.Server.Implementations.Library.Validators
|
2013-10-18 21:08:48 +02:00
|
|
|
|
{
|
|
|
|
|
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<double> progress, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2016-05-10 21:20:17 +02:00
|
|
|
|
var yearNumber = 1900;
|
|
|
|
|
var maxYear = DateTime.UtcNow.Year + 3;
|
|
|
|
|
var count = maxYear - yearNumber + 1;
|
2013-10-18 21:08:48 +02:00
|
|
|
|
var numComplete = 0;
|
|
|
|
|
|
2016-05-11 04:21:28 +02:00
|
|
|
|
while (yearNumber < maxYear)
|
2013-10-18 21:08:48 +02:00
|
|
|
|
{
|
2017-05-10 21:12:03 +02:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
2013-10-18 21:08:48 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2015-01-17 19:15:09 +01:00
|
|
|
|
var year = _libraryManager.GetYear(yearNumber);
|
|
|
|
|
|
2013-10-18 21:08:48 +02:00
|
|
|
|
await year.RefreshMetadata(cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
catch (OperationCanceledException)
|
|
|
|
|
{
|
|
|
|
|
// Don't clutter the log
|
2017-05-10 21:12:03 +02:00
|
|
|
|
throw;
|
2013-10-18 21:08:48 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2015-01-17 19:15:09 +01:00
|
|
|
|
_logger.ErrorException("Error refreshing year {0}", ex, yearNumber);
|
2013-10-18 21:08:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
numComplete++;
|
|
|
|
|
double percent = numComplete;
|
|
|
|
|
percent /= count;
|
2015-01-17 19:15:09 +01:00
|
|
|
|
percent *= 100;
|
2013-10-18 21:08:48 +02:00
|
|
|
|
|
2015-01-17 19:15:09 +01:00
|
|
|
|
progress.Report(percent);
|
2016-05-10 21:30:20 +02:00
|
|
|
|
yearNumber++;
|
2013-10-18 21:08:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|