/// <summary> /// Adds the pat token. /// </summary> /// <param name="friendlyName">Name of the friendly.</param> /// <param name="userName">Name of the user.</param> /// <param name="patToken">The pat token.</param> /// <exception cref="AzureDevOpsMgmt.Exceptions.ObjectExistsException">Pat Token</exception> /// <exception cref="T:AzureDevOpsMgmt.Exceptions.ObjectExistsException">This exception is thrown if the user attempts to add a Pat Token and an existing Token with that friendly name is found in the /// repository.</exception> public void AddPatToken(string friendlyName, string userName, string patToken) { if (this.PatTokens.Any(p => p.FriendlyName.Equals(friendlyName, StringComparison.OrdinalIgnoreCase))) { throw new ObjectExistsException("Pat Token"); } var protoToken = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{userName}:{patToken}")); var item = new AzureDevOpsPatToken(friendlyName, protoToken); this.PatTokens.Add(item); }
/// <summary> /// Performs the pat token transaction. /// </summary> /// <param name="selector">The selector.</param> /// <param name="updateData">The update data.</param> /// <returns><c>true</c> if operation was successful, <c>false</c> otherwise.</returns> internal bool PerformPatTokenUpdate(Func <AzureDevOpsPatToken, bool> selector, AzureDevOpsPatToken updateData) { var tempItem = this.PatTokens.First(selector); try { this.PatTokens.Remove(tempItem); this.PatTokens.Add(updateData); return(true); } catch (Exception) { // TODO: Add some logging here if (this.PatTokens.Contains(tempItem)) { this.PatTokens.Remove(tempItem); this.PatTokens.Add(tempItem); } else { this.PatTokens.Add(tempItem); } return(false); } }