aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/EntryPoints/SystemEvents.cs
blob: 4ab6d32f35e63bd026c14638ac6633fd169b0e59 (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MediaBrowser.Model.System;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Common;
using MediaBrowser.Controller;

namespace Emby.Server.Implementations.EntryPoints
{
    public class SystemEvents : IServerEntryPoint
    {
        private readonly ISystemEvents _systemEvents;
        private readonly IServerApplicationHost _appHost;

        public SystemEvents(ISystemEvents systemEvents, IServerApplicationHost appHost)
        {
            _systemEvents = systemEvents;
            _appHost = appHost;
        }

        public void Run()
        {
            _systemEvents.SessionLogoff += _systemEvents_SessionLogoff;
            _systemEvents.SystemShutdown += _systemEvents_SystemShutdown;
        }

        private void _systemEvents_SessionLogoff(object sender, EventArgs e)
        {
            if (!_appHost.IsRunningAsService)
            {
                _appHost.Shutdown();
            }
        }

        private void _systemEvents_SystemShutdown(object sender, EventArgs e)
        {
            _appHost.Shutdown();
        }

        public void Dispose()
        {
            _systemEvents.SystemShutdown -= _systemEvents_SystemShutdown;
        }
    }
}