using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Tasks;
namespace Emby.Server.Implementations.EntryPoints
{
///
/// Class RefreshUsersMetadata.
///
public class RefreshUsersMetadata : IScheduledTask, IConfigurableScheduledTask
{
///
/// The user manager.
///
private readonly IUserManager _userManager;
private readonly IFileSystem _fileSystem;
///
/// Initializes a new instance of the class.
///
public RefreshUsersMetadata(IUserManager userManager, IFileSystem fileSystem)
{
_userManager = userManager;
_fileSystem = fileSystem;
}
///
public string Name => "Refresh Users";
///
public string Key => "RefreshUsers";
///
public string Description => "Refresh user infos";
///
public string Category => "Library";
///
public bool IsHidden => true;
///
public bool IsEnabled => true;
///
public bool IsLogged => true;
///
public async Task Execute(CancellationToken cancellationToken, IProgress progress)
{
foreach (var user in _userManager.Users)
{
cancellationToken.ThrowIfCancellationRequested();
await user.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_fileSystem)), cancellationToken).ConfigureAwait(false);
}
}
///
public IEnumerable GetDefaultTriggers()
{
return new[]
{
new TaskTriggerInfo
{
IntervalTicks = TimeSpan.FromDays(1).Ticks,
Type = TaskTriggerInfo.TriggerInterval
}
};
}
}
}