using MediaBrowser.Common.Security;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Logging;
using System;
using System.Threading.Tasks;
using MediaBrowser.Model.Threading;
namespace Emby.Server.Implementations.EntryPoints
{
///
/// Class LoadRegistrations
///
public class LoadRegistrations : IServerEntryPoint
{
///
/// The _security manager
///
private readonly ISecurityManager _securityManager;
///
/// The _logger
///
private readonly ILogger _logger;
private ITimer _timer;
private readonly ITimerFactory _timerFactory;
///
/// Initializes a new instance of the class.
///
/// The security manager.
/// The log manager.
public LoadRegistrations(ISecurityManager securityManager, ILogManager logManager, ITimerFactory timerFactory)
{
_securityManager = securityManager;
_timerFactory = timerFactory;
_logger = logManager.GetLogger("Registration Loader");
}
///
/// Runs this instance.
///
public void Run()
{
_timer = _timerFactory.Create(s => LoadAllRegistrations(), null, TimeSpan.FromMilliseconds(100), TimeSpan.FromHours(12));
}
private async Task LoadAllRegistrations()
{
try
{
await _securityManager.LoadAllRegistrationInfo().ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.ErrorException("Error loading registration info", ex);
}
}
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
public void Dispose()
{
if (_timer != null)
{
_timer.Dispose();
_timer = null;
}
}
}
}