using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Tasks;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.ScheduledTasks
{
///
/// Class RefreshMediaLibraryTask
///
public class RefreshMediaLibraryTask : IScheduledTask
{
///
/// The _library manager
///
private readonly ILibraryManager _libraryManager;
///
/// Initializes a new instance of the class.
///
/// The library manager.
public RefreshMediaLibraryTask(ILibraryManager libraryManager)
{
_libraryManager = libraryManager;
}
///
/// Gets the default triggers.
///
/// IEnumerable{BaseTaskTrigger}.
public IEnumerable GetDefaultTriggers()
{
return new ITaskTrigger[] {
new StartupTrigger(),
new SystemEventTrigger{ SystemEvent = SystemEvent.WakeFromSleep},
new IntervalTrigger{ Interval = TimeSpan.FromHours(2)}
};
}
///
/// Executes the internal.
///
/// The cancellation token.
/// The progress.
/// Task.
public Task Execute(CancellationToken cancellationToken, IProgress progress)
{
cancellationToken.ThrowIfCancellationRequested();
progress.Report(0);
return _libraryManager.ValidateMediaLibrary(progress, cancellationToken);
}
///
/// Gets the name.
///
/// The name.
public string Name
{
get { return "Scan media library"; }
}
///
/// Gets the description.
///
/// The description.
public string Description
{
get { return "Scans your media library and refreshes metatata based on configuration."; }
}
///
/// Gets the category.
///
/// The category.
public string Category
{
get
{
return "Library";
}
}
}
}