Work on cleaning up the client

This commit is contained in:
Jordan Brown
2018-08-13 14:37:30 -04:00
parent 6825b772c5
commit 7ad64b966e
10 changed files with 120 additions and 83 deletions
@@ -1,29 +1,27 @@
using System;
using System.Threading;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Rights;
namespace Tgstation.Server.Client.Components
{
/// <summary>
/// For managing the <see cref="Byond"/> installation
/// </summary>
public interface IByondClient : IRightsClient<ByondRights>
public interface IByondClient
{
/// <summary>
/// Get the <see cref="Byond"/> represented by the <see cref="IByondClient"/>
/// Get the <see cref="Byond"/> information
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="Byond"/> represented by the <see cref="IByondClient"/></returns>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="Byond"/> information</returns>
Task<Byond> Read(CancellationToken cancellationToken);
/// <summary>
/// Updates the installed BYOND <see cref="Version"/>
/// </summary>
/// <param name="version">The <see cref="Version"/> to set to active</param>
/// <param name="version">The <see cref="Byond"/> information 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 SetActiveVersion(Version version, CancellationToken cancellationToken);
/// <returns>A <see cref="Task{TResult}"/> resulting in the updated <see cref="Byond"/> information</returns>
Task<Byond> Update(Byond byond, CancellationToken cancellationToken);
}
}
@@ -1,28 +1,44 @@
using System.Threading;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Rights;
namespace Tgstation.Server.Client.Components
{
/// <summary>
/// For managing the chat bots
/// </summary>
public interface IChatSettingsClient : IRightsClient<ChatSettingsRights>
public interface IChatSettingsClient
{
/// <summary>
/// Get the <see cref="ChatSettings"/> represented by the <see cref="IChatSettingsClient"/>
/// List the <see cref="ChatSettings"/>
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="ChatSettings"/> represented by the <see cref="IChatSettingsClient"/></returns>
Task<ChatSettings> Read(CancellationToken cancellationToken);
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="IReadOnlyList{T}"/> of the <see cref="ChatSettings"/> of the server</returns>
Task<IReadOnlyList<ChatSettings>> List(CancellationToken cancellationToken);
/// <summary>
/// Updates the <see cref="ChatSettings"/> setttings
/// Create a <see cref="ChatSettings"/>
/// </summary>
/// <param name="chat">The <see cref="ChatSettings"/> to update</param>
/// <param name="settings">The <see cref="ChatSettings"/> 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="ChatSettings"/></returns>
Task<ChatSettings> Create(ChatSettings settings, CancellationToken cancellationToken);
/// <summary>
/// Updates a <see cref="ChatSettings"/> setttings
/// </summary>
/// <param name="settings">The <see cref="ChatSettings"/> to update</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the updated <see cref="ChatSettings"/></returns>
Task<ChatSettings> Update(ChatSettings settings, CancellationToken cancellationToken);
/// <summary>
/// Delete a <see cref="ChatSettings"/>
/// </summary>
/// <param name="settings">The <see cref="ChatSettings"/> 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 Update(ChatSettings chat, CancellationToken cancellationToken);
Task Delete(ChatSettings settings, CancellationToken cancellationToken);
}
}
@@ -1,5 +1,4 @@
using System.Threading;
using System.Threading.Tasks;
using System;
using Tgstation.Server.Api.Models;
namespace Tgstation.Server.Client.Components
@@ -7,8 +6,13 @@ namespace Tgstation.Server.Client.Components
/// <summary>
/// For managing a single <see cref="Instance"/>
/// </summary>
public interface IInstanceClient
public interface IInstanceClient : IDisposable
{
/// <summary>
/// The <see cref="Instance"/> used to create the <see cref="IInstanceClient"/>
/// </summary>
Instance Metadata { get; }
/// <summary>
/// Access the <see cref="IByondClient"/>
/// </summary>
@@ -19,10 +23,10 @@ namespace Tgstation.Server.Client.Components
/// </summary>
IRepositoryClient Repository { get; }
/// <summary>
/// Access the <see cref="IDreamDaemonClient"/>
/// </summary>
IDreamDaemonClient DreamDaemon { get; }
/// <summary>
/// Access the <see cref="IDreamDaemonClient"/>
/// </summary>
IDreamDaemonClient DreamDaemon { get; }
/// <summary>
/// Access the <see cref="IConfigurationClient"/>
@@ -38,17 +42,15 @@ namespace Tgstation.Server.Client.Components
/// Access the <see cref="IChatSettingsClient"/>
/// </summary>
IChatSettingsClient Chat { get; }
/// <summary>
/// Access the <see cref="IDreamMakerClient"/>
/// </summary>
IDreamMakerClient DreamMaker { get; }
/// <summary>
/// Get the <see cref="Instance"/> represented by the <see cref="IInstanceClient"/>
/// Access the <see cref="IJobsClient"/>
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="Instance"/> represented by the <see cref="IInstanceClient"/></returns>
Task<Instance> Read(CancellationToken cancellationToken);
IJobsClient Jobs { get; }
}
}
@@ -1,14 +1,13 @@
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Rights;
namespace Tgstation.Server.Client.Components
namespace Tgstation.Server.Client
{
/// <summary>
/// For managing server administration
/// </summary>
public interface IAdministrationClient : IRightsClient<AdministrationRights>
public interface IAdministrationClient
{
/// <summary>
/// Get the <see cref="Administration"/> represented by the <see cref="IAdministrationClient"/>
@@ -2,37 +2,37 @@
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Rights;
using Tgstation.Server.Client.Components;
namespace Tgstation.Server.Client.Components
namespace Tgstation.Server.Client
{
/// <summary>
/// For managing <see cref="Instance"/>s
/// </summary>
public interface IInstanceManagerClient : IRightsClient<InstanceUserRights>
public interface IInstanceManagerClient
{
/// <summary>
/// Get all <see cref="IInstanceClient"/>s for <see cref="Instance"/>s the user 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 all <see cref="IInstanceClient"/>s for <see cref="Instance"/>s the user can view</returns>
Task<IReadOnlyList<IInstanceClient>> Read(CancellationToken cancellationToken);
/// <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<Instance>> List(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> Create(Instance instance, CancellationToken cancellationToken);
/// <returns>A <see cref="Task{TResult}"/> resulting in the created <see cref="Instance"/></returns>
Task<Instance> Create(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 Update(Instance instance, CancellationToken cancellationToken);
/// <returns>A <see cref="Task{TResult}"/> resulting in the updated <see cref="Instance"/></returns>
Task<Instance> Update(Instance instance, CancellationToken cancellationToken);
/// <summary>
/// Deletes an <paramref name="instance"/>
@@ -41,5 +41,12 @@ namespace Tgstation.Server.Client.Components
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task Delete(Instance instance, CancellationToken cancellationToken);
/// <summary>
/// Create an <see cref="IInstanceClient"/> for a given <see cref="Instance"/>
/// </summary>
/// <param name="instance">The <see cref="Instance"/> to create an <see cref="IInstanceClient"/> for</param>
/// <returns>A new <see cref="IInstanceClient"/></returns>
IInstanceClient CreateClient(Instance instance);
}
}
@@ -1,19 +0,0 @@
using System.Threading;
using System.Threading.Tasks;
namespace Tgstation.Server.Client
{
/// <summary>
/// <see cref="Api"/> client that has a <typeparamref name="TRights"/> bitset
/// </summary>
/// <typeparam name="TRights">The <see cref="Api.Rights"/> for the <see cref="IRightsClient{TRights}"/></typeparam>
public interface IRightsClient<TRights>
{
/// <summary>
/// Get the <typeparamref name="TRights"/> for the <see cref="IRightsClient{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="IRightsClient{TRights}"/></returns>
Task<TRights> Rights(CancellationToken cancellationToken);
}
}
+16 -19
View File
@@ -1,7 +1,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Client.Components;
using Tgstation.Server.Api.Models;
namespace Tgstation.Server.Client
{
@@ -10,26 +10,21 @@ namespace Tgstation.Server.Client
/// </summary>
public interface IServerClient : IDisposable
{
/// <summary>
/// The <see cref="Token"/> being used to access the server
/// </summary>
Token Token { get; }
/// <summary>
/// The <see cref="System.Version"/> of the <see cref="IServerClient"/>
/// </summary>
Version Version { get; }
Task<Version> Version(CancellationToken cancellationToken);
/// <summary>
/// The connection timeout in milliseconds. Defaults to 10000
/// The connection timeout in milliseconds
/// </summary>
int Timeout { get; set; }
/// <summary>
/// How long to return initially cached models for in seconds. Defaults to 60
/// </summary>
int CacheExpiry { get; set; }
/// <summary>
/// The requery rate for job updates in milliseconds. Defaults to 5000
/// </summary>
int RequeryRate { get; set; }
/// <summary>
/// Access the <see cref="IInstanceManagerClient"/>
/// </summary>
@@ -41,15 +36,17 @@ namespace Tgstation.Server.Client
IAdministrationClient Administration { get; }
/// <summary>
/// These generally shouldn't be used in favor of the <see cref="Task"/> based polling and <see cref="CancellationToken"/>s other clients use. However, this is the only way to access jobs the client didn't start in it's current session
/// Access the <see cref="IUsersClient"/>
/// </summary>
IJobsClient Jobs { get; }
IUsersClient Users { get; }
/// <summary>
/// The <see cref="System.Version"/> of the connected server
/// Creates a <see cref="Task{TResult}"/> that completes when a given <paramref name="job"/> is completed
/// </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(CancellationToken cancellationToken);
/// <param name="job">The <see cref="Job"/> to create a <see cref="Task"/> for</param>
/// <param name="requeryRate">The rate in seconds to poll the server for results</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> which will trigger the cancellation of the <paramref name="job"/></param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a complete <see cref="Job"/></returns>
Task<Job> CreateTaskFromJob(Job job, int requeryRate, CancellationToken cancellationToken);
}
}
@@ -1,5 +1,6 @@
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Api.Models;
namespace Tgstation.Server.Client
{
@@ -24,11 +25,11 @@ namespace Tgstation.Server.Client
/// Create a <see cref="IServerClient"/>
/// </summary>
/// <param name="hostname">The URL to access tgstation-server at</param>
/// <param name="token">The <see cref="Api.Models.Token.Bearer"/> to access the API with</param>
/// <param name="token">The <see cref="Api.Models.Token"/> 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, CancellationToken cancellationToken);
Task<IServerClient> CreateServerClient(string hostname, Token token, int timeout, CancellationToken cancellationToken);
}
}
@@ -0,0 +1,35 @@
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Api.Models;
namespace Tgstation.Server.Client
{
/// <summary>
/// For managing <see cref="User"/>s
/// </summary>
public interface IUsersClient
{
/// <summary>
/// Read the current user's information and general rights
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns></returns>
Task<User> Read(CancellationToken cancellationToken);
/// <summary>
/// Create a new <paramref name="user"/>
/// </summary>
/// <param name="user">The <see cref="UserUpdate"/> used to create the new <see cref="User"/></param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>The new <see cref="User"/></returns>
Task<User> Create(UserUpdate user, CancellationToken cancellationToken);
/// <summary>
/// Update a <paramref name="user"/>
/// </summary>
/// <param name="user">The <see cref="UserUpdate"/> used to update the <see cref="User"/></param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>The updated <see cref="User"/></returns>
Task<User> Update(UserUpdate user, CancellationToken cancellationToken);
}
}
@@ -1,6 +1,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Api.Models;
namespace Tgstation.Server.Client
{
@@ -11,6 +12,6 @@ namespace Tgstation.Server.Client
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, CancellationToken cancellationToken) => throw new NotImplementedException();
public Task<IServerClient> CreateServerClient(string hostname, Token token, int timeout, CancellationToken cancellationToken) => throw new NotImplementedException();
}
}