public async Task <Account> AddAccountAsync(Auth.TokenInfo token, Auth.CharacterInfo charinfo, Auth.AccessFlag permissions) { using (var dbop = new DBOperation()) { mCmd_AddAccount.Parameters["@id"].Value = charinfo.CharacterId; mCmd_AddAccount.Parameters["@name"].Value = charinfo.CharacterName; mCmd_AddAccount.Parameters["@permissions"].Value = (int)permissions; try { await mCmd_AddAccount.ExecuteNonQueryAsync(); Account account = new Account(this, charinfo.CharacterId, charinfo.CharacterName, permissions); mAccounts.Add(account); account.UpdateAuthInfo(token); await SaveChangesAsync(); return(account); } catch (SQLiteException e) { if (e.ErrorCode == 19) { throw new AccountExistsException(); } throw new AccountDatabaseException(string.Format("Unable to create account. Database error({0}).", e.ErrorCode)); } } }
public async Task AddAccountAsync(Auth.TokenInfo token, Auth.CharacterInfo charinfo, Auth.AccessFlag permissions) { DB.Account dbaccount = await mAccountDB.AddAccountAsync(token, charinfo, permissions); Account account = new Account(this, dbaccount); mAccounts.Add(account); mViewAccounts.Add(account.ViewAccount); OnAccountAction(true, account); }
public async Task <bool> UpdateAccountAuthAsync(Auth.TokenInfo token, Auth.CharacterInfo charinfo, Auth.AccessFlag permissions) { foreach (Account i in Accounts) { if (i.Id != charinfo.CharacterId) { continue; } i.DBAccount.UpdateAuthInfo(token, permissions); await mAccountDB.SaveChangesAsync(); return(true); } return(false); }
private async Task <bool> RefreshToken() { mViewAccount.AccountState = AccountState; if (mDBAccount.Expires < DateTime.Now) { mLog.Info($"{this.UserName}: Refreshing tokens"); Auth.TokenInfo token = await Auth.SSOAuth.RefreshTokenInfoAsync(DBAccount.RefreshToken); if (token == null) { mReadFailed = true; return(false); } mDBAccount.UpdateAuthInfo(token); } return(true); }