jellyfin/MediaBrowser.Api/SystemService.cs

94 lines
2.5 KiB
C#
Raw Normal View History

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