2019-01-13 14:54:44 -05:00
|
|
|
using System;
|
2017-09-18 12:52:22 -04:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2019-01-13 14:20:41 -05:00
|
|
|
using System.Threading;
|
2017-09-18 12:52:22 -04:00
|
|
|
using System.Threading.Tasks;
|
2019-01-13 14:20:41 -05:00
|
|
|
using MediaBrowser.Controller.Library;
|
2017-09-18 12:52:22 -04:00
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.IO;
|
2019-01-13 14:20:41 -05:00
|
|
|
using MediaBrowser.Model.Tasks;
|
2018-12-14 14:17:29 -05:00
|
|
|
using Microsoft.Extensions.Logging;
|
2013-03-08 00:08:27 -05:00
|
|
|
|
2016-11-03 18:06:00 -04:00
|
|
|
namespace Emby.Server.Implementations.EntryPoints
|
2013-03-08 00:08:27 -05:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Class RefreshUsersMetadata
|
|
|
|
/// </summary>
|
2017-09-18 12:52:22 -04:00
|
|
|
public class RefreshUsersMetadata : IScheduledTask, IConfigurableScheduledTask
|
2013-03-08 00:08:27 -05:00
|
|
|
{
|
2018-12-14 14:17:29 -05:00
|
|
|
private readonly ILogger _logger;
|
2013-03-08 00:08:27 -05:00
|
|
|
/// <summary>
|
|
|
|
/// The _user manager
|
|
|
|
/// </summary>
|
|
|
|
private readonly IUserManager _userManager;
|
2018-12-14 14:17:29 -05:00
|
|
|
|
2017-09-18 12:52:22 -04:00
|
|
|
private IFileSystem _fileSystem;
|
|
|
|
|
|
|
|
public string Name => "Refresh Users";
|
|
|
|
|
|
|
|
public string Key => "RefreshUsers";
|
|
|
|
|
|
|
|
public string Description => "Refresh user infos";
|
|
|
|
|
2019-01-06 15:50:43 -05:00
|
|
|
public string Category => "Library";
|
2017-09-18 12:52:22 -04:00
|
|
|
|
|
|
|
public bool IsHidden => true;
|
|
|
|
|
|
|
|
public bool IsEnabled => true;
|
|
|
|
|
|
|
|
public bool IsLogged => true;
|
2013-03-08 00:08:27 -05:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="RefreshUsersMetadata" /> class.
|
|
|
|
/// </summary>
|
2018-12-14 14:17:29 -05:00
|
|
|
public RefreshUsersMetadata(ILogger logger, IUserManager userManager, IFileSystem fileSystem)
|
2013-03-08 00:08:27 -05:00
|
|
|
{
|
2018-12-14 14:17:29 -05:00
|
|
|
_logger = logger;
|
2013-03-08 00:08:27 -05:00
|
|
|
_userManager = userManager;
|
2017-09-18 12:52:22 -04:00
|
|
|
_fileSystem = fileSystem;
|
2013-03-08 00:08:27 -05:00
|
|
|
}
|
|
|
|
|
2017-09-18 12:52:22 -04:00
|
|
|
public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
|
2013-03-08 00:08:27 -05:00
|
|
|
{
|
2017-09-18 12:52:22 -04:00
|
|
|
var users = _userManager.Users.ToList();
|
|
|
|
|
|
|
|
foreach (var user in users)
|
|
|
|
{
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
2018-12-14 14:17:29 -05:00
|
|
|
await user.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)), cancellationToken).ConfigureAwait(false);
|
2017-09-18 12:52:22 -04:00
|
|
|
}
|
2013-03-08 00:08:27 -05:00
|
|
|
}
|
|
|
|
|
2017-09-18 12:52:22 -04:00
|
|
|
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
|
2013-03-08 00:08:27 -05:00
|
|
|
{
|
2017-09-18 12:52:22 -04:00
|
|
|
return new List<TaskTriggerInfo>
|
|
|
|
{
|
|
|
|
new TaskTriggerInfo
|
|
|
|
{
|
|
|
|
IntervalTicks = TimeSpan.FromDays(1).Ticks,
|
|
|
|
Type = TaskTriggerInfo.TriggerInterval
|
|
|
|
}
|
|
|
|
};
|
2013-03-08 00:08:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|