コード例 #1
0
        /// <summary>
        /// Method which performs the work of the background task.
        /// </summary>
        /// <param name="taskInstance">The interface to an instance of the background task</param>
        private async void Update(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

#if !DEBUG
            if (!(DateTime.Today.Month == 7 || DateTime.Today.Month == 8))
#else
            if (true)
#endif
            {
                PasswordCredential credential = SecurityExtensions.RetrieveCredentials();
                if (credential != null)
                {
                    credential.RetrievePassword();

                    try
                    {
                        TileUpdateManager.CreateTileUpdaterForApplication().Clear();
                        ToastNotificationManager.History.Clear();

                        using (ClientExtensions client = new ClientExtensions())
                        {
                            await client.AuthenticateAndInitDataAsync(new UserCredentials(credential.UserName, credential.Password), false);

                            CheckAndSendNotification(BackgroundTaskExtensions.EVENTS, client.AccountDetails.AbsenceEvents.Count(item => !item.IsJustified), "AbsenceNotification".GetLocalized());
                            CheckAndSendNotification(BackgroundTaskExtensions.APPOINTMENTS, client.AccountDetails.AgendaEvents.Count, "AgendaNotification".GetLocalized());
                            CheckAndSendNotification(BackgroundTaskExtensions.DIDACTICS, client.AccountDetails.DidacticsItems.Count, "DidactictNotification".GetLocalized());
                            CheckAndSendNotification(BackgroundTaskExtensions.GRADES, client.AccountDetails.Grades.Count, "GradeNotification".GetLocalized());
                            CheckAndSendNotification(BackgroundTaskExtensions.NOTES, client.AccountDetails.Notes.Count, "NoteNotification".GetLocalized());
                            CheckAndSendNotification(BackgroundTaskExtensions.ITEMS, client.AccountDetails.NoticeboardItems.Count, "NoticeboardNotification".GetLocalized());
                        }
                    }
                    catch (Exception)
                    {
                        //
                    }
                }
            }
            else
            {
                ResourceExtensions.StoreRoamingObject(BackgroundTaskExtensions.EVENTS, 0);
                ResourceExtensions.StoreRoamingObject(BackgroundTaskExtensions.APPOINTMENTS, 0);
                ResourceExtensions.StoreRoamingObject(BackgroundTaskExtensions.DIDACTICS, 0);
                ResourceExtensions.StoreRoamingObject(BackgroundTaskExtensions.GRADES, 0);
                ResourceExtensions.StoreRoamingObject(BackgroundTaskExtensions.NOTES, 0);
                ResourceExtensions.StoreRoamingObject(BackgroundTaskExtensions.ITEMS, 0);
            }

            deferral.Complete();
        }
コード例 #2
0
        /// <summary>
        /// Method invoked once navigated to the page.
        /// Begins user login.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Page_Loaded()
        {
            if (SystemInformation.IsFirstRun)
            {
                await new PrivacyPolicyDialog().ShowAsync();
            }

            PasswordCredential credentials = SecurityExtensions.RetrieveCredentials();

            if (credentials != null)
            {
                _avoidCheck = true;

                credentials.RetrievePassword();

                UsernameTextBox.Text         = credentials.UserName;
                PasswordPasswordBox.Password = credentials.Password;

                Button_Click(null, null);
            }
        }