Beispiel #1
0
        protected override async void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            //LoggingChannel lc = new LoggingChannel("UCQU_BackgroundTask", null, new Guid("4bd2826e-54a1-4ba9-bf63-92b73ea1ac4a"));
            //lc.LogMessage("Background Task Activated.");
            base.OnBackgroundActivated(args);
            //lc.LogMessage("Base Handler Called.");
            IBackgroundTaskInstance taskInstance = args.TaskInstance;
            //lc.LogMessage("Task Instance Set.");
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            //lc.LogMessage("Task Deferral Obtained.");
            //lc.LogMessage("Executing Payload Method.");
            switch (args.TaskInstance.Task.Name)
            {
            case "Hourly Tile Update Task":
            case "Login Tile Update Task":
                try
                {
                    string id, pwdHash;
                    Login.LoadCredentials(out id, out pwdHash);
                    if (id == null)
                    {
                        return;
                    }

                    try
                    {
                        string token = await WebClient.LoginAsync(id, pwdHash);

                        DL444.UcquLibrary.Models.Schedule schedule = await WebClient.GetScheduleAsync(token);

                        await ScheduleNotificationUpdateTasks.UpdateTile(schedule);
                    }
                    catch (Exception) { }
                }
                catch (Exception e)
                {
                    //lc.LogMessage($"Unhandled exception thrown when executing task payload.\n\n{e.Message}\n\n{e.StackTrace}");
                }
                break;
            }
            //lc.LogMessage("Completing Deferral.");
            deferral.Complete();
            //lc.LogMessage("Task Completed.");
        }
Beispiel #2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            HeaderControl.DataContext = new HeaderInfo(RuntimeData.StudentInfo, RuntimeData.UserId, RuntimeData.Score.GPA);

            ContentFrame.Navigate(typeof(Home));

            try
            {
                var channel = await Windows.Networking.PushNotifications.
                              PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

                await WebClient.PostWnsChannelAsync(RuntimeData.Token, channel.Uri);
            }
            catch (Exception ex)
            {
                await WebClient.ReportException(ex);
            }

            // Reselect campus and reschedule tasks.
            if (RuntimeData.LaunchState)
            {
                RuntimeData.LaunchState = false;
                if (RuntimeData.LoadSetting("campus", out _) == false)
                {
                    CampusSelect campusSelect = new CampusSelect();
                    await campusSelect.ShowAsync();

                    RuntimeData.LoadSetting("campus", out _);
                }

                var tasks = BackgroundTaskRegistration.AllTasks;
                foreach (var task in tasks)
                {
                    task.Value.Unregister(true);
                }
                BackgroundExecutionManager.RemoveAccess();

                var backgroundStatus = await BackgroundExecutionManager.RequestAccessAsync();

                if (backgroundStatus == BackgroundAccessStatus.DeniedBySystemPolicy ||
                    backgroundStatus == BackgroundAccessStatus.DeniedByUser ||
                    backgroundStatus == BackgroundAccessStatus.Unspecified)
                {
                    return;
                }

                var builder = new BackgroundTaskBuilder();
                builder.Name = "Hourly Tile Update Task";
                builder.SetTrigger(new TimeTrigger(30, false));
                builder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable));
                builder.IsNetworkRequested = true;
                builder.Register();
                builder.Name = "Login Tile Update Task";
                builder.SetTrigger(new SystemTrigger(SystemTriggerType.UserPresent, false));
                builder.Register();
            }

            await ScheduleNotificationUpdateTasks.UpdateTile(RuntimeData.Schedule);
        }
Beispiel #3
0
 private async void LogoutBtn_Click(object sender, RoutedEventArgs e)
 {
     (Window.Current.Content as Frame).Navigate(typeof(Login), "logout");
     RuntimeData.LaunchState = true;
     await ScheduleNotificationUpdateTasks.UpdateTile(null);
 }