From 1d62a88fd8147e9c1bf01cac2852b929b1737c17 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 3 Nov 2016 18:06:00 -0400 Subject: move classes to portable server project --- .../EntryPoints/LoadRegistrations.cs | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Emby.Server.Implementations/EntryPoints/LoadRegistrations.cs (limited to 'Emby.Server.Implementations/EntryPoints/LoadRegistrations.cs') diff --git a/Emby.Server.Implementations/EntryPoints/LoadRegistrations.cs b/Emby.Server.Implementations/EntryPoints/LoadRegistrations.cs new file mode 100644 index 0000000000..0203b51928 --- /dev/null +++ b/Emby.Server.Implementations/EntryPoints/LoadRegistrations.cs @@ -0,0 +1,73 @@ +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; + } + } + } +} -- cgit v1.2.3