Exemplo n.º 1
0
        /// <summary>
        /// Performs the account transaction.
        /// </summary>
        /// <param name="updateData">The update data.</param>
        /// <returns><c>true</c> if operation succeed, <c>false</c> otherwise.</returns>
        internal bool PerformAccountUpdate(AzureDevOpsAccount updateData)
        {
            var tempItem = this.Accounts.First(a => a.FriendlyName == updateData.FriendlyName);

            try
            {
                this.Accounts.Remove(tempItem);
                this.Accounts.Add(updateData);
                return(true);
            }
            catch (Exception)
            {
                // TODO: Add some logging here
                if (this.Accounts.Contains(tempItem))
                {
                    this.Accounts.Remove(tempItem);
                    this.Accounts.Add(tempItem);
                }
                else
                {
                    this.Accounts.Add(tempItem);
                }

                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds the account.
        /// </summary>
        /// <param name="friendlyName">Name of the friendly.</param>
        /// <param name="accountName">Name of the account.</param>
        /// <exception cref="AzureDevOpsMgmt.Exceptions.ObjectExistsException">Account Already Exists</exception>
        /// <exception cref="T:AzureDevOpsMgmt.Exceptions.ObjectExistsException">This exception is thrown if the user attempts to add an account and an existing account with that name or friendly name is found in the
        /// repository.</exception>
        public void AddAccount(string friendlyName, string accountName)
        {
            if (this.Accounts.Any(
                    a => a.AccountName.Equals(accountName, StringComparison.OrdinalIgnoreCase)
                    | a.FriendlyName.Equals(friendlyName, StringComparison.OrdinalIgnoreCase)))
            {
                throw new ObjectExistsException("Account");
            }

            var url     = $"https://dev.azure.com/{accountName}";
            var account = new AzureDevOpsAccount(friendlyName, accountName, url);

            this.Accounts.Add(account);
        }