Пример #1
0
        /// <summary>
        /// Updates the specified account in the account list with the details provided in the
        /// <see cref="Account"/> object
        /// </summary>
        /// <param name="securityType">The value to update: password or api key</param>
        /// <param name="updatedAccount">The account containing the username to update and the updated value (password/api key)</param>
        /// <returns><see cref="true"/> if the update was successful, <see cref="false"/> otherwise</returns>
        public bool UpdateAccount(AccountSecurityType securityType, Account updatedAccount)
        {
            var accounts = GetAllAccountsFromJson();

            if (!accounts.DoesAccountExist(updatedAccount.Username))
            {
                Console.WriteLine($"Account '{updatedAccount.Username}' does not exist in the list of accounts; can't update what isn't in the list!");
                return(false);
            }

            var index = accounts.FindIndexOfAccount(updatedAccount.Username);

            switch (securityType)
            {
            case AccountSecurityType.Password:
                accounts[index].Password = updatedAccount.Password;
                break;

            case AccountSecurityType.APIKey:
                accounts[index].ApiKey = updatedAccount.ApiKey;
                break;
            }

            var accountsJsonString = JsonConvert.SerializeObject(accounts, Formatting.Indented);

            File.WriteAllText(_accountFile, accountsJsonString);

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Create a <see cref="Account"/> object from the command line information. Used for
        /// adding or updating accounts.
        /// </summary>
        /// <param name="securityType">The type of API security this account will use to access the API</param>
        /// <param name="account">The list from the command line input</param>
        /// <returns>A <see cref="Account"/> object populated with the relevant information</returns>
        private Account ScaffoldAccount(AccountSecurityType securityType, List <string> account)
        {
            Account parsedAccount;

            if (securityType == AccountSecurityType.APIKey)
            {
                parsedAccount = new Account
                {
                    Username = account[0],
                    ApiKey   = account[1]
                };
            }
            else
            {
                parsedAccount = new Account
                {
                    Username = account[0],
                    Password = account[1]
                };
            }

            return(parsedAccount);
        }
Пример #3
0
        /// <summary>
        /// Updates an existing account
        /// </summary>
        /// <param name="securityType">The account security type that's being updated (either password or api key)</param>
        /// <param name="account">The account with updated details</param>
        /// <returns><see cref="true"/> if the update was successful, <see cref="false"/> otherwise</returns>
        public bool UpdateAccount(AccountSecurityType securityType, List <string> account)
        {
            Account parsedAccount = ScaffoldAccount(securityType, account);

            return(_accountManager.UpdateAccount(securityType, parsedAccount));
        }