/// <summary>
        /// Thread safe
        /// </summary>
        /// <returns></returns>
        public static async Task <List <AccountDataItem> > GetAllAccounts()
        {
            List <AccountDataItem> accounts = new List <AccountDataItem>();

            IList <IFolder> folders;

            folders = await System.Threading.Tasks.Task.Run(async delegate
            {
                using (await Locks.LockAccounts())
                {
                    return(await FileHelper.GetAllAccountFolders());
                }
            });

            foreach (IFolder accountFolder in folders)
            {
                if (Guid.TryParse(accountFolder.Name, out Guid localAccountId))
                {
                    AccountDataItem account = await AccountsManager.GetOrLoad(localAccountId);

                    if (account != null)
                    {
                        accounts.Add(account);
                    }
                }
            }

            return(accounts);
        }
Beispiel #2
0
        /// <summary>
        /// Saves locally and then uploads premium status to account without waiting
        /// </summary>
        /// <returns></returns>
        public async System.Threading.Tasks.Task SetAsLifetimePremiumAsync()
        {
            PremiumAccountExpiresOn = PowerPlannerSending.DateValues.LIFETIME_PREMIUM_ACCOUNT;

            await AccountsManager.Save(this);

            var dontWait = Sync.SetAsPremiumAccount(this);
        }
Beispiel #3
0
        private async System.Threading.Tasks.Task <string> RefreshOnlineTokenHelperAsync()
        {
            var resp = await PowerPlannerAppAuthLibrary.PowerPlannerAuth.RefreshOnlineTokenAsync(AccountId, Username, LocalToken);

            if (resp.Error == null)
            {
                Token = resp.Token;
                await AccountsManager.Save(this);

                return(null);
            }
            else
            {
                return(resp.Error);
            }
        }
        public static async System.Threading.Tasks.Task <AccountDataItem> CreateAndInitializeAccountAsync(string username, string localToken, string token, long accountId, int deviceId)
        {
            var account = await CreateAccountHelper.CreateAccountLocally(username, localToken, token, accountId, deviceId, needsInitialSync : false);

            if (account != null)
            {
                AccountsManager.SetLastLoginIdentifier(account.LocalAccountId);

                // Add the default year/semester
                try
                {
                    DataItemYear year = new DataItemYear()
                    {
                        Identifier = Guid.NewGuid(),
                        Name       = PowerPlannerResources.GetString("DummyFirstYear")
                    };

                    DataItemSemester semester = new DataItemSemester()
                    {
                        Identifier      = Guid.NewGuid(),
                        UpperIdentifier = year.Identifier,
                        Name            = PowerPlannerResources.GetString("DummyFirstSemester")
                    };

                    DataChanges changes = new DataChanges();
                    changes.Add(year);
                    changes.Add(semester);

                    await PowerPlannerApp.Current.SaveChanges(account, changes);

                    await account.SetCurrentSemesterAsync(semester.Identifier);

                    NavigationManager.MainMenuSelection = NavigationManager.MainMenuSelections.Schedule;

                    return(account);
                }
                catch (Exception ex)
                {
                    TelemetryExtension.Current?.TrackException(ex);
                }
            }

            return(null);
        }
Beispiel #5
0
        /// <summary>
        /// Sets current semester and saves changes, also updates primary tile
        /// </summary>
        public async System.Threading.Tasks.Task SetCurrentSemesterAsync(Guid currentSemesterId, bool uploadSettings = true)
        {
            if (CurrentSemesterId == currentSemesterId)
            {
                return;
            }

            // If semester is being cleared (going to Years page), ignore this change.
            // That's to allow easily being able to view overall GPA without losing curr semester.
            if (currentSemesterId == Guid.Empty)
            {
                return;
            }

            CurrentSemesterId = currentSemesterId;

            NeedsToSyncSettings    = true;
            IsAppointmentsUpToDate = false;
#if ANDROID
            DateLastDayBeforeReminderWasSent = DateTime.MinValue;
#endif
            await AccountsManager.Save(this);

            // Upload their changed setting
            if (uploadSettings)
            {
                var dontWait = Sync.SyncSettings(this, Sync.ChangedSetting.SelectedSemesterId);
            }

            var dataStore = await AccountDataStore.Get(this.LocalAccountId);

            AppointmentsExtension.Current?.ResetAll(this, dataStore);
            RemindersExtension.Current?.ResetReminders(this, dataStore);

            TilesExtension.Current?.UpdateTileNotificationsForAccountAsync(this, dataStore);
        }
 private async System.Threading.Tasks.Task SaveOnThread()
 {
     await AccountsManager.Save(this);
 }