2014-02-02 06:36:31 -07:00
|
|
|
|
using MediaBrowser.Controller;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using MediaBrowser.Model.System;
|
2013-12-07 08:52:38 -07:00
|
|
|
|
using ServiceStack;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
2013-02-24 14:53:54 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetSystemInfo
|
|
|
|
|
/// </summary>
|
2014-03-23 12:36:25 -07:00
|
|
|
|
[Route("/System/Info", "GET", Summary = "Gets information about the server")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public class GetSystemInfo : IReturn<SystemInfo>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class RestartApplication
|
|
|
|
|
/// </summary>
|
2014-03-23 12:36:25 -07:00
|
|
|
|
[Route("/System/Restart", "POST", Summary = "Restarts the application, if needed")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public class RestartApplication
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 12:36:25 -07:00
|
|
|
|
[Route("/System/Shutdown", "POST", Summary = "Shuts down the application")]
|
2013-02-26 09:10:55 -07:00
|
|
|
|
public class ShutdownApplication
|
|
|
|
|
{
|
|
|
|
|
}
|
2014-03-23 12:36:25 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class SystemInfoService
|
|
|
|
|
/// </summary>
|
2013-03-15 22:52:33 -07:00
|
|
|
|
public class SystemService : BaseApiService
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-02-26 09:10:55 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _app host
|
|
|
|
|
/// </summary>
|
2013-03-06 22:34:00 -07:00
|
|
|
|
private readonly IServerApplicationHost _appHost;
|
2013-02-26 09:10:55 -07:00
|
|
|
|
|
2013-10-31 07:03:23 -07:00
|
|
|
|
|
2013-02-24 14:53:54 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="SystemService" /> class.
|
|
|
|
|
/// </summary>
|
2013-02-26 09:10:55 -07:00
|
|
|
|
/// <param name="appHost">The app host.</param>
|
2013-02-24 14:53:54 -07:00
|
|
|
|
/// <exception cref="System.ArgumentNullException">jsonSerializer</exception>
|
2014-02-02 06:36:31 -07:00
|
|
|
|
public SystemService(IServerApplicationHost appHost)
|
2013-02-24 14:53:54 -07:00
|
|
|
|
{
|
2013-02-26 09:10:55 -07:00
|
|
|
|
_appHost = appHost;
|
2013-02-24 14:53:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetSystemInfo request)
|
|
|
|
|
{
|
2013-03-06 22:34:00 -07:00
|
|
|
|
var result = _appHost.GetSystemInfo();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Post(RestartApplication request)
|
|
|
|
|
{
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
2013-09-20 10:32:10 -07:00
|
|
|
|
await Task.Delay(100).ConfigureAwait(false);
|
|
|
|
|
await _appHost.Restart().ConfigureAwait(false);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-26 09:10:55 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Post(ShutdownApplication request)
|
|
|
|
|
{
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
2013-09-20 10:32:10 -07:00
|
|
|
|
await Task.Delay(100).ConfigureAwait(false);
|
|
|
|
|
await _appHost.Shutdown().ConfigureAwait(false);
|
2013-02-26 09:10:55 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
}
|