SystemService.cs 2.5 KB

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