tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
AdministrationClient.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Threading;
5using System.Threading.Tasks;
6using System.Web;
7
11
13{
16 {
22 : base(apiClient)
23 {
24 }
25
27 public ValueTask<AdministrationResponse> Read(bool forceFresh, CancellationToken cancellationToken) => ApiClient.Read<AdministrationResponse>($"{Routes.Administration}?fresh={forceFresh}", cancellationToken);
28
30 public async ValueTask<ServerUpdateResponse> Update(
31 ServerUpdateRequest updateRequest,
32 Stream? zipFileStream,
33 CancellationToken cancellationToken)
34 {
35 if (updateRequest == null)
36 throw new ArgumentNullException(nameof(updateRequest));
37
38 if (updateRequest.UploadZip == true && zipFileStream == null)
39 throw new ArgumentNullException(nameof(zipFileStream));
40
41 var result = await ApiClient.Update<ServerUpdateRequest, ServerUpdateResponse>(
43 updateRequest,
44 cancellationToken);
45
46 if (updateRequest.UploadZip == true)
47 await ApiClient.Upload(result, zipFileStream, cancellationToken).ConfigureAwait(false);
48
49 return result;
50 }
51
53 public ValueTask Restart(CancellationToken cancellationToken) => ApiClient.Delete(Routes.Administration, cancellationToken);
54
56 public ValueTask<List<LogFileResponse>> ListLogs(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
57 => ReadPaged<LogFileResponse>(paginationSettings, Routes.Logs, null, cancellationToken);
58
60 public async ValueTask<Tuple<LogFileResponse, Stream>> GetLog(LogFileResponse logFile, CancellationToken cancellationToken)
61 {
62 var resultFile = await ApiClient.Read<LogFileResponse>(
63 Routes.Logs + Routes.SanitizeGetPath(
64 HttpUtility.UrlEncode(
65 logFile?.Name ?? throw new ArgumentNullException(nameof(logFile)))),
66 cancellationToken)
67 .ConfigureAwait(false);
68
69 var stream = await ApiClient.Download(resultFile, cancellationToken).ConfigureAwait(false);
70 try
71 {
72 return Tuple.Create(resultFile, stream);
73 }
74 catch
75 {
76 stream.Dispose();
77 throw;
78 }
79 }
80 }
81}
bool? UploadZip
If the user will provide the server update package .zip file via file transfer as opposed to TGS retr...
Routes to a server actions.
Definition Routes.cs:9
const string Administration
The server administration controller.
Definition Routes.cs:28
static string SanitizeGetPath(string path)
Sanitize a Models.Response.FileTicketResponse path for use in a GET Uri.
Definition Routes.cs:140
const string Logs
The endpoint to download server logs.
Definition Routes.cs:33
async ValueTask< Tuple< LogFileResponse, Stream > > GetLog(LogFileResponse logFile, CancellationToken cancellationToken)
Download a given logFile .A ValueTask<TResult> resulting a Tuple<T1, T2> containing the downloaded Lo...
ValueTask< List< LogFileResponse > > ListLogs(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
Lists the log files available for download.A ValueTask<TResult> resulting in an List<T> of LogFileRes...
async ValueTask< ServerUpdateResponse > Update(ServerUpdateRequest updateRequest, Stream? zipFileStream, CancellationToken cancellationToken)
Updates the AdministrationResponse setttings.A ValueTask<TResult> resulting in the echoed ServerUpdat...
ValueTask< AdministrationResponse > Read(bool forceFresh, CancellationToken cancellationToken)
Get the AdministrationResponse represented by the IAdministrationClient.A ValueTask<TResult> resultin...
AdministrationClient(IApiClient apiClient)
Initializes a new instance of the AdministrationClient class.
ValueTask Restart(CancellationToken cancellationToken)
Restarts the TGS server.A ValueTask representing the running operation.
ValueTask< Stream > Download(FileTicketResponse ticket, CancellationToken cancellationToken)
Downloads a file Stream for a given ticket .A ValueTask<TResult> resulting in the downloaded Stream.
Definition ApiClient.cs:285
async ValueTask Upload(FileTicketResponse ticket, Stream? uploadStream, CancellationToken cancellationToken)
Uploads a given uploadStream for a given ticket .A ValueTask representing the running operation.
Definition ApiClient.cs:300
ValueTask Delete(string route, CancellationToken cancellationToken)
Run an HTTP DELETE request.A ValueTask representing the running operation.
Client that deals with getting paginated results.
Settings for a paginated request.
Web interface for the API.
Definition IApiClient.cs:17