SystemService.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using MediaBrowser.Controller;
  2. using MediaBrowser.Model.System;
  3. using ServiceStack;
  4. using System.Threading.Tasks;
  5. namespace MediaBrowser.Api
  6. {
  7. /// <summary>
  8. /// Class GetSystemInfo
  9. /// </summary>
  10. [Route("/System/Info", "GET", Summary = "Gets information about the server")]
  11. public class GetSystemInfo : IReturn<SystemInfo>
  12. {
  13. }
  14. /// <summary>
  15. /// Class RestartApplication
  16. /// </summary>
  17. [Route("/System/Restart", "POST", Summary = "Restarts the application, if needed")]
  18. public class RestartApplication
  19. {
  20. }
  21. [Route("/System/Shutdown", "POST", Summary = "Shuts down the application")]
  22. public class ShutdownApplication
  23. {
  24. }
  25. /// <summary>
  26. /// Class SystemInfoService
  27. /// </summary>
  28. public class SystemService : BaseApiService
  29. {
  30. /// <summary>
  31. /// The _app host
  32. /// </summary>
  33. private readonly IServerApplicationHost _appHost;
  34. /// <summary>
  35. /// Initializes a new instance of the <see cref="SystemService" /> class.
  36. /// </summary>
  37. /// <param name="appHost">The app host.</param>
  38. /// <exception cref="System.ArgumentNullException">jsonSerializer</exception>
  39. public SystemService(IServerApplicationHost appHost)
  40. {
  41. _appHost = appHost;
  42. }
  43. /// <summary>
  44. /// Gets the specified request.
  45. /// </summary>
  46. /// <param name="request">The request.</param>
  47. /// <returns>System.Object.</returns>
  48. public object Get(GetSystemInfo request)
  49. {
  50. var result = _appHost.GetSystemInfo();
  51. return ToOptimizedResult(result);
  52. }
  53. /// <summary>
  54. /// Posts the specified request.
  55. /// </summary>
  56. /// <param name="request">The request.</param>
  57. public void Post(RestartApplication request)
  58. {
  59. Task.Run(async () =>
  60. {
  61. await Task.Delay(100).ConfigureAwait(false);
  62. await _appHost.Restart().ConfigureAwait(false);
  63. });
  64. }
  65. /// <summary>
  66. /// Posts the specified request.
  67. /// </summary>
  68. /// <param name="request">The request.</param>
  69. public void Post(ShutdownApplication request)
  70. {
  71. Task.Run(async () =>
  72. {
  73. await Task.Delay(100).ConfigureAwait(false);
  74. await _appHost.Shutdown().ConfigureAwait(false);
  75. });
  76. }
  77. }
  78. }