/// <summary> /// Adds a new <paramref name="user"/> to the store asynchronously. /// </summary> /// <param name="user">A A <see cref="AzureTableUser"/>-derived type-derived type</param> /// <param name="login"><see cref="UserLoginInfo"/></param> /// <returns><see cref="Task"/></returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="user"/> or <paramref name="login"/> is <c>null</c>.</exception> /// <see cref="AzureTableUserException">Thrown whenever a table operation results in a <see cref="StorageException"/> being thrown.</see> public virtual async Task AddLoginAsync(T user, UserLoginInfo login) { AssertNotDisposed(); if (user == null) { throw new ArgumentNullException("user"); } if (login == null) { throw new ArgumentNullException("login"); } var atul = new AzureTableUserLogin { LoginProvider = login.LoginProvider, ProviderKey = Encode(login.ProviderKey), // goog's is a fukken URL. Damnit, goog. UserId = user.Id, }; try { await Run(UserLoginTableName, TableOperation.InsertOrReplace(atul)); } catch (StorageException ex) { //TODO: Not sure if I should throw or silently swallow this exception if (ex.RequestInformation.HttpStatusCode == (int)HttpStatusCode.Conflict) { throw new AzureTableRoleException("The login info already exists", ex); } throw new AzureTableUserException("An exception was thrown while attempting to add this login info. See the inner exception for details.", ex); } }
/// <summary> /// Removes the given <paramref name="login"/> for the given <paramref name="user"/>. /// </summary> /// <param name="user">A A <see cref="AzureTableUser"/>-derived type-derived type</param> /// <param name="login"><see cref="UserLoginInfo"/></param> /// <returns><see cref="Task"/></returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="login"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">Thrown when <paramref name="user"/> is <c>null</c>.</exception> public async Task RemoveLoginAsync(T user, UserLoginInfo login) { AssertNotDisposed(); if (user == null) { throw new ArgumentNullException("user"); } if (login == null) { throw new ArgumentNullException("login"); } try { var atul = new AzureTableUserLogin { PartitionKey = AzureTableUserLoginPartitionKey, ProviderKey = Encode(login.ProviderKey) }; atul.EnsureETagSet(); await Run(UserLoginTableName, TableOperation.Delete(atul)); } catch (StorageException ex) { throw new AzureTableUserException("An exception was thrown while attempting to find the logins for this user. See the inner exception for details.", ex); } }