private async void BtnStart_Click(object sender, RoutedEventArgs e) { //Create Passport LoginHelp loginHelp = new LoginHelp(this.activeAccount); bool rev = await loginHelp.CreatePassportKey(this.activeAccount.Name); if (rev) { //add possport to server. bool serverAddedPassportToAccount = await loginHelp.AddPassportToAccountOnServer(); if (serverAddedPassportToAccount == true) { //update userPassport state this.activeAccount.UsesPassport = true; foreach (Account a in UserSelect.accountList) { if (a.Email == this.activeAccount.Email) { UserSelect.accountList.Remove(a); break; } } UserSelect.accountList.Add(this.activeAccount); AccountsHelper.SaveAccountList(UserSelect.accountList); } this.Frame.Navigate(typeof(AccountDetails), this.activeAccount); } }
/// <summary> /// The function that will be called when this frame is navigated to. /// /// Checks to see if Microsoft Passport is available and checks to see if an /// account was passed in. /// /// If an account was passed, check if it uses Microsoft Passport. /// and set the "adding user" flag so we don't add a new account /// to the list of users. /// </summary> /// <param name="e"></param> protected async override void OnNavigatedTo(NavigationEventArgs e) { rootPage = MainPage.Current; if (e.Parameter != null) { m_account = (Account)e.Parameter; textbox_Username.Text = m_account.Email; textbox_Username.IsEnabled = false; if (this.m_account.UsesPassport) { LoginHelp loginHelp = new LoginHelp(this.m_account); bool rev = await loginHelp.SignInPassport(); if (rev) { this.Frame.Navigate(typeof(AccountDetails), this.m_account); } } } var accountList = await AccountsHelper.LoadAccountList(); if (accountList.Count > 1) { this.btnSelectUser.Visibility = Visibility.Visible; } else { this.btnSelectUser.Visibility = Visibility.Collapsed; } }
private void updateAccount() { //find current account and update foreach (Account a in UserSelect.accountList) { if (a.Email == this.activeAccount.Email) { UserSelect.accountList.Remove(a); break; } } UserSelect.accountList.Add(this.activeAccount); AccountsHelper.SaveAccountList(UserSelect.accountList); }
/// <summary> /// Uses the AccountsHelper to load the list of accounts from a saved local app file, /// then checks to see if it was empty or not. If it is empty then just go to the sign in form. /// </summary> private async void SetUpAccounts() { accountList = await AccountsHelper.LoadAccountList(); this.listUser.ItemsSource = accountList; if (accountList.Count > 0) { if (accountList.Count == 1) { this.Frame.Navigate(typeof(SignIn)); } else { this.listUser.SelectedIndex = 0; } } }
/// <summary> /// Handles user saving for our list of users if this is a new user /// </summary> private void SuccessfulSignIn(bool isAdd) { // If this is an already existing account, replace the old // version of this account in the account list. if (isAdd == false) { foreach (Account a in UserSelect.accountList) { if (a.Email == this.activeAccount.Email) { UserSelect.accountList.Remove(a); break; } } } UserSelect.accountList.Add(this.activeAccount); AccountsHelper.SaveAccountList(UserSelect.accountList); }
/// <summary> /// Gets the account list file and deserializes it from XML to a list of accounts object. /// </summary> /// <returns>List of account objects</returns> static public async Task <List <Account> > LoadAccountList() { try { StorageFile accountsFile = await ApplicationData.Current.LocalFolder.GetFileAsync(USER_LIST_FILE_NAME); string accountsXml = await Windows.Storage.FileIO.ReadTextAsync(accountsFile); List <Account> listAccount = AccountsHelper.DeserializeXmlToAccountList(accountsXml); listAccount.Add(new Account() { head = "Assets/head_add.png", Name = ResourceManagerHelper.ReadValue("addusertip"), isAdd = true }); return(listAccount); } catch (FileNotFoundException e) { List <Account> emptyAccountList = new List <Account>(); return(emptyAccountList); } }
private void btnClearAccount_Click(object sender, RoutedEventArgs e) { UserSelect.accountList.Clear(); AccountsHelper.SaveAccountList(UserSelect.accountList); rootPage.ShowMessage("Clear Account Success."); }