Merge branch 'dev' into issues/302

This commit is contained in:
RogueException
2016-12-05 18:48:38 -04:00

View File

@@ -70,21 +70,17 @@ namespace Discord.Rpc
=> new API.DiscordRpcApiClient(clientId, DiscordRestConfig.UserAgent, origin, config.RestClientProvider, config.WebSocketProvider, requestQueue: new RequestQueue()); => new API.DiscordRpcApiClient(clientId, DiscordRestConfig.UserAgent, origin, config.RestClientProvider, config.WebSocketProvider, requestQueue: new RequestQueue());
/// <inheritdoc /> /// <inheritdoc />
public Task ConnectAsync() => ConnectAsync(false); public async Task ConnectAsync()
internal async Task ConnectAsync(bool ignoreLoginCheck)
{ {
await _connectionLock.WaitAsync().ConfigureAwait(false); await _connectionLock.WaitAsync().ConfigureAwait(false);
try try
{ {
await ConnectInternalAsync(ignoreLoginCheck, false).ConfigureAwait(false); await ConnectInternalAsync(false).ConfigureAwait(false);
} }
finally { _connectionLock.Release(); } finally { _connectionLock.Release(); }
} }
private async Task ConnectInternalAsync(bool ignoreLoginCheck, bool isReconnecting) private async Task ConnectInternalAsync(bool isReconnecting)
{ {
if (!ignoreLoginCheck && LoginState != LoginState.LoggedIn)
throw new InvalidOperationException("You must log in before connecting.");
if (!isReconnecting && _reconnectCancelToken != null && !_reconnectCancelToken.IsCancellationRequested) if (!isReconnecting && _reconnectCancelToken != null && !_reconnectCancelToken.IsCancellationRequested)
_reconnectCancelToken.Cancel(); _reconnectCancelToken.Cancel();
@@ -198,7 +194,7 @@ namespace Discord.Rpc
try try
{ {
if (cancelToken.IsCancellationRequested) return; if (cancelToken.IsCancellationRequested) return;
await ConnectInternalAsync(false, true).ConfigureAwait(false); await ConnectInternalAsync(true).ConfigureAwait(false);
_reconnectTask = null; _reconnectTask = null;
return; return;
} }
@@ -223,7 +219,7 @@ namespace Discord.Rpc
public async Task<string> AuthorizeAsync(string[] scopes, string rpcToken = null, RequestOptions options = null) public async Task<string> AuthorizeAsync(string[] scopes, string rpcToken = null, RequestOptions options = null)
{ {
await ConnectAsync(true).ConfigureAwait(false); await ConnectAsync().ConfigureAwait(false);
var result = await ApiClient.SendAuthorizeAsync(scopes, rpcToken, options).ConfigureAwait(false); var result = await ApiClient.SendAuthorizeAsync(scopes, rpcToken, options).ConfigureAwait(false);
await DisconnectAsync().ConfigureAwait(false); await DisconnectAsync().ConfigureAwait(false);
return result.Code; return result.Code;