jellyfin/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs

74 lines
2.1 KiB
C#
Raw Normal View History

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