public async void Run(IBackgroundTaskInstance taskInstance) { // Get a deferral, to prevent the task from closing prematurely // while asynchronous code is still running. BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); // check for new grades try { GradesModel gradesModel = GradesModel.GetInstance(); SettingsModel settingsModel = SettingsModel.GetInstance(); int countNewGrades = await gradesModel.GetNewGradesCount(settingsModel.SNummer, settingsModel.RZLogin); if (countNewGrades > 0) { ToastContent content = new ToastContent() { Visual = new ToastVisual() { TitleText = new ToastText() { Text = countNewGrades + " neue Noten verfügbar!" } }, Audio = new ToastAudio() { Src = new Uri("ms-winsoundevent:Notification.IM") } }; XmlDocument xmlContent = content.GetXml(); var toast = new ToastNotification(xmlContent); ToastNotificationManager.CreateToastNotifier().Show(toast); } } catch { Debug.WriteLine("Grades could not be retrieved."); } // Inform the system that the task is finished. deferral.Complete(); }
async Task LoadGrades() { SettingsModel settingsModel = SettingsModel.GetInstance(); GradesModel gradesModel = GradesModel.GetInstance(); GradeObjectsList gradeObjectsList; // only show if correct user name/password try { gradeObjectsList = await gradesModel.GetGrades(settingsModel.SNummer, settingsModel.RZLogin); } catch (Exception e) { Debug.WriteLine(e); MessageDialog md = new MessageDialog("Ungültiger Benutzername und/oder Passwort in den Einstellungen hinterlegt!"); await md.ShowAsync(); return; } if (gradeObjectsList != null) { // get all semesters List <string> semester = new List <string>(); foreach (GradeObject gradeObject in gradeObjectsList.gradeObjects) { if (!semester.Contains(gradeObject.Semester)) { semester.Add(gradeObject.Semester); } } // create as many listviews as there are semester List <ListView> semesterList = new List <ListView>(); foreach (string s in semester) { ListView listView = new ListView(); listView.Name = s; semesterList.Add(listView); } // fill listviews with entries foreach (ListView listView in semesterList) { int i = 0; foreach (GradeObject gradeObject in gradeObjectsList.gradeObjects) { if (gradeObject.Semester == listView.Name) { // custom page as ListViewItem template double grade = double.Parse(gradeObject.PrNote) / 100; GradesItem gradesItem = new GradesItem(); gradesItem.Tb_title.Text = gradeObject.PrTxt + " (" + gradeObject.PrForm + ")"; gradesItem.Tb_grade.Text = grade.ToString(); gradesItem.Tb_credits.Text = gradeObject.EctsCredits; /*if (i % 2 == 1) * gradesItem.Gg.Background = new SolidColorBrush(Colors.LightGray); * gradesItem.Tb_title.Width = this.ActualWidth * .75;*/ listView.Items.Add(gradesItem); i++; } } } // clear listview ClearListView(mainView); // add listviews to page foreach (ListView listView in semesterList) { ListViewItem listViewHeader = new ListViewItem(); string year = listView.Name.Substring(0, 4); string yearPart = listView.Name.Substring(4, 1); if (yearPart.Equals("1")) { listViewHeader.Content = "Sommersemester " + year; } else if (yearPart.Equals("2")) { listViewHeader.Content = "Wintersemester " + year; } listViewHeader.Background = new SolidColorBrush(Colors.LightSteelBlue); mainView.Items.Add(listViewHeader); ListViewItem listViewContent = new ListViewItem(); listViewContent.Content = listView; mainView.Items.Add(listViewContent); } mainView.IsItemClickEnabled = true; mainView.ItemClick += new ItemClickEventHandler(ItemClick); timestamp.Text = "Stand: " + gradeObjectsList.timestamp.ToLocalTime().ToString(); CollapseOldEntries(); } }