using System.Linq;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Library;
using MediaBrowser.Server.Implementations.Library;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.ScheduledTasks
{
///
/// Class RefreshMediaLibraryTask
///
public class RefreshMediaLibraryTask : IScheduledTask, IHasKey
{
///
/// The _library manager
///
private readonly ILibraryManager _libraryManager;
private readonly IServerConfigurationManager _config;
///
/// Initializes a new instance of the class.
///
/// The library manager.
public RefreshMediaLibraryTask(ILibraryManager libraryManager, IServerConfigurationManager config)
{
_libraryManager = libraryManager;
_config = config;
}
///
/// Gets the default triggers.
///
/// IEnumerable{BaseTaskTrigger}.
public IEnumerable GetDefaultTriggers()
{
var list = new ITaskTrigger[] {
new IntervalTrigger{ Interval = TimeSpan.FromHours(12)}
}.ToList();
if (!_config.Configuration.DisableStartupScan)
{
list.Add(new StartupTrigger());
}
return list;
}
///
/// Executes the internal.
///
/// The cancellation token.
/// The progress.
/// Task.
public Task Execute(CancellationToken cancellationToken, IProgress progress)
{
cancellationToken.ThrowIfCancellationRequested();
progress.Report(0);
return ((LibraryManager)_libraryManager).ValidateMediaLibraryInternal(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";
}
}
public string Key
{
get { return "RefreshLibrary"; }
}
}
}