Merge branch 'dev' into V6

This commit is contained in:
tgstation-server
2023-10-08 04:56:51 +00:00
231 changed files with 1837 additions and 1556 deletions
@@ -24,10 +24,10 @@ namespace Tgstation.Server.Client
}
/// <inheritdoc />
public Task<AdministrationResponse> Read(CancellationToken cancellationToken) => ApiClient.Read<AdministrationResponse>(Routes.Administration, cancellationToken);
public ValueTask<AdministrationResponse> Read(CancellationToken cancellationToken) => ApiClient.Read<AdministrationResponse>(Routes.Administration, cancellationToken);
/// <inheritdoc />
public async Task<ServerUpdateResponse> Update(
public async ValueTask<ServerUpdateResponse> Update(
ServerUpdateRequest updateRequest,
Stream? zipFileStream,
CancellationToken cancellationToken)
@@ -50,14 +50,14 @@ namespace Tgstation.Server.Client
}
/// <inheritdoc />
public Task Restart(CancellationToken cancellationToken) => ApiClient.Delete(Routes.Administration, cancellationToken);
public ValueTask Restart(CancellationToken cancellationToken) => ApiClient.Delete(Routes.Administration, cancellationToken);
/// <inheritdoc />
public Task<IReadOnlyList<LogFileResponse>> ListLogs(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
public ValueTask<List<LogFileResponse>> ListLogs(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
=> ReadPaged<LogFileResponse>(paginationSettings, Routes.Logs, null, cancellationToken);
/// <inheritdoc />
public async Task<Tuple<LogFileResponse, Stream>> GetLog(LogFileResponse logFile, CancellationToken cancellationToken)
public async ValueTask<Tuple<LogFileResponse, Stream>> GetLog(LogFileResponse logFile, CancellationToken cancellationToken)
{
var resultFile = await ApiClient.Read<LogFileResponse>(
Routes.Logs + Routes.SanitizeGetPath(
+82 -31
View File
@@ -20,6 +20,7 @@ using Newtonsoft.Json.Serialization;
using Tgstation.Server.Api;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Models.Response;
using Tgstation.Server.Common.Extensions;
using Tgstation.Server.Common.Http;
namespace Tgstation.Server.Client
@@ -168,84 +169,84 @@ namespace Tgstation.Server.Client
}
/// <inheritdoc />
public Task<TResult> Create<TResult>(string route, CancellationToken cancellationToken)
public ValueTask<TResult> Create<TResult>(string route, CancellationToken cancellationToken)
=> RunRequest<object, TResult>(route, new object(), HttpMethod.Put, null, false, cancellationToken);
/// <inheritdoc />
public Task<TResult> Read<TResult>(string route, CancellationToken cancellationToken)
public ValueTask<TResult> Read<TResult>(string route, CancellationToken cancellationToken)
=> RunRequest<object, TResult>(route, null, HttpMethod.Get, null, false, cancellationToken);
/// <inheritdoc />
public Task<TResult> Update<TResult>(string route, CancellationToken cancellationToken)
public ValueTask<TResult> Update<TResult>(string route, CancellationToken cancellationToken)
=> RunRequest<object, TResult>(route, new object(), HttpMethod.Post, null, false, cancellationToken);
/// <inheritdoc />
public Task<TResult> Update<TBody, TResult>(string route, TBody body, CancellationToken cancellationToken)
public ValueTask<TResult> Update<TBody, TResult>(string route, TBody body, CancellationToken cancellationToken)
where TBody : class
=> RunRequest<TBody, TResult>(route, body, HttpMethod.Post, null, false, cancellationToken);
/// <inheritdoc />
public Task Patch(string route, CancellationToken cancellationToken) => RunRequest<object>(route, null, HttpPatch, null, false, cancellationToken);
public ValueTask Patch(string route, CancellationToken cancellationToken) => RunRequest(route, HttpPatch, null, false, cancellationToken);
/// <inheritdoc />
public Task Update<TBody>(string route, TBody body, CancellationToken cancellationToken)
public ValueTask Update<TBody>(string route, TBody body, CancellationToken cancellationToken)
where TBody : class
=> RunRequest<TBody, object>(route, body, HttpMethod.Post, null, false, cancellationToken);
=> RunResultlessRequest(route, body, HttpMethod.Post, null, false, cancellationToken);
/// <inheritdoc />
public Task<TResult> Create<TBody, TResult>(string route, TBody body, CancellationToken cancellationToken)
public ValueTask<TResult> Create<TBody, TResult>(string route, TBody body, CancellationToken cancellationToken)
where TBody : class
=> RunRequest<TBody, TResult>(route, body, HttpMethod.Put, null, false, cancellationToken);
/// <inheritdoc />
public Task Delete(string route, CancellationToken cancellationToken)
=> RunRequest<object>(route, null, HttpMethod.Delete, null, false, cancellationToken);
public ValueTask Delete(string route, CancellationToken cancellationToken)
=> RunRequest(route, HttpMethod.Delete, null, false, cancellationToken);
/// <inheritdoc />
public Task<TResult> Create<TBody, TResult>(string route, TBody body, long instanceId, CancellationToken cancellationToken)
public ValueTask<TResult> Create<TBody, TResult>(string route, TBody body, long instanceId, CancellationToken cancellationToken)
where TBody : class
=> RunRequest<TBody, TResult>(route, body, HttpMethod.Put, instanceId, false, cancellationToken);
/// <inheritdoc />
public Task<TResult> Read<TResult>(string route, long instanceId, CancellationToken cancellationToken)
public ValueTask<TResult> Read<TResult>(string route, long instanceId, CancellationToken cancellationToken)
=> RunRequest<TResult>(route, null, HttpMethod.Get, instanceId, false, cancellationToken);
/// <inheritdoc />
public Task<TResult> Update<TBody, TResult>(string route, TBody body, long instanceId, CancellationToken cancellationToken)
public ValueTask<TResult> Update<TBody, TResult>(string route, TBody body, long instanceId, CancellationToken cancellationToken)
where TBody : class
=> RunRequest<TBody, TResult>(route, body, HttpMethod.Post, instanceId, false, cancellationToken);
/// <inheritdoc />
public Task Delete(string route, long instanceId, CancellationToken cancellationToken)
=> RunRequest<object>(route, null, HttpMethod.Delete, instanceId, false, cancellationToken);
public ValueTask Delete(string route, long instanceId, CancellationToken cancellationToken)
=> RunRequest(route, HttpMethod.Delete, instanceId, false, cancellationToken);
/// <inheritdoc />
public Task Delete<TBody>(string route, TBody body, long instanceId, CancellationToken cancellationToken)
public ValueTask Delete<TBody>(string route, TBody body, long instanceId, CancellationToken cancellationToken)
where TBody : class
=> RunRequest<TBody, object>(route, body, HttpMethod.Delete, instanceId, false, cancellationToken);
=> RunResultlessRequest(route, body, HttpMethod.Delete, instanceId, false, cancellationToken);
/// <inheritdoc />
public Task<TResult> Delete<TResult>(string route, long instanceId, CancellationToken cancellationToken)
public ValueTask<TResult> Delete<TResult>(string route, long instanceId, CancellationToken cancellationToken)
=> RunRequest<TResult>(route, null, HttpMethod.Delete, instanceId, false, cancellationToken);
/// <inheritdoc />
public Task<TResult> Delete<TBody, TResult>(string route, TBody body, long instanceId, CancellationToken cancellationToken)
public ValueTask<TResult> Delete<TBody, TResult>(string route, TBody body, long instanceId, CancellationToken cancellationToken)
where TBody : class
=> RunRequest<TBody, TResult>(route, body, HttpMethod.Delete, instanceId, false, cancellationToken);
/// <inheritdoc />
public Task<TResult> Create<TResult>(string route, long instanceId, CancellationToken cancellationToken)
public ValueTask<TResult> Create<TResult>(string route, long instanceId, CancellationToken cancellationToken)
=> RunRequest<object, TResult>(route, new object(), HttpMethod.Put, instanceId, false, cancellationToken);
/// <inheritdoc />
public Task<TResult> Patch<TResult>(string route, long instanceId, CancellationToken cancellationToken)
public ValueTask<TResult> Patch<TResult>(string route, long instanceId, CancellationToken cancellationToken)
=> RunRequest<object, TResult>(route, new object(), HttpPatch, instanceId, false, cancellationToken);
/// <inheritdoc />
public void AddRequestLogger(IRequestLogger requestLogger) => requestLoggers.Add(requestLogger ?? throw new ArgumentNullException(nameof(requestLogger)));
/// <inheritdoc />
public Task<Stream> Download(FileTicketResponse ticket, CancellationToken cancellationToken)
public ValueTask<Stream> Download(FileTicketResponse ticket, CancellationToken cancellationToken)
{
if (ticket == null)
throw new ArgumentNullException(nameof(ticket));
@@ -260,7 +261,7 @@ namespace Tgstation.Server.Client
}
/// <inheritdoc />
public async Task Upload(FileTicketResponse ticket, Stream? uploadStream, CancellationToken cancellationToken)
public async ValueTask Upload(FileTicketResponse ticket, Stream? uploadStream, CancellationToken cancellationToken)
{
if (ticket == null)
throw new ArgumentNullException(nameof(ticket));
@@ -303,8 +304,8 @@ namespace Tgstation.Server.Client
/// <param name="instanceId">The optional instance <see cref="EntityId.Id"/> for the request.</param>
/// <param name="tokenRefresh">If this is a token refresh operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response on success.</returns>
protected virtual async Task<TResult> RunRequest<TResult>(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the response on success.</returns>
protected virtual async ValueTask<TResult> RunRequest<TResult>(
string route,
HttpContent? content,
HttpMethod method,
@@ -339,7 +340,7 @@ namespace Tgstation.Server.Client
if (fileDownload)
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Octet));
await Task.WhenAll(requestLoggers.Select(x => x.LogRequest(request, cancellationToken))).ConfigureAwait(false);
await ValueTaskExtensions.WhenAll(requestLoggers.Select(x => x.LogRequest(request, cancellationToken))).ConfigureAwait(false);
response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
}
@@ -352,7 +353,7 @@ namespace Tgstation.Server.Client
try
{
await Task.WhenAll(requestLoggers.Select(x => x.LogResponse(response, cancellationToken))).ConfigureAwait(false);
await ValueTaskExtensions.WhenAll(requestLoggers.Select(x => x.LogResponse(response, cancellationToken))).ConfigureAwait(false);
// just stream
if (fileDownload && response.IsSuccessStatusCode)
@@ -396,8 +397,8 @@ namespace Tgstation.Server.Client
/// Attempt to refresh the bearer token in the <see cref="headers"/>.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in <see langword="true"/> if the refresh was successful, <see langword="false"/> otherwise.</returns>
async Task<bool> RefreshToken(CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in <see langword="true"/> if the refresh was successful, <see langword="false"/> otherwise.</returns>
async ValueTask<bool> RefreshToken(CancellationToken cancellationToken)
{
if (tokenRefreshHeaders == null)
return false;
@@ -435,8 +436,8 @@ namespace Tgstation.Server.Client
/// <param name="instanceId">The optional instance <see cref="EntityId.Id"/> for the request.</param>
/// <param name="tokenRefresh">If this is a token refresh operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response on success.</returns>
async Task<TResult> RunRequest<TBody, TResult>(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the response on success.</returns>
async ValueTask<TResult> RunRequest<TBody, TResult>(
string route,
TBody? body,
HttpMethod method,
@@ -462,5 +463,55 @@ namespace Tgstation.Server.Client
cancellationToken)
.ConfigureAwait(false);
}
/// <summary>
/// Main request method.
/// </summary>
/// <typeparam name="TBody">The body <see cref="Type"/>.</typeparam>
/// <param name="route">The route to run.</param>
/// <param name="body">The body of the request.</param>
/// <param name="method">The method of the request.</param>
/// <param name="instanceId">The optional instance <see cref="EntityId.Id"/> for the request.</param>
/// <param name="tokenRefresh">If this is a token refresh operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the response on success.</returns>
async ValueTask RunResultlessRequest<TBody>(
string route,
TBody? body,
HttpMethod method,
long? instanceId,
bool tokenRefresh,
CancellationToken cancellationToken)
where TBody : class
=> await RunRequest<TBody, object>(
route,
body,
method,
instanceId,
tokenRefresh,
cancellationToken);
/// <summary>
/// Main request method.
/// </summary>
/// <param name="route">The route to run.</param>
/// <param name="method">The method of the request.</param>
/// <param name="instanceId">The optional instance <see cref="EntityId.Id"/> for the request.</param>
/// <param name="tokenRefresh">If this is a token refresh operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the response on success.</returns>
ValueTask RunRequest(
string route,
HttpMethod method,
long? instanceId,
bool tokenRefresh,
CancellationToken cancellationToken)
=> RunResultlessRequest<object>(
route,
null,
method,
instanceId,
tokenRefresh,
cancellationToken);
}
}
@@ -31,18 +31,18 @@ namespace Tgstation.Server.Client.Components
}
/// <inheritdoc />
public Task<ByondResponse> ActiveVersion(CancellationToken cancellationToken) => ApiClient.Read<ByondResponse>(Routes.Byond, instance.Id!.Value, cancellationToken);
public ValueTask<ByondResponse> ActiveVersion(CancellationToken cancellationToken) => ApiClient.Read<ByondResponse>(Routes.Byond, instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<JobResponse> DeleteVersion(ByondVersionDeleteRequest deleteRequest, CancellationToken cancellationToken)
public ValueTask<JobResponse> DeleteVersion(ByondVersionDeleteRequest deleteRequest, CancellationToken cancellationToken)
=> ApiClient.Delete<ByondVersionDeleteRequest, JobResponse>(Routes.Byond, deleteRequest, instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<IReadOnlyList<ByondResponse>> InstalledVersions(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
public ValueTask<List<ByondResponse>> InstalledVersions(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
=> ReadPaged<ByondResponse>(paginationSettings, Routes.ListRoute(Routes.Byond), instance.Id, cancellationToken);
/// <inheritdoc />
public async Task<ByondInstallResponse> SetActiveVersion(ByondVersionRequest installRequest, Stream? zipFileStream, CancellationToken cancellationToken)
public async ValueTask<ByondInstallResponse> SetActiveVersion(ByondVersionRequest installRequest, Stream? zipFileStream, CancellationToken cancellationToken)
{
if (installRequest == null)
throw new ArgumentNullException(nameof(installRequest));
@@ -30,19 +30,19 @@ namespace Tgstation.Server.Client.Components
}
/// <inheritdoc />
public Task<ChatBotResponse> Create(ChatBotCreateRequest settings, CancellationToken cancellationToken) => ApiClient.Create<ChatBotCreateRequest, ChatBotResponse>(Routes.Chat, settings ?? throw new ArgumentNullException(nameof(settings)), instance.Id!.Value, cancellationToken);
public ValueTask<ChatBotResponse> Create(ChatBotCreateRequest settings, CancellationToken cancellationToken) => ApiClient.Create<ChatBotCreateRequest, ChatBotResponse>(Routes.Chat, settings ?? throw new ArgumentNullException(nameof(settings)), instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task Delete(EntityId settingsId, CancellationToken cancellationToken) => ApiClient.Delete(Routes.SetID(Routes.Chat, settingsId?.Id ?? throw new ArgumentNullException(nameof(settingsId))), instance.Id!.Value, cancellationToken);
public ValueTask Delete(EntityId settingsId, CancellationToken cancellationToken) => ApiClient.Delete(Routes.SetID(Routes.Chat, settingsId?.Id ?? throw new ArgumentNullException(nameof(settingsId))), instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<IReadOnlyList<ChatBotResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
public ValueTask<List<ChatBotResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
=> ReadPaged<ChatBotResponse>(paginationSettings, Routes.ListRoute(Routes.Chat), instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<ChatBotResponse> Update(ChatBotUpdateRequest settings, CancellationToken cancellationToken) => ApiClient.Update<ChatBotUpdateRequest, ChatBotResponse>(Routes.Chat, settings ?? throw new ArgumentNullException(nameof(settings)), instance.Id!.Value, cancellationToken);
public ValueTask<ChatBotResponse> Update(ChatBotUpdateRequest settings, CancellationToken cancellationToken) => ApiClient.Update<ChatBotUpdateRequest, ChatBotResponse>(Routes.Chat, settings ?? throw new ArgumentNullException(nameof(settings)), instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<ChatBotResponse> GetId(EntityId settingsId, CancellationToken cancellationToken) => ApiClient.Read<ChatBotResponse>(Routes.SetID(Routes.Chat, settingsId?.Id ?? throw new ArgumentNullException(nameof(settingsId))), instance.Id!.Value, cancellationToken);
public ValueTask<ChatBotResponse> GetId(EntityId settingsId, CancellationToken cancellationToken) => ApiClient.Read<ChatBotResponse>(Routes.SetID(Routes.Chat, settingsId?.Id ?? throw new ArgumentNullException(nameof(settingsId))), instance.Id!.Value, cancellationToken);
}
}
@@ -31,13 +31,13 @@ namespace Tgstation.Server.Client.Components
}
/// <inheritdoc />
public Task DeleteEmptyDirectory(IConfigurationFile directory, CancellationToken cancellationToken) => ApiClient.Delete(Routes.Configuration, directory, instance.Id!.Value, cancellationToken);
public ValueTask DeleteEmptyDirectory(IConfigurationFile directory, CancellationToken cancellationToken) => ApiClient.Delete(Routes.Configuration, directory, instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<ConfigurationFileResponse> CreateDirectory(IConfigurationFile directory, CancellationToken cancellationToken) => ApiClient.Create<IConfigurationFile, ConfigurationFileResponse>(Routes.Configuration, directory, instance.Id!.Value, cancellationToken);
public ValueTask<ConfigurationFileResponse> CreateDirectory(IConfigurationFile directory, CancellationToken cancellationToken) => ApiClient.Create<IConfigurationFile, ConfigurationFileResponse>(Routes.Configuration, directory, instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<IReadOnlyList<ConfigurationFileResponse>> List(
public ValueTask<List<ConfigurationFileResponse>> List(
PaginationSettings? paginationSettings,
string directory,
CancellationToken cancellationToken)
@@ -48,7 +48,7 @@ namespace Tgstation.Server.Client.Components
cancellationToken);
/// <inheritdoc />
public async Task<Tuple<ConfigurationFileResponse, Stream>> Read(IConfigurationFile file, CancellationToken cancellationToken)
public async ValueTask<Tuple<ConfigurationFileResponse, Stream>> Read(IConfigurationFile file, CancellationToken cancellationToken)
{
if (file == null)
throw new ArgumentNullException(nameof(file));
@@ -70,7 +70,7 @@ namespace Tgstation.Server.Client.Components
}
/// <inheritdoc />
public async Task<ConfigurationFileResponse> Write(ConfigurationFileRequest file, Stream uploadStream, CancellationToken cancellationToken)
public async ValueTask<ConfigurationFileResponse> Write(ConfigurationFileRequest file, Stream uploadStream, CancellationToken cancellationToken)
{
long initialStreamPosition = 0;
MemoryStream? memoryStream = null;
@@ -34,21 +34,21 @@ namespace Tgstation.Server.Client.Components
}
/// <inheritdoc />
public Task Shutdown(CancellationToken cancellationToken) => apiClient.Delete(Routes.DreamDaemon, instance.Id!.Value, cancellationToken);
public ValueTask Shutdown(CancellationToken cancellationToken) => apiClient.Delete(Routes.DreamDaemon, instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<JobResponse> Start(CancellationToken cancellationToken) => apiClient.Create<JobResponse>(Routes.DreamDaemon, instance.Id!.Value, cancellationToken);
public ValueTask<JobResponse> Start(CancellationToken cancellationToken) => apiClient.Create<JobResponse>(Routes.DreamDaemon, instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<JobResponse> Restart(CancellationToken cancellationToken) => apiClient.Patch<JobResponse>(Routes.DreamDaemon, instance.Id!.Value, cancellationToken);
public ValueTask<JobResponse> Restart(CancellationToken cancellationToken) => apiClient.Patch<JobResponse>(Routes.DreamDaemon, instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<DreamDaemonResponse> Read(CancellationToken cancellationToken) => apiClient.Read<DreamDaemonResponse>(Routes.DreamDaemon, instance.Id!.Value, cancellationToken);
public ValueTask<DreamDaemonResponse> Read(CancellationToken cancellationToken) => apiClient.Read<DreamDaemonResponse>(Routes.DreamDaemon, instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<DreamDaemonResponse> Update(DreamDaemonRequest dreamDaemon, CancellationToken cancellationToken) => apiClient.Update<DreamDaemonRequest, DreamDaemonResponse>(Routes.DreamDaemon, dreamDaemon ?? throw new ArgumentNullException(nameof(dreamDaemon)), instance.Id!.Value, cancellationToken);
public ValueTask<DreamDaemonResponse> Update(DreamDaemonRequest dreamDaemon, CancellationToken cancellationToken) => apiClient.Update<DreamDaemonRequest, DreamDaemonResponse>(Routes.DreamDaemon, dreamDaemon ?? throw new ArgumentNullException(nameof(dreamDaemon)), instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<JobResponse> CreateDump(CancellationToken cancellationToken) => apiClient.Patch<JobResponse>(Routes.Diagnostics, instance.Id!.Value, cancellationToken);
public ValueTask<JobResponse> CreateDump(CancellationToken cancellationToken) => apiClient.Patch<JobResponse>(Routes.Diagnostics, instance.Id!.Value, cancellationToken);
}
}
@@ -30,19 +30,19 @@ namespace Tgstation.Server.Client.Components
}
/// <inheritdoc />
public Task<JobResponse> Compile(CancellationToken cancellationToken) => ApiClient.Create<JobResponse>(Routes.DreamMaker, instance.Id!.Value, cancellationToken);
public ValueTask<JobResponse> Compile(CancellationToken cancellationToken) => ApiClient.Create<JobResponse>(Routes.DreamMaker, instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<CompileJobResponse> GetCompileJob(EntityId compileJob, CancellationToken cancellationToken) => ApiClient.Read<CompileJobResponse>(Routes.SetID(Routes.DreamMaker, compileJob?.Id ?? throw new ArgumentNullException(nameof(compileJob))), instance.Id!.Value, cancellationToken);
public ValueTask<CompileJobResponse> GetCompileJob(EntityId compileJob, CancellationToken cancellationToken) => ApiClient.Read<CompileJobResponse>(Routes.SetID(Routes.DreamMaker, compileJob?.Id ?? throw new ArgumentNullException(nameof(compileJob))), instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<IReadOnlyList<CompileJobResponse>> ListCompileJobs(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
public ValueTask<List<CompileJobResponse>> ListCompileJobs(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
=> ReadPaged<CompileJobResponse>(paginationSettings, Routes.ListRoute(Routes.DreamMaker), instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<DreamMakerResponse> Read(CancellationToken cancellationToken) => ApiClient.Read<DreamMakerResponse>(Routes.DreamMaker, instance.Id!.Value, cancellationToken);
public ValueTask<DreamMakerResponse> Read(CancellationToken cancellationToken) => ApiClient.Read<DreamMakerResponse>(Routes.DreamMaker, instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<DreamMakerResponse> Update(DreamMakerRequest dreamMaker, CancellationToken cancellationToken) => ApiClient.Update<DreamMakerRequest, DreamMakerResponse>(Routes.DreamMaker, dreamMaker ?? throw new ArgumentNullException(nameof(dreamMaker)), instance.Id!.Value, cancellationToken);
public ValueTask<DreamMakerResponse> Update(DreamMakerRequest dreamMaker, CancellationToken cancellationToken) => ApiClient.Update<DreamMakerRequest, DreamMakerResponse>(Routes.DreamMaker, dreamMaker ?? throw new ArgumentNullException(nameof(dreamMaker)), instance.Id!.Value, cancellationToken);
}
}
@@ -17,16 +17,16 @@ namespace Tgstation.Server.Client.Components
/// Get the <see cref="ByondInstallResponse"/> active <see cref="System.Version"/> information.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="ByondInstallResponse"/> active <see cref="System.Version"/> information.</returns>
Task<ByondResponse> ActiveVersion(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="ByondInstallResponse"/> active <see cref="System.Version"/> information.</returns>
ValueTask<ByondResponse> ActiveVersion(CancellationToken cancellationToken);
/// <summary>
/// Get all installed <see cref="ByondInstallResponse"/> <see cref="System.Version"/>s.
/// </summary>
/// <param name="paginationSettings">The optional <see cref="PaginationSettings"/> for the operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in an <see cref="IReadOnlyList{T}"/> of installed <see cref="ByondInstallResponse"/> <see cref="System.Version"/>s.</returns>
Task<IReadOnlyList<ByondResponse>> InstalledVersions(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in an <see cref="List{T}"/> of installed <see cref="ByondInstallResponse"/> <see cref="System.Version"/>s.</returns>
ValueTask<List<ByondResponse>> InstalledVersions(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <summary>
/// Updates the active BYOND version.
@@ -34,15 +34,15 @@ namespace Tgstation.Server.Client.Components
/// <param name="installRequest">The <see cref="ByondVersionRequest"/>.</param>
/// <param name="zipFileStream">The <see cref="Stream"/> for the .zip file if <see cref="ByondVersionRequest.UploadCustomZip"/> is <see langword="true"/>. Will be ignored if it is <see langword="false"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the updated <see cref="ByondInstallResponse"/> information.</returns>
Task<ByondInstallResponse> SetActiveVersion(ByondVersionRequest installRequest, Stream? zipFileStream, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the updated <see cref="ByondInstallResponse"/> information.</returns>
ValueTask<ByondInstallResponse> SetActiveVersion(ByondVersionRequest installRequest, Stream? zipFileStream, CancellationToken cancellationToken);
/// <summary>
/// Starts a jobs to delete a specific BYOND version.
/// </summary>
/// <param name="deleteRequest">The <see cref="ByondVersionDeleteRequest"/> specifying the version to delete.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="JobResponse"/> for the delete job.</returns>
Task<JobResponse> DeleteVersion(ByondVersionDeleteRequest deleteRequest, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="JobResponse"/> for the delete job.</returns>
ValueTask<JobResponse> DeleteVersion(ByondVersionDeleteRequest deleteRequest, CancellationToken cancellationToken);
}
}
@@ -18,39 +18,39 @@ namespace Tgstation.Server.Client.Components
/// </summary>
/// <param name="paginationSettings">The optional <see cref="PaginationSettings"/> for the operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="IReadOnlyList{T}"/> of the <see cref="ChatBotResponse"/>s.</returns>
Task<IReadOnlyList<ChatBotResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="List{T}"/> of the <see cref="ChatBotResponse"/>s.</returns>
ValueTask<List<ChatBotResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <summary>
/// Create a chat bot.
/// </summary>
/// <param name="settings">The <see cref="ChatBotCreateRequest"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="ChatBotResponse"/> of the newly created chat bot.</returns>
Task<ChatBotResponse> Create(ChatBotCreateRequest settings, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="ChatBotResponse"/> of the newly created chat bot.</returns>
ValueTask<ChatBotResponse> Create(ChatBotCreateRequest settings, CancellationToken cancellationToken);
/// <summary>
/// Updates a chat bot's setttings.
/// </summary>
/// <param name="settings">The <see cref="ChatBotUpdateRequest"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the updated chat bot's <see cref="ChatBotResponse"/>.</returns>
Task<ChatBotResponse> Update(ChatBotUpdateRequest settings, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the updated chat bot's <see cref="ChatBotResponse"/>.</returns>
ValueTask<ChatBotResponse> Update(ChatBotUpdateRequest settings, CancellationToken cancellationToken);
/// <summary>
/// Get a specific chat bot's settings.
/// </summary>
/// <param name="settingsId">The <see cref="EntityId"/> of the chat bot to get.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="ChatBotResponse"/>.</returns>
Task<ChatBotResponse> GetId(EntityId settingsId, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="ChatBotResponse"/>.</returns>
ValueTask<ChatBotResponse> GetId(EntityId settingsId, CancellationToken cancellationToken);
/// <summary>
/// Delete a chat bot.
/// </summary>
/// <param name="settingsId">The <see cref="EntityId"/> of the chat bot to delete.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task Delete(EntityId settingsId, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask Delete(EntityId settingsId, CancellationToken cancellationToken);
}
}
@@ -21,8 +21,8 @@ namespace Tgstation.Server.Client.Components
/// <param name="paginationSettings">The optional <see cref="PaginationSettings"/> for the operation.</param>
/// <param name="directory">The path to the directory to list files in.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="IReadOnlyList{T}"/> of <see cref="ConfigurationFileResponse"/>s in the <paramref name="directory"/>.</returns>
Task<IReadOnlyList<ConfigurationFileResponse>> List(
/// <returns>A <see cref="List{T}"/> of <see cref="ConfigurationFileResponse"/>s in the <paramref name="directory"/>.</returns>
ValueTask<List<ConfigurationFileResponse>> List(
PaginationSettings? paginationSettings,
string directory,
CancellationToken cancellationToken);
@@ -32,8 +32,8 @@ namespace Tgstation.Server.Client.Components
/// </summary>
/// <param name="file">The <see cref="IConfigurationFile"/> file to read.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> resulting in a <see cref="Tuple{T1, T2}"/> containing the <see cref="ConfigurationFileResponse"/> and downloaded <see cref="FileTicketResponse"/> <see cref="Stream"/>.</returns>
Task<Tuple<ConfigurationFileResponse, Stream>> Read(IConfigurationFile file, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> resulting in a <see cref="Tuple{T1, T2}"/> containing the <see cref="ConfigurationFileResponse"/> and downloaded <see cref="FileTicketResponse"/> <see cref="Stream"/>.</returns>
ValueTask<Tuple<ConfigurationFileResponse, Stream>> Read(IConfigurationFile file, CancellationToken cancellationToken);
/// <summary>
/// Overwrite a <paramref name="file"/>.
@@ -41,23 +41,23 @@ namespace Tgstation.Server.Client.Components
/// <param name="file">The <see cref="ConfigurationFileRequest"/>.</param>
/// <param name="uploadStream">The <see cref="Stream"/> of uploaded data. If <see langword="null"/>, a delete will be attempted.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the new <see cref="ConfigurationFileResponse"/>.</returns>
Task<ConfigurationFileResponse> Write(ConfigurationFileRequest file, Stream uploadStream, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the new <see cref="ConfigurationFileResponse"/>.</returns>
ValueTask<ConfigurationFileResponse> Write(ConfigurationFileRequest file, Stream uploadStream, CancellationToken cancellationToken);
/// <summary>
/// Delete an empty <paramref name="directory"/>.
/// </summary>
/// <param name="directory">The <see cref="IConfigurationFile"/> representing the directory to delete.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task DeleteEmptyDirectory(IConfigurationFile directory, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask DeleteEmptyDirectory(IConfigurationFile directory, CancellationToken cancellationToken);
/// <summary>
/// Creates an empty <paramref name="directory"/>.
/// </summary>
/// <param name="directory">The <see cref="IConfigurationFile"/> representing the directory to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the new <see cref="ConfigurationFileResponse"/>.</returns>
Task<ConfigurationFileResponse> CreateDirectory(IConfigurationFile directory, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the new <see cref="ConfigurationFileResponse"/>.</returns>
ValueTask<ConfigurationFileResponse> CreateDirectory(IConfigurationFile directory, CancellationToken cancellationToken);
}
}
@@ -15,43 +15,43 @@ namespace Tgstation.Server.Client.Components
/// Get the <see cref="DreamDaemonResponse"/> represented by the <see cref="IDreamDaemonClient"/>.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="DreamDaemonResponse"/> information.</returns>
Task<DreamDaemonResponse> Read(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="DreamDaemonResponse"/> information.</returns>
ValueTask<DreamDaemonResponse> Read(CancellationToken cancellationToken);
/// <summary>
/// Start <see cref="DreamDaemonResponse"/>.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="JobResponse"/> of the running operation.</returns>
Task<JobResponse> Start(CancellationToken cancellationToken);
ValueTask<JobResponse> Start(CancellationToken cancellationToken);
/// <summary>
/// Restart <see cref="DreamDaemonResponse"/>.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="JobResponse"/> of the running operation.</returns>
Task<JobResponse> Restart(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="JobResponse"/> of the running operation.</returns>
ValueTask<JobResponse> Restart(CancellationToken cancellationToken);
/// <summary>
/// Shutdown <see cref="DreamDaemonResponse"/>.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="DreamDaemonResponse"/> information.</returns>
Task Shutdown(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="DreamDaemonResponse"/> information.</returns>
ValueTask Shutdown(CancellationToken cancellationToken);
/// <summary>
/// Update <see cref="DreamDaemonResponse"/>. This may trigger a <see cref="Api.Models.Internal.DreamDaemonApiBase.SoftRestart"/>.
/// </summary>
/// <param name="dreamDaemon">The <see cref="DreamDaemonRequest"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="DreamDaemonResponse"/> information.</returns>
Task<DreamDaemonResponse> Update(DreamDaemonRequest dreamDaemon, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="DreamDaemonResponse"/> information.</returns>
ValueTask<DreamDaemonResponse> Update(DreamDaemonRequest dreamDaemon, CancellationToken cancellationToken);
/// <summary>
/// Start a job to create a process dump of the active DreamDaemon executable.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="JobResponse"/> of the running operation.</returns>
Task<JobResponse> CreateDump(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="JobResponse"/> of the running operation.</returns>
ValueTask<JobResponse> CreateDump(CancellationToken cancellationToken);
}
}
@@ -17,38 +17,38 @@ namespace Tgstation.Server.Client.Components
/// Get the <see cref="DreamMakerResponse"/>.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="DreamMakerResponse"/>.</returns>
Task<DreamMakerResponse> Read(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="DreamMakerResponse"/>.</returns>
ValueTask<DreamMakerResponse> Read(CancellationToken cancellationToken);
/// <summary>
/// Updates the <see cref="Api.Models.Internal.DreamMakerSettings"/>.
/// </summary>
/// <param name="dreamMaker">The <see cref="DreamMakerRequest"/> to update.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task<DreamMakerResponse> Update(DreamMakerRequest dreamMaker, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask<DreamMakerResponse> Update(DreamMakerRequest dreamMaker, CancellationToken cancellationToken);
/// <summary>
/// Compile the current repository revision.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="JobResponse"/> for the compile.</returns>
Task<JobResponse> Compile(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="JobResponse"/> for the compile.</returns>
ValueTask<JobResponse> Compile(CancellationToken cancellationToken);
/// <summary>
/// Gets the <see cref="CompileJobResponse"/>s for the instance.
/// </summary>
/// <param name="paginationSettings">The optional <see cref="PaginationSettings"/> for the operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="IReadOnlyList{T}"/> of <see cref="CompileJobResponse"/>s.</returns>
Task<IReadOnlyList<CompileJobResponse>> ListCompileJobs(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="List{T}"/> of <see cref="CompileJobResponse"/>s.</returns>
ValueTask<List<CompileJobResponse>> ListCompileJobs(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <summary>
/// Get a <paramref name="compileJob"/>.
/// </summary>
/// <param name="compileJob">The <see cref="Api.Models.Internal.CompileJob"/>'s <see cref="EntityId"/> to get.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="CompileJobResponse"/>.</returns>
Task<CompileJobResponse> GetCompileJob(EntityId compileJob, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="CompileJobResponse"/>.</returns>
ValueTask<CompileJobResponse> GetCompileJob(EntityId compileJob, CancellationToken cancellationToken);
}
}
@@ -17,47 +17,47 @@ namespace Tgstation.Server.Client.Components
/// Get the instance permission sets associated with the logged on user.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="InstancePermissionSetResponse"/> associated with the logged on user.</returns>
Task<InstancePermissionSetResponse> Read(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="InstancePermissionSetResponse"/> associated with the logged on user.</returns>
ValueTask<InstancePermissionSetResponse> Read(CancellationToken cancellationToken);
/// <summary>
/// Get a specific <paramref name="instancePermissionSet"/>.
/// </summary>
/// <param name="instancePermissionSet">The <see cref="InstancePermissionSetRequest"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the requested <paramref name="instancePermissionSet"/>.</returns>
Task<InstancePermissionSetResponse> GetId(InstancePermissionSet instancePermissionSet, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the requested <paramref name="instancePermissionSet"/>.</returns>
ValueTask<InstancePermissionSetResponse> GetId(InstancePermissionSet instancePermissionSet, CancellationToken cancellationToken);
/// <summary>
/// Get the instance permission sets in the instance.
/// </summary>
/// <param name="paginationSettings">The optional <see cref="PaginationSettings"/> for the operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="IReadOnlyList{T}"/> of <see cref="InstancePermissionSetResponse"/>s in the instance.</returns>
Task<IReadOnlyList<InstancePermissionSetResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="List{T}"/> of <see cref="InstancePermissionSetResponse"/>s in the instance.</returns>
ValueTask<List<InstancePermissionSetResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <summary>
/// Update a <paramref name="instancePermissionSet"/>.
/// </summary>
/// <param name="instancePermissionSet">The <see cref="InstancePermissionSetRequest"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task<InstancePermissionSetResponse> Update(InstancePermissionSetRequest instancePermissionSet, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask<InstancePermissionSetResponse> Update(InstancePermissionSetRequest instancePermissionSet, CancellationToken cancellationToken);
/// <summary>
/// Create a <paramref name="instancePermissionSet"/>.
/// </summary>
/// <param name="instancePermissionSet">The <see cref="InstancePermissionSetRequest"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> reulting in the new <see cref="InstancePermissionSetResponse"/>.</returns>
Task<InstancePermissionSetResponse> Create(InstancePermissionSetRequest instancePermissionSet, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> reulting in the new <see cref="InstancePermissionSetResponse"/>.</returns>
ValueTask<InstancePermissionSetResponse> Create(InstancePermissionSetRequest instancePermissionSet, CancellationToken cancellationToken);
/// <summary>
/// Delete a <paramref name="instancePermissionSet"/>.
/// </summary>
/// <param name="instancePermissionSet">The <see cref="InstancePermissionSetRequest"/> to delete.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task Delete(InstancePermissionSet instancePermissionSet, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask Delete(InstancePermissionSet instancePermissionSet, CancellationToken cancellationToken);
}
}
@@ -17,31 +17,31 @@ namespace Tgstation.Server.Client.Components
/// </summary>
/// <param name="paginationSettings">The optional <see cref="PaginationSettings"/> for the operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="IReadOnlyList{T}"/> of the <see cref="JobResponse"/> <see cref="EntityId"/>s in the <see cref="Instance"/>.</returns>
Task<IReadOnlyList<JobResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="List{T}"/> of the <see cref="JobResponse"/> <see cref="EntityId"/>s in the <see cref="Instance"/>.</returns>
ValueTask<List<JobResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <summary>
/// List the active <see cref="JobResponse"/>s in the <see cref="Instance"/>.
/// </summary>
/// <param name="paginationSettings">The optional <see cref="PaginationSettings"/> for the operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="IReadOnlyList{T}"/> of the active <see cref="JobResponse"/>s in the <see cref="Instance"/>.</returns>
Task<IReadOnlyList<JobResponse>> ListActive(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="List{T}"/> of the active <see cref="JobResponse"/>s in the <see cref="Instance"/>.</returns>
ValueTask<List<JobResponse>> ListActive(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <summary>
/// Get a <paramref name="job"/>.
/// </summary>
/// <param name="job">The <see cref="JobResponse"/>'s <see cref="EntityId"/> to get.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="JobResponse"/>.</returns>
Task<JobResponse> GetId(EntityId job, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="JobResponse"/>.</returns>
ValueTask<JobResponse> GetId(EntityId job, CancellationToken cancellationToken);
/// <summary>
/// Cancels a <paramref name="job"/>.
/// </summary>
/// <param name="job">The <see cref="JobResponse"/> to cancel.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task Cancel(JobResponse job, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask Cancel(JobResponse job, CancellationToken cancellationToken);
}
}
@@ -15,30 +15,30 @@ namespace Tgstation.Server.Client.Components
/// Get the repository's current status.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="RepositoryResponse"/>.</returns>
Task<RepositoryResponse> Read(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="RepositoryResponse"/>.</returns>
ValueTask<RepositoryResponse> Read(CancellationToken cancellationToken);
/// <summary>
/// Update the repository.
/// </summary>
/// <param name="repository">The <see cref="RepositoryUpdateRequest"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="RepositoryResponse"/>.</returns>
Task<RepositoryResponse> Update(RepositoryUpdateRequest repository, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="RepositoryResponse"/>.</returns>
ValueTask<RepositoryResponse> Update(RepositoryUpdateRequest repository, CancellationToken cancellationToken);
/// <summary>
/// Clones a <paramref name="repository"/>.
/// </summary>
/// <param name="repository">The <see cref="RepositoryCreateRequest"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="RepositoryResponse"/>/.</returns>
Task<RepositoryResponse> Clone(RepositoryCreateRequest repository, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="RepositoryResponse"/>/.</returns>
ValueTask<RepositoryResponse> Clone(RepositoryCreateRequest repository, CancellationToken cancellationToken);
/// <summary>
/// Deletes the repository.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="RepositoryResponse"/>.</returns>
Task<RepositoryResponse> Delete(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="RepositoryResponse"/>.</returns>
ValueTask<RepositoryResponse> Delete(CancellationToken cancellationToken);
}
}
@@ -31,10 +31,10 @@ namespace Tgstation.Server.Client.Components
}
/// <inheritdoc />
public Task<InstancePermissionSetResponse> Create(InstancePermissionSetRequest instancePermissionSet, CancellationToken cancellationToken) => ApiClient.Create<InstancePermissionSetRequest, InstancePermissionSetResponse>(Routes.InstancePermissionSet, instancePermissionSet ?? throw new ArgumentNullException(nameof(instancePermissionSet)), instance.Id!.Value, cancellationToken);
public ValueTask<InstancePermissionSetResponse> Create(InstancePermissionSetRequest instancePermissionSet, CancellationToken cancellationToken) => ApiClient.Create<InstancePermissionSetRequest, InstancePermissionSetResponse>(Routes.InstancePermissionSet, instancePermissionSet ?? throw new ArgumentNullException(nameof(instancePermissionSet)), instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task Delete(InstancePermissionSet instancePermissionSet, CancellationToken cancellationToken) => ApiClient.Delete(
public ValueTask Delete(InstancePermissionSet instancePermissionSet, CancellationToken cancellationToken) => ApiClient.Delete(
Routes.SetID(
Routes.InstancePermissionSet,
instancePermissionSet.PermissionSetId),
@@ -42,13 +42,13 @@ namespace Tgstation.Server.Client.Components
cancellationToken);
/// <inheritdoc />
public Task<InstancePermissionSetResponse> Read(CancellationToken cancellationToken) => ApiClient.Read<InstancePermissionSetResponse>(Routes.InstancePermissionSet, instance.Id!.Value, cancellationToken);
public ValueTask<InstancePermissionSetResponse> Read(CancellationToken cancellationToken) => ApiClient.Read<InstancePermissionSetResponse>(Routes.InstancePermissionSet, instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<InstancePermissionSetResponse> Update(InstancePermissionSetRequest instancePermissionSet, CancellationToken cancellationToken) => ApiClient.Update<InstancePermissionSetRequest, InstancePermissionSetResponse>(Routes.InstancePermissionSet, instancePermissionSet ?? throw new ArgumentNullException(nameof(instancePermissionSet)), instance.Id!.Value, cancellationToken);
public ValueTask<InstancePermissionSetResponse> Update(InstancePermissionSetRequest instancePermissionSet, CancellationToken cancellationToken) => ApiClient.Update<InstancePermissionSetRequest, InstancePermissionSetResponse>(Routes.InstancePermissionSet, instancePermissionSet ?? throw new ArgumentNullException(nameof(instancePermissionSet)), instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<IReadOnlyList<InstancePermissionSetResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
public ValueTask<List<InstancePermissionSetResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
=> ReadPaged<InstancePermissionSetResponse>(
paginationSettings,
Routes.ListRoute(Routes.InstancePermissionSet),
@@ -56,6 +56,6 @@ namespace Tgstation.Server.Client.Components
cancellationToken);
/// <inheritdoc />
public Task<InstancePermissionSetResponse> GetId(InstancePermissionSet instancePermissionSet, CancellationToken cancellationToken) => ApiClient.Read<InstancePermissionSetResponse>(Routes.SetID(Routes.InstancePermissionSet, instancePermissionSet?.PermissionSetId ?? throw new ArgumentNullException(nameof(instancePermissionSet))), instance.Id!.Value, cancellationToken);
public ValueTask<InstancePermissionSetResponse> GetId(InstancePermissionSet instancePermissionSet, CancellationToken cancellationToken) => ApiClient.Read<InstancePermissionSetResponse>(Routes.SetID(Routes.InstancePermissionSet, instancePermissionSet?.PermissionSetId ?? throw new ArgumentNullException(nameof(instancePermissionSet))), instance.Id!.Value, cancellationToken);
}
}
@@ -29,17 +29,17 @@ namespace Tgstation.Server.Client.Components
}
/// <inheritdoc />
public Task Cancel(JobResponse job, CancellationToken cancellationToken) => ApiClient.Delete(Routes.SetID(Routes.Jobs, job?.Id ?? throw new ArgumentNullException(nameof(job))), instance.Id!.Value, cancellationToken);
public ValueTask Cancel(JobResponse job, CancellationToken cancellationToken) => ApiClient.Delete(Routes.SetID(Routes.Jobs, job?.Id ?? throw new ArgumentNullException(nameof(job))), instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<IReadOnlyList<JobResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
public ValueTask<List<JobResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
=> ReadPaged<JobResponse>(paginationSettings, Routes.ListRoute(Routes.Jobs), instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<IReadOnlyList<JobResponse>> ListActive(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
public ValueTask<List<JobResponse>> ListActive(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
=> ReadPaged<JobResponse>(paginationSettings, Routes.Jobs, instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<JobResponse> GetId(EntityId job, CancellationToken cancellationToken) => ApiClient.Read<JobResponse>(Routes.SetID(Routes.Jobs, job?.Id ?? throw new ArgumentNullException(nameof(job))), instance.Id!.Value, cancellationToken);
public ValueTask<JobResponse> GetId(EntityId job, CancellationToken cancellationToken) => ApiClient.Read<JobResponse>(Routes.SetID(Routes.Jobs, job?.Id ?? throw new ArgumentNullException(nameof(job))), instance.Id!.Value, cancellationToken);
}
}
@@ -34,15 +34,15 @@ namespace Tgstation.Server.Client.Components
}
/// <inheritdoc />
public Task<RepositoryResponse> Clone(RepositoryCreateRequest repository, CancellationToken cancellationToken) => apiClient.Create<RepositoryCreateRequest, RepositoryResponse>(Routes.Repository, repository, instance.Id!.Value, cancellationToken);
public ValueTask<RepositoryResponse> Clone(RepositoryCreateRequest repository, CancellationToken cancellationToken) => apiClient.Create<RepositoryCreateRequest, RepositoryResponse>(Routes.Repository, repository, instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<RepositoryResponse> Delete(CancellationToken cancellationToken) => apiClient.Delete<RepositoryResponse>(Routes.Repository, instance.Id!.Value, cancellationToken);
public ValueTask<RepositoryResponse> Delete(CancellationToken cancellationToken) => apiClient.Delete<RepositoryResponse>(Routes.Repository, instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<RepositoryResponse> Read(CancellationToken cancellationToken) => apiClient.Read<RepositoryResponse>(Routes.Repository, instance.Id!.Value, cancellationToken);
public ValueTask<RepositoryResponse> Read(CancellationToken cancellationToken) => apiClient.Read<RepositoryResponse>(Routes.Repository, instance.Id!.Value, cancellationToken);
/// <inheritdoc />
public Task<RepositoryResponse> Update(RepositoryUpdateRequest repository, CancellationToken cancellationToken) => apiClient.Update<RepositoryUpdateRequest, RepositoryResponse>(Routes.Repository, repository ?? throw new ArgumentNullException(nameof(repository)), instance.Id!.Value, cancellationToken);
public ValueTask<RepositoryResponse> Update(RepositoryUpdateRequest repository, CancellationToken cancellationToken) => apiClient.Update<RepositoryUpdateRequest, RepositoryResponse>(Routes.Repository, repository ?? throw new ArgumentNullException(nameof(repository)), instance.Id!.Value, cancellationToken);
}
}
@@ -18,8 +18,8 @@ namespace Tgstation.Server.Client
/// Get the <see cref="AdministrationResponse"/> represented by the <see cref="IAdministrationClient"/>.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="AdministrationResponse"/> represented by the <see cref="IAdministrationClient"/>.</returns>
Task<AdministrationResponse> Read(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="AdministrationResponse"/> represented by the <see cref="IAdministrationClient"/>.</returns>
ValueTask<AdministrationResponse> Read(CancellationToken cancellationToken);
/// <summary>
/// Updates the <see cref="AdministrationResponse"/> setttings.
@@ -27,30 +27,30 @@ namespace Tgstation.Server.Client
/// <param name="updateRequest">The <see cref="ServerUpdateRequest"/>.</param>
/// <param name="zipFileStream">The <see cref="Stream"/> for the .zip file if <see cref="ServerUpdateRequest.UploadZip"/> is <see langword="true"/>. Will be ignored if it is <see langword="false"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the echoed <see cref="ServerUpdateResponse"/>.</returns>
Task<ServerUpdateResponse> Update(ServerUpdateRequest updateRequest, Stream? zipFileStream, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the echoed <see cref="ServerUpdateResponse"/>.</returns>
ValueTask<ServerUpdateResponse> Update(ServerUpdateRequest updateRequest, Stream? zipFileStream, CancellationToken cancellationToken);
/// <summary>
/// Restarts the TGS server.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task Restart(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask Restart(CancellationToken cancellationToken);
/// <summary>
/// Lists the log files available for download.
/// </summary>
/// <param name="paginationSettings">The optional <see cref="PaginationSettings"/> for the operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in an <see cref="IReadOnlyList{T}"/> of <see cref="LogFileResponse"/> metadata.</returns>
Task<IReadOnlyList<LogFileResponse>> ListLogs(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in an <see cref="List{T}"/> of <see cref="LogFileResponse"/> metadata.</returns>
ValueTask<List<LogFileResponse>> ListLogs(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <summary>
/// Download a given <paramref name="logFile"/>.
/// </summary>
/// <param name="logFile">The <see cref="LogFileResponse"/> to download.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting a <see cref="Tuple{T1, T2}"/> containing the downloaded <see cref="LogFileResponse"/> and associated <see cref="Stream"/>.</returns>
Task<Tuple<LogFileResponse, Stream>> GetLog(LogFileResponse logFile, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting a <see cref="Tuple{T1, T2}"/> containing the downloaded <see cref="LogFileResponse"/> and associated <see cref="Stream"/>.</returns>
ValueTask<Tuple<LogFileResponse, Stream>> GetLog(LogFileResponse logFile, CancellationToken cancellationToken);
}
}
+38 -38
View File
@@ -43,8 +43,8 @@ namespace Tgstation.Server.Client
/// <param name="route">The server route to make the request to.</param>
/// <param name="body">The request body.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
Task<TResult> Create<TBody, TResult>(string route, TBody body, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
ValueTask<TResult> Create<TBody, TResult>(string route, TBody body, CancellationToken cancellationToken)
where TBody : class;
/// <summary>
@@ -53,8 +53,8 @@ namespace Tgstation.Server.Client
/// <typeparam name="TResult">The type of the response body.</typeparam>
/// <param name="route">The server route to make the request to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
Task<TResult> Create<TResult>(string route, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
ValueTask<TResult> Create<TResult>(string route, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP GET request.
@@ -62,8 +62,8 @@ namespace Tgstation.Server.Client
/// <typeparam name="TResult">The type of the response body.</typeparam>
/// <param name="route">The server route to make the request to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
Task<TResult> Read<TResult>(string route, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
ValueTask<TResult> Read<TResult>(string route, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP POST request.
@@ -73,8 +73,8 @@ namespace Tgstation.Server.Client
/// <param name="route">The server route to make the request to.</param>
/// <param name="body">The request body.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
Task<TResult> Update<TBody, TResult>(string route, TBody body, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
ValueTask<TResult> Update<TBody, TResult>(string route, TBody body, CancellationToken cancellationToken)
where TBody : class;
/// <summary>
@@ -83,8 +83,8 @@ namespace Tgstation.Server.Client
/// <typeparam name="TResult">The type of the response body.</typeparam>
/// <param name="route">The server route to make the request to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
Task<TResult> Update<TResult>(string route, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
ValueTask<TResult> Update<TResult>(string route, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP POST request.
@@ -93,8 +93,8 @@ namespace Tgstation.Server.Client
/// <param name="route">The server route to make the request to.</param>
/// <param name="body">The request body.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task Update<TBody>(string route, TBody body, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask Update<TBody>(string route, TBody body, CancellationToken cancellationToken)
where TBody : class;
/// <summary>
@@ -102,16 +102,16 @@ namespace Tgstation.Server.Client
/// </summary>
/// <param name="route">The server route to make the request to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task Patch(string route, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask Patch(string route, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP DELETE request.
/// </summary>
/// <param name="route">The server route to make the request to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task Delete(string route, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask Delete(string route, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP PUT request.
@@ -122,8 +122,8 @@ namespace Tgstation.Server.Client
/// <param name="body">The request body.</param>
/// <param name="instanceId">The instance <see cref="EntityId.Id"/> to make the request to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
Task<TResult> Create<TBody, TResult>(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
ValueTask<TResult> Create<TBody, TResult>(
string route,
TBody body,
long instanceId,
@@ -137,8 +137,8 @@ namespace Tgstation.Server.Client
/// <param name="route">The server route to make the request to.</param>
/// <param name="instanceId">The instance <see cref="EntityId.Id"/> to make the request to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
Task<TResult> Create<TResult>(string route, long instanceId, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
ValueTask<TResult> Create<TResult>(string route, long instanceId, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP PATCH request.
@@ -147,8 +147,8 @@ namespace Tgstation.Server.Client
/// <param name="route">The server route to make the request to.</param>
/// <param name="instanceId">The instance <see cref="EntityId.Id"/> to make the request to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
Task<TResult> Patch<TResult>(string route, long instanceId, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
ValueTask<TResult> Patch<TResult>(string route, long instanceId, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP GET request.
@@ -157,8 +157,8 @@ namespace Tgstation.Server.Client
/// <param name="route">The server route to make the request to.</param>
/// <param name="instanceId">The instance <see cref="EntityId.Id"/> to make the request to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
Task<TResult> Read<TResult>(string route, long instanceId, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
ValueTask<TResult> Read<TResult>(string route, long instanceId, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP POST request.
@@ -169,8 +169,8 @@ namespace Tgstation.Server.Client
/// <param name="body">The request body.</param>
/// <param name="instanceId">The instance <see cref="EntityId.Id"/> to make the request to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
Task<TResult> Update<TBody, TResult>(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
ValueTask<TResult> Update<TBody, TResult>(
string route,
TBody body,
long instanceId,
@@ -183,8 +183,8 @@ namespace Tgstation.Server.Client
/// <param name="route">The server route to make the request to.</param>
/// <param name="instanceId">The instance <see cref="EntityId.Id"/> to make the request to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task Delete(string route, long instanceId, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask Delete(string route, long instanceId, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP DELETE request.
@@ -194,8 +194,8 @@ namespace Tgstation.Server.Client
/// <param name="body">The request body.</param>
/// <param name="instanceId">The instance <see cref="EntityId.Id"/> to make the request to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task Delete<TBody>(string route, TBody body, long instanceId, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask Delete<TBody>(string route, TBody body, long instanceId, CancellationToken cancellationToken)
where TBody : class;
/// <summary>
@@ -205,8 +205,8 @@ namespace Tgstation.Server.Client
/// <param name="route">The server route to make the request to.</param>
/// <param name="instanceId">The instance <see cref="EntityId.Id"/> to make the request to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
Task<TResult> Delete<TResult>(string route, long instanceId, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/>.</returns>
ValueTask<TResult> Delete<TResult>(string route, long instanceId, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP DELETE request.
@@ -217,8 +217,8 @@ namespace Tgstation.Server.Client
/// <param name="body">The request body.</param>
/// <param name="instanceId">The instance <see cref="EntityId.Id"/> to make the request to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task<TResult> Delete<TBody, TResult>(string route, TBody body, long instanceId, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask<TResult> Delete<TBody, TResult>(string route, TBody body, long instanceId, CancellationToken cancellationToken)
where TBody : class;
/// <summary>
@@ -226,8 +226,8 @@ namespace Tgstation.Server.Client
/// </summary>
/// <param name="ticket">The <see cref="FileTicketResponse"/> to download.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the downloaded <see cref="Stream"/>.</returns>
Task<Stream> Download(FileTicketResponse ticket, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the downloaded <see cref="Stream"/>.</returns>
ValueTask<Stream> Download(FileTicketResponse ticket, CancellationToken cancellationToken);
/// <summary>
/// Uploads a given <paramref name="uploadStream"/> for a given <paramref name="ticket"/>.
@@ -235,7 +235,7 @@ namespace Tgstation.Server.Client
/// <param name="ticket">The <see cref="FileTicketResponse"/> to download.</param>
/// <param name="uploadStream">The <see cref="Stream"/> to upload. <see langword="null"/> represents an empty file.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task Upload(FileTicketResponse ticket, Stream? uploadStream, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask Upload(FileTicketResponse ticket, Stream? uploadStream, CancellationToken cancellationToken);
}
}
@@ -19,48 +19,48 @@ namespace Tgstation.Server.Client
/// </summary>
/// <param name="paginationSettings">The optional <see cref="PaginationSettings"/> for the operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="IReadOnlyList{T}"/> of all <see cref="Instance"/>s the user can view.</returns>
Task<IReadOnlyList<InstanceResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="List{T}"/> of all <see cref="Instance"/>s the user can view.</returns>
ValueTask<List<InstanceResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <summary>
/// Create or attach an <paramref name="instance"/>.
/// </summary>
/// <param name="instance">The <see cref="InstanceCreateRequest"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the created or attached <see cref="Instance"/>.</returns>
Task<InstanceResponse> CreateOrAttach(InstanceCreateRequest instance, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the created or attached <see cref="Instance"/>.</returns>
ValueTask<InstanceResponse> CreateOrAttach(InstanceCreateRequest instance, CancellationToken cancellationToken);
/// <summary>
/// Relocates, renamed, and/or on/offlines an <paramref name="instance"/>.
/// </summary>
/// <param name="instance">The <see cref="InstanceUpdateRequest"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the updated <see cref="Instance"/>.</returns>
Task<InstanceResponse> Update(InstanceUpdateRequest instance, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the updated <see cref="Instance"/>.</returns>
ValueTask<InstanceResponse> Update(InstanceUpdateRequest instance, CancellationToken cancellationToken);
/// <summary>
/// Get a specific <paramref name="instance"/>.
/// </summary>
/// <param name="instance">The <see cref="Instance"/> to get.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="Instance"/>.</returns>
Task<InstanceResponse> GetId(EntityId instance, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="Instance"/>.</returns>
ValueTask<InstanceResponse> GetId(EntityId instance, CancellationToken cancellationToken);
/// <summary>
/// Deletes an <paramref name="instance"/>.
/// </summary>
/// <param name="instance">The <see cref="EntityId"/> of the <see cref="Instance"/> to delete.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task Detach(EntityId instance, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask Detach(EntityId instance, CancellationToken cancellationToken);
/// <summary>
/// Gives the user full permissions on an <paramref name="instance"/>.
/// </summary>
/// <param name="instance">The <see cref="EntityId"/> of the <see cref="Instance"/> to grant permissions on.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task GrantPermissions(EntityId instance, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask GrantPermissions(EntityId instance, CancellationToken cancellationToken);
/// <summary>
/// Create an <see cref="IInstanceClient"/> for a given <see cref="Instance"/>.
@@ -14,15 +14,15 @@ namespace Tgstation.Server.Client
/// </summary>
/// <param name="requestMessage">The <see cref="HttpRequestMessage"/> representing the request.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task LogRequest(HttpRequestMessage requestMessage, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask LogRequest(HttpRequestMessage requestMessage, CancellationToken cancellationToken);
/// <summary>
/// Log a response.
/// </summary>
/// <param name="responseMessage">The <see cref="HttpResponseMessage"/> representing the request.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task LogResponse(HttpResponseMessage responseMessage, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask LogResponse(HttpResponseMessage responseMessage, CancellationToken cancellationToken);
}
}
+1 -1
View File
@@ -51,7 +51,7 @@ namespace Tgstation.Server.Client
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="ServerInformationResponse"/> of the target server.</returns>
Task<ServerInformationResponse> ServerInformation(CancellationToken cancellationToken);
ValueTask<ServerInformationResponse> ServerInformation(CancellationToken cancellationToken);
/// <summary>
/// Adds a <paramref name="requestLogger"/> to the request pipeline.
@@ -20,8 +20,8 @@ namespace Tgstation.Server.Client
/// <param name="requestLoggers">Optional <see cref="IRequestLogger"/>s.</param>
/// <param name="timeout">Optional <see cref="TimeSpan"/> representing timeout for the HTTP request.</param>
/// <param name="cancellationToken">Optional <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="ServerInformationResponse"/>.</returns>
Task<ServerInformationResponse> GetServerInformation(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="ServerInformationResponse"/>.</returns>
ValueTask<ServerInformationResponse> GetServerInformation(
Uri host,
IEnumerable<IRequestLogger>? requestLoggers = null,
TimeSpan? timeout = null,
@@ -37,8 +37,8 @@ namespace Tgstation.Server.Client
/// <param name="timeout">Optional <see cref="TimeSpan"/> representing timeout for the connection.</param>
/// <param name="attemptLoginRefresh">Attempt to refresh the received <see cref="TokenResponse"/> when it expires or becomes invalid. <paramref name="username"/> and <paramref name="password"/> will be stored in memory if this is <see langword="true"/>.</param>
/// <param name="cancellationToken">Optional <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a new <see cref="IServerClient"/>.</returns>
Task<IServerClient> CreateFromLogin(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a new <see cref="IServerClient"/>.</returns>
ValueTask<IServerClient> CreateFromLogin(
Uri host,
string username,
string password,
@@ -56,8 +56,8 @@ namespace Tgstation.Server.Client
/// <param name="requestLoggers">Optional initial <see cref="IRequestLogger"/>s to add to the <see cref="IServerClient"/>.</param>
/// <param name="timeout">Optional <see cref="TimeSpan"/> representing timeout for the connection.</param>
/// <param name="cancellationToken">Optional <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a new <see cref="IServerClient"/>.</returns>
Task<IServerClient> CreateFromOAuth(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a new <see cref="IServerClient"/>.</returns>
ValueTask<IServerClient> CreateFromOAuth(
Uri host,
string oAuthCode,
OAuthProvider oAuthProvider,
@@ -18,39 +18,39 @@ namespace Tgstation.Server.Client
/// </summary>
/// <param name="group">The <see cref="EntityId"/> of the user group to get.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the requested <paramref name="group"/>.</returns>
Task<UserGroupResponse> GetId(EntityId group, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the requested <paramref name="group"/>.</returns>
ValueTask<UserGroupResponse> GetId(EntityId group, CancellationToken cancellationToken);
/// <summary>
/// List all <see cref="UserGroupResponse"/>s.
/// </summary>
/// <param name="paginationSettings">The optional <see cref="PaginationSettings"/> for the operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="IReadOnlyList{T}"/> of all <see cref="UserGroupResponse"/>s.</returns>
Task<IReadOnlyList<UserGroupResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="List{T}"/> of all <see cref="UserGroupResponse"/>s.</returns>
ValueTask<List<UserGroupResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <summary>
/// Create a new <paramref name="group"/>.
/// </summary>
/// <param name="group">The <see cref="UserGroupCreateRequest"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>The new <see cref="UserResponse"/>.</returns>
Task<UserGroupResponse> Create(UserGroupCreateRequest group, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the new <see cref="UserGroupResponse"/>.</returns>
ValueTask<UserGroupResponse> Create(UserGroupCreateRequest group, CancellationToken cancellationToken);
/// <summary>
/// Update a <paramref name="group"/>.
/// </summary>
/// <param name="group">The <see cref="UserGroupUpdateRequest"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>The updated <see cref="UserResponse"/>.</returns>
Task<UserGroupResponse> Update(UserGroupUpdateRequest group, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the updated <see cref="UserGroupResponse"/>.</returns>
ValueTask<UserGroupResponse> Update(UserGroupUpdateRequest group, CancellationToken cancellationToken);
/// <summary>
/// Deletes a <paramref name="group"/>.
/// </summary>
/// <param name="group">The <see cref="EntityId"/> of the user group to delete.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task Delete(EntityId group, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask Delete(EntityId group, CancellationToken cancellationToken);
}
}
+10 -10
View File
@@ -17,39 +17,39 @@ namespace Tgstation.Server.Client
/// Read the current user's information and general rights.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the current <see cref="UserResponse"/>.</returns>
Task<UserResponse> Read(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the current <see cref="UserResponse"/>.</returns>
ValueTask<UserResponse> Read(CancellationToken cancellationToken);
/// <summary>
/// Get a specific <paramref name="user"/>.
/// </summary>
/// <param name="user">The <see cref="EntityId"/> of the <see cref="UserResponse"/> to get.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the requested <paramref name="user"/>.</returns>
Task<UserResponse> GetId(EntityId user, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the requested <paramref name="user"/>.</returns>
ValueTask<UserResponse> GetId(EntityId user, CancellationToken cancellationToken);
/// <summary>
/// List all <see cref="UserResponse"/>s.
/// </summary>
/// <param name="paginationSettings">The optional <see cref="PaginationSettings"/> for the operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="IReadOnlyList{T}"/> of all <see cref="UserResponse"/>s.</returns>
Task<IReadOnlyList<UserResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="List{T}"/> of all <see cref="UserResponse"/>s.</returns>
ValueTask<List<UserResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken);
/// <summary>
/// Create a new <paramref name="user"/>.
/// </summary>
/// <param name="user">The <see cref="UserCreateRequest"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>The new <see cref="UserResponse"/>.</returns>
Task<UserResponse> Create(UserCreateRequest user, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the new <see cref="UserResponse"/>.</returns>
ValueTask<UserResponse> Create(UserCreateRequest user, CancellationToken cancellationToken);
/// <summary>
/// Update a <paramref name="user"/>.
/// </summary>
/// <param name="user">The <see cref="UserUpdateRequest"/> used to update the <see cref="UserResponse"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>The updated <see cref="UserResponse"/>.</returns>
Task<UserResponse> Update(UserUpdateRequest user, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the updated <see cref="UserResponse"/>.</returns>
ValueTask<UserResponse> Update(UserUpdateRequest user, CancellationToken cancellationToken);
}
}
@@ -24,23 +24,23 @@ namespace Tgstation.Server.Client
}
/// <inheritdoc />
public Task<InstanceResponse> CreateOrAttach(InstanceCreateRequest instance, CancellationToken cancellationToken) => ApiClient.Create<InstanceCreateRequest, InstanceResponse>(Routes.InstanceManager, instance ?? throw new ArgumentNullException(nameof(instance)), cancellationToken);
public ValueTask<InstanceResponse> CreateOrAttach(InstanceCreateRequest instance, CancellationToken cancellationToken) => ApiClient.Create<InstanceCreateRequest, InstanceResponse>(Routes.InstanceManager, instance ?? throw new ArgumentNullException(nameof(instance)), cancellationToken);
/// <inheritdoc />
public Task Detach(EntityId instance, CancellationToken cancellationToken) => ApiClient.Delete(Routes.SetID(Routes.InstanceManager, instance?.Id ?? throw new ArgumentNullException(nameof(instance))), cancellationToken);
public ValueTask Detach(EntityId instance, CancellationToken cancellationToken) => ApiClient.Delete(Routes.SetID(Routes.InstanceManager, instance?.Id ?? throw new ArgumentNullException(nameof(instance))), cancellationToken);
/// <inheritdoc />
public Task<IReadOnlyList<InstanceResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
public ValueTask<List<InstanceResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
=> ReadPaged<InstanceResponse>(paginationSettings, Routes.ListRoute(Routes.InstanceManager), null, cancellationToken);
/// <inheritdoc />
public Task<InstanceResponse> Update(InstanceUpdateRequest instance, CancellationToken cancellationToken) => ApiClient.Update<InstanceUpdateRequest, InstanceResponse>(Routes.InstanceManager, instance ?? throw new ArgumentNullException(nameof(instance)), cancellationToken);
public ValueTask<InstanceResponse> Update(InstanceUpdateRequest instance, CancellationToken cancellationToken) => ApiClient.Update<InstanceUpdateRequest, InstanceResponse>(Routes.InstanceManager, instance ?? throw new ArgumentNullException(nameof(instance)), cancellationToken);
/// <inheritdoc />
public Task<InstanceResponse> GetId(EntityId instance, CancellationToken cancellationToken) => ApiClient.Read<InstanceResponse>(Routes.SetID(Routes.InstanceManager, instance?.Id ?? throw new ArgumentNullException(nameof(instance))), cancellationToken);
public ValueTask<InstanceResponse> GetId(EntityId instance, CancellationToken cancellationToken) => ApiClient.Read<InstanceResponse>(Routes.SetID(Routes.InstanceManager, instance?.Id ?? throw new ArgumentNullException(nameof(instance))), cancellationToken);
/// <inheritdoc />
public Task GrantPermissions(EntityId instance, CancellationToken cancellationToken) => ApiClient.Patch(Routes.SetID(Routes.InstanceManager, instance?.Id ?? throw new ArgumentNullException(nameof(instance))), cancellationToken);
public ValueTask GrantPermissions(EntityId instance, CancellationToken cancellationToken) => ApiClient.Patch(Routes.SetID(Routes.InstanceManager, instance?.Id ?? throw new ArgumentNullException(nameof(instance))), cancellationToken);
/// <inheritdoc />
public IInstanceClient CreateClient(Instance instance)
@@ -37,8 +37,8 @@ namespace Tgstation.Server.Client
/// <param name="route">The route.</param>
/// <param name="instanceId">The optional <see cref="Instance"/> <see cref="EntityId.Id"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in an <see cref="IReadOnlyList{T}"/> of the paginated <typeparamref name="TModel"/>s.</returns>
protected async Task<IReadOnlyList<TModel>> ReadPaged<TModel>(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in an <see cref="List{T}"/> of the paginated <typeparamref name="TModel"/>s.</returns>
protected async ValueTask<List<TModel>> ReadPaged<TModel>(
PaginationSettings? paginationSettings,
string route,
long? instanceId,
@@ -74,7 +74,7 @@ namespace Tgstation.Server.Client
}
}
Task<PaginatedResponse<TModel>> GetPage() => instanceId.HasValue
ValueTask<PaginatedResponse<TModel>> GetPage() => instanceId.HasValue
? ApiClient.Read<PaginatedResponse<TModel>>(
String.Format(CultureInfo.InvariantCulture, routeFormatter, currentPage),
instanceId.Value,
+1 -1
View File
@@ -76,7 +76,7 @@ namespace Tgstation.Server.Client
public void Dispose() => apiClient.Dispose();
/// <inheritdoc />
public Task<ServerInformationResponse> ServerInformation(CancellationToken cancellationToken) => apiClient.Read<ServerInformationResponse>(Routes.Root, cancellationToken);
public ValueTask<ServerInformationResponse> ServerInformation(CancellationToken cancellationToken) => apiClient.Read<ServerInformationResponse>(Routes.Root, cancellationToken);
/// <inheritdoc />
public void AddRequestLogger(IRequestLogger requestLogger) => apiClient.AddRequestLogger(requestLogger);
@@ -42,7 +42,7 @@ namespace Tgstation.Server.Client
}
/// <inheritdoc />
public Task<IServerClient> CreateFromLogin(
public ValueTask<IServerClient> CreateFromLogin(
Uri host,
string username,
string password,
@@ -69,7 +69,7 @@ namespace Tgstation.Server.Client
}
/// <inheritdoc />
public Task<IServerClient> CreateFromOAuth(
public ValueTask<IServerClient> CreateFromOAuth(
Uri host,
string oAuthCode,
OAuthProvider oAuthProvider,
@@ -106,7 +106,7 @@ namespace Tgstation.Server.Client
}
/// <inheritdoc />
public async Task<ServerInformationResponse> GetServerInformation(
public async ValueTask<ServerInformationResponse> GetServerInformation(
Uri host,
IEnumerable<IRequestLogger>? requestLoggers = null,
TimeSpan? timeout = null,
@@ -133,8 +133,8 @@ namespace Tgstation.Server.Client
/// <param name="timeout">Optional <see cref="TimeSpan"/> representing timeout for the connection.</param>
/// <param name="attemptLoginRefresh">If <paramref name="loginHeaders"/> may be used to re-login in the future.</param>
/// <param name="cancellationToken">Optional <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a new <see cref="IServerClient"/>.</returns>
async Task<IServerClient> CreateWithNewToken(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a new <see cref="IServerClient"/>.</returns>
async ValueTask<IServerClient> CreateWithNewToken(
Uri host,
ApiHeaders loginHeaders,
IEnumerable<IRequestLogger>? requestLoggers,
@@ -23,19 +23,19 @@ namespace Tgstation.Server.Client
}
/// <inheritdoc />
public Task<UserGroupResponse> Create(UserGroupCreateRequest group, CancellationToken cancellationToken) => ApiClient.Create<UserGroupCreateRequest, UserGroupResponse>(Routes.UserGroup, group ?? throw new ArgumentNullException(nameof(group)), cancellationToken);
public ValueTask<UserGroupResponse> Create(UserGroupCreateRequest group, CancellationToken cancellationToken) => ApiClient.Create<UserGroupCreateRequest, UserGroupResponse>(Routes.UserGroup, group ?? throw new ArgumentNullException(nameof(group)), cancellationToken);
/// <inheritdoc />
public Task<UserGroupResponse> GetId(EntityId group, CancellationToken cancellationToken) => ApiClient.Read<UserGroupResponse>(Routes.SetID(Routes.UserGroup, group?.Id ?? throw new ArgumentNullException(nameof(group))), cancellationToken);
public ValueTask<UserGroupResponse> GetId(EntityId group, CancellationToken cancellationToken) => ApiClient.Read<UserGroupResponse>(Routes.SetID(Routes.UserGroup, group?.Id ?? throw new ArgumentNullException(nameof(group))), cancellationToken);
/// <inheritdoc />
public Task<IReadOnlyList<UserGroupResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
public ValueTask<List<UserGroupResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
=> ReadPaged<UserGroupResponse>(paginationSettings, Routes.ListRoute(Routes.UserGroup), null, cancellationToken);
/// <inheritdoc />
public Task<UserGroupResponse> Update(UserGroupUpdateRequest group, CancellationToken cancellationToken) => ApiClient.Update<UserGroupUpdateRequest, UserGroupResponse>(Routes.UserGroup, group ?? throw new ArgumentNullException(nameof(group)), cancellationToken);
public ValueTask<UserGroupResponse> Update(UserGroupUpdateRequest group, CancellationToken cancellationToken) => ApiClient.Update<UserGroupUpdateRequest, UserGroupResponse>(Routes.UserGroup, group ?? throw new ArgumentNullException(nameof(group)), cancellationToken);
/// <inheritdoc />
public Task Delete(EntityId group, CancellationToken cancellationToken) => ApiClient.Delete(Routes.SetID(Routes.UserGroup, group?.Id ?? throw new ArgumentNullException(nameof(group))), cancellationToken);
public ValueTask Delete(EntityId group, CancellationToken cancellationToken) => ApiClient.Delete(Routes.SetID(Routes.UserGroup, group?.Id ?? throw new ArgumentNullException(nameof(group))), cancellationToken);
}
}
+5 -5
View File
@@ -23,19 +23,19 @@ namespace Tgstation.Server.Client
}
/// <inheritdoc />
public Task<UserResponse> Create(UserCreateRequest user, CancellationToken cancellationToken) => ApiClient.Create<UserCreateRequest, UserResponse>(Routes.User, user ?? throw new ArgumentNullException(nameof(user)), cancellationToken);
public ValueTask<UserResponse> Create(UserCreateRequest user, CancellationToken cancellationToken) => ApiClient.Create<UserCreateRequest, UserResponse>(Routes.User, user ?? throw new ArgumentNullException(nameof(user)), cancellationToken);
/// <inheritdoc />
public Task<UserResponse> GetId(EntityId user, CancellationToken cancellationToken) => ApiClient.Read<UserResponse>(Routes.SetID(Routes.User, user?.Id ?? throw new ArgumentNullException(nameof(user))), cancellationToken);
public ValueTask<UserResponse> GetId(EntityId user, CancellationToken cancellationToken) => ApiClient.Read<UserResponse>(Routes.SetID(Routes.User, user?.Id ?? throw new ArgumentNullException(nameof(user))), cancellationToken);
/// <inheritdoc />
public Task<IReadOnlyList<UserResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
public ValueTask<List<UserResponse>> List(PaginationSettings? paginationSettings, CancellationToken cancellationToken)
=> ReadPaged<UserResponse>(paginationSettings, Routes.ListRoute(Routes.User), null, cancellationToken);
/// <inheritdoc />
public Task<UserResponse> Read(CancellationToken cancellationToken) => ApiClient.Read<UserResponse>(Routes.User, cancellationToken);
public ValueTask<UserResponse> Read(CancellationToken cancellationToken) => ApiClient.Read<UserResponse>(Routes.User, cancellationToken);
/// <inheritdoc />
public Task<UserResponse> Update(UserUpdateRequest user, CancellationToken cancellationToken) => ApiClient.Update<UserUpdateRequest, UserResponse>(Routes.User, user ?? throw new ArgumentNullException(nameof(user)), cancellationToken);
public ValueTask<UserResponse> Update(UserUpdateRequest user, CancellationToken cancellationToken) => ApiClient.Update<UserUpdateRequest, UserResponse>(Routes.User, user ?? throw new ArgumentNullException(nameof(user)), cancellationToken);
}
}
@@ -0,0 +1,157 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
namespace Tgstation.Server.Common.Extensions
{
/// <summary>
/// Extension methods for the <see cref="ValueTask"/> and <see cref="ValueTask{TResult}"/> <see langword="class"/>es.
/// </summary>
public static class ValueTaskExtensions
{
/// <summary>
/// Fully <see langword="await"/> a given list of <paramref name="tasks"/>.
/// </summary>
/// <typeparam name="T">The <see cref="ValueTask{TResult}.Result"/> type.</typeparam>
/// <param name="tasks">An <see cref="IEnumerable{T}"/> of <see cref="ValueTask{TResult}"/>s.</param>
/// <param name="totalTasks">The number of elements in <paramref name="tasks"/>.</param>
/// <returns>A <see cref="ValueTask"/> representing the combined <see langword="await"/>.</returns>
public static async ValueTask<T[]> WhenAll<T>(IEnumerable<ValueTask<T>> tasks, int totalTasks)
{
if (tasks == null)
throw new ArgumentNullException(nameof(tasks));
// We don't allocate the list if no task throws
Exception? exception = null;
int i = 0;
var results = new T[totalTasks];
foreach (var task in tasks)
{
try
{
results[i] = await task.ConfigureAwait(false);
}
catch (Exception ex)
{
exception ??= ex;
}
++i;
}
Debug.Assert(i == totalTasks, "Incorrect totalTasks specified!");
if (exception != null)
throw exception;
return results;
}
/// <summary>
/// Fully <see langword="await"/> a given list of <paramref name="tasks"/>.
/// </summary>
/// <typeparam name="T">The <see cref="ValueTask{TResult}.Result"/> type.</typeparam>
/// <param name="tasks">An <see cref="IReadOnlyList{T}"/> of <see cref="ValueTask{TResult}"/>s.</param>
/// <returns>A <see cref="ValueTask{TResult}"/> containing the <see cref="Array"/> of results based on <paramref name="tasks"/>.</returns>
/// <exception cref="AggregateException">An <see cref="AggregateException"/> containing any <see cref="Exception"/>s thrown by the <paramref name="tasks"/>.</exception>
public static async ValueTask<T[]> WhenAll<T>(IReadOnlyList<ValueTask<T>> tasks)
{
if (tasks == null)
throw new ArgumentNullException(nameof(tasks));
var totalTasks = tasks.Count;
if (totalTasks == 0)
return Array.Empty<T>();
// We don't allocate the list if no task throws
Exception? exception = null;
var results = new T[totalTasks];
for (var i = 0; i < totalTasks; i++)
try
{
results[i] = await tasks[i].ConfigureAwait(false);
}
catch (Exception ex)
{
exception ??= ex;
}
if (exception != null)
throw exception;
return results;
}
/// <summary>
/// Fully <see langword="await"/> a given list of <paramref name="tasks"/>.
/// </summary>
/// <typeparam name="T">The <see cref="ValueTask{TResult}.Result"/> type.</typeparam>
/// <param name="tasks">An <see cref="Array"/> of <see cref="ValueTask{TResult}"/>s.</param>
/// <returns>A <see cref="ValueTask{TResult}"/> containing the <see cref="Array"/> of results based on <paramref name="tasks"/>.</returns>
public static ValueTask<T[]> WhenAll<T>(params ValueTask<T>[] tasks) => WhenAll((IReadOnlyList<ValueTask<T>>)tasks);
/// <summary>
/// Fully <see langword="await"/> a given list of <paramref name="tasks"/>.
/// </summary>
/// <param name="tasks">An <see cref="IEnumerable{T}"/> of <see cref="ValueTask"/>s.</param>
/// <returns>A <see cref="ValueTask"/> representing the combined <see langword="await"/>.</returns>
public static async ValueTask WhenAll(IEnumerable<ValueTask> tasks)
{
if (tasks == null)
throw new ArgumentNullException(nameof(tasks));
// We don't allocate the list if no task throws
Exception? exception = null;
foreach (var task in tasks)
try
{
await task.ConfigureAwait(false);
}
catch (Exception ex)
{
exception ??= ex;
}
if (exception != null)
throw exception;
}
/// <summary>
/// Fully <see langword="await"/> a given list of <paramref name="tasks"/>.
/// </summary>
/// <param name="tasks">An <see cref="IReadOnlyList{T}"/> of <see cref="ValueTask"/>s.</param>
/// <returns>A <see cref="ValueTask"/> representing the combined <see langword="await"/>.</returns>
/// <exception cref="AggregateException">An <see cref="AggregateException"/> containing any <see cref="Exception"/>s thrown by the <paramref name="tasks"/>.</exception>
public static async ValueTask WhenAll(IReadOnlyList<ValueTask> tasks)
{
if (tasks == null)
throw new ArgumentNullException(nameof(tasks));
// We don't allocate the list if no task throws
List<Exception>? exceptions = null;
for (var i = 0; i < tasks.Count; ++i)
try
{
var task = tasks[i];
await task.ConfigureAwait(false);
}
catch (Exception ex)
{
exceptions ??= new (tasks.Count - i);
exceptions.Add(ex);
}
if (exceptions != null)
throw new AggregateException(exceptions);
}
/// <summary>
/// Fully <see langword="await"/> a given list of <paramref name="tasks"/>.
/// </summary>
/// <param name="tasks">An <see cref="Array"/> of <see cref="ValueTask"/>s.</param>
/// <returns>A <see cref="ValueTask"/> representing the combined <see langword="await"/>.</returns>
/// <exception cref="AggregateException">An <see cref="AggregateException"/> containing any <see cref="Exception"/>s thrown by the <paramref name="tasks"/>.</exception>
public static ValueTask WhenAll(params ValueTask[] tasks) => WhenAll((IReadOnlyList<ValueTask>)tasks);
}
}
@@ -25,7 +25,7 @@ namespace Tgstation.Server.Common.Http
/// </summary>
/// <param name="response">The <see cref="HttpResponseMessage"/> to build from.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a new <see cref="CachedResponseStream"/>.</returns>
public static async Task<CachedResponseStream> Create(HttpResponseMessage response)
public static async ValueTask<CachedResponseStream> Create(HttpResponseMessage response)
{
if (response == null)
throw new ArgumentNullException(nameof(response));
@@ -9,6 +9,11 @@
<PackageReleaseNotes>$(TGS_NUGET_RELEASE_NOTES_COMMON)</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>
<!-- Usage: ValueTask netstandard backport -->
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
</ItemGroup>
<!-- This is here because I know we have node as a build dep so this just works -->
<Target Name="IconGeneration" BeforeTargets="ResolveAssemblyReferences" Inputs="build_logo.js;../../build/logo.svg" Outputs="../../artifacts/tgs.ico;../../artifacts/tgs.png">
<Message Text="Restoring yarn packages..." Importance="high" />
@@ -31,7 +31,7 @@ namespace Tgstation.Server.Host.Console
}
/// <inheritdoc />
public async Task CheckSignals(Func<string, (int, Task)> startChild, CancellationToken cancellationToken)
public async ValueTask CheckSignals(Func<string, (int, Task)> startChild, CancellationToken cancellationToken)
{
var (childPid, _) = startChild?.Invoke(null) ?? throw new ArgumentNullException(nameof(startChild));
var signalTcs = new TaskCompletionSource<Signum>();
+2 -2
View File
@@ -116,7 +116,7 @@ namespace Tgstation.Server.Host.Service
}
if (Configure)
await RunConfigure(CancellationToken.None); // DCT: None available
await RunConfigure(CancellationToken.None); // DCT: None available
bool stopped = false;
if (Uninstall)
@@ -281,7 +281,7 @@ namespace Tgstation.Server.Host.Service
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task RunConfigure(CancellationToken cancellationToken)
async ValueTask RunConfigure(CancellationToken cancellationToken)
{
using var loggerFactory = LoggerFactory.Create(builder =>
{
@@ -90,7 +90,7 @@ namespace Tgstation.Server.Host.Service
}
/// <inheritdoc />
public async Task CheckSignals(Func<string, (int, Task)> startChildAndGetPid, CancellationToken cancellationToken)
public async ValueTask CheckSignals(Func<string, (int, Task)> startChildAndGetPid, CancellationToken cancellationToken)
{
await using (commandPipeServer = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable))
await using (readyPipeServer = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable))
@@ -14,7 +14,7 @@ namespace Tgstation.Server.Host.Watchdog
/// </summary>
/// <param name="startChild">An <see cref="Func{TResult}"/> to start the main process. It accepts an optional additional command line argument as a paramter and returns it's <see cref="System.Diagnostics.Process.Id"/> and lifetime <see cref="Task"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task CheckSignals(Func<string, (int, Task)> startChild, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask CheckSignals(Func<string, (int, Task)> startChild, CancellationToken cancellationToken);
}
}
@@ -20,7 +20,7 @@ namespace Tgstation.Server.Host.Watchdog
/// <param name="runConfigure">If the <see cref="IWatchdog"/> should just run the host configuration wizard and exit.</param>
/// <param name="args">The arguments for the <see cref="IWatchdog"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in <see langword="true"/> if there were no errors, <see langword="false"/> otherwise.</returns>
Task<bool> RunAsync(bool runConfigure, string[] args, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in <see langword="true"/> if there were no errors, <see langword="false"/> otherwise.</returns>
ValueTask<bool> RunAsync(bool runConfigure, string[] args, CancellationToken cancellationToken);
}
}
@@ -10,11 +10,11 @@ namespace Tgstation.Server.Host.Watchdog
public sealed class NoopSignalChecker : ISignalChecker
{
/// <inheritdoc />
public Task CheckSignals(Func<string, (int, Task)> startChild, CancellationToken cancellationToken)
public ValueTask CheckSignals(Func<string, (int, Task)> startChild, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(startChild);
startChild(null);
return Task.CompletedTask;
return ValueTask.CompletedTask;
}
}
}
@@ -46,7 +46,7 @@ namespace Tgstation.Server.Host.Watchdog
/// <inheritdoc />
#pragma warning disable CA1502 // TODO: Decomplexify
#pragma warning disable CA1506
public async Task<bool> RunAsync(bool runConfigure, string[] args, CancellationToken cancellationToken)
public async ValueTask<bool> RunAsync(bool runConfigure, string[] args, CancellationToken cancellationToken)
{
logger.LogInformation("Host watchdog starting...");
int currentProcessId;
@@ -77,24 +77,20 @@ namespace Tgstation.Server.Host.Components.Byond
CacheDirectoryName),
cancellationToken);
}
catch (OperationCanceledException)
catch (Exception ex) when (ex is not OperationCanceledException)
{
throw;
}
catch (Exception e)
{
Logger.LogWarning(e, "Error deleting BYOND cache!");
Logger.LogWarning(ex, "Error deleting BYOND cache!");
}
}
/// <inheritdoc />
public abstract Task InstallByond(Version version, string path, CancellationToken cancellationToken);
public abstract ValueTask InstallByond(Version version, string path, CancellationToken cancellationToken);
/// <inheritdoc />
public abstract Task UpgradeInstallation(Version version, string path, CancellationToken cancellationToken);
public abstract ValueTask UpgradeInstallation(Version version, string path, CancellationToken cancellationToken);
/// <inheritdoc />
public async Task<MemoryStream> DownloadVersion(Version version, CancellationToken cancellationToken)
public async ValueTask<MemoryStream> DownloadVersion(Version version, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(version);
@@ -10,6 +10,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Common.Extensions;
using Tgstation.Server.Host.Components.Events;
using Tgstation.Server.Host.IO;
using Tgstation.Server.Host.Jobs;
@@ -133,7 +134,7 @@ namespace Tgstation.Server.Host.Components.Byond
public void Dispose() => changeDeleteSemaphore.Dispose();
/// <inheritdoc />
public async Task ChangeVersion(
public async ValueTask ChangeVersion(
JobProgressReporter progressReporter,
Version version,
Stream customVersionStream,
@@ -145,12 +146,12 @@ namespace Tgstation.Server.Host.Components.Byond
using (await SemaphoreSlimContext.Lock(changeDeleteSemaphore, cancellationToken))
{
using var installLock = await AssertAndLockVersion(
progressReporter,
version,
customVersionStream,
false,
allowInstallation,
cancellationToken);
progressReporter,
version,
customVersionStream,
false,
allowInstallation,
cancellationToken);
// We reparse the version because it could be changed after a custom install.
version = installLock.Version;
@@ -176,7 +177,7 @@ namespace Tgstation.Server.Host.Components.Byond
}
/// <inheritdoc />
public async Task<IByondExecutableLock> UseExecutables(Version requiredVersion, string trustDmbFullPath, CancellationToken cancellationToken)
public async ValueTask<IByondExecutableLock> UseExecutables(Version requiredVersion, string trustDmbFullPath, CancellationToken cancellationToken)
{
logger.LogTrace(
"Acquiring lock on BYOND version {version}...",
@@ -204,7 +205,7 @@ namespace Tgstation.Server.Host.Components.Byond
}
/// <inheritdoc />
public async Task DeleteVersion(JobProgressReporter progressReporter, Version version, CancellationToken cancellationToken)
public async ValueTask DeleteVersion(JobProgressReporter progressReporter, Version version, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(progressReporter);
@@ -293,7 +294,7 @@ namespace Tgstation.Server.Host.Components.Byond
/// <inheritdoc />
public async Task StartAsync(CancellationToken cancellationToken)
{
async Task<byte[]> GetActiveVersion()
async ValueTask<byte[]> GetActiveVersion()
{
var activeVersionFileExists = await ioManager.FileExists(ActiveVersionFileName, cancellationToken);
return !activeVersionFileExists ? null : await ioManager.ReadAllBytes(ActiveVersionFileName, cancellationToken);
@@ -329,7 +330,7 @@ namespace Tgstation.Server.Host.Components.Byond
var installedVersionPaths = new Dictionary<string, Version>();
async Task ReadVersion(string path)
async ValueTask ReadVersion(string path)
{
var versionFile = ioManager.ConcatPath(path, VersionFileName);
if (!await ioManager.FileExists(versionFile, cancellationToken))
@@ -368,10 +369,14 @@ namespace Tgstation.Server.Host.Components.Byond
installedVersionPaths.Add(ioManager.ResolvePath(version.ToString()), version);
}
await Task.WhenAll(directories.Select(ReadVersion));
await ValueTaskExtensions.WhenAll(
directories
.Select(ReadVersion));
logger.LogTrace("Upgrading BYOND installations...");
await Task.WhenAll(installedVersionPaths.Select(kvp => byondInstaller.UpgradeInstallation(kvp.Value, kvp.Key, cancellationToken)));
await ValueTaskExtensions.WhenAll(
installedVersionPaths
.Select(kvp => byondInstaller.UpgradeInstallation(kvp.Value, kvp.Key, cancellationToken)));
var activeVersionBytes = await activeVersionBytesTask;
if (activeVersionBytes != null)
@@ -406,8 +411,8 @@ namespace Tgstation.Server.Host.Components.Byond
/// <param name="neededForLock">If this BYOND version is required as part of a locking operation.</param>
/// <param name="allowInstallation">If an installation should be performed if the <paramref name="version"/> is not installed. If <see langword="false"/> and an installation is required an <see cref="InvalidOperationException"/> will be thrown.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="ByondExecutableLock"/>.</returns>
async Task<ByondExecutableLock> AssertAndLockVersion(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="ByondExecutableLock"/>.</returns>
async ValueTask<ByondExecutableLock> AssertAndLockVersion(
JobProgressReporter progressReporter,
Version version,
Stream customVersionStream,
@@ -511,11 +516,11 @@ namespace Tgstation.Server.Host.Components.Byond
/// <param name="version">The BYOND <see cref="Version"/> being installed with the <see cref="Version.Build"/> number set if appropriate.</param>
/// <param name="customVersionStream">Custom zip file <see cref="Stream"/> to use. Will cause a <see cref="Version.Build"/> number to be added.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task InstallVersionFiles(JobProgressReporter progressReporter, Version version, Stream customVersionStream, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask InstallVersionFiles(JobProgressReporter progressReporter, Version version, Stream customVersionStream, CancellationToken cancellationToken)
{
var installFullPath = ioManager.ResolvePath(version.ToString());
async Task DirectoryCleanup()
async ValueTask DirectoryCleanup()
{
await ioManager.DeleteDirectory(installFullPath, cancellationToken);
await ioManager.CreateDirectory(installFullPath, cancellationToken);
@@ -563,10 +568,10 @@ namespace Tgstation.Server.Host.Components.Byond
Encoding.UTF8.GetBytes(version.ToString()),
cancellationToken);
}
catch (HttpRequestException e)
catch (HttpRequestException ex)
{
// since the user can easily provide non-exitent version numbers, we'll turn this into a JobException
throw new JobException(ErrorCode.ByondDownloadFail, e);
throw new JobException(ErrorCode.ByondDownloadFail, ex);
}
catch (OperationCanceledException)
{
@@ -583,7 +588,7 @@ namespace Tgstation.Server.Host.Components.Byond
/// Create and add a new <see cref="ByondInstallation"/> to <see cref="installedVersions"/>.
/// </summary>
/// <param name="version">The <see cref="Version"/> being added.</param>
/// <param name="installationTask">The <see cref="Task"/> representing the installation process.</param>
/// <param name="installationTask">The <see cref="ValueTask"/> representing the installation process.</param>
/// <returns>The new <see cref="ReferenceCountingContainer{TWrapped, TReference}"/> containing the new <see cref="ByondInstallation"/>.</returns>
ReferenceCountingContainer<ByondInstallation, ByondExecutableLock> AddInstallationContainer(Version version, Task installationTask)
{
@@ -618,8 +623,8 @@ namespace Tgstation.Server.Host.Components.Byond
/// </summary>
/// <param name="fullDmbPath">Full path to the .dmb that should be trusted.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task TrustDmbPath(string fullDmbPath, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask TrustDmbPath(string fullDmbPath, CancellationToken cancellationToken)
{
var byondDir = byondInstaller.PathToUserByondFolder;
if (String.IsNullOrWhiteSpace(byondDir))
@@ -34,8 +34,8 @@ namespace Tgstation.Server.Host.Components.Byond
/// </summary>
/// <param name="version">The <see cref="Version"/> of BYOND to download.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="MemoryStream"/> of the zipfile.</returns>
Task<MemoryStream> DownloadVersion(Version version, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="MemoryStream"/> of the zipfile.</returns>
ValueTask<MemoryStream> DownloadVersion(Version version, CancellationToken cancellationToken);
/// <summary>
/// Does actions necessary to get an extracted BYOND installation working.
@@ -43,8 +43,8 @@ namespace Tgstation.Server.Host.Components.Byond
/// <param name="version">The <see cref="Version"/> of BYOND being installed.</param>
/// <param name="path">The path to the BYOND installation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task InstallByond(Version version, string path, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask InstallByond(Version version, string path, CancellationToken cancellationToken);
/// <summary>
/// Does actions necessary to get upgrade a BYOND version installed by a previous version of TGS.
@@ -52,8 +52,8 @@ namespace Tgstation.Server.Host.Components.Byond
/// <param name="version">The <see cref="Version"/> of BYOND being installed.</param>
/// <param name="path">The path to the BYOND installation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task UpgradeInstallation(Version version, string path, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask UpgradeInstallation(Version version, string path, CancellationToken cancellationToken);
/// <summary>
/// Attempts to cleans the BYOND cache folder for the system.
@@ -32,8 +32,8 @@ namespace Tgstation.Server.Host.Components.Byond
/// <param name="customVersionStream">Optional <see cref="Stream"/> of a custom BYOND version zip file.</param>
/// <param name="allowInstallation">If an installation should be performed if the <paramref name="version"/> is not installed. If <see langword="false"/> and an installation is required an <see cref="InvalidOperationException"/> will be thrown.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task ChangeVersion(JobProgressReporter progressReporter, Version version, Stream customVersionStream, bool allowInstallation, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask ChangeVersion(JobProgressReporter progressReporter, Version version, Stream customVersionStream, bool allowInstallation, CancellationToken cancellationToken);
/// <summary>
/// Deletes a given BYOND version from the disk.
@@ -41,8 +41,8 @@ namespace Tgstation.Server.Host.Components.Byond
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> for the operation.</param>
/// <param name="version">The <see cref="Version"/> to delete.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task DeleteVersion(JobProgressReporter progressReporter, Version version, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask DeleteVersion(JobProgressReporter progressReporter, Version version, CancellationToken cancellationToken);
/// <summary>
/// Lock the current installation's location and return a <see cref="IByondExecutableLock"/>.
@@ -50,8 +50,8 @@ namespace Tgstation.Server.Host.Components.Byond
/// <param name="requiredVersion">The BYOND <see cref="Version"/> required.</param>
/// <param name="trustDmbFullPath">The optional full path to .dmb to trust while using the executables.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the requested <see cref="IByondExecutableLock"/>.</returns>
Task<IByondExecutableLock> UseExecutables(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the requested <see cref="IByondExecutableLock"/>.</returns>
ValueTask<IByondExecutableLock> UseExecutables(
Version requiredVersion,
string trustDmbFullPath,
CancellationToken cancellationToken);
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Tgstation.Server.Common.Extensions;
using Tgstation.Server.Host.IO;
namespace Tgstation.Server.Host.Components.Byond
@@ -78,7 +79,7 @@ namespace Tgstation.Server.Host.Components.Byond
}
/// <inheritdoc />
public override Task InstallByond(Version version, string path, CancellationToken cancellationToken)
public override ValueTask InstallByond(Version version, string path, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(version);
ArgumentNullException.ThrowIfNull(path);
@@ -90,7 +91,7 @@ namespace Tgstation.Server.Host.Components.Byond
var dreamDaemonScript = String.Format(CultureInfo.InvariantCulture, StandardScript, DreamDaemonExecutableName);
var dreamMakerScript = String.Format(CultureInfo.InvariantCulture, StandardScript, DreamMakerExecutableName);
async Task WriteAndMakeExecutable(string pathToScript, string script)
async ValueTask WriteAndMakeExecutable(string pathToScript, string script)
{
Logger.LogTrace("Writing script {path}:{newLine}{scriptContents}", pathToScript, Environment.NewLine, script);
await IOManager.WriteAllBytes(pathToScript, Encoding.ASCII.GetBytes(script), cancellationToken);
@@ -99,13 +100,17 @@ namespace Tgstation.Server.Host.Components.Byond
var basePath = IOManager.ConcatPath(path, ByondManager.BinPath);
var task = Task.WhenAll(
WriteAndMakeExecutable(
IOManager.ConcatPath(basePath, GetDreamDaemonName(version, out _, out _)),
dreamDaemonScript),
WriteAndMakeExecutable(
IOManager.ConcatPath(basePath, DreamMakerName),
dreamMakerScript));
var ddTask = WriteAndMakeExecutable(
IOManager.ConcatPath(basePath, GetDreamDaemonName(version, out _, out _)),
dreamDaemonScript);
var dmTask = WriteAndMakeExecutable(
IOManager.ConcatPath(basePath, DreamMakerName),
dreamMakerScript);
var task = ValueTaskExtensions.WhenAll(
ddTask,
dmTask);
postWriteHandler.HandleWrite(IOManager.ConcatPath(basePath, DreamDaemonExecutableName));
postWriteHandler.HandleWrite(IOManager.ConcatPath(basePath, DreamMakerExecutableName));
@@ -114,12 +119,12 @@ namespace Tgstation.Server.Host.Components.Byond
}
/// <inheritdoc />
public override Task UpgradeInstallation(Version version, string path, CancellationToken cancellationToken)
public override ValueTask UpgradeInstallation(Version version, string path, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(version);
ArgumentNullException.ThrowIfNull(path);
return Task.CompletedTask;
return ValueTask.CompletedTask;
}
}
}
@@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Common.Extensions;
using Tgstation.Server.Host.Configuration;
using Tgstation.Server.Host.IO;
using Tgstation.Server.Host.Jobs;
@@ -123,9 +124,9 @@ namespace Tgstation.Server.Host.Components.Byond
}
/// <inheritdoc />
public override Task InstallByond(Version version, string path, CancellationToken cancellationToken)
public override ValueTask InstallByond(Version version, string path, CancellationToken cancellationToken)
{
var tasks = new List<Task>
var tasks = new List<ValueTask>(3)
{
SetNoPromptTrusted(path, cancellationToken),
InstallDirectX(path, cancellationToken),
@@ -134,11 +135,11 @@ namespace Tgstation.Server.Host.Components.Byond
if (!generalConfiguration.SkipAddingByondFirewallException)
tasks.Add(AddDreamDaemonToFirewall(version, path, cancellationToken));
return Task.WhenAll(tasks);
return ValueTaskExtensions.WhenAll(tasks);
}
/// <inheritdoc />
public override async Task UpgradeInstallation(Version version, string path, CancellationToken cancellationToken)
public override async ValueTask UpgradeInstallation(Version version, string path, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(version);
ArgumentNullException.ThrowIfNull(path);
@@ -162,7 +163,7 @@ namespace Tgstation.Server.Host.Components.Byond
/// <param name="path">The path to the BYOND installation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task SetNoPromptTrusted(string path, CancellationToken cancellationToken)
async ValueTask SetNoPromptTrusted(string path, CancellationToken cancellationToken)
{
var configPath = IOManager.ConcatPath(path, ByondConfigDirectory);
await IOManager.CreateDirectory(configPath, cancellationToken);
@@ -180,8 +181,8 @@ namespace Tgstation.Server.Host.Components.Byond
/// </summary>
/// <param name="path">The path to the BYOND installation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task InstallDirectX(string path, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask InstallDirectX(string path, CancellationToken cancellationToken)
{
using var lockContext = await SemaphoreSlimContext.Lock(semaphore, cancellationToken);
if (installedDirectX)
@@ -225,8 +226,8 @@ namespace Tgstation.Server.Host.Components.Byond
/// <param name="version">The BYOND <see cref="Version"/>.</param>
/// <param name="path">The path to the BYOND installation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task AddDreamDaemonToFirewall(Version version, string path, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask AddDreamDaemonToFirewall(Version version, string path, CancellationToken cancellationToken)
{
var dreamDaemonName = GetDreamDaemonName(version, out var usesDDExe, out var _);
@@ -12,6 +12,7 @@ using Newtonsoft.Json;
using Serilog.Context;
using Tgstation.Server.Api.Models.Internal;
using Tgstation.Server.Common.Extensions;
using Tgstation.Server.Host.Components.Chat.Commands;
using Tgstation.Server.Host.Components.Chat.Providers;
using Tgstation.Server.Host.Components.Interop;
@@ -177,7 +178,7 @@ namespace Tgstation.Server.Host.Components.Chat
}
/// <inheritdoc />
public async Task ChangeChannels(long connectionId, IEnumerable<Models.ChatChannel> newChannels, CancellationToken cancellationToken)
public async ValueTask ChangeChannels(long connectionId, IEnumerable<Models.ChatChannel> newChannels, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(newChannels);
@@ -260,7 +261,7 @@ namespace Tgstation.Server.Host.Components.Chat
}
/// <inheritdoc />
public async Task ChangeSettings(Models.ChatBot newSettings, CancellationToken cancellationToken)
public async ValueTask ChangeSettings(Models.ChatBot newSettings, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(newSettings);
@@ -370,7 +371,7 @@ namespace Tgstation.Server.Host.Components.Chat
logger.LogTrace("Sending deployment message for RevisionInformation: {revisionInfoId}", revisionInformation.Id);
var callbacks = new List<Func<string, string, Task<Func<bool, Task>>>>();
var callbacks = new List<Func<string, string, ValueTask<Func<bool, ValueTask>>>>();
var task = Task.WhenAll(
wdChannels.Select(
@@ -410,21 +411,19 @@ namespace Tgstation.Server.Host.Components.Chat
AddMessageTask(task);
Task callbackTask = null;
Task callbackTask;
Func<bool, Task> finalUpdateAction = null;
async Task CallbackTask(string errorMessage, string dreamMakerOutput)
{
await task;
var callbackResultTasks =
var callbackResults = await ValueTaskExtensions.WhenAll(
callbacks.Select(
x => x(
errorMessage,
dreamMakerOutput))
.ToList();
dreamMakerOutput)),
callbacks.Count);
await Task.WhenAll(callbackResultTasks);
finalUpdateAction = active => Task.WhenAll(callbackResultTasks.Select(task => task.Result(active)));
finalUpdateAction = active => ValueTaskExtensions.WhenAll(callbackResults.Select(finalizerCallback => finalizerCallback(active))).AsTask();
}
async Task CompletionTask(bool active)
@@ -456,7 +455,7 @@ namespace Tgstation.Server.Host.Components.Chat
foreach (var tgsCommand in commandFactory.GenerateCommands())
builtinCommands.Add(tgsCommand.Name.ToUpperInvariant(), tgsCommand);
var initialChatBots = activeChatBots.ToList();
await Task.WhenAll(initialChatBots.Select(x => ChangeSettings(x, cancellationToken)));
await ValueTaskExtensions.WhenAll(initialChatBots.Select(x => ChangeSettings(x, cancellationToken)));
initialProviderConnectionsTask = InitialConnection();
chatHandler = MonitorMessages(handlerCts.Token);
}
@@ -496,7 +495,7 @@ namespace Tgstation.Server.Host.Components.Chat
}
/// <inheritdoc />
public async Task UpdateTrackingContexts(CancellationToken cancellationToken)
public async ValueTask UpdateTrackingContexts(CancellationToken cancellationToken)
{
var logMessageSent = 0;
async Task UpdateTrackingContext(IChatTrackingContext channelSink, IEnumerable<ChannelRepresentation> channels)
@@ -562,7 +561,7 @@ namespace Tgstation.Server.Host.Components.Chat
}
/// <inheritdoc />
public Task HandleRestart(Version updateVersion, bool handlerMayDelayShutdownWithExtremelyLongRunningTasks, CancellationToken cancellationToken)
public ValueTask HandleRestart(Version updateVersion, bool handlerMayDelayShutdownWithExtremelyLongRunningTasks, CancellationToken cancellationToken)
{
var message = updateVersion == null
? $"TGS: {(handlerMayDelayShutdownWithExtremelyLongRunningTasks ? "Graceful shutdown" : "Going down")}..."
@@ -590,8 +589,8 @@ namespace Tgstation.Server.Host.Components.Chat
/// <param name="connectionId">The <see cref="Api.Models.EntityId.Id"/> of the <see cref="IProvider"/> to delete.</param>
/// <param name="removeProvider">If the provider should be removed from <see cref="providers"/> and <see cref="trackingContexts"/> should be update.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="IProvider"/> being removed if it exists, <see langword="null"/> otherwise.</returns>
async Task<IProvider> RemoveProviderChannels(long connectionId, bool removeProvider, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="IProvider"/> being removed if it exists, <see langword="null"/> otherwise.</returns>
async ValueTask<IProvider> RemoveProviderChannels(long connectionId, bool removeProvider, CancellationToken cancellationToken)
{
logger.LogTrace("RemoveProviderChannels {connectionId}...", connectionId);
IProvider provider;
@@ -607,7 +606,7 @@ namespace Tgstation.Server.Host.Components.Chat
providers.Remove(connectionId);
}
Task trackingContextsUpdateTask;
ValueTask trackingContextsUpdateTask;
lock (mappedChannels)
{
foreach (var mappedConnectionChannel in mappedChannels.Where(x => x.Value.ProviderId == connectionId).Select(x => x.Key).ToList())
@@ -617,9 +616,9 @@ namespace Tgstation.Server.Host.Components.Chat
if (removeProvider)
lock (trackingContexts)
trackingContextsUpdateTask = Task.WhenAll(trackingContexts.Select(x => x.UpdateChannels(newMappedChannels, cancellationToken)));
trackingContextsUpdateTask = ValueTaskExtensions.WhenAll(trackingContexts.Select(x => x.UpdateChannels(newMappedChannels, cancellationToken)));
else
trackingContextsUpdateTask = Task.CompletedTask;
trackingContextsUpdateTask = ValueTask.CompletedTask;
}
await trackingContextsUpdateTask;
@@ -632,8 +631,8 @@ namespace Tgstation.Server.Host.Components.Chat
/// </summary>
/// <param name="provider">The <see cref="IProvider"/> to remap channels for.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task RemapProvider(IProvider provider, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask RemapProvider(IProvider provider, CancellationToken cancellationToken)
{
logger.LogTrace("Remapping channels for provider reconnection...");
IEnumerable<Models.ChatChannel> channelsToMap;
@@ -655,9 +654,9 @@ namespace Tgstation.Server.Host.Components.Chat
/// <param name="message">The <see cref="Message"/> to process. If <see langword="null"/>, this indicates the provider reconnected.</param>
/// <param name="recursed">If we are called recursively after remapping the provider.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
#pragma warning disable CA1502
async Task ProcessMessage(IProvider provider, Message message, bool recursed, CancellationToken cancellationToken)
async ValueTask ProcessMessage(IProvider provider, Message message, bool recursed, CancellationToken cancellationToken)
#pragma warning restore CA1502
{
if (!provider.Connected)
@@ -937,7 +936,7 @@ namespace Tgstation.Server.Host.Components.Chat
{
logger.LogTrace("Starting processing loop...");
var messageTasks = new Dictionary<IProvider, Task<Message>>();
Task activeProcessingTask = Task.CompletedTask;
ValueTask activeProcessingTask = ValueTask.CompletedTask;
try
{
Task updatedTask = null;
@@ -955,7 +954,9 @@ namespace Tgstation.Server.Host.Components.Chat
lock (providers)
foreach (var providerKvp in providers)
if (!messageTasks.ContainsKey(providerKvp.Value))
messageTasks.Add(providerKvp.Value, providerKvp.Value.NextMessage(cancellationToken));
messageTasks.Add(
providerKvp.Value,
providerKvp.Value.NextMessage(cancellationToken));
if (messageTasks.Count == 0)
{
@@ -980,7 +981,7 @@ namespace Tgstation.Server.Host.Components.Chat
var message = await completedMessageTaskKvp.Value;
var messageNumber = Interlocked.Increment(ref messagesProcessed);
async Task WrapProcessMessage()
async ValueTask WrapProcessMessage()
{
var localActiveProcessingTask = activeProcessingTask;
using (LogContext.PushProperty(SerilogContextHelper.ChatMessageIterationContextProperty, messageNumber))
@@ -1024,30 +1025,30 @@ namespace Tgstation.Server.Host.Components.Chat
/// <param name="message">The <see cref="MessageContent"/> to send.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task SendMessage(IEnumerable<ulong> channelIds, Message replyTo, MessageContent message, CancellationToken cancellationToken)
ValueTask SendMessage(IEnumerable<ulong> channelIds, Message replyTo, MessageContent message, CancellationToken cancellationToken)
{
channelIds = channelIds.ToList();
var channelIdsList = channelIds.ToList();
logger.LogTrace(
"Chat send \"{message}\"{embed} to channels: [{channelIdsCommaSeperated}]",
message.Text,
message.Embed != null ? " (with embed)" : String.Empty,
String.Join(", ", channelIds));
String.Join(", ", channelIdsList));
if (!channelIds.Any())
return Task.CompletedTask;
if (!channelIdsList.Any())
return ValueTask.CompletedTask;
return Task.WhenAll(
channelIds.Select(x =>
return ValueTaskExtensions.WhenAll(
channelIdsList.Select(x =>
{
ChannelMapping channelMapping;
lock (mappedChannels)
if (!mappedChannels.TryGetValue(x, out channelMapping))
return Task.CompletedTask;
return ValueTask.CompletedTask;
IProvider provider;
lock (providers)
if (!providers.TryGetValue(channelMapping.ProviderId, out provider))
return Task.CompletedTask;
return ValueTask.CompletedTask;
return provider.SendMessage(replyTo, message, channelMapping.ProviderChannelId, cancellationToken);
}));
}
@@ -133,15 +133,15 @@ namespace Tgstation.Server.Host.Components.Chat
}
/// <inheritdoc />
public Task UpdateChannels(IEnumerable<ChannelRepresentation> newChannels, CancellationToken cancellationToken)
public ValueTask UpdateChannels(IEnumerable<ChannelRepresentation> newChannels, CancellationToken cancellationToken)
{
logger.LogTrace("UpdateChannels...");
var completed = newChannels.ToList();
Task updateTask;
ValueTask updateTask;
lock (synchronizationLock)
{
Channels = completed;
updateTask = channelSink?.UpdateChannels(newChannels, cancellationToken) ?? Task.CompletedTask;
updateTask = channelSink?.UpdateChannels(newChannels, cancellationToken) ?? ValueTask.CompletedTask;
}
return updateTask;
@@ -47,19 +47,19 @@ namespace Tgstation.Server.Host.Components.Chat.Commands
}
/// <inheritdoc />
public Task<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
public ValueTask<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
{
if (arguments.Split(' ').Any(x => x.ToUpperInvariant() == "--ACTIVE"))
return Task.FromResult(new MessageContent
return ValueTask.FromResult(new MessageContent
{
Text = byondManager.ActiveVersion == null ? "None!" : String.Format(CultureInfo.InvariantCulture, "{0}.{1}", byondManager.ActiveVersion.Major, byondManager.ActiveVersion.Minor),
});
if (watchdog.Status == WatchdogStatus.Offline)
return Task.FromResult(new MessageContent
return ValueTask.FromResult(new MessageContent
{
Text = "Server offline!",
});
return Task.FromResult(new MessageContent
return ValueTask.FromResult(new MessageContent
{
Text = watchdog.ActiveCompileJob?.ByondVersion ?? "None!",
});
@@ -37,7 +37,7 @@ namespace Tgstation.Server.Host.Components.Chat.Commands
}
/// <inheritdoc />
public Task<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
public ValueTask<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
{
if (handler == null)
throw new InvalidOperationException("SetHandler() has not been called!");
@@ -31,7 +31,7 @@ namespace Tgstation.Server.Host.Components.Chat.Commands
/// <param name="arguments">The text after <see cref="Name"/> with leading whitespace trimmed.</param>
/// <param name="user">The <see cref="ChatUser"/> who invoked the command.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="MessageContent"/> to send to the invoker.</returns>
Task<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="MessageContent"/> to send to the invoker.</returns>
ValueTask<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken);
}
}
@@ -25,7 +25,7 @@ namespace Tgstation.Server.Host.Components.Chat.Commands
public bool AdminOnly => false;
/// <inheritdoc />
public Task<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken) => Task.FromResult(new MessageContent
public ValueTask<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken) => ValueTask.FromResult(new MessageContent
{
Text = Kek,
});
@@ -79,7 +79,7 @@ namespace Tgstation.Server.Host.Components.Chat.Commands
/// <inheritdoc />
// TODO: Decomplexify
#pragma warning disable CA1506
public async Task<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
public async ValueTask<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
{
IEnumerable<Models.TestMerge> results = null;
var splits = arguments.Split(' ');
@@ -47,7 +47,7 @@ namespace Tgstation.Server.Host.Components.Chat.Commands
}
/// <inheritdoc />
public async Task<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
public async ValueTask<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
{
string result;
if (arguments.Split(' ').Any(x => x.ToUpperInvariant() == "--REPO"))
@@ -36,7 +36,7 @@ namespace Tgstation.Server.Host.Components.Chat.Commands
}
/// <inheritdoc />
public Task<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken) => Task.FromResult(new MessageContent
public ValueTask<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken) => ValueTask.FromResult(new MessageContent
{
Text = assemblyInformationProvider.VersionString,
});
@@ -14,7 +14,7 @@ namespace Tgstation.Server.Host.Components.Chat
/// </summary>
/// <param name="newChannels">The <see cref="IEnumerable{T}"/> of new <see cref="ChannelRepresentation"/>s.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task UpdateChannels(IEnumerable<ChannelRepresentation> newChannels, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask UpdateChannels(IEnumerable<ChannelRepresentation> newChannels, CancellationToken cancellationToken);
}
}
@@ -24,8 +24,8 @@ namespace Tgstation.Server.Host.Components.Chat
/// </summary>
/// <param name="newSettings">The new <see cref="Models.ChatBot"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation. Will complete immediately if the <see cref="ChatBotSettings.Enabled"/> property of <paramref name="newSettings"/> is <see langword="false"/>.</returns>
Task ChangeSettings(Models.ChatBot newSettings, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation. Will complete immediately if the <see cref="ChatBotSettings.Enabled"/> property of <paramref name="newSettings"/> is <see langword="false"/>.</returns>
ValueTask ChangeSettings(Models.ChatBot newSettings, CancellationToken cancellationToken);
/// <summary>
/// Disconnects and deletes a given connection.
@@ -41,8 +41,8 @@ namespace Tgstation.Server.Host.Components.Chat
/// <param name="connectionId">The <see cref="Api.Models.EntityId.Id"/> of the connection.</param>
/// <param name="newChannels">An <see cref="IEnumerable{T}"/> of the new list of <see cref="Models.ChatChannel"/>s.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task ChangeChannels(long connectionId, IEnumerable<Models.ChatChannel> newChannels, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask ChangeChannels(long connectionId, IEnumerable<Models.ChatChannel> newChannels, CancellationToken cancellationToken);
/// <summary>
/// Queue a chat <paramref name="message"/> to a given set of <paramref name="channelIds"/>.
@@ -85,7 +85,7 @@ namespace Tgstation.Server.Host.Components.Chat
/// Force an update with the active channels on all active <see cref="IChatTrackingContext"/>s.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task UpdateTrackingContexts(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask UpdateTrackingContexts(CancellationToken cancellationToken);
}
}
@@ -17,7 +17,7 @@ namespace Tgstation.Server.Host.Components.Chat
/// <param name="arguments">Everything typed after <paramref name="commandName"/> minus leading spaces.</param>
/// <param name="sender">The sending <see cref="ChatUser"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="MessageContent"/> text to send back.</returns>
Task<MessageContent> HandleChatCommand(string commandName, string arguments, ChatUser sender, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="MessageContent"/> text to send back.</returns>
ValueTask<MessageContent> HandleChatCommand(string commandName, string arguments, ChatUser sender, CancellationToken cancellationToken);
}
}
@@ -22,6 +22,7 @@ using Remora.Rest.Results;
using Remora.Results;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Common.Extensions;
using Tgstation.Server.Host.Components.Interop;
using Tgstation.Server.Host.Extensions;
using Tgstation.Server.Host.Jobs;
@@ -229,7 +230,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
}
/// <inheritdoc />
public override async Task SendMessage(Message replyTo, MessageContent message, ulong channelId, CancellationToken cancellationToken)
public override async ValueTask SendMessage(Message replyTo, MessageContent message, ulong channelId, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(message);
@@ -251,7 +252,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
var embeds = ConvertEmbed(message.Embed);
var channelsClient = serviceProvider.GetRequiredService<IDiscordRestChannelAPI>();
async Task SendToChannel(Snowflake channelId)
async ValueTask SendToChannel(Snowflake channelId)
{
var result = await channelsClient.CreateMessageAsync(
channelId,
@@ -303,7 +304,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
if (unmappedTextChannels.Any())
{
Logger.LogDebug("Dispatching to {count} unmapped channels...", unmappedTextChannels.Count());
await Task.WhenAll(
await ValueTaskExtensions.WhenAll(
unmappedTextChannels.Select(
x => SendToChannel(x.ID)));
}
@@ -320,7 +321,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
}
/// <inheritdoc />
public override async Task<Func<string, string, Task<Func<bool, Task>>>> SendUpdateMessage(
public override async ValueTask<Func<string, string, ValueTask<Func<bool, ValueTask>>>> SendUpdateMessage(
Models.RevisionInformation revisionInformation,
Version byondVersion,
DateTimeOffset? estimatedCompletionTime,
@@ -421,7 +422,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
var updatedMessageText = errorMessage == null ? $"DM: Deployment pending reboot..." : $"DM: Deployment failed!";
IMessage updatedMessage = null;
async Task CreateUpdatedMessage()
async ValueTask CreateUpdatedMessage()
{
var createUpdatedMessageResponse = await channelsClient.CreateMessageAsync(
new Snowflake(channelId),
@@ -603,7 +604,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
}
/// <inheritdoc />
protected override async Task Connect(CancellationToken cancellationToken)
protected override async ValueTask Connect(CancellationToken cancellationToken)
{
try
{
@@ -663,7 +664,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
}
/// <inheritdoc />
protected override async Task DisconnectImpl(CancellationToken cancellationToken)
protected override async ValueTask DisconnectImpl(CancellationToken cancellationToken)
{
Task<Result> localGatewayTask;
CancellationTokenSource localGatewayCts;
@@ -688,14 +689,14 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
}
/// <inheritdoc />
protected override async Task<Dictionary<Models.ChatChannel, IEnumerable<ChannelRepresentation>>> MapChannelsImpl(IEnumerable<Models.ChatChannel> channels, CancellationToken cancellationToken)
protected override async ValueTask<Dictionary<Models.ChatChannel, IEnumerable<ChannelRepresentation>>> MapChannelsImpl(IEnumerable<Models.ChatChannel> channels, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(channels);
var remapRequired = false;
var guildsClient = serviceProvider.GetRequiredService<IDiscordRestGuildAPI>();
async Task<Tuple<Models.ChatChannel, IEnumerable<ChannelRepresentation>>> GetModelChannelFromDBChannel(Models.ChatChannel channelFromDB)
async ValueTask<Tuple<Models.ChatChannel, IEnumerable<ChannelRepresentation>>> GetModelChannelFromDBChannel(Models.ChatChannel channelFromDB)
{
if (!channelFromDB.DiscordChannelId.HasValue)
throw new InvalidOperationException("ChatChannel missing DiscordChannelId!");
@@ -760,10 +761,13 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
var tasks = channels
.Where(x => x.DiscordChannelId != 0)
.Select(GetModelChannelFromDBChannel)
.ToList();
.Select(GetModelChannelFromDBChannel);
await Task.WhenAll(tasks);
var channelTuples = await ValueTaskExtensions.WhenAll(tasks.ToList());
var enumerator = channelTuples
.Where(x => x != null)
.ToList();
var channelIdZeroModel = channels.FirstOrDefault(x => x.DiscordChannelId == 0);
if (channelIdZeroModel != null)
@@ -773,7 +777,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
var unmappedTextChannels = allAccessibleChannels
.Where(x => !tasks.Any(task => task.Result != null && new Snowflake(task.Result.Item1.DiscordChannelId.Value) == x.ID));
async Task<Tuple<Models.ChatChannel, IEnumerable<ChannelRepresentation>>> CreateMappingsForUnmappedChannels()
async ValueTask<Tuple<Models.ChatChannel, IEnumerable<ChannelRepresentation>>> CreateMappingsForUnmappedChannels()
{
var unmappedTasks =
unmappedTextChannels.Select(
@@ -810,15 +814,10 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
}
var task = CreateMappingsForUnmappedChannels();
await task;
tasks.Add(task);
var tuple = await task;
enumerator.Add(tuple);
}
var enumerator = tasks
.Select(x => x.Result)
.Where(x => x != null)
.ToList();
lock (mappedChannels)
{
mappedChannels.Clear();
@@ -839,7 +838,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in an <see cref="IEnumerable{T}"/> of accessible and compatible <see cref="IChannel"/>s.</returns>
async Task<IEnumerable<IChannel>> GetAllAccessibleTextChannels(CancellationToken cancellationToken)
async ValueTask<IEnumerable<IChannel>> GetAllAccessibleTextChannels(CancellationToken cancellationToken)
{
var usersClient = serviceProvider.GetRequiredService<IDiscordRestUserAPI>();
var currentGuildsResponse = await usersClient.GetCurrentUserGuildsAsync(ct: cancellationToken);
@@ -853,7 +852,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
var guildsClient = serviceProvider.GetRequiredService<IDiscordRestGuildAPI>();
async Task<IEnumerable<IChannel>> GetGuildChannels(IPartialGuild guild)
async ValueTask<IEnumerable<IChannel>> GetGuildChannels(IPartialGuild guild)
{
var channelsTask = guildsClient.GetGuildChannelsAsync(guild.ID.Value, cancellationToken);
var threads = await guildsClient.ListActiveGuildThreadsAsync(guild.ID.Value, cancellationToken);
@@ -882,13 +881,12 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
}
var guildsChannelsTasks = currentGuildsResponse.Entity
.Select(GetGuildChannels)
.ToList();
.Select(GetGuildChannels);
await Task.WhenAll(guildsChannelsTasks);
var guildsChannels = await ValueTaskExtensions.WhenAll(guildsChannelsTasks, currentGuildsResponse.Entity.Count);
var allAccessibleChannels = guildsChannelsTasks
.SelectMany(task => task.Result)
var allAccessibleChannels = guildsChannels
.SelectMany(channels => channels)
.Where(guildChannel => SupportedGuildChannelTypes.Contains(guildChannel.Type));
return allAccessibleChannels;
@@ -43,23 +43,23 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the next available <see cref="Message"/> or <see langword="null"/> if the <see cref="IProvider"/> needed to reconnect.</returns>
/// <remarks>Note that private messages will come in the form of <see cref="ChannelRepresentation"/>s not returned in <see cref="MapChannels(IEnumerable{ChatChannel}, CancellationToken)"/>. Do not <see cref="IDisposable.Dispose"/> the <see cref="IProvider"/> on continuations run from the returned <see cref="Task"/>.</remarks>
/// <remarks>Note that private messages will come in the form of <see cref="ChannelRepresentation"/>s not returned in <see cref="MapChannels(IEnumerable{ChatChannel}, CancellationToken)"/>.</remarks>
Task<Message> NextMessage(CancellationToken cancellationToken);
/// <summary>
/// Gracefully disconnects the provider. Permanently stops the reconnection timer.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task Disconnect(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask Disconnect(CancellationToken cancellationToken);
/// <summary>
/// Get the <see cref="ChannelRepresentation"/>s for given <paramref name="channels"/>.
/// </summary>
/// <param name="channels">The <see cref="Api.Models.ChatChannel"/>s to map.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="Dictionary{TKey, TValue}"/> of the <see cref="ChatChannel"/>'s <see cref="ChannelRepresentation"/>s representing <paramref name="channels"/>.</returns>
Task<Dictionary<ChatChannel, IEnumerable<ChannelRepresentation>>> MapChannels(IEnumerable<ChatChannel> channels, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="Dictionary{TKey, TValue}"/> of the <see cref="ChatChannel"/>'s <see cref="ChannelRepresentation"/>s representing <paramref name="channels"/>.</returns>
ValueTask<Dictionary<ChatChannel, IEnumerable<ChannelRepresentation>>> MapChannels(IEnumerable<ChatChannel> channels, CancellationToken cancellationToken);
/// <summary>
/// Send a message to the <see cref="IProvider"/>.
@@ -68,8 +68,8 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
/// <param name="message">The <see cref="MessageContent"/>.</param>
/// <param name="channelId">The <see cref="ChannelRepresentation.RealId"/> to send to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task SendMessage(Message replyTo, MessageContent message, ulong channelId, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask SendMessage(Message replyTo, MessageContent message, ulong channelId, CancellationToken cancellationToken);
/// <summary>
/// Set the interval at which the provider starts jobs to try to reconnect.
@@ -90,8 +90,8 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
/// <param name="channelId">The <see cref="ChannelRepresentation.RealId"/> to send to.</param>
/// <param name="localCommitPushed"><see langword="true"/> if the local deployment commit was pushed to the remote repository.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="Func{T1, T2, TResult}"/> to call to update the message at the deployment's conclusion. Parameters: Error message if any, DreamMaker output if any. Returns another callback which should be called to mark the deployment as active.</returns>
Task<Func<string, string, Task<Func<bool, Task>>>> SendUpdateMessage(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="Func{T1, T2, TResult}"/> to call to update the message at the deployment's conclusion. Parameters: Error message if any, DreamMaker output if any. Returns another callback which should be called to mark the deployment as active.</returns>
ValueTask<Func<string, string, ValueTask<Func<bool, ValueTask>>>> SendUpdateMessage(
RevisionInformation revisionInformation,
Version byondVersion,
DateTimeOffset? estimatedCompletionTime,
@@ -88,7 +88,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
ulong channelIdCounter;
/// <summary>
/// The <see cref="Task"/> used for <see cref="IrcConnection.Listen(bool)"/>.
/// The <see cref="ValueTask"/> used for <see cref="IrcConnection.Listen(bool)"/>.
/// </summary>
Task listenTask;
@@ -164,11 +164,11 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
}
/// <inheritdoc />
public override Task SendMessage(Message replyTo, MessageContent message, ulong channelId, CancellationToken cancellationToken)
public override async ValueTask SendMessage(Message replyTo, MessageContent message, ulong channelId, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(message);
return Task.Factory.StartNew(
await Task.Factory.StartNew(
() =>
{
// IRC doesn't allow newlines
@@ -218,7 +218,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
}
/// <inheritdoc />
public override async Task<Func<string, string, Task<Func<bool, Task>>>> SendUpdateMessage(
public override async ValueTask<Func<string, string, ValueTask<Func<bool, ValueTask>>>> SendUpdateMessage(
Models.RevisionInformation revisionInformation,
Version byondVersion,
DateTimeOffset? estimatedCompletionTime,
@@ -292,15 +292,15 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
channelId,
cancellationToken);
return active => Task.CompletedTask;
return active => ValueTask.CompletedTask;
};
}
/// <inheritdoc />
protected override Task<Dictionary<Models.ChatChannel, IEnumerable<ChannelRepresentation>>> MapChannelsImpl(
protected override async ValueTask<Dictionary<Models.ChatChannel, IEnumerable<ChannelRepresentation>>> MapChannelsImpl(
IEnumerable<Models.ChatChannel> channels,
CancellationToken cancellationToken)
=> Task.Factory.StartNew(
=> await Task.Factory.StartNew(
() =>
{
if (channels.Any(x => x.IrcChannel == null))
@@ -371,7 +371,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
TaskScheduler.Current);
/// <inheritdoc />
protected override async Task Connect(CancellationToken cancellationToken)
protected override async ValueTask Connect(CancellationToken cancellationToken)
{
disconnecting = false;
cancellationToken.ThrowIfCancellationRequested();
@@ -460,7 +460,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
}
/// <inheritdoc />
protected override async Task DisconnectImpl(CancellationToken cancellationToken)
protected override async ValueTask DisconnectImpl(CancellationToken cancellationToken)
{
try
{
@@ -595,8 +595,8 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
/// Run SASL authentication on <see cref="client"/>.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task SaslAuthenticate(CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask SaslAuthenticate(CancellationToken cancellationToken)
{
client.WriteLine("CAP REQ :sasl", Priority.Critical); // needs to be put in the buffer before anything else
cancellationToken.ThrowIfCancellationRequested();
@@ -665,8 +665,8 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
/// Attempt to disconnect from IRC immediately.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task HardDisconnect(CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask HardDisconnect(CancellationToken cancellationToken)
{
if (!Connected)
{
@@ -84,7 +84,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
ChatBot = chatBot ?? throw new ArgumentNullException(nameof(chatBot));
messageQueue = new Queue<Message>();
nextMessage = new TaskCompletionSource();
nextMessage = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
initialConnectionTcs = new TaskCompletionSource();
reconnectTaskLock = new object();
@@ -112,7 +112,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
}
/// <inheritdoc />
public async Task Disconnect(CancellationToken cancellationToken)
public async ValueTask Disconnect(CancellationToken cancellationToken)
{
await StopReconnectionTimer();
@@ -128,7 +128,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
public void InitialMappingComplete() => initialConnectionTcs.TrySetResult();
/// <inheritdoc />
public async Task<Dictionary<ChatChannel, IEnumerable<ChannelRepresentation>>> MapChannels(IEnumerable<ChatChannel> channels, CancellationToken cancellationToken)
public async ValueTask<Dictionary<ChatChannel, IEnumerable<ChannelRepresentation>>> MapChannels(IEnumerable<ChatChannel> channels, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(channels);
@@ -178,10 +178,10 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
}
/// <inheritdoc />
public abstract Task SendMessage(Message replyTo, MessageContent message, ulong channelId, CancellationToken cancellationToken);
public abstract ValueTask SendMessage(Message replyTo, MessageContent message, ulong channelId, CancellationToken cancellationToken);
/// <inheritdoc />
public abstract Task<Func<string, string, Task<Func<bool, Task>>>> SendUpdateMessage(
public abstract ValueTask<Func<string, string, ValueTask<Func<bool, ValueTask>>>> SendUpdateMessage(
RevisionInformation revisionInformation,
Version byondVersion,
DateTimeOffset? estimatedCompletionTime,
@@ -195,23 +195,23 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
/// Attempt to connect the <see cref="Provider"/>.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
protected abstract Task Connect(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
protected abstract ValueTask Connect(CancellationToken cancellationToken);
/// <summary>
/// Gracefully disconnects the provider.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
protected abstract Task DisconnectImpl(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
protected abstract ValueTask DisconnectImpl(CancellationToken cancellationToken);
/// <summary>
/// Implementation of <see cref="MapChannels(IEnumerable{ChatChannel}, CancellationToken)"/>.
/// </summary>
/// <param name="channels">The <see cref="ChatChannel"/>s to map.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="Dictionary{TKey, TValue}"/> of the <see cref="ChatChannel"/>'s <see cref="ChannelRepresentation"/>s representing <paramref name="channels"/>.</returns>
protected abstract Task<Dictionary<ChatChannel, IEnumerable<ChannelRepresentation>>> MapChannelsImpl(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="Dictionary{TKey, TValue}"/> of the <see cref="ChatChannel"/>'s <see cref="ChannelRepresentation"/>s representing <paramref name="channels"/>.</returns>
protected abstract ValueTask<Dictionary<ChatChannel, IEnumerable<ChannelRepresentation>>> MapChannelsImpl(
IEnumerable<ChatChannel> channels,
CancellationToken cancellationToken);
@@ -244,7 +244,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
reconnectCts.Cancel();
reconnectCts.Dispose();
reconnectCts = null;
Task reconnectTask = this.reconnectTask;
var reconnectTask = this.reconnectTask;
this.reconnectTask = null;
return reconnectTask;
}
@@ -8,6 +8,7 @@ using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Tgstation.Server.Common.Extensions;
using Tgstation.Server.Host.Components.Deployment.Remote;
using Tgstation.Server.Host.Components.Events;
using Tgstation.Server.Host.Database;
@@ -128,7 +129,7 @@ namespace Tgstation.Server.Host.Components.Deployment
public void Dispose() => cleanupCts.Dispose(); // we don't dispose nextDmbProvider here, since it might be the only thing we have
/// <inheritdoc />
public async Task LoadCompileJob(CompileJob job, Action<bool> activationAction, CancellationToken cancellationToken)
public async ValueTask LoadCompileJob(CompileJob job, Action<bool> activationAction, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(job);
@@ -222,7 +223,7 @@ namespace Tgstation.Server.Host.Components.Deployment
/// <inheritdoc />
#pragma warning disable CA1506 // TODO: Decomplexify
public async Task<IDmbProvider> FromCompileJob(CompileJob compileJob, CancellationToken cancellationToken)
public async ValueTask<IDmbProvider> FromCompileJob(CompileJob compileJob, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(compileJob);
@@ -327,7 +328,7 @@ namespace Tgstation.Server.Host.Components.Deployment
/// <inheritdoc />
#pragma warning disable CA1506 // TODO: Decomplexify
public async Task CleanUnusedCompileJobs(CancellationToken cancellationToken)
public async ValueTask CleanUnusedCompileJobs(CancellationToken cancellationToken)
{
List<long> jobIdsToSkip;
@@ -420,7 +421,7 @@ namespace Tgstation.Server.Host.Components.Deployment
{
try
{
await Task.WhenAll(deleteTask, deploymentJob);
await ValueTaskExtensions.WhenAll(deleteTask, deploymentJob);
}
catch (Exception ex)
{
@@ -453,8 +454,8 @@ namespace Tgstation.Server.Host.Components.Deployment
/// </summary>
/// <param name="directory">The directory to cleanup.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for this <see cref="Task"/>.</param>
/// <returns>The deletion <see cref="Task"/>.</returns>
async Task DeleteCompileJobContent(string directory, CancellationToken cancellationToken)
/// <returns>The deletion <see cref="ValueTask"/>.</returns>
async ValueTask DeleteCompileJobContent(string directory, CancellationToken cancellationToken)
{
// Then call the cleanup event, waiting here first
await eventConsumer.HandleEvent(EventType.DeploymentCleanup, new List<string> { ioManager.ResolvePath(directory) }, true, cancellationToken);
@@ -10,6 +10,7 @@ using Microsoft.Extensions.Logging;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Models.Internal;
using Tgstation.Server.Common.Extensions;
using Tgstation.Server.Host.Components.Byond;
using Tgstation.Server.Host.Components.Chat;
using Tgstation.Server.Host.Components.Deployment.Remote;
@@ -192,7 +193,7 @@ namespace Tgstation.Server.Host.Components.Deployment
/// <inheritdoc />
#pragma warning disable CA1506
public async Task DeploymentProcess(
public async ValueTask DeploymentProcess(
Models.Job job,
IDatabaseContextFactory databaseContextFactory,
JobProgressReporter progressReporter,
@@ -390,7 +391,7 @@ namespace Tgstation.Server.Host.Components.Deployment
try
{
await Task.WhenAll(commentsTask, eventTask);
await ValueTaskExtensions.WhenAll(commentsTask, eventTask);
}
catch (Exception ex)
{
@@ -421,8 +422,8 @@ namespace Tgstation.Server.Host.Components.Deployment
/// </summary>
/// <param name="databaseContext">The <see cref="IDatabaseContext"/> to retrieve previous deployment <see cref="Job"/>s from.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the average <see cref="TimeSpan"/> of the 10 previous deployments or <see langword="null"/> if there are none.</returns>
async Task<TimeSpan?> CalculateExpectedDeploymentTime(IDatabaseContext databaseContext, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the average <see cref="TimeSpan"/> of the 10 previous deployments or <see langword="null"/> if there are none.</returns>
async ValueTask<TimeSpan?> CalculateExpectedDeploymentTime(IDatabaseContext databaseContext, CancellationToken cancellationToken)
{
var previousCompileJobs = await databaseContext
.CompileJobs
@@ -461,8 +462,8 @@ namespace Tgstation.Server.Host.Components.Deployment
/// <param name="estimatedDuration">The optional estimated <see cref="TimeSpan"/> of the compilation.</param>
/// <param name="localCommitExistsOnRemote">Whether or not the <paramref name="repository"/>'s current commit exists on the remote repository.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the completed <see cref="CompileJob"/>.</returns>
async Task<Models.CompileJob> Compile(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the completed <see cref="CompileJob"/>.</returns>
async ValueTask<Models.CompileJob> Compile(
Models.RevisionInformation revisionInformation,
Api.Models.Internal.DreamMakerSettings dreamMakerSettings,
DreamDaemonLaunchParameters launchParameters,
@@ -556,8 +557,8 @@ namespace Tgstation.Server.Host.Components.Deployment
/// <param name="repository">The <see cref="IRepository"/> to use.</param>
/// <param name="remoteDeploymentManager">The <see cref="IRemoteDeploymentManager"/> to use.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task RunCompileJob(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask RunCompileJob(
JobProgressReporter progressReporter,
Models.CompileJob job,
Api.Models.Internal.DreamMakerSettings dreamMakerSettings,
@@ -710,8 +711,8 @@ namespace Tgstation.Server.Host.Components.Deployment
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> to report progress of the operation.</param>
/// <param name="estimatedDuration">A <see cref="TimeSpan"/> representing the duration to give progress over if any.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task ProgressTask(JobProgressReporter progressReporter, TimeSpan? estimatedDuration, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask ProgressTask(JobProgressReporter progressReporter, TimeSpan? estimatedDuration, CancellationToken cancellationToken)
{
double? lastReport = estimatedDuration.HasValue ? 0 : null;
progressReporter.ReportProgress(lastReport);
@@ -773,8 +774,8 @@ namespace Tgstation.Server.Host.Components.Deployment
/// <param name="requireValidate">If the API validation is required to complete the deployment.</param>
/// <param name="logOutput">If output should be logged to the DreamDaemon Diagnostics folder.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task VerifyApi(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask VerifyApi(
uint timeout,
DreamDaemonSecurity securityLevel,
Models.CompileJob job,
@@ -855,8 +856,8 @@ namespace Tgstation.Server.Host.Components.Deployment
/// <param name="dreamMakerPath">The path to the DreamMaker executable.</param>
/// <param name="job">The <see cref="CompileJob"/> for the operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task<int> RunDreamMaker(string dreamMakerPath, Models.CompileJob job, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask<int> RunDreamMaker(string dreamMakerPath, Models.CompileJob job, CancellationToken cancellationToken)
{
await using var dm = processExecutor.LaunchProcess(
dreamMakerPath,
@@ -886,8 +887,8 @@ namespace Tgstation.Server.Host.Components.Deployment
/// </summary>
/// <param name="job">The <see cref="CompileJob"/> for the operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task ModifyDme(Models.CompileJob job, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask ModifyDme(Models.CompileJob job, CancellationToken cancellationToken)
{
var dmeFileName = String.Join('.', job.DmeName, DmeExtension);
var dmePath = ioManager.ConcatPath(job.DirectoryName.ToString(), dmeFileName);
@@ -950,10 +951,10 @@ namespace Tgstation.Server.Host.Components.Deployment
/// <param name="job">The running <see cref="CompileJob"/>.</param>
/// <param name="remoteDeploymentManager">The <see cref="IRemoteDeploymentManager"/> associated with the <paramref name="job"/>.</param>
/// <param name="exception">The <see cref="Exception"/> that was thrown.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task CleanupFailedCompile(Models.CompileJob job, IRemoteDeploymentManager remoteDeploymentManager, Exception exception)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask CleanupFailedCompile(Models.CompileJob job, IRemoteDeploymentManager remoteDeploymentManager, Exception exception)
{
async Task CleanDir()
async ValueTask CleanDir()
{
logger.LogTrace("Cleaning compile directory...");
var jobPath = job.DirectoryName.ToString();
@@ -970,7 +971,7 @@ namespace Tgstation.Server.Host.Components.Deployment
}
// DCT: None available
await Task.WhenAll(
return ValueTaskExtensions.WhenAll(
CleanDir(),
remoteDeploymentManager.FailDeployment(
job,
@@ -17,7 +17,7 @@ namespace Tgstation.Server.Host.Components.Deployment
/// <param name="job">The <see cref="CompileJob"/> to load.</param>
/// <param name="activationAction">An <see cref="Action{T1}"/> to be called when the <see cref="CompileJob"/> becomes active or is discarded with <see langword="true"/> or <see langword="false"/> respectively.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task LoadCompileJob(CompileJob job, Action<bool> activationAction, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask LoadCompileJob(CompileJob job, Action<bool> activationAction, CancellationToken cancellationToken);
}
}
@@ -34,14 +34,14 @@ namespace Tgstation.Server.Host.Components.Deployment
/// </summary>
/// <param name="compileJob">The <see cref="CompileJob"/> to make the <see cref="IDmbProvider"/> for.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a new <see cref="IDmbProvider"/> representing the <see cref="CompileJob"/> on success, <see langword="null"/> on failure.</returns>
Task<IDmbProvider> FromCompileJob(CompileJob compileJob, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a new <see cref="IDmbProvider"/> representing the <see cref="CompileJob"/> on success, <see langword="null"/> on failure.</returns>
ValueTask<IDmbProvider> FromCompileJob(CompileJob compileJob, CancellationToken cancellationToken);
/// <summary>
/// Deletes all compile jobs that are inactive in the Game folder.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task CleanUnusedCompileJobs(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask CleanUnusedCompileJobs(CancellationToken cancellationToken);
}
}
@@ -19,8 +19,8 @@ namespace Tgstation.Server.Host.Components.Deployment
/// <param name="databaseContextFactory">The <see cref="IDatabaseContextFactory"/> for the operation.</param>
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> to report compilation progress.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task DeploymentProcess(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask DeploymentProcess(
Job job,
IDatabaseContextFactory databaseContextFactory,
JobProgressReporter progressReporter,
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Tgstation.Server.Common.Extensions;
using Tgstation.Server.Host.Components.Repository;
using Tgstation.Server.Host.Models;
@@ -49,7 +50,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public async Task PostDeploymentComments(
public async ValueTask PostDeploymentComments(
CompileJob compileJob,
RevisionInformation previousRevisionInformation,
RepositorySettings repositorySettings,
@@ -102,7 +103,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
removedTestMerges.Count,
updatedTestMerges.Count);
var tasks = new List<Task>(addedTestMerges.Count + updatedTestMerges.Count + removedTestMerges.Count);
var tasks = new List<ValueTask>(addedTestMerges.Count + updatedTestMerges.Count + removedTestMerges.Count);
foreach (var addedTestMerge in addedTestMerges)
tasks.Add(
CommentOnTestMergeSource(
@@ -146,11 +147,11 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
cancellationToken));
if (tasks.Any())
await Task.WhenAll(tasks);
await ValueTaskExtensions.WhenAll(tasks);
}
/// <inheritdoc />
public Task ApplyDeployment(CompileJob compileJob, CancellationToken cancellationToken)
public ValueTask ApplyDeployment(CompileJob compileJob, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(compileJob);
@@ -161,10 +162,10 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public abstract Task FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken);
public abstract ValueTask FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken);
/// <inheritdoc />
public Task MarkInactive(CompileJob compileJob, CancellationToken cancellationToken)
public ValueTask MarkInactive(CompileJob compileJob, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(compileJob);
@@ -175,14 +176,14 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public abstract Task<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
public abstract ValueTask<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
IRepository repository,
RepositorySettings repositorySettings,
RevisionInformation revisionInformation,
CancellationToken cancellationToken);
/// <inheritdoc />
public Task StageDeployment(CompileJob compileJob, Action<bool> activationCallback, CancellationToken cancellationToken)
public ValueTask StageDeployment(CompileJob compileJob, Action<bool> activationCallback, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(compileJob);
@@ -193,7 +194,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public abstract Task StartDeployment(
public abstract ValueTask StartDeployment(
Api.Models.Internal.IGitRemoteInformation remoteInformation,
CompileJob compileJob,
CancellationToken cancellationToken);
@@ -203,24 +204,24 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// </summary>
/// <param name="compileJob">The staged <see cref="CompileJob"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
protected abstract Task StageDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
protected abstract ValueTask StageDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken);
/// <summary>
/// Implementation of <see cref="ApplyDeployment(CompileJob, CancellationToken)"/>.
/// </summary>
/// <param name="compileJob">The <see cref="CompileJob"/> being applied.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
protected abstract Task ApplyDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
protected abstract ValueTask ApplyDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken);
/// <summary>
/// Implementation of <see cref="MarkInactive(CompileJob, CancellationToken)"/>.
/// </summary>
/// <param name="compileJob">The inactive <see cref="CompileJob"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
protected abstract Task MarkInactiveImpl(CompileJob compileJob, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
protected abstract ValueTask MarkInactiveImpl(CompileJob compileJob, CancellationToken cancellationToken);
/// <summary>
/// Formats a comment for a given <paramref name="testMerge"/>.
@@ -231,7 +232,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="remoteRepositoryOwner">The <see cref="Api.Models.Internal.IGitRemoteInformation.RemoteRepositoryOwner"/>.</param>
/// <param name="remoteRepositoryName">The <see cref="Api.Models.Internal.IGitRemoteInformation.RemoteRepositoryName"/>.</param>
/// <param name="updated">If <see langword="false"/> <paramref name="testMerge"/> is new, otherwise it has been updated to a different <see cref="Api.Models.TestMergeParameters.TargetCommitSha"/>.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
/// <returns>A formatted <see cref="string"/> for posting a informative comment about the <paramref name="testMerge"/>.</returns>
protected abstract string FormatTestMerge(
RepositorySettings repositorySettings,
CompileJob compileJob,
@@ -249,8 +250,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="comment">The comment to post.</param>
/// <param name="testMergeNumber">The <see cref="Api.Models.TestMergeParameters.Number"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
protected abstract Task CommentOnTestMergeSource(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
protected abstract ValueTask CommentOnTestMergeSource(
RepositorySettings repositorySettings,
string remoteRepositoryOwner,
string remoteRepositoryName,
@@ -55,7 +55,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public override async Task StartDeployment(
public override async ValueTask StartDeployment(
Api.Models.Internal.IGitRemoteInformation remoteInformation,
CompileJob compileJob,
CancellationToken cancellationToken)
@@ -148,7 +148,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public override Task FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken)
public override ValueTask FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken)
=> UpdateDeployment(
compileJob,
errorMessage,
@@ -156,7 +156,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
cancellationToken);
/// <inheritdoc />
public override async Task<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
public override async ValueTask<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
IRepository repository,
RepositorySettings repositorySettings,
RevisionInformation revisionInformation,
@@ -191,7 +191,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
var newList = revisionInformation.ActiveTestMerges.Select(x => x.TestMerge).ToList();
PullRequest lastMerged = null;
async Task CheckRemovePR(Task<PullRequest> task)
async ValueTask CheckRemovePR(Task<PullRequest> task)
{
var pr = await task;
if (!pr.Merged)
@@ -215,7 +215,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
protected override Task StageDeploymentImpl(
protected override ValueTask StageDeploymentImpl(
CompileJob compileJob,
CancellationToken cancellationToken)
=> UpdateDeployment(
@@ -225,7 +225,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
cancellationToken);
/// <inheritdoc />
protected override Task ApplyDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken)
protected override ValueTask ApplyDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken)
=> UpdateDeployment(
compileJob,
"The deployment is now live on the server.",
@@ -233,7 +233,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
cancellationToken);
/// <inheritdoc />
protected override Task MarkInactiveImpl(CompileJob compileJob, CancellationToken cancellationToken)
protected override ValueTask MarkInactiveImpl(CompileJob compileJob, CancellationToken cancellationToken)
=> UpdateDeployment(
compileJob,
"The deployment has been superceeded.",
@@ -241,7 +241,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
cancellationToken);
/// <inheritdoc />
protected override async Task CommentOnTestMergeSource(
protected override async ValueTask CommentOnTestMergeSource(
RepositorySettings repositorySettings,
string remoteRepositoryOwner,
string remoteRepositoryName,
@@ -302,8 +302,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="description">A description of the update.</param>
/// <param name="deploymentState">The new <see cref="DeploymentState"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task UpdateDeployment(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask UpdateDeployment(
CompileJob compileJob,
string description,
DeploymentState deploymentState,
@@ -36,7 +36,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public override async Task<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
public override async ValueTask<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
IRepository repository,
RepositorySettings repositorySettings,
RevisionInformation revisionInformation,
@@ -76,7 +76,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
var newList = revisionInformation.ActiveTestMerges.Select(x => x.TestMerge).ToList();
MergeRequest lastMerged = null;
async Task CheckRemoveMR(Task<MergeRequest> task)
async ValueTask CheckRemoveMR(Task<MergeRequest> task)
{
var mergeRequest = await task;
if (mergeRequest.State != MergeRequestState.Merged)
@@ -100,30 +100,30 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public override Task FailDeployment(
public override ValueTask FailDeployment(
CompileJob compileJob,
string errorMessage,
CancellationToken cancellationToken) => Task.CompletedTask;
CancellationToken cancellationToken) => ValueTask.CompletedTask;
/// <inheritdoc />
public override Task StartDeployment(
public override ValueTask StartDeployment(
Api.Models.Internal.IGitRemoteInformation remoteInformation,
CompileJob compileJob,
CancellationToken cancellationToken) => Task.CompletedTask;
CancellationToken cancellationToken) => ValueTask.CompletedTask;
/// <inheritdoc />
protected override Task ApplyDeploymentImpl(
protected override ValueTask ApplyDeploymentImpl(
CompileJob compileJob,
CancellationToken cancellationToken) => Task.CompletedTask;
CancellationToken cancellationToken) => ValueTask.CompletedTask;
/// <inheritdoc />
protected override Task StageDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken) => Task.CompletedTask;
protected override ValueTask StageDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken) => ValueTask.CompletedTask;
/// <inheritdoc />
protected override Task MarkInactiveImpl(CompileJob compileJob, CancellationToken cancellationToken) => Task.CompletedTask;
protected override ValueTask MarkInactiveImpl(CompileJob compileJob, CancellationToken cancellationToken) => ValueTask.CompletedTask;
/// <inheritdoc />
protected override async Task CommentOnTestMergeSource(
protected override async ValueTask CommentOnTestMergeSource(
RepositorySettings repositorySettings,
string remoteRepositoryOwner,
string remoteRepositoryName,
@@ -19,8 +19,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="remoteInformation">The <see cref="Api.Models.Internal.IGitRemoteInformation"/> of the repository being deployed.</param>
/// <param name="compileJob">The active <see cref="CompileJob"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task StartDeployment(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask StartDeployment(
Api.Models.Internal.IGitRemoteInformation remoteInformation,
CompileJob compileJob,
CancellationToken cancellationToken);
@@ -31,8 +31,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="compileJob">The staged <see cref="CompileJob"/>.</param>
/// <param name="activationCallback">An optional <see cref="Action{T1}"/> to be called when the <see cref="CompileJob"/> becomes active or is discarded with <see langword="true"/> or <see langword="false"/> respectively.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task StageDeployment(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask StageDeployment(
CompileJob compileJob,
Action<bool> activationCallback,
CancellationToken cancellationToken);
@@ -42,8 +42,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// </summary>
/// <param name="compileJob">The <see cref="CompileJob"/> being applied.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task ApplyDeployment(CompileJob compileJob, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask ApplyDeployment(CompileJob compileJob, CancellationToken cancellationToken);
/// <summary>
/// Fail a deployment for a given <paramref name="compileJob"/>.
@@ -51,8 +51,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="compileJob">The failed <see cref="CompileJob"/>.</param>
/// <param name="errorMessage">The error message.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken);
/// <summary>
/// Mark the deplotment for a given <paramref name="compileJob"/> as inactive.
@@ -60,7 +60,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="compileJob">The inactive <see cref="CompileJob"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task MarkInactive(CompileJob compileJob, CancellationToken cancellationToken);
ValueTask MarkInactive(CompileJob compileJob, CancellationToken cancellationToken);
/// <summary>
/// Post deployment comments to the test merge ticket.
@@ -71,8 +71,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="repoOwner">The GitHub repostiory owner.</param>
/// <param name="repoName">The GitHub repostiory name.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task PostDeploymentComments(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask PostDeploymentComments(
CompileJob compileJob,
RevisionInformation previousRevisionInformation,
RepositorySettings repositorySettings,
@@ -87,8 +87,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="repositorySettings">The <see cref="RepositorySettings"/>.</param>
/// <param name="revisionInformation">The current <see cref="RevisionInformation"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="IReadOnlyCollection{T}"/> of <see cref="TestMerge"/>s that should remain the new <see cref="RevisionInformation"/>.</returns>
Task<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="IReadOnlyCollection{T}"/> of <see cref="TestMerge"/>s that should remain the new <see cref="RevisionInformation"/>.</returns>
ValueTask<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
IRepository repository,
RepositorySettings repositorySettings,
RevisionInformation revisionInformation,
@@ -32,31 +32,31 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public override Task FailDeployment(Models.CompileJob compileJob, string errorMessage, CancellationToken cancellationToken)
public override ValueTask FailDeployment(Models.CompileJob compileJob, string errorMessage, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public override Task<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(IRepository repository, Models.RepositorySettings repositorySettings, Models.RevisionInformation revisionInformation, CancellationToken cancellationToken)
=> Task.FromResult<IReadOnlyCollection<TestMerge>>(Array.Empty<TestMerge>());
public override ValueTask<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(IRepository repository, Models.RepositorySettings repositorySettings, Models.RevisionInformation revisionInformation, CancellationToken cancellationToken)
=> ValueTask.FromResult<IReadOnlyCollection<TestMerge>>(Array.Empty<TestMerge>());
/// <inheritdoc />
public override Task StartDeployment(IGitRemoteInformation remoteInformation, Models.CompileJob compileJob, CancellationToken cancellationToken)
=> Task.CompletedTask;
public override ValueTask StartDeployment(IGitRemoteInformation remoteInformation, Models.CompileJob compileJob, CancellationToken cancellationToken)
=> ValueTask.CompletedTask;
/// <inheritdoc />
protected override Task ApplyDeploymentImpl(Models.CompileJob compileJob, CancellationToken cancellationToken) => Task.CompletedTask;
protected override ValueTask ApplyDeploymentImpl(Models.CompileJob compileJob, CancellationToken cancellationToken) => ValueTask.CompletedTask;
/// <inheritdoc />
protected override Task CommentOnTestMergeSource(
protected override ValueTask CommentOnTestMergeSource(
Models.RepositorySettings repositorySettings,
string remoteRepositoryOwner,
string remoteRepositoryName,
string comment,
int testMergeNumber,
CancellationToken cancellationToken)
=> Task.CompletedTask;
=> ValueTask.CompletedTask;
/// <inheritdoc />
protected override string FormatTestMerge(
@@ -69,12 +69,12 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
=> String.Empty;
/// <inheritdoc />
protected override Task MarkInactiveImpl(Models.CompileJob compileJob, CancellationToken cancellationToken)
protected override ValueTask MarkInactiveImpl(Models.CompileJob compileJob, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <inheritdoc />
protected override Task StageDeploymentImpl(Models.CompileJob compileJob, CancellationToken cancellationToken) => Task.CompletedTask;
protected override ValueTask StageDeploymentImpl(Models.CompileJob compileJob, CancellationToken cancellationToken) => ValueTask.CompletedTask;
}
}
@@ -74,8 +74,8 @@ namespace Tgstation.Server.Host.Components.Deployment
/// Make the <see cref="SwappableDmbProvider"/> active by replacing the live link with our <see cref="CompileJob"/>.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
public async Task MakeActive(CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
public async ValueTask MakeActive(CancellationToken cancellationToken)
{
if (Interlocked.Exchange(ref swapped, 1) != 0)
throw new InvalidOperationException("Already swapped!");
@@ -31,7 +31,7 @@ namespace Tgstation.Server.Host.Components.Events
}
/// <inheritdoc />
public async Task HandleEvent(EventType eventType, IEnumerable<string> parameters, bool deploymentPipeline, CancellationToken cancellationToken)
public async ValueTask HandleEvent(EventType eventType, IEnumerable<string> parameters, bool deploymentPipeline, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(parameters);
@@ -16,7 +16,7 @@ namespace Tgstation.Server.Host.Components.Events
/// <param name="parameters">An <see cref="IEnumerable{T}"/> of <see cref="string"/> parameters for <paramref name="eventType"/>.</param>
/// <param name="deploymentPipeline">If this event is part of the deployment pipeline.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task HandleEvent(EventType eventType, IEnumerable<string> parameters, bool deploymentPipeline, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask HandleEvent(EventType eventType, IEnumerable<string> parameters, bool deploymentPipeline, CancellationToken cancellationToken);
}
}
@@ -48,7 +48,7 @@ namespace Tgstation.Server.Host.Components
/// Change the <see cref="Api.Models.Instance.AutoUpdateInterval"/> for the <see cref="IInstanceCore"/>.
/// </summary>
/// <param name="newInterval">The new auto update inteval.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task SetAutoUpdateInterval(uint newInterval);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask SetAutoUpdateInterval(uint newInterval);
}
}
@@ -15,8 +15,8 @@ namespace Tgstation.Server.Host.Components
/// </summary>
/// <param name="bridgeRegistrar">The <see cref="IBridgeRegistrar"/> to use.</param>
/// <param name="metadata">The <see cref="Models.Instance"/>.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a new <see cref="IInstance"/>.</returns>
Task<IInstance> CreateInstance(IBridgeRegistrar bridgeRegistrar, Models.Instance metadata);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a new <see cref="IInstance"/>.</returns>
ValueTask<IInstance> CreateInstance(IBridgeRegistrar bridgeRegistrar, Models.Instance metadata);
/// <summary>
/// Create an <see cref="IIOManager"/> that resolves to the "Game" directory of the <see cref="Models.Instance"/> defined by <paramref name="metadata"/>.
@@ -15,8 +15,8 @@ namespace Tgstation.Server.Host.Components
/// </summary>
/// <param name="metadata">The <see cref="Models.Instance"/> of the desired <see cref="IInstance"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task OnlineInstance(Models.Instance metadata, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask OnlineInstance(Models.Instance metadata, CancellationToken cancellationToken);
/// <summary>
/// Offline an <see cref="IInstance"/>.
@@ -24,8 +24,8 @@ namespace Tgstation.Server.Host.Components
/// <param name="metadata">The <see cref="Models.Instance"/> of the desired <see cref="IInstance"/>.</param>
/// <param name="user">The <see cref="User"/> performing the operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task OfflineInstance(Models.Instance metadata, User user, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask OfflineInstance(Models.Instance metadata, User user, CancellationToken cancellationToken);
/// <summary>
/// Move an <see cref="IInstance"/>.
@@ -33,7 +33,7 @@ namespace Tgstation.Server.Host.Components
/// <param name="metadata">The <see cref="Models.Instance"/> of the desired <see cref="IInstance"/> with the updated path.</param>
/// <param name="oldPath">The old path of the <see cref="IInstance"/>. <paramref name="metadata"/> will have this set on <see cref="Api.Models.Instance.Path"/> if the operation fails.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task MoveInstance(Models.Instance metadata, string oldPath, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask MoveInstance(Models.Instance metadata, string oldPath, CancellationToken cancellationToken);
}
}
@@ -13,7 +13,7 @@ namespace Tgstation.Server.Host.Components
/// </summary>
/// <param name="newInstanceName">The new <see cref="Api.Models.NamedEntity.Name"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task InstanceRenamed(string newInstanceName, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask InstanceRenamed(string newInstanceName, CancellationToken cancellationToken);
}
}
@@ -167,7 +167,7 @@ namespace Tgstation.Server.Host.Components
}
/// <inheritdoc />
public Task InstanceRenamed(string newName, CancellationToken cancellationToken)
public ValueTask InstanceRenamed(string newName, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(newName);
if (String.IsNullOrWhiteSpace(newName))
@@ -183,11 +183,11 @@ namespace Tgstation.Server.Host.Components
using (LogContext.PushProperty(SerilogContextHelper.InstanceIdContextProperty, metadata.Id))
{
await Task.WhenAll(
SetAutoUpdateInterval(metadata.AutoUpdateInterval.Value),
Configuration.StartAsync(cancellationToken),
ByondManager.StartAsync(cancellationToken),
Chat.StartAsync(cancellationToken),
dmbFactory.StartAsync(cancellationToken));
SetAutoUpdateInterval(metadata.AutoUpdateInterval.Value).AsTask(),
Configuration.StartAsync(cancellationToken),
ByondManager.StartAsync(cancellationToken),
Chat.StartAsync(cancellationToken),
dmbFactory.StartAsync(cancellationToken));
// dependent on so many things, its just safer this way
await Watchdog.StartAsync(cancellationToken);
@@ -213,7 +213,7 @@ namespace Tgstation.Server.Host.Components
}
/// <inheritdoc />
public async Task SetAutoUpdateInterval(uint newInterval)
public async ValueTask SetAutoUpdateInterval(uint newInterval)
{
Task toWait;
lock (timerLock)
@@ -263,9 +263,9 @@ namespace Tgstation.Server.Host.Components
/// <param name="job">The <see cref="Job"/> being run.</param>
/// <param name="progressReporter">The progress reporter action for the <paramref name="job"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
#pragma warning disable CA1502 // Cyclomatic complexity
Task RepositoryAutoUpdateJob(
ValueTask RepositoryAutoUpdateJob(
IInstanceCore core,
IDatabaseContextFactory databaseContextFactory,
Job job,
@@ -317,7 +317,7 @@ namespace Tgstation.Server.Host.Components
var hasDbChanges = false;
RevisionInformation currentRevInfo = null;
Models.Instance attachedInstance = null;
async Task UpdateRevInfo(string currentHead, bool onOrigin, IEnumerable<TestMerge> updatedTestMerges)
async ValueTask UpdateRevInfo(string currentHead, bool onOrigin, IEnumerable<TestMerge> updatedTestMerges)
{
if (currentRevInfo == null)
{
@@ -257,7 +257,7 @@ namespace Tgstation.Server.Host.Components
/// <inheritdoc />
#pragma warning disable CA1506 // TODO: Decomplexify
public async Task<IInstance> CreateInstance(IBridgeRegistrar bridgeRegistrar, Models.Instance metadata)
public async ValueTask<IInstance> CreateInstance(IBridgeRegistrar bridgeRegistrar, Models.Instance metadata)
{
ArgumentNullException.ThrowIfNull(bridgeRegistrar);
ArgumentNullException.ThrowIfNull(metadata);
@@ -11,6 +11,7 @@ using Microsoft.Extensions.Options;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Common;
using Tgstation.Server.Common.Extensions;
using Tgstation.Server.Host.Components.Interop;
using Tgstation.Server.Host.Components.Interop.Bridge;
using Tgstation.Server.Host.Configuration;
@@ -246,7 +247,7 @@ namespace Tgstation.Server.Host.Components
}
/// <inheritdoc />
public async Task MoveInstance(Models.Instance instance, string oldPath, CancellationToken cancellationToken)
public async ValueTask MoveInstance(Models.Instance instance, string oldPath, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(oldPath);
@@ -274,7 +275,7 @@ namespace Tgstation.Server.Host.Components
logger.LogDebug("Reverting instance {instanceId}'s path to {oldPath} in the DB...", instance.Id, oldPath);
// DCT: Operation must always run
await databaseContextFactory.UseContext(db =>
await databaseContextFactory.UseContextTaskReturn(db =>
{
var targetInstance = new Models.Instance
{
@@ -317,7 +318,7 @@ namespace Tgstation.Server.Host.Components
}
/// <inheritdoc />
public async Task OfflineInstance(Models.Instance metadata, Models.User user, CancellationToken cancellationToken)
public async ValueTask OfflineInstance(Models.Instance metadata, Models.User user, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(metadata);
@@ -342,7 +343,7 @@ namespace Tgstation.Server.Host.Components
await container.OnZeroReferences.WaitAsync(cancellationToken);
// we are the one responsible for cancelling his jobs
var tasks = new List<Task>();
var tasks = new List<ValueTask<Models.Job>>();
await databaseContextFactory.UseContext(
async db =>
{
@@ -359,7 +360,7 @@ namespace Tgstation.Server.Host.Components
tasks.Add(jobService.CancelJob(job, user, true, cancellationToken));
});
await Task.WhenAll(tasks);
await ValueTaskExtensions.WhenAll(tasks);
}
catch
{
@@ -383,7 +384,7 @@ namespace Tgstation.Server.Host.Components
}
/// <inheritdoc />
public async Task OnlineInstance(Models.Instance metadata, CancellationToken cancellationToken)
public async ValueTask OnlineInstance(Models.Instance metadata, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(metadata);
@@ -459,7 +460,7 @@ namespace Tgstation.Server.Host.Components
var instanceFactoryStopTask = instanceFactory.StopAsync(cancellationToken);
await jobService.StopAsync(cancellationToken);
async Task OfflineInstanceImmediate(IInstance instance, CancellationToken cancellationToken)
async ValueTask OfflineInstanceImmediate(IInstance instance, CancellationToken cancellationToken)
{
try
{
@@ -471,7 +472,7 @@ namespace Tgstation.Server.Host.Components
}
}
await Task.WhenAll(instances.Select(x => OfflineInstanceImmediate(x.Value.Instance, cancellationToken)));
await ValueTaskExtensions.WhenAll(instances.Select(x => OfflineInstanceImmediate(x.Value.Instance, cancellationToken)));
await instanceFactoryStopTask;
await swarmServiceController.Shutdown(cancellationToken);
@@ -489,7 +490,7 @@ namespace Tgstation.Server.Host.Components
}
/// <inheritdoc />
public async Task<BridgeResponse> ProcessBridgeRequest(BridgeParameters parameters, CancellationToken cancellationToken)
public async ValueTask<BridgeResponse> ProcessBridgeRequest(BridgeParameters parameters, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(parameters);
@@ -569,8 +570,9 @@ namespace Tgstation.Server.Host.Components
await InitializeSwarm(cancellationToken);
List<Models.Instance> dbInstances = null;
var instanceEnumeration = databaseContextFactory.UseContext(
async databaseContext => dbInstances = await databaseContext
async ValueTask EnumerateInstances(IDatabaseContext databaseContext)
=> dbInstances = await databaseContext
.Instances
.AsQueryable()
.Where(x => x.Online.Value && x.SwarmIdentifer == swarmConfiguration.Identifier)
@@ -578,12 +580,14 @@ namespace Tgstation.Server.Host.Components
.Include(x => x.ChatSettings)
.ThenInclude(x => x.Channels)
.Include(x => x.DreamDaemonSettings)
.ToListAsync(cancellationToken));
.ToListAsync(cancellationToken);
var instanceEnumeration = databaseContextFactory.UseContext(EnumerateInstances);
var factoryStartup = instanceFactory.StartAsync(cancellationToken);
var jobManagerStartup = jobService.StartAsync(cancellationToken);
await Task.WhenAll(instanceEnumeration, factoryStartup, jobManagerStartup);
await Task.WhenAll(instanceEnumeration.AsTask(), factoryStartup, jobManagerStartup);
var instanceOnliningTasks = dbInstances.Select(
async metadata =>
@@ -646,8 +650,8 @@ namespace Tgstation.Server.Host.Components
/// Initializes the connection to the TGS swarm.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task InitializeSwarm(CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask InitializeSwarm(CancellationToken cancellationToken)
{
SwarmRegistrationResult registrationResult;
do
@@ -48,10 +48,10 @@ namespace Tgstation.Server.Host.Components
}
/// <inheritdoc />
public Task InstanceRenamed(string newInstanceName, CancellationToken cancellationToken) => Instance.InstanceRenamed(newInstanceName, cancellationToken);
public ValueTask InstanceRenamed(string newInstanceName, CancellationToken cancellationToken) => Instance.InstanceRenamed(newInstanceName, cancellationToken);
/// <inheritdoc />
public Task SetAutoUpdateInterval(uint newInterval) => Instance.SetAutoUpdateInterval(newInterval);
public ValueTask SetAutoUpdateInterval(uint newInterval) => Instance.SetAutoUpdateInterval(newInterval);
/// <inheritdoc />
public CompileJob LatestCompileJob() => Instance.LatestCompileJob();
@@ -13,7 +13,7 @@ namespace Tgstation.Server.Host.Components.Interop.Bridge
/// </summary>
/// <param name="parameters">The <see cref="BridgeParameters"/> to handle.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="BridgeResponse"/> for the request or <see langword="null"/> if the request could not be dispatched.</returns>
Task<BridgeResponse> ProcessBridgeRequest(BridgeParameters parameters, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="BridgeResponse"/> for the request or <see langword="null"/> if the request could not be dispatched.</returns>
ValueTask<BridgeResponse> ProcessBridgeRequest(BridgeParameters parameters, CancellationToken cancellationToken);
}
}
@@ -63,9 +63,9 @@ namespace Tgstation.Server.Host.Components.Interop
/// <param name="chunkErrorCallback">The callback that generates a <typeparamref name="TResponse"/> for a given error.</param>
/// <param name="chunk">The <see cref="ChunkData"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <typeparamref name="TResponse"/> for the chunked request.</returns>
protected async Task<TResponse> ProcessChunk<TCommnication, TResponse>(
Func<TCommnication, CancellationToken, Task<TResponse>> completionCallback,
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <typeparamref name="TResponse"/> for the chunked request.</returns>
protected async ValueTask<TResponse> ProcessChunk<TCommnication, TResponse>(
Func<TCommnication, CancellationToken, ValueTask<TResponse>> completionCallback,
Func<string, TResponse> chunkErrorCallback,
ChunkData chunk,
CancellationToken cancellationToken)
@@ -27,7 +27,7 @@ namespace Tgstation.Server.Host.Components.Repository
public string RemoteRepositoryName => null;
/// <inheritdoc />
public Task<Models.TestMerge> GetTestMerge(
public ValueTask<Models.TestMerge> GetTestMerge(
TestMergeParameters parameters,
Api.Models.Internal.RepositorySettings repositorySettings,
CancellationToken cancellationToken) => throw new NotSupportedException();
@@ -56,7 +56,7 @@ namespace Tgstation.Server.Host.Components.Repository
}
/// <inheritdoc />
protected override async Task<Models.TestMerge> GetTestMergeImpl(
protected override async ValueTask<Models.TestMerge> GetTestMergeImpl(
TestMergeParameters parameters,
RepositorySettings repositorySettings,
CancellationToken cancellationToken)
@@ -51,7 +51,7 @@ namespace Tgstation.Server.Host.Components.Repository
}
/// <inheritdoc />
protected override async Task<Models.TestMerge> GetTestMergeImpl(
protected override async ValueTask<Models.TestMerge> GetTestMergeImpl(
TestMergeParameters parameters,
RepositorySettings repositorySettings,
CancellationToken cancellationToken)
@@ -54,7 +54,7 @@ namespace Tgstation.Server.Host.Components.Repository
}
/// <inheritdoc />
public async Task<Models.TestMerge> GetTestMerge(
public async ValueTask<Models.TestMerge> GetTestMerge(
TestMergeParameters parameters,
RepositorySettings repositorySettings,
CancellationToken cancellationToken)
@@ -85,8 +85,8 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="parameters">The <see cref="TestMergeParameters"/>.</param>
/// <param name="repositorySettings">The <see cref="RepositorySettings"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="Models.TestMerge"/> of the <paramref name="parameters"/>.</returns>
protected abstract Task<Models.TestMerge> GetTestMergeImpl(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="Models.TestMerge"/> of the <paramref name="parameters"/>.</returns>
protected abstract ValueTask<Models.TestMerge> GetTestMergeImpl(
TestMergeParameters parameters,
RepositorySettings repositorySettings,
CancellationToken cancellationToken);
@@ -17,9 +17,9 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="parameters">The <see cref="TestMergeParameters"/>.</param>
/// <param name="repositorySettings">The <see cref="RepositorySettings"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="Models.TestMerge"/> of the <paramref name="parameters"/>.</returns>
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="Models.TestMerge"/> of the <paramref name="parameters"/>.</returns>
/// <remarks><see cref="TestMergeApiBase.MergedAt"/> and <see cref="Models.TestMerge.MergedBy"/> will be unset.</remarks>
Task<Models.TestMerge> GetTestMerge(
ValueTask<Models.TestMerge> GetTestMerge(
TestMergeParameters parameters,
RepositorySettings repositorySettings,
CancellationToken cancellationToken);
@@ -22,8 +22,8 @@ namespace Tgstation.Server.Host.Components.Repository
/// </summary>
/// <param name="path">The full path to the <see cref="LibGit2Sharp.IRepository"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the loaded <see cref="LibGit2Sharp.IRepository"/>.</returns>
Task<LibGit2Sharp.IRepository> CreateFromPath(string path, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the loaded <see cref="LibGit2Sharp.IRepository"/>.</returns>
ValueTask<LibGit2Sharp.IRepository> CreateFromPath(string path, CancellationToken cancellationToken);
/// <summary>
/// Clone a remote <see cref="LibGit2Sharp.IRepository"/>.
@@ -49,8 +49,8 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="updateSubmodules">If a submodule update should be attempted after the merge.</param>
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> to report progress of the operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task CheckoutObject(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask CheckoutObject(
string committish,
string username,
string password,
@@ -69,8 +69,8 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="updateSubmodules">If a submodule update should be attempted after the merge.</param>
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> to report progress of the operation.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="TestMergeResult"/>.</returns>
Task<TestMergeResult> AddTestMerge(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="TestMergeResult"/>.</returns>
ValueTask<TestMergeResult> AddTestMerge(
TestMergeParameters testMergeParameters,
string committerName,
string committerEmail,
@@ -88,8 +88,8 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="password">The password to fetch from the origin repository.</param>
/// <param name="deploymentPipeline">If any events created should be marked as part of the deployment pipeline.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task FetchOrigin(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask FetchOrigin(
JobProgressReporter progressReporter,
string username,
string password,
@@ -105,8 +105,8 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="updateSubmodules">If a submodule update should be attempted after the merge.</param>
/// <param name="deploymentPipeline">If any events created should be marked as part of the deployment pipeline.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the SHA of the new HEAD.</returns>
Task ResetToOrigin(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the SHA of the new HEAD.</returns>
ValueTask ResetToOrigin(
JobProgressReporter progressReporter,
string username,
string password,
@@ -131,8 +131,8 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="committerEmail">The e-mail of the merge committer.</param>
/// <param name="deploymentPipeline">If any events created should be marked as part of the deployment pipeline.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="Nullable{T}"/> <see cref="bool"/> representing the merge result that is <see langword="true"/> after a fast forward, <see langword="false"/> on a merge or up to date, <see langword="null"/> on a conflict.</returns>
Task<bool?> MergeOrigin(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="Nullable{T}"/> <see cref="bool"/> representing the merge result that is <see langword="true"/> after a fast forward, <see langword="false"/> on a merge or up to date, <see langword="null"/> on a conflict.</returns>
ValueTask<bool?> MergeOrigin(
JobProgressReporter progressReporter,
string committerName,
string committerEmail,
@@ -150,8 +150,8 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="synchronizeTrackedBranch">If the synchronizations should be made to the tracked reference as opposed to a temporary branch.</param>
/// <param name="deploymentPipeline">If any events created should be marked as part of the deployment pipeline.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in <see langword="true"/> if commits were pushed to the tracked origin reference, <see langword="false"/> otherwise.</returns>
Task<bool> Sychronize(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in <see langword="true"/> if commits were pushed to the tracked origin reference, <see langword="false"/> otherwise.</returns>
ValueTask<bool> Sychronize(
JobProgressReporter progressReporter,
string username,
string password,
@@ -166,8 +166,8 @@ namespace Tgstation.Server.Host.Components.Repository
/// </summary>
/// <param name="path">The path to copy repository contents to.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task CopyTo(string path, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask CopyTo(string path, CancellationToken cancellationToken);
/// <summary>
/// Check if a given <paramref name="sha"/> is a parent of the current <see cref="Head"/>.
@@ -25,8 +25,8 @@ namespace Tgstation.Server.Host.Components.Repository
/// Attempt to load the <see cref="IRepository"/> from the default location.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>The loaded <see cref="IRepository"/> if it exists, <see langword="null"/> otherwise.</returns>
Task<IRepository> LoadRepository(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the loaded <see cref="IRepository"/> if it exists, <see langword="null"/> otherwise.</returns>
ValueTask<IRepository> LoadRepository(CancellationToken cancellationToken);
/// <summary>
/// Clone the repository at <paramref name="url"/>.
@@ -38,8 +38,8 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> for progress of the clone.</param>
/// <param name="recurseSubmodules">If submodules should be recusively cloned and initialized.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>The newly cloned <see cref="IRepository"/>, <see langword="null"/> if one already exists.</returns>
Task<IRepository> CloneRepository(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting i the newly cloned <see cref="IRepository"/>, <see langword="null"/> if one already exists.</returns>
ValueTask<IRepository> CloneRepository(
Uri url,
string initialBranch,
string username,
@@ -52,7 +52,7 @@ namespace Tgstation.Server.Host.Components.Repository
/// Delete the current repository.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task DeleteRepository(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask DeleteRepository(CancellationToken cancellationToken);
}
}
@@ -38,7 +38,7 @@ namespace Tgstation.Server.Host.Components.Repository
}
/// <inheritdoc />
public async Task<LibGit2Sharp.IRepository> CreateFromPath(string path, CancellationToken cancellationToken)
public async ValueTask<LibGit2Sharp.IRepository> CreateFromPath(string path, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(path);
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using LibGit2Sharp;
using LibGit2Sharp.Handlers;
using Microsoft.Extensions.Logging;
using Tgstation.Server.Api.Models;
@@ -20,6 +21,7 @@ using Tgstation.Server.Host.Jobs;
namespace Tgstation.Server.Host.Components.Repository
{
/// <inheritdoc />
#pragma warning disable CA1506 // TODO: Decomplexify
sealed class Repository : IRepository
{
/// <summary>
@@ -181,7 +183,7 @@ namespace Tgstation.Server.Host.Components.Repository
/// <inheritdoc />
#pragma warning disable CA1506 // TODO: Decomplexify
public async Task<TestMergeResult> AddTestMerge(
public async ValueTask<TestMergeResult> AddTestMerge(
TestMergeParameters testMergeParameters,
string committerName,
string committerEmail,
@@ -384,7 +386,7 @@ namespace Tgstation.Server.Host.Components.Repository
#pragma warning restore CA1506
/// <inheritdoc />
public async Task CheckoutObject(
public async ValueTask CheckoutObject(
string committish,
string username,
string password,
@@ -419,7 +421,7 @@ namespace Tgstation.Server.Host.Components.Repository
}
/// <inheritdoc />
public async Task FetchOrigin(
public async ValueTask FetchOrigin(
JobProgressReporter progressReporter,
string username,
string password,
@@ -466,7 +468,7 @@ namespace Tgstation.Server.Host.Components.Repository
}
/// <inheritdoc />
public async Task ResetToOrigin(
public async ValueTask ResetToOrigin(
JobProgressReporter progressReporter,
string username,
string password,
@@ -522,7 +524,7 @@ namespace Tgstation.Server.Host.Components.Repository
TaskScheduler.Current);
/// <inheritdoc />
public async Task CopyTo(string path, CancellationToken cancellationToken)
public async ValueTask CopyTo(string path, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(path);
logger.LogTrace("Copying to {path}...", path);
@@ -533,7 +535,7 @@ namespace Tgstation.Server.Host.Components.Repository
if (postWriteHandler.NeedsPostWrite(src))
postWriteHandler.HandleWrite(dest);
return Task.CompletedTask;
return ValueTask.CompletedTask;
},
ioMananger.ResolvePath(),
path,
@@ -557,7 +559,7 @@ namespace Tgstation.Server.Host.Components.Repository
TaskScheduler.Current);
/// <inheritdoc />
public async Task<bool?> MergeOrigin(
public async ValueTask<bool?> MergeOrigin(
JobProgressReporter progressReporter,
string committerName,
string committerEmail,
@@ -636,7 +638,7 @@ namespace Tgstation.Server.Host.Components.Repository
}
/// <inheritdoc />
public async Task<bool> Sychronize(
public async ValueTask<bool> Sychronize(
JobProgressReporter progressReporter,
string username,
string password,
@@ -828,7 +830,7 @@ namespace Tgstation.Server.Host.Components.Repository
TaskScheduler.Current);
/// <inheritdoc />
public Task<Models.TestMerge> GetTestMerge(
public ValueTask<Models.TestMerge> GetTestMerge(
TestMergeParameters parameters,
RepositorySettings repositorySettings,
CancellationToken cancellationToken) => gitRemoteFeatures.GetTestMerge(
@@ -990,8 +992,8 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="password">The password for the <see cref="credentialsProvider"/>.</param>
/// <param name="deploymentPipeline">If any events created should be marked as part of the deployment pipeline.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task UpdateSubmodules(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask UpdateSubmodules(
JobProgressReporter progressReporter,
string username,
string password,
@@ -1131,4 +1133,5 @@ namespace Tgstation.Server.Host.Components.Repository
return !cancellationToken.IsCancellationRequested;
};
}
#pragma warning restore CA1506
}
@@ -117,7 +117,7 @@ namespace Tgstation.Server.Host.Components.Repository
}
/// <inheritdoc />
public async Task<IRepository> CloneRepository(
public async ValueTask<IRepository> CloneRepository(
Uri url,
string initialBranch,
string username,
@@ -202,7 +202,7 @@ namespace Tgstation.Server.Host.Components.Repository
}
/// <inheritdoc />
public async Task<IRepository> LoadRepository(CancellationToken cancellationToken)
public async ValueTask<IRepository> LoadRepository(CancellationToken cancellationToken)
{
logger.LogTrace("Begin LoadRepository...");
lock (semaphore)
@@ -248,7 +248,7 @@ namespace Tgstation.Server.Host.Components.Repository
}
/// <inheritdoc />
public async Task DeleteRepository(CancellationToken cancellationToken)
public async ValueTask DeleteRepository(CancellationToken cancellationToken)
{
logger.LogInformation("Deleting repository...");
try
@@ -6,9 +6,9 @@ using System.Threading.Tasks;
using LibGit2Sharp;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Models.Request;
using Tgstation.Server.Host.Database;
@@ -79,8 +79,8 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="lastOriginCommitSha">The last known origin commit SHA of the <paramref name="repository"/> if any.</param>
/// <param name="revInfoSink">An optional <see cref="Action{T}"/> to receive the loaded <see cref="RevisionInformation"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in <see langword="true"/> if the <paramref name="databaseContext"/> was modified in a way that requires saving, <see langword="false"/> otherwise.</returns>
public static async Task<bool> LoadRevisionInformation(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in <see langword="true"/> if the <paramref name="databaseContext"/> was modified in a way that requires saving, <see langword="false"/> otherwise.</returns>
public static async ValueTask<bool> LoadRevisionInformation(
IRepository repository,
IDatabaseContext databaseContext,
ILogger logger,
@@ -142,9 +142,9 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="job">The running <see cref="Job"/>, ignored.</param>
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> for the job.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
#pragma warning disable CA1502, CA1506 // TODO: Decomplexify
public async Task<IActionResult> RepositoryUpdateJob(
public async ValueTask RepositoryUpdateJob(
IInstanceCore instance,
IDatabaseContextFactory databaseContextFactory,
Job job,
@@ -191,7 +191,7 @@ namespace Tgstation.Server.Host.Components.Repository
Id = instanceId,
};
Task CallLoadRevInfo(Models.TestMerge testMergeToAdd = null, string lastOriginCommitSha = null) => databaseContextFactory
ValueTask CallLoadRevInfo(Models.TestMerge testMergeToAdd = null, string lastOriginCommitSha = null) => databaseContextFactory
.UseContext(
async databaseContext =>
{
@@ -242,7 +242,7 @@ namespace Tgstation.Server.Host.Components.Repository
await CallLoadRevInfo();
// apply new rev info, tracking applied test merges
Task UpdateRevInfo(Models.TestMerge testMergeToAdd = null) => CallLoadRevInfo(testMergeToAdd, lastRevisionInfo.OriginCommitSha);
ValueTask UpdateRevInfo(Models.TestMerge testMergeToAdd = null) => CallLoadRevInfo(testMergeToAdd, lastRevisionInfo.OriginCommitSha);
try
{
@@ -557,8 +557,6 @@ namespace Tgstation.Server.Host.Components.Repository
cancellationToken);
await UpdateRevInfo();
}
return null;
}
catch
{
@@ -87,16 +87,16 @@ namespace Tgstation.Server.Host.Components.Session
/// <summary>
/// Releases the <see cref="IProcess"/> without terminating it. Also calls <see cref="IDisposable.Dispose"/>.
/// </summary>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task Release();
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask Release();
/// <summary>
/// Sends a command to DreamDaemon through /world/Topic().
/// </summary>
/// <param name="parameters">The <see cref="TopicParameters"/> to send.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="TopicResponse"/> of /world/Topic().</returns>
Task<TopicResponse> SendCommand(TopicParameters parameters, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="TopicResponse"/> of /world/Topic().</returns>
ValueTask<TopicResponse> SendCommand(TopicParameters parameters, CancellationToken cancellationToken);
/// <summary>
/// Causes the world to start listening on a <paramref name="newPort"/>.
@@ -111,8 +111,8 @@ namespace Tgstation.Server.Host.Components.Session
/// </summary>
/// <param name="newRebootState">The new <see cref="RebootState"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in <see langword="true"/> if the operation succeeded, <see langword="false"/> otherwise.</returns>
Task<bool> SetRebootState(RebootState newRebootState, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in <see langword="true"/> if the operation succeeded, <see langword="false"/> otherwise.</returns>
ValueTask<bool> SetRebootState(RebootState newRebootState, CancellationToken cancellationToken);
/// <summary>
/// Changes <see cref="RebootState"/> to <see cref="RebootState.Normal"/> without telling the DMAPI.

Some files were not shown because too many files have changed in this diff Show More