Beispiel #1
0
 /// <summary>
 ///     Ensures the <see cref="Session" /> gets reauthenticated, no matter how long it takes.
 /// </summary>
 private async Task Reauthenticate()
 {
     ReauthenticateMutex.WaitOne();
     if (_client.AccessToken.IsExpired)
     {
         _client.AccessToken = null;
         var tries = 0;
         while (_client.AccessToken == null)
         {
             try
             {
                 await _client.Login.DoLogin();
             }
             catch (Exception exception)
             {
                 Logger.Write($"Reauthenticate exception was catched: {exception}");
             }
             finally
             {
                 if (_client.AccessToken == null)
                 {
                     var sleepSeconds = Math.Min(60, ++tries * 5);
                     Logger.Write($"Reauthentication failed, trying again in {sleepSeconds} seconds.");
                     await Task.Delay(sleepSeconds * 1000);
                 }
             }
         }
         OnAccessTokenUpdated?.Invoke(this, null);
     }
     ReauthenticateMutex.ReleaseMutex();
 }
Beispiel #2
0
 /// <summary>
 /// Request worked, reset retry count and check if we have an updated token
 /// </summary>
 /// <param name="request"></param>
 /// <param name="response"></param>
 public void HandleApiSuccess(RequestEnvelope request, ResponseEnvelope response)
 {
     _retryCount = 0;
     // Check if we got an updated ticket
     if (response.AuthTicket == null)
     {
         return;
     }
     // Update the new token
     _client.AccessToken.AuthTicket = response.AuthTicket;
     OnAccessTokenUpdated?.Invoke(this, null);
     Logger.Write("Received a new AuthTicket from Pokémon!");
 }