mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-26 06:27:19 +01:00
Penultimate ValueTask conversion
This commit is contained in:
@@ -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;
|
||||
@@ -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.UseContext2(db =>
|
||||
await databaseContextFactory.UseContextTaskReturn(db =>
|
||||
{
|
||||
var targetInstance = new Models.Instance
|
||||
{
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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>
|
||||
@@ -1131,4 +1133,5 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
return !cancellationToken.IsCancellationRequested;
|
||||
};
|
||||
}
|
||||
#pragma warning restore CA1506
|
||||
}
|
||||
|
||||
@@ -145,16 +145,15 @@ namespace Tgstation.Server.Host.Controllers
|
||||
/// <summary>
|
||||
/// Main page of the <see cref="Application"/>.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{TResult}"/> resuting in the <see cref="JsonResult"/> containing <see cref="ServerInformationResponse"/> of the <see cref="Application"/> if a properly authenticated API request, the web control panel if on a browser and enabled, <see cref="UnauthorizedResult"/> otherwise.
|
||||
/// The <see cref="JsonResult"/> containing <see cref="ServerInformationResponse"/> of the <see cref="Application"/> if a properly authenticated API request, the web control panel if on a browser and enabled, <see cref="UnauthorizedResult"/> otherwise.
|
||||
/// </returns>
|
||||
/// <response code="200"><see cref="ServerInformationResponse"/> retrieved successfully.</response>
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(typeof(ServerInformationResponse), 200)]
|
||||
#pragma warning disable CA1506
|
||||
public async ValueTask<IActionResult> Home(CancellationToken cancellationToken)
|
||||
public IActionResult Home()
|
||||
{
|
||||
if (controlPanelConfiguration.Enable)
|
||||
Response.Headers.Add(
|
||||
@@ -201,7 +200,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
ValidInstancePaths = generalConfiguration.ValidInstancePaths,
|
||||
WindowsHost = platformIdentifier.IsWindows,
|
||||
SwarmServers = swarmService.GetSwarmServers(),
|
||||
OAuthProviderInfos = await oAuthProviders.ProviderInfos(cancellationToken),
|
||||
OAuthProviderInfos = oAuthProviders.ProviderInfos(),
|
||||
UpdateInProgress = serverControl.UpdateInProgress,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -48,6 +48,6 @@ namespace Tgstation.Server.Host.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<Stream> GetResult(CancellationToken cancellationToken) => Task.FromResult(stream);
|
||||
public ValueTask<Stream> GetResult(CancellationToken cancellationToken) => ValueTask.FromResult(stream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Tgstation.Server.Host.Database
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask UseContext2(Func<IDatabaseContext, Task> operation)
|
||||
public async ValueTask UseContextTaskReturn(Func<IDatabaseContext, Task> operation)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(operation);
|
||||
|
||||
|
||||
@@ -20,6 +20,6 @@ namespace Tgstation.Server.Host.Database
|
||||
/// </summary>
|
||||
/// <param name="operation">The operation to run.</param>
|
||||
/// <returns>A <see cref="ValueTask"/> representing the running <paramref name="operation"/>.</returns>
|
||||
ValueTask UseContext2(Func<IDatabaseContext, Task> operation);
|
||||
ValueTask UseContextTaskReturn(Func<IDatabaseContext, Task> operation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,14 +77,14 @@ namespace Tgstation.Server.Host.IO
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Stream> GetResult(CancellationToken cancellationToken)
|
||||
public async ValueTask<Stream> GetResult(CancellationToken cancellationToken)
|
||||
{
|
||||
var (sharedStream, _) = await GetResultInternal(cancellationToken);
|
||||
return sharedStream;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<MemoryStream> GetOwnedResult(CancellationToken cancellationToken)
|
||||
public async ValueTask<MemoryStream> GetOwnedResult(CancellationToken cancellationToken)
|
||||
{
|
||||
var (sharedStream, length) = await GetResultInternal(cancellationToken);
|
||||
return new MemoryStream(sharedStream.GetBuffer(), 0, (int)length, false, true);
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace Tgstation.Server.Host.IO
|
||||
/// Gets the provided <see cref="Stream"/>. May be called multiple times, though cancelling any may cause all calls to be cancelled. All calls yield the same <see cref="Stream"/> reference.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the provided <see cref="Stream"/> on success, <see langword="null"/> if it could not be provided.</returns>
|
||||
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the provided <see cref="Stream"/> on success, <see langword="null"/> if it could not be provided.</returns>
|
||||
/// <remarks>The resulting <see cref="Stream"/> is owned by the <see cref="IFileStreamProvider"/> and is short lived unless otherwise specified. It should be buffered if it needs use outside the lifetime of the <see cref="IFileStreamProvider"/>.</remarks>
|
||||
Task<Stream> GetResult(CancellationToken cancellationToken);
|
||||
ValueTask<Stream> GetResult(CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Tgstation.Server.Host.IO
|
||||
/// Gets the provided <see cref="MemoryStream"/>. May be called multiple times, though cancelling any may cause all calls to be cancelled.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the provided <see cref="MemoryStream"/> on success, <see langword="null"/> if it could not be provided.</returns>
|
||||
Task<MemoryStream> GetOwnedResult(CancellationToken cancellationToken);
|
||||
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the provided <see cref="MemoryStream"/> on success, <see langword="null"/> if it could not be provided.</returns>
|
||||
ValueTask<MemoryStream> GetOwnedResult(CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace Tgstation.Server.Host.IO
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Stream> GetResult(CancellationToken cancellationToken)
|
||||
public async ValueTask<Stream> GetResult(CancellationToken cancellationToken)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException(nameof(RequestFileStreamProvider));
|
||||
|
||||
@@ -33,8 +33,8 @@ namespace Tgstation.Server.Host.Jobs
|
||||
/// <param name="canceller">The <see cref="User"/> to cancel the <paramref name="job"/>. If <see langword="null"/> the TGS user will be used.</param>
|
||||
/// <param name="jobCancellationToken">A <see cref="CancellationToken"/> that will cancel the <paramref name="job"/>.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task"/> representing the <see cref="Job"/>.</returns>
|
||||
Task WaitForJobCompletion(Job job, User canceller, CancellationToken jobCancellationToken, CancellationToken cancellationToken);
|
||||
/// <returns>A <see cref="ValueTask"/> representing the <see cref="Job"/>.</returns>
|
||||
ValueTask WaitForJobCompletion(Job job, User canceller, CancellationToken jobCancellationToken, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Cancels a give <paramref name="job"/>.
|
||||
@@ -43,7 +43,7 @@ namespace Tgstation.Server.Host.Jobs
|
||||
/// <param name="user">The <see cref="User"/> who cancelled the <paramref name="job"/>. If <see langword="null"/> the TGS user will be used.</param>
|
||||
/// <param name="blocking">If the operation should wait until the job exits before completing.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the updated <paramref name="job"/> if it was cancelled, <see langword="null"/> if it couldn't be found.</returns>
|
||||
Task<Job> CancelJob(Job job, User user, bool blocking, CancellationToken cancellationToken);
|
||||
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the updated <paramref name="job"/> if it was cancelled, <see langword="null"/> if it couldn't be found.</returns>
|
||||
ValueTask<Job> CancelJob(Job job, User user, bool blocking, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog.Context;
|
||||
using Tgstation.Server.Api.Models.Response;
|
||||
using Tgstation.Server.Common.Extensions;
|
||||
using Tgstation.Server.Host.Components;
|
||||
using Tgstation.Server.Host.Database;
|
||||
using Tgstation.Server.Host.Extensions;
|
||||
@@ -172,9 +173,9 @@ namespace Tgstation.Server.Host.Jobs
|
||||
.AsTask();
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
List<Task<Job>> joinTasks;
|
||||
List<ValueTask<Job>> joinTasks;
|
||||
lock (addCancelLock)
|
||||
lock (synchronizationLock)
|
||||
{
|
||||
@@ -190,11 +191,11 @@ namespace Tgstation.Server.Host.Jobs
|
||||
.ToList();
|
||||
}
|
||||
|
||||
await Task.WhenAll(joinTasks);
|
||||
return ValueTaskExtensions.WhenAll(joinTasks).AsTask();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Job> CancelJob(Job job, User user, bool blocking, CancellationToken cancellationToken)
|
||||
public async ValueTask<Job> CancelJob(Job job, User user, bool blocking, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(job);
|
||||
|
||||
@@ -248,7 +249,7 @@ namespace Tgstation.Server.Host.Jobs
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task WaitForJobCompletion(Job job, User canceller, CancellationToken jobCancellationToken, CancellationToken cancellationToken)
|
||||
public async ValueTask WaitForJobCompletion(Job job, User canceller, CancellationToken jobCancellationToken, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(job);
|
||||
|
||||
@@ -268,12 +269,12 @@ namespace Tgstation.Server.Host.Jobs
|
||||
if (noMoreJobsShouldStart && !handler.Started)
|
||||
await Extensions.TaskExtensions.InfiniteTask.WaitAsync(cancellationToken);
|
||||
|
||||
Task cancelTask = null;
|
||||
ValueTask<Job>? cancelTask = null;
|
||||
using (jobCancellationToken.Register(() => cancelTask = CancelJob(job, canceller, true, cancellationToken)))
|
||||
await handler.Wait(cancellationToken);
|
||||
|
||||
if (cancelTask != null)
|
||||
await cancelTask;
|
||||
if (cancelTask.HasValue)
|
||||
await cancelTask.Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Tgstation.Server.Host.Security
|
||||
public void Dispose() => CurrentAuthenticationContext?.Dispose();
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task CreateAuthenticationContext(long userId, long? instanceId, DateTimeOffset validAfter, CancellationToken cancellationToken)
|
||||
public async ValueTask CreateAuthenticationContext(long userId, long? instanceId, DateTimeOffset validAfter, CancellationToken cancellationToken)
|
||||
{
|
||||
if (CurrentAuthenticationContext != null)
|
||||
throw new InvalidOperationException("Authentication context has already been loaded");
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Tgstation.Server.Host.Security
|
||||
/// <param name="instanceId">The <see cref="Api.Models.EntityId.Id"/> of the operation.</param>
|
||||
/// <param name="validAfter">The <see cref="DateTimeOffset"/> the resulting <see cref="IAuthenticationContext.User"/>'s password must be valid after.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
|
||||
Task CreateAuthenticationContext(long userId, long? instanceId, DateTimeOffset validAfter, CancellationToken cancellationToken);
|
||||
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
|
||||
ValueTask CreateAuthenticationContext(long userId, long? instanceId, DateTimeOffset validAfter, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Tgstation.Server.Host.Security
|
||||
/// </summary>
|
||||
/// <param name="user">The user to create a <see cref="ISystemIdentity"/> for.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A new <see cref="ISystemIdentity"/> or <see langword="null"/> if the <paramref name="user"/> has no <see cref="ISystemIdentity"/>.</returns>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in a new <see cref="ISystemIdentity"/> based on the given <paramref name="user"/> or <see langword="null"/> if the <paramref name="user"/> has no <see cref="ISystemIdentity"/>.</returns>
|
||||
Task<ISystemIdentity> CreateSystemIdentity(User user, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
@@ -30,7 +30,7 @@ namespace Tgstation.Server.Host.Security
|
||||
/// <param name="username">The username of the user.</param>
|
||||
/// <param name="password">The password of the user.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A new <see cref="ISystemIdentity"/>.</returns>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in a new <see cref="ISystemIdentity"/> based on the given credentials.</returns>
|
||||
Task<ISystemIdentity> CreateSystemIdentity(string username, string password, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Tgstation.Server.Host.Security
|
||||
/// <param name="user">The <see cref="Models.User"/> to create the token for. Must have the <see cref="Api.Models.EntityId.Id"/> field available.</param>
|
||||
/// <param name="oAuth">Whether or not this is an OAuth login.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in a new <see cref="TokenResponse"/>.</returns>
|
||||
Task<TokenResponse> CreateToken(Models.User user, bool oAuth, CancellationToken cancellationToken);
|
||||
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a new <see cref="TokenResponse"/>.</returns>
|
||||
ValueTask<TokenResponse> CreateToken(Models.User user, bool oAuth, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace Tgstation.Server.Host.Security.OAuth
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<string> ValidateResponseCode(string code, CancellationToken cancellationToken)
|
||||
public async ValueTask<string> ValidateResponseCode(string code, CancellationToken cancellationToken)
|
||||
{
|
||||
using var httpClient = CreateHttpClient();
|
||||
string tokenResponsePayload = null;
|
||||
@@ -140,13 +140,13 @@ namespace Tgstation.Server.Host.Security.OAuth
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<OAuthProviderInfo> GetProviderInfo(CancellationToken cancellationToken) => Task.FromResult(
|
||||
new OAuthProviderInfo
|
||||
public OAuthProviderInfo GetProviderInfo()
|
||||
=> new ()
|
||||
{
|
||||
ClientId = OAuthConfiguration.ClientId,
|
||||
RedirectUri = OAuthConfiguration.RedirectUrl,
|
||||
ServerUrl = OAuthConfiguration.ServerUrl,
|
||||
});
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Decode the token payload <paramref name="responseJson"/>.
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Tgstation.Server.Host.Security.OAuth
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<string> ValidateResponseCode(string code, CancellationToken cancellationToken)
|
||||
public async ValueTask<string> ValidateResponseCode(string code, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(code);
|
||||
|
||||
@@ -84,11 +84,11 @@ namespace Tgstation.Server.Host.Security.OAuth
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<OAuthProviderInfo> GetProviderInfo(CancellationToken cancellationToken) => Task.FromResult(
|
||||
new OAuthProviderInfo
|
||||
public OAuthProviderInfo GetProviderInfo()
|
||||
=> new ()
|
||||
{
|
||||
ClientId = oAuthConfiguration.ClientId,
|
||||
RedirectUri = oAuthConfiguration.RedirectUrl,
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Tgstation.Server.Api.Models;
|
||||
|
||||
@@ -21,8 +19,7 @@ namespace Tgstation.Server.Host.Security.OAuth
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Dictionary{TKey, TValue}"/> of the provider client IDs.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in a anew <see cref="Dictionary{TKey, TValue}"/> of the active <see cref="OAuthProviderInfo"/>s.</returns>
|
||||
Task<Dictionary<OAuthProvider, OAuthProviderInfo>> ProviderInfos(CancellationToken cancellationToken);
|
||||
/// <returns>A new <see cref="Dictionary{TKey, TValue}"/> of the active <see cref="OAuthProviderInfo"/>s.</returns>
|
||||
Dictionary<OAuthProvider, OAuthProviderInfo> ProviderInfos();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,16 +18,15 @@ namespace Tgstation.Server.Host.Security.OAuth
|
||||
/// <summary>
|
||||
/// Gets the <see cref="OAuthProvider"/> of validator.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the client ID of the validator on success, <see langword="null"/> on failure.</returns>
|
||||
Task<OAuthProviderInfo> GetProviderInfo(CancellationToken cancellationToken);
|
||||
/// <returns>The client ID of the validator on success, <see langword="null"/> on failure.</returns>
|
||||
OAuthProviderInfo GetProviderInfo();
|
||||
|
||||
/// <summary>
|
||||
/// Validate a given OAuth response <paramref name="code"/>.
|
||||
/// </summary>
|
||||
/// <param name="code">The OAuth response string from web application.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in <see langword="null"/> if authentication failed, <see cref="global::System.UInt64.MaxValue"/> if a rate limit occurred, and the validated <see cref="OAuthConnection.ExternalUserId"/> otherwise.</returns>
|
||||
Task<string> ValidateResponseCode(string code, CancellationToken cancellationToken);
|
||||
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in <see langword="null"/> if authentication failed, <see cref="global::System.UInt64.MaxValue"/> if a rate limit occurred, and the validated <see cref="OAuthConnection.ExternalUserId"/> otherwise.</returns>
|
||||
ValueTask<string> ValidateResponseCode(string code, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
@@ -85,19 +83,17 @@ namespace Tgstation.Server.Host.Security.OAuth
|
||||
public IOAuthValidator GetValidator(OAuthProvider oAuthProvider) => validators.FirstOrDefault(x => x.Provider == oAuthProvider);
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Dictionary<OAuthProvider, OAuthProviderInfo>> ProviderInfos(CancellationToken cancellationToken)
|
||||
public Dictionary<OAuthProvider, OAuthProviderInfo> ProviderInfos()
|
||||
{
|
||||
var providersAndTasks = validators.ToDictionary(
|
||||
x => x.Provider,
|
||||
x => x.GetProviderInfo(cancellationToken));
|
||||
|
||||
await Task.WhenAll(providersAndTasks.Values);
|
||||
x => x.GetProviderInfo());
|
||||
|
||||
return providersAndTasks
|
||||
.Where(x => x.Value.Result != null)
|
||||
.Where(x => x.Value != null)
|
||||
.ToDictionary(
|
||||
x => x.Key,
|
||||
x => x.Value.Result);
|
||||
x => x.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace Tgstation.Server.Host.Security
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<TokenResponse> CreateToken(Models.User user, bool oAuth, CancellationToken cancellationToken)
|
||||
public async ValueTask<TokenResponse> CreateToken(Models.User user, bool oAuth, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(user);
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace Tgstation.Server.Host.Transfer
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Stream> GetResult(CancellationToken cancellationToken)
|
||||
public async ValueTask<Stream> GetResult(CancellationToken cancellationToken)
|
||||
{
|
||||
using (cancellationToken.Register(() => streamTcs.TrySetCanceled(cancellationToken)))
|
||||
using (ticketExpiryCts.Token.Register(() => streamTcs.TrySetResult(null)))
|
||||
@@ -88,7 +88,7 @@ namespace Tgstation.Server.Host.Transfer
|
||||
/// <param name="stream">The <see cref="Stream"/> containing uploaded data.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in <see langword="null"/>, <see cref="ErrorMessageResponse"/> otherwise.</returns>
|
||||
public async Task<ErrorMessageResponse> Completion(Stream stream, CancellationToken cancellationToken)
|
||||
public async ValueTask<ErrorMessageResponse> Completion(Stream stream, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(stream);
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers.Tests
|
||||
.Returns(ValueTask.CompletedTask);
|
||||
mockSetup
|
||||
.Setup(x => x.WaitForJobCompletion(It.IsNotNull<Job>(), It.IsAny<User>(), It.IsAny<CancellationToken>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(Task.CompletedTask);
|
||||
.Returns(ValueTask.CompletedTask);
|
||||
mockJobManager = mockSetup.Object;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers.Tests
|
||||
.Returns(ValueTask.CompletedTask);
|
||||
mockSetup
|
||||
.Setup(x => x.WaitForJobCompletion(It.IsNotNull<Job>(), It.IsAny<User>(), It.IsAny<CancellationToken>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(Task.CompletedTask);
|
||||
.Returns(ValueTask.CompletedTask);
|
||||
var mockJobManager = mockSetup.Object;
|
||||
await using var provider = new IrcProvider(mockJobManager, new AsyncDelayer(), loggerFactory.CreateLogger<IrcProvider>(), Mock.Of<IAssemblyInformationProvider>(), new ChatBot
|
||||
{
|
||||
|
||||
@@ -133,9 +133,9 @@ namespace Tgstation.Server.Host.IO.Tests
|
||||
|
||||
cts2.Cancel();
|
||||
|
||||
await Assert.ThrowsExceptionAsync<TaskCanceledException>(() => task1);
|
||||
await Assert.ThrowsExceptionAsync<TaskCanceledException>(() => task2);
|
||||
await Assert.ThrowsExceptionAsync<TaskCanceledException>(() => task3);
|
||||
await Assert.ThrowsExceptionAsync<TaskCanceledException>(() => task1.AsTask());
|
||||
await Assert.ThrowsExceptionAsync<TaskCanceledException>(() => task2.AsTask());
|
||||
await Assert.ThrowsExceptionAsync<TaskCanceledException>(() => task3.AsTask());
|
||||
|
||||
mockHttpClient.VerifyAll();
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace Tgstation.Server.Host.Swarm.Tests
|
||||
.Setup(x => x.UseContext(It.IsNotNull<Func<IDatabaseContext, ValueTask>>()))
|
||||
.Callback<Func<IDatabaseContext, ValueTask>>((func) => func(mockDatabaseContext));
|
||||
mockDBContextFactory
|
||||
.Setup(x => x.UseContext2(It.IsNotNull<Func<IDatabaseContext, Task>>()))
|
||||
.Setup(x => x.UseContextTaskReturn(It.IsNotNull<Func<IDatabaseContext, Task>>()))
|
||||
.Callback<Func<IDatabaseContext, Task>>((func) => func(mockDatabaseContext));
|
||||
|
||||
var mockHttpClientFactory = new Mock<IAbstractHttpClientFactory>();
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace Tgstation.Server.Tests
|
||||
|
||||
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
|
||||
|
||||
public async Task<Stream> GetResult(CancellationToken cancellationToken)
|
||||
public async ValueTask<Stream> GetResult(CancellationToken cancellationToken)
|
||||
=> await CacheFile(logger, url, bearerToken, null, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user