Browse Source

Start documenting some things to reduce CS1591 warnings

pull/222/head
FiniteReality 9 years ago
parent
commit
14f0ab75c0
3 changed files with 20 additions and 0 deletions
  1. +6
    -0
      src/Discord.Net/Net/Rest/DefaultRestClient.cs
  2. +4
    -0
      src/Discord.Net/Net/RpcException.cs
  3. +10
    -0
      src/Discord.Net/Rest/DiscordRestClient.cs

+ 6
- 0
src/Discord.Net/Net/Rest/DefaultRestClient.cs View File

@@ -13,6 +13,7 @@ using System.Threading.Tasks;

namespace Discord.Net.Rest
{
///<summary> A default implementation of a <see cref="IRestClient"/> </summary>
public sealed class DefaultRestClient : IRestClient
{
private const int HR_SECURECHANNELFAILED = -2146233079;
@@ -24,6 +25,7 @@ namespace Discord.Net.Rest
private CancellationToken _cancelToken, _parentToken;
private bool _isDisposed;

/// <summary> Creates a new instance of <see cref="DefaultRestClient"/> </summary>
public DefaultRestClient(string baseUrl)
{
_baseUrl = baseUrl;
@@ -50,23 +52,27 @@ namespace Discord.Net.Rest
_isDisposed = true;
}
}
/// <summary> Disposes any resources allocated by this instance. </summary>
public void Dispose()
{
Dispose(true);
}

/// <summary> Sets a header to be used in REST requests. </summary>
public void SetHeader(string key, string value)
{
_client.DefaultRequestHeaders.Remove(key);
if (value != null)
_client.DefaultRequestHeaders.Add(key, value);
}
/// <summary> Sets the global cancellation token for any requests made by this instance. </summary>
public void SetCancelToken(CancellationToken cancelToken)
{
_parentToken = cancelToken;
_cancelToken = CancellationTokenSource.CreateLinkedTokenSource(_parentToken, _cancelTokenSource.Token).Token;
}

/// <summary> Sends a request with no body to the given endpoint. </summary>
public async Task<Stream> SendAsync(string method, string endpoint, bool headerOnly = false)
{
string uri = Path.Combine(_baseUrl, endpoint);


+ 4
- 0
src/Discord.Net/Net/RpcException.cs View File

@@ -2,11 +2,15 @@

namespace Discord
{
/// <summary> An exception thrown whenever an RPC error occurs. </summary>
public class RpcException : Exception
{
/// <summary> The code for this error. </summary>
public int ErrorCode { get; }
/// <summary> The reason this error occured. </summary>
public string Reason { get; }

/// <summary> Creates a new instance of <see cref="RpcException"/> </summary>
public RpcException(int errorCode, string reason = null)
: base($"The server sent error {errorCode}{(reason != null ? $": \"{reason}\"" : "")}")
{


+ 10
- 0
src/Discord.Net/Rest/DiscordRestClient.cs View File

@@ -15,15 +15,19 @@ using Discord.WebSocket;

namespace Discord.Rest
{
/// <summary> A client which invokes Discord's REST API. </summary>
public class DiscordRestClient : IDiscordClient
{
private readonly object _eventLock = new object();

/// <summary> Fired whenever a message is logged. </summary>
public event Func<LogMessage, Task> Log { add { _logEvent.Add(value); } remove { _logEvent.Remove(value); } }
private readonly AsyncEvent<Func<LogMessage, Task>> _logEvent = new AsyncEvent<Func<LogMessage, Task>>();

/// <summary> Fired whenever the client logs in. </summary>
public event Func<Task> LoggedIn { add { _loggedInEvent.Add(value); } remove { _loggedInEvent.Remove(value); } }
private readonly AsyncEvent<Func<Task>> _loggedInEvent = new AsyncEvent<Func<Task>>();
/// <summary> Fired whenever the client logs out. </summary>
public event Func<Task> LoggedOut { add { _loggedOutEvent.Add(value); } remove { _loggedOutEvent.Remove(value); } }
private readonly AsyncEvent<Func<Task>> _loggedOutEvent = new AsyncEvent<Func<Task>>();

@@ -33,12 +37,15 @@ namespace Discord.Rest
private bool _isFirstLogSub;
internal bool _isDisposed;

/// <summary> The API client used for making API calls. </summary>
public API.DiscordRestApiClient ApiClient { get; }
internal LogManager LogManager { get; }
/// <summary> The current login state of the client. </summary>
public LoginState LoginState { get; private set; }

/// <summary> Creates a new REST-only discord client. </summary>
public DiscordRestClient() : this(new DiscordRestConfig()) { }
/// <summary> Creates a new REST-only discord client. </summary>
public DiscordRestClient(DiscordRestConfig config) : this(config, CreateApiClient(config)) { }
/// <summary> Creates a new REST-only discord client. </summary>
internal DiscordRestClient(DiscordRestConfig config, API.DiscordRestApiClient client)
@@ -103,6 +110,7 @@ namespace Discord.Rest

await _loggedInEvent.InvokeAsync().ConfigureAwait(false);
}
/// <summary> Validates a token with the given type. </summary>
protected virtual async Task ValidateTokenAsync(TokenType tokenType, string token)
{
try
@@ -121,6 +129,7 @@ namespace Discord.Rest
throw new ArgumentException("Token validation failed", nameof(token), ex);
}
}
/// <summary> A Promise for when the client successfully logs in. </summary>
protected virtual Task OnLoginAsync(TokenType tokenType, string token) => Task.CompletedTask;


@@ -149,6 +158,7 @@ namespace Discord.Rest

await _loggedOutEvent.InvokeAsync().ConfigureAwait(false);
}
/// <summary> A Promise for when the client successfully logs out. </summary>
protected virtual Task OnLogoutAsync() => Task.CompletedTask;

/// <inheritdoc />


Loading…
Cancel
Save