SystemEvents.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. using MediaBrowser.Controller;
  10. namespace Emby.Server.Implementations.EntryPoints
  11. {
  12. public class SystemEvents : IServerEntryPoint
  13. {
  14. private readonly ISystemEvents _systemEvents;
  15. private readonly IServerApplicationHost _appHost;
  16. public SystemEvents(ISystemEvents systemEvents, IServerApplicationHost appHost)
  17. {
  18. _systemEvents = systemEvents;
  19. _appHost = appHost;
  20. }
  21. public void Run()
  22. {
  23. _systemEvents.SessionLogoff += _systemEvents_SessionLogoff;
  24. _systemEvents.SystemShutdown += _systemEvents_SystemShutdown;
  25. }
  26. private void _systemEvents_SessionLogoff(object sender, EventArgs e)
  27. {
  28. if (!_appHost.IsRunningAsService)
  29. {
  30. _appHost.Shutdown();
  31. }
  32. }
  33. private void _systemEvents_SystemShutdown(object sender, EventArgs e)
  34. {
  35. _appHost.Shutdown();
  36. }
  37. public void Dispose()
  38. {
  39. _systemEvents.SystemShutdown -= _systemEvents_SystemShutdown;
  40. }
  41. }
  42. }