public bool ContainsAccount(VATRPAccount account) { var query = from record in this.accountsList where record.Username == account.Username && record.AccountType == account.AccountType select record; if (query.Any()) { return(true); } IEnumerable <VATRPAccount> allItems = (from c in this.accountsList where c.Username == account.Username && c.AccountType == account.AccountType select c).ToList(); foreach (var c in allItems) { accountsList.Remove(c); } this.DeferredSave(); return(false); }
/// <summary> /// Loads an account from the cached account list file /// </summary> /// <remarks> /// Since we can start the login process with either a config /// file or the text edit fields its necessary to place this /// cache file lookup in a wrapper that checks if it has already /// been called. Otherwise, it's possible for information to be /// overwritten when it is called following a config file upload. /// /// _needToAddAccount will be set to True if the file does not exist /// in the cached file accounts list so that it will be added in the /// future. /// </remarks> /// <returns>the account and a boolean if it needs to be added</returns> private VATRPAccount LoadCachedAccountFromFile(string username) { VATRPAccount loadedAccount = null; if (_accountNotYetLoaded) { loadedAccount = ServiceManager.Instance.AccountService.FindAccount(username, Address); _needToAddAccount = loadedAccount == null; } _accountNotYetLoaded = false; return(loadedAccount); }
public bool DeleteAccount(VATRPAccount account) { if (string.IsNullOrEmpty(account.AccountID)) { return(false); } var query = from record in this.accountsList where record.AccountID == account.AccountID select record; if (!query.Any()) { return(false); } this.accountsList.Remove(account); this.DeferredSave(); return(true); }
public bool Stop() { if (IsStarting || IsStopping) { return(false); } _isStopping = true; _isStopped = true; // clear all empty accounts bool saveAccounts = false; do { var vatrpAccounts = this.accountsList; IEnumerable <VATRPAccount> allAccounts = (from c in vatrpAccounts where c.Username == string.Empty select c).ToList(); VATRPAccount emptyAccount = allAccounts.FirstOrDefault(); if (emptyAccount == null) { break; } DeleteAccount(emptyAccount); saveAccounts = true; } while (true); if (saveAccounts) { ImmediateSave(); } if (ServiceStopped != null) { ServiceStopped(this, EventArgs.Empty); } return(true); }
public bool AddAccount(VATRPAccount account) { if (account.AccountType == VATRPAccountType.Unknown) { return(false); } this.loadProperAccount(); // cjm-sep17 -- trying to persist the changes to the list if (this.accountsList != null) { if (this.accountsList.Exists(x => x.AccountID == account.AccountID && x.AccountType == account.AccountType)) { return(true); } } else { accountsList = new List <VATRPAccount>(); } this.accountsList.Insert(0, account); this.DeferredSave(); return(true); }
public void InitializeToAccount(VATRPAccount account) { if (account != null) { UserNameBox.Text = account.PhoneNumber; // The VATRP PhoneNumber variable holds either a phone number or registrtion username AuthIDBox.Text = account.AuthID; OutboundProxyServerBox.Text = account.OutboundProxy; InitializeToProvider(account.ProxyHostname); RememberPasswordBox.IsChecked = account.RememberPassword; AutoLoginBox.IsChecked = ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL, Configuration.ConfEntry.AUTO_LOGIN, false); //AutoLoginBox.IsChecked = account.AutoLogin; HostPort = account.HostPort; HostPortBox.Text = account.HostPort.ToString(); string transport = account.Transport; if (string.IsNullOrWhiteSpace(transport)) { transport = "TCP"; } foreach (var item in TransportComboBox.Items) { var tb = item as TextBlock; string itemString = tb.Text; if (itemString.Equals(transport, StringComparison.InvariantCultureIgnoreCase)) { TransportComboBox.SelectedItem = item; TextBlock selectedItem = TransportComboBox.SelectedItem as TextBlock; if (selectedItem != null) { string test = selectedItem.Text; } break; } } string hostName = account.ProxyHostname; if (!string.IsNullOrWhiteSpace(hostName)) { HostnameBox.Text = hostName; } string loginMethod = account.LoginMethod; if (string.IsNullOrWhiteSpace(loginMethod)) { loginMethod = "Old"; } foreach (var item in LoginComboBox.Items) { var tb = item as TextBlock; string itemString = tb.Text; if (itemString.Equals(loginMethod)) { LoginComboBox.SelectedItem = item; TextBlock selectedItem = LoginComboBox.SelectedItem as TextBlock; if (selectedItem != null) { string test = selectedItem.Text; } break; } } } }