private static async Task <string> GetUploadToken() { if (!string.IsNullOrEmpty(Account.Instance.UploadToken)) { return(Account.Instance.UploadToken); } UploadTokenHistory.Write("Trying to request new token"); string token; try { Log.Info("Requesting new upload token..."); token = await Client.CreateUploadToken(); if (string.IsNullOrEmpty(token)) { throw new Exception("Reponse contained no upload-token."); } } catch (Exception e) { Log.Error(e); UploadTokenHistory.Write("Requesting new token failed:\n" + e); throw new Exception("Webrequest to obtain upload-token failed.", e); } Account.Instance.UploadToken = token; Account.Instance.TokenClaimed = false; Account.Save(); UploadTokenHistory.Write("Received " + token); Log.Info("Received new upload-token."); return(token); }
public void Reset() { UploadTokenHistory.Write("Deleting token"); UploadToken = string.Empty; CollectionState.Clear(); Update(0, null); }
internal static async Task <bool> ClaimUploadToken(string token) { UploadTokenHistory.Write("Trying to claim " + token); try { if (!await UpdateToken()) { Log.Error("Could not update token data"); return(false); } var response = await Client.Value.ClaimUploadToken(token); UploadTokenHistory.Write($"Claimed {token}: {response}"); Log.Debug(response); UploadTokenClaimed?.Invoke(); return(true); } catch (Exception e) { UploadTokenHistory.Write($"Error claming {token}\n" + e); Log.Error(e); return(false); } }