SystemEvents.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using MediaBrowser.Model.System;
  7. using MediaBrowser.Controller.Plugins;
  8. using MediaBrowser.Common;
  9. namespace Emby.Server.Implementations.EntryPoints
  10. {
  11. public class SystemEvents : IServerEntryPoint
  12. {
  13. private readonly ISystemEvents _systemEvents;
  14. private readonly IApplicationHost _appHost;
  15. public SystemEvents(ISystemEvents systemEvents, IApplicationHost appHost)
  16. {
  17. _systemEvents = systemEvents;
  18. _appHost = appHost;
  19. }
  20. public void Run()
  21. {
  22. _systemEvents.SessionLogoff += _systemEvents_SessionLogoff;
  23. _systemEvents.SystemShutdown += _systemEvents_SystemShutdown;
  24. }
  25. private void _systemEvents_SessionLogoff(object sender, EventArgs e)
  26. {
  27. if (!_appHost.IsRunningAsService)
  28. {
  29. _appHost.Shutdown();
  30. }
  31. }
  32. private void _systemEvents_SystemShutdown(object sender, EventArgs e)
  33. {
  34. _appHost.Shutdown();
  35. }
  36. public void Dispose()
  37. {
  38. _systemEvents.SystemShutdown -= _systemEvents_SystemShutdown;
  39. }
  40. }
  41. }