using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.ScheduledTasks
{
///
/// Class ImageCleanupTask
///
public class ImageCleanupTask : IScheduledTask
{
///
/// The _kernel
///
private readonly Kernel _kernel;
///
/// The _logger
///
private readonly ILogger _logger;
private readonly ILibraryManager _libraryManager;
private readonly IServerApplicationPaths _appPaths;
private readonly IItemRepository _itemRepo;
///
/// Initializes a new instance of the class.
///
/// The kernel.
/// The logger.
/// The library manager.
/// The app paths.
public ImageCleanupTask(Kernel kernel, ILogger logger, ILibraryManager libraryManager, IServerApplicationPaths appPaths, IItemRepository itemRepo)
{
_kernel = kernel;
_logger = logger;
_libraryManager = libraryManager;
_appPaths = appPaths;
_itemRepo = itemRepo;
}
///
/// Creates the triggers that define when the task will run
///
/// IEnumerable{BaseTaskTrigger}.
public IEnumerable GetDefaultTriggers()
{
return new ITaskTrigger[]
{
new DailyTrigger { TimeOfDay = TimeSpan.FromHours(2) }
};
}
///
/// Returns the task to be executed
///
/// The cancellation token.
/// The progress.
/// Task.
public async Task Execute(CancellationToken cancellationToken, IProgress progress)
{
var items = _libraryManager.RootFolder.RecursiveChildren.ToList();
foreach (var video in items.OfType