2013-04-08 08:55:53 -07:00
|
|
|
|
using MediaBrowser.Common.Security;
|
|
|
|
|
using MediaBrowser.Controller.Plugins;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
2014-08-31 12:15:33 -07:00
|
|
|
|
using System.Threading.Tasks;
|
2016-11-03 15:06:00 -07:00
|
|
|
|
using MediaBrowser.Model.Threading;
|
2013-04-08 08:55:53 -07:00
|
|
|
|
|
2016-11-03 15:06:00 -07:00
|
|
|
|
namespace Emby.Server.Implementations.EntryPoints
|
2013-04-08 08:55:53 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class LoadRegistrations
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class LoadRegistrations : IServerEntryPoint
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _security manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly ISecurityManager _securityManager;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _logger
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
2016-11-03 15:06:00 -07:00
|
|
|
|
private ITimer _timer;
|
|
|
|
|
private readonly ITimerFactory _timerFactory;
|
2014-08-31 12:15:33 -07:00
|
|
|
|
|
2013-04-08 08:55:53 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="LoadRegistrations" /> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="securityManager">The security manager.</param>
|
|
|
|
|
/// <param name="logManager">The log manager.</param>
|
2016-11-03 15:06:00 -07:00
|
|
|
|
public LoadRegistrations(ISecurityManager securityManager, ILogManager logManager, ITimerFactory timerFactory)
|
2013-04-08 08:55:53 -07:00
|
|
|
|
{
|
|
|
|
|
_securityManager = securityManager;
|
2016-11-03 15:06:00 -07:00
|
|
|
|
_timerFactory = timerFactory;
|
2013-04-08 08:55:53 -07:00
|
|
|
|
|
|
|
|
|
_logger = logManager.GetLogger("Registration Loader");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Runs this instance.
|
|
|
|
|
/// </summary>
|
2014-08-31 12:15:33 -07:00
|
|
|
|
public void Run()
|
|
|
|
|
{
|
2016-11-03 15:06:00 -07:00
|
|
|
|
_timer = _timerFactory.Create(s => LoadAllRegistrations(), null, TimeSpan.FromMilliseconds(100), TimeSpan.FromHours(12));
|
2014-08-31 12:15:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task LoadAllRegistrations()
|
2013-04-08 08:55:53 -07:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await _securityManager.LoadAllRegistrationInfo().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error loading registration info", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2014-08-31 12:15:33 -07:00
|
|
|
|
if (_timer != null)
|
|
|
|
|
{
|
|
|
|
|
_timer.Dispose();
|
|
|
|
|
_timer = null;
|
|
|
|
|
}
|
2017-09-05 12:49:02 -07:00
|
|
|
|
GC.SuppressFinalize(this);
|
2013-04-08 08:55:53 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|