/// <summary> /// Ensures there's only one reference of each account. Creates new account object if account file wasn't found. /// </summary> /// <param name="localAccountId"></param> /// <returns></returns> /// <exception cref="Exception">Throws exception if the folder for the account isn't found.</exception> private static async Task <AccountWin> getAccount(LoginWin login) { if (login.Account != null) { return(login.Account); } StorageFolder accountFolder = await GetAccountFolder(login.LocalAccountId); if (accountFolder == null) { throw new Exception("The folder for the requested account with id " + login.LocalAccountId + " wasn't found."); } //using (Stream s = await StorageHelper.LoadStream(accountFolder, Files.ACCOUNT_FILE)) //{ // if (s != null) // UIHandler.ShowMessageBox(new StreamReader(s).ReadToEnd(), "Data"); // //return null; //} AccountWin account = await StorageHelper.Load <AccountWin>(accountFolder, Files.ACCOUNT_FILE); if (account == null) { account = new AccountWin(); } //just in case data was randomly wiped, we'll make sure it syncs everything //if (account.School.Years.Count == 0) // account.CurrentChangeNumber = 0; //throw new ArgumentException("The account with id " + login.LocalAccountId + " was not found."); account.Login = login; login.Account = account; account.Initialize(); return(account); }
public static async System.Threading.Tasks.Task LoadLogins() { _logins = new MyObservableList <LoginWin>(); foreach (StorageFolder accountFolder in await(await GetAccountsFolder()).GetFoldersAsync()) { Guid localAccountId; if (Guid.TryParse(accountFolder.Name, out localAccountId)) { LoginWin login = await getLogin(localAccountId); if (login != null) { _logins.Add(login); } } } }
public static async System.Threading.Tasks.Task LoadData(LoginWin login) { await getAccount(login); }