public void UpdateAccountInformation(long accountId, string nickname = null,
                                      string screenname = null, string profileImageUrl = null)
 {
     if (FindAccountById(accountId) is CTwitterAccountInformation account)
     {
         if (!account.Nickname.Equals(nickname) || !account.ScreenName.Equals(screenname) || !account.ProfileImageUrl.Equals(profileImageUrl))
         {
             var tempDecryptedAccessTokens = DecryptAccessTokens(account);
             var refreshedAccount          = new CTwitterAccountInformation()
             {
                 AccountID       = accountId,
                 Nickname        = nickname,
                 ScreenName      = screenname,
                 ProfileImageUrl = profileImageUrl,
                 TokenInfo       = new CTwitterAccountTokenInformation()
                 {
                     AccessToken       = tempDecryptedAccessTokens.Item1.ReadAsString(),
                     AccessTokenSecret = tempDecryptedAccessTokens.Item2.ReadAsString()
                 }
             };
             EncryptAccessTokens(refreshedAccount);
             ReplaceAccount(accountId, refreshedAccount);
         }
         else
         {
             account.Nickname        = nickname;
             account.ScreenName      = screenname;
             account.ProfileImageUrl = profileImageUrl;
         }
     }
 }
        public void AddAccount(int index, CTwitterAccountInformation accountInformation)
        {
            if (!accountInformation.TokenInfo.Secured)
            {
                EncryptAccessTokens(accountInformation);
            }

            AccountInformations.Insert(index, accountInformation);
        }
        public CTwitterAccountInformation FindAccountById(long accountId)
        {
            CTwitterAccountInformation item = null;

            AccountInformations.ForEach(i => {
                if (i.AccountID == accountId)
                {
                    item = i;
                }
            });

            return(item);
        }
        public bool ReplaceAccount(long accountId, CTwitterAccountInformation accountInformation)
        {
            int currentIndex = GetAccountIndex(accountId);

            if (currentIndex != -1)
            {
                RemoveAccount(accountId);
                AddAccount(currentIndex, accountInformation);

                if (AccountInformations[currentIndex] == accountInformation)
                {
                    return(true);
                }
            }

            return(false);
        }
        internal void EncryptAccessTokens(CTwitterAccountInformation accountInformation)
        {
            if (!accountInformation.TokenInfo.Secured)
            {
                accountInformation.TokenInfo.AccessToken
                    = accountInformation.TokenInfo.AccessToken.Encrypt(
                          accountInformation.GetPW(accountInformation.Nickname.Substring(
                                                       accountInformation.Nickname.Length - 1 - (accountInformation.Nickname.Length < 4 ? 0 : 1), 1)).ReadAsString(),
                          accountInformation.GetSALT(nameof(accountInformation.TokenInfo.AccessToken)).ReadAsString(),
                          accountInformation.GetIV(@"CoLA").ReadAsString()).ReadAsString();
                accountInformation.TokenInfo.AccessTokenSecret
                    = accountInformation.TokenInfo.AccessTokenSecret.Encrypt(
                          accountInformation.GetPW(accountInformation.Nickname.Substring(
                                                       accountInformation.Nickname.Length - 1 - (accountInformation.Nickname.Length < 4 ? 0 : 3), 1)).ReadAsString(),
                          accountInformation.GetSALT(nameof(accountInformation.TokenInfo.AccessTokenSecret)).ReadAsString(),
                          accountInformation.GetIV(@"CH!K").ReadAsString()).ReadAsString();

                accountInformation.TokenInfo.Secured = true;
            }
        }
 internal Tuple <SecureString, SecureString> DecryptAccessTokens(CTwitterAccountInformation accountInformation)
 {
     if (accountInformation.TokenInfo.Secured)
     {
         return(new Tuple <SecureString, SecureString>(
                    accountInformation.TokenInfo.AccessToken.Decrypt(
                        accountInformation.GetPW(accountInformation.Nickname.Substring(
                                                     accountInformation.Nickname.Length - 1 - (accountInformation.Nickname.Length < 4 ? 0 : 1), 1)).ReadAsString(),
                        accountInformation.GetSALT(nameof(accountInformation.TokenInfo.AccessToken)).ReadAsString(),
                        accountInformation.GetIV(@"CoLA").ReadAsString()),
                    accountInformation.TokenInfo.AccessTokenSecret.Decrypt(
                        accountInformation.GetPW(accountInformation.Nickname.Substring(
                                                     accountInformation.Nickname.Length - 1 - (accountInformation.Nickname.Length < 4 ? 0 : 3), 1)).ReadAsString(),
                        accountInformation.GetSALT(nameof(accountInformation.TokenInfo.AccessTokenSecret)).ReadAsString(),
                        accountInformation.GetIV(@"CH!K").ReadAsString())));
     }
     else
     {
         return(new Tuple <SecureString, SecureString>(
                    accountInformation.TokenInfo.AccessToken.ToSecureString(),
                    accountInformation.TokenInfo.AccessTokenSecret.ToSecureString()));
     }
 }
 public void RemoveAccount(CTwitterAccountInformation accountInformation)
 => AccountInformations.Remove(accountInformation);
 public void AddAccount(CTwitterAccountInformation accountInformation)
 => AddAccount(AccountInformations.Count, accountInformation);
 public int GetAccountIndex(CTwitterAccountInformation accountInformation)
 => AccountInformations.IndexOf(accountInformation);