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

83 lines
2.3 KiB
C#
Raw Normal View History

using System;
2017-09-18 16:52:22 +00:00
using System.Collections.Generic;
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>
2019-11-01 17:38:54 +00:00
/// 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;
2019-11-01 17:38:54 +00:00
/// <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;
2019-11-01 17:38:54 +00:00
/// <summary>
/// Initializes a new instance of the <see cref="RefreshUsersMetadata" /> class.
/// </summary>
public RefreshUsersMetadata(ILogger logger, IUserManager userManager, IFileSystem fileSystem)
{
_logger = logger;
_userManager = userManager;
_fileSystem = fileSystem;
}
/// <inheritdoc />
2017-09-18 16:52:22 +00:00
public string Name => "Refresh Users";
2019-11-01 17:38:54 +00:00
/// <inheritdoc />
2017-09-18 16:52:22 +00:00
public string Key => "RefreshUsers";
2019-11-01 17:38:54 +00:00
/// <inheritdoc />
2017-09-18 16:52:22 +00:00
public string Description => "Refresh user infos";
2019-11-01 17:38:54 +00:00
/// <inheritdoc />
public string Category => "Library";
2017-09-18 16:52:22 +00:00
2019-11-01 17:38:54 +00:00
/// <inheritdoc />
2017-09-18 16:52:22 +00:00
public bool IsHidden => true;
2019-11-01 17:38:54 +00:00
/// <inheritdoc />
2017-09-18 16:52:22 +00:00
public bool IsEnabled => true;
2019-11-01 17:38:54 +00:00
/// <inheritdoc />
2017-09-18 16:52:22 +00:00
public bool IsLogged => true;
2019-11-01 17:38:54 +00:00
/// <inheritdoc />
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();
2019-09-10 20:37:53 +00:00
await user.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_fileSystem)), cancellationToken).ConfigureAwait(false);
2017-09-18 16:52:22 +00:00
}
}
2019-11-01 17:38:54 +00:00
/// <inheritdoc />
2017-09-18 16:52:22 +00:00
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
2019-11-01 17:38:54 +00:00
return new[]
2017-09-18 16:52:22 +00:00
{
new TaskTriggerInfo
{
IntervalTicks = TimeSpan.FromDays(1).Ticks,
Type = TaskTriggerInfo.TriggerInterval
}
};
}
}
}