mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-07-12 08:33:43 +01:00
Adds CancellationTokens to all operations
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Tgstation.Server.Api.Models;
|
||||
using Tgstation.Server.Client.Rights;
|
||||
@@ -13,21 +14,24 @@ namespace Tgstation.Server.Client.Components
|
||||
/// <summary>
|
||||
/// Gets the current status of any BYOND updates
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="ByondStatus"/> updater</returns>
|
||||
Task<ByondStatus> CurrentStatus();
|
||||
Task<ByondStatus> CurrentStatus(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the installed BYOND <see cref="Version"/>
|
||||
/// </summary>
|
||||
/// <param name="version">The <see cref="Version"/> to update to. Only considers the <see cref="Version.Major"/> and <see cref="Version.Minor"/> numbers</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task"/> representing the running operation</returns>
|
||||
Task UpdateToVersion(Version version);
|
||||
Task UpdateToVersion(Version version, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Get the currently installed BYOND <see cref="Version"/>
|
||||
/// </summary>
|
||||
/// <param name="staged">Read the staged <see cref="Version"/> instead if applicable</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the installed BYOND version or <see langword="null"/> if none is installed</returns>
|
||||
Task<Version> GetVersion(bool staged);
|
||||
Task<Version> GetVersion(bool staged, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Tgstation.Server.Api.Models;
|
||||
using Tgstation.Server.Client.Rights;
|
||||
@@ -13,28 +14,32 @@ namespace Tgstation.Server.Client.Components
|
||||
/// <summary>
|
||||
/// Get all <see cref="IInstanceClient"/>s for <see cref="Instance"/>s that the <see cref="IClient{TRights}"/> can view
|
||||
/// </summary>
|
||||
/// <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="IInstanceClient"/>s</returns>
|
||||
Task<IReadOnlyList<IInstanceClient>> GetInstanceClients();
|
||||
Task<IReadOnlyList<IInstanceClient>> GetInstanceClients(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Create an <paramref name="instance"/>
|
||||
/// </summary>
|
||||
/// <param name="instance">The <see cref="Instance"/> to create. <see cref="Instance.Id"/> will be ignored</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in <see cref="IInstanceClient"/> for the created <see cref="Instance"/></returns>
|
||||
Task<IInstanceClient> CreateInstance(Instance instance);
|
||||
Task<IInstanceClient> CreateInstance(Instance instance, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Relocates, renamed, and/or on/offlines an <paramref name="instance"/>
|
||||
/// </summary>
|
||||
/// <param name="instance">The <see cref="Instance"/> 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 UpdateInstance(Instance instance);
|
||||
Task UpdateInstance(Instance instance, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an <paramref name="instance"/>
|
||||
/// </summary>
|
||||
/// <param name="instance">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 DeleteInstance(Instance instance);
|
||||
Task DeleteInstance(Instance instance, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Tgstation.Server.Api.Models;
|
||||
using Tgstation.Server.Client.Rights;
|
||||
@@ -13,38 +14,44 @@ namespace Tgstation.Server.Client.Components
|
||||
/// <summary>
|
||||
/// Generates a new token for the <see cref="IServerClient"/>'s <see cref="System.Net.IPAddress"/>
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task"/> resulting in a new <see cref="Token"/> for the <see cref="IServerClient"/></returns>
|
||||
Task<Token> Generate();
|
||||
Task<Token> Generate(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all active <see cref="TokenInfo"/>s for the <see cref="IServerClient"/>
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task"/> resulting a <see cref="IReadOnlyList{T}"/> of active <see cref="TokenInfo"/>s for the <see cref="IServerClient"/></returns>
|
||||
Task<IReadOnlyList<TokenInfo>> GetClientInfos();
|
||||
Task<IReadOnlyList<TokenInfo>> GetClientInfos(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all active <see cref="TokenInfo"/>s for all users
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task"/> resulting a <see cref="IReadOnlyDictionary{TKey, TValue}"/> of active <see cref="TokenInfo"/>s for the <see cref="IServerClient"/> keyed by username</returns>
|
||||
Task<IReadOnlyDictionary<string, TokenInfo>> GetAllInfos();
|
||||
Task<IReadOnlyDictionary<string, TokenInfo>> GetAllInfos(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Invalidate the specified active <see cref="Token"/> designated by <paramref name="tokenId"/>
|
||||
/// </summary>
|
||||
/// <param name="tokenId">The <see cref="TokenInfo.Id"/> of the <see cref="Token"/> to invalidate</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task"/> representing the running operation</returns>
|
||||
Task Invalidate(long tokenId);
|
||||
Task Invalidate(long tokenId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Invalidate all active <see cref="Token"/>s for a <see cref="IServerClient"/>
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task"/> representing the running operation</returns>
|
||||
Task InvalidateAllClient();
|
||||
Task InvalidateAllClient(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Invalidate all active <see cref="Token"/>s
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task"/> representing the running operation</returns>
|
||||
Task InvalidateAll();
|
||||
Task InvalidateAll(CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tgstation.Server.Client
|
||||
{
|
||||
@@ -21,7 +22,8 @@ namespace Tgstation.Server.Client
|
||||
/// <summary>
|
||||
/// Get the <typeparamref name="TRights"/> for the <see cref="IClient{TRights}"/>
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the <typeparamref name="TRights"/> for the <see cref="IClient{TRights}"/></returns>
|
||||
Task<TRights> Rights();
|
||||
Task<TRights> Rights(CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Tgstation.Server.Client.Components;
|
||||
using Tgstation.Server.Client.Rights;
|
||||
@@ -31,6 +32,6 @@ namespace Tgstation.Server.Client
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="System.Version"/> of the connected server</returns>
|
||||
/// <remarks>Note that if the <see cref="System.Version.Build"/> differs from the <see cref="Version"/>'s API functionality will most likely be compromised</remarks>
|
||||
Task<Version> GetServerVersion();
|
||||
Task<Version> GetServerVersion(CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tgstation.Server.Client
|
||||
{
|
||||
@@ -13,10 +14,11 @@ namespace Tgstation.Server.Client
|
||||
/// <param name="hostname">The URL to access tgstation-server at</param>
|
||||
/// <param name="username">The username to for the <see cref="IServerClient"/></param>
|
||||
/// <param name="password">The password for the <see cref="IServerClient"/></param>
|
||||
/// <param name="timeout">The initial timeout for the connection</param>
|
||||
/// <param name="timeout">The initial timeout for the connection in milliseconds</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in a new <see cref="IServerClient"/></returns>
|
||||
/// <exception cref="System.UnauthorizedAccessException">If the <paramref name="username"/> and/or <paramref name="password"/> is invalid</exception>
|
||||
Task<IServerClient> CreateServerClient(string hostname, string username, string password, int timeout = 10000);
|
||||
Task<IServerClient> CreateServerClient(string hostname, string username, string password, int timeout, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Create a <see cref="IServerClient"/>
|
||||
@@ -24,8 +26,9 @@ namespace Tgstation.Server.Client
|
||||
/// <param name="hostname">The URL to access tgstation-server at</param>
|
||||
/// <param name="token">The <see cref="Api.Models.Token.Value"/> to access the API with</param>
|
||||
/// <param name="timeout">The initial timeout for the connection</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in a new <see cref="IServerClient"/></returns>
|
||||
/// <exception cref="System.UnauthorizedAccessException">If the <paramref name="token"/> invalid</exception>
|
||||
Task<IServerClient> CreateServerClient(string hostname, string token, int timeout = 10000);
|
||||
Task<IServerClient> CreateServerClient(string hostname, string token, int timeout, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tgstation.Server.Client
|
||||
@@ -7,9 +8,9 @@ namespace Tgstation.Server.Client
|
||||
public sealed class ServerClientFactory : IServerClientFactory
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public Task<IServerClient> CreateServerClient(string hostname, string username, string password, int timeout = 10000) => throw new NotImplementedException();
|
||||
public Task<IServerClient> CreateServerClient(string hostname, string username, string password, int timeout, CancellationToken cancellationToken) => throw new NotImplementedException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<IServerClient> CreateServerClient(string hostname, string token, int timeout = 10000) => throw new NotImplementedException();
|
||||
public Task<IServerClient> CreateServerClient(string hostname, string token, int timeout, CancellationToken cancellationToken) => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ namespace Tgstation.Server.Client.Tests
|
||||
public async Task TestUserConstruction()
|
||||
{
|
||||
var factory = new ServerClientFactory();
|
||||
await Assert.ThrowsExceptionAsync<NotImplementedException>(() => factory.CreateServerClient(null, null, null)).ConfigureAwait(false);
|
||||
await Assert.ThrowsExceptionAsync<NotImplementedException>(() => factory.CreateServerClient(null, null, null, default, default)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TestTokenConstruction()
|
||||
{
|
||||
var factory = new ServerClientFactory();
|
||||
await Assert.ThrowsExceptionAsync<NotImplementedException>(() => factory.CreateServerClient(null, null)).ConfigureAwait(false);
|
||||
await Assert.ThrowsExceptionAsync<NotImplementedException>(() => factory.CreateServerClient(null, null, default, default)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user