aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/EntryPoints/LoadRegistrations.cs
blob: 21e075cf5c5d94d7ab58fd71930a9e95be9ae527 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
{
    /// <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;

        private ITimer _timer;
        private readonly ITimerFactory _timerFactory;

        /// <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>
        public LoadRegistrations(ISecurityManager securityManager, ILogManager logManager, ITimerFactory timerFactory)
        {
            _securityManager = securityManager;
            _timerFactory = timerFactory;

            _logger = logManager.GetLogger("Registration Loader");
        }

        /// <summary>
        /// Runs this instance.
        /// </summary>
        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);
            }
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (_timer != null)
            {
                _timer.Dispose();
                _timer = null;
            }
            GC.SuppressFinalize(this);
        }
    }
}