private static async Task <ClassData> LoadDataBlocking(AccountDataStore data, Guid classId, DateTime todayAsUtc, ClassTileSettings settings) { DateTime dateToStartDisplayingFrom = DateTime.SpecifyKind(settings.GetDateToStartDisplayingOn(todayAsUtc), DateTimeKind.Local); Guid semesterId = Guid.Empty; // We lock the outside, since we are allowing trackChanges on the view items groups (so we have a chance of loading a cached one)... and since we're on a background thread, the lists inside the // view items groups could change while we're enumerating, hence throwing an exception. So we lock it to ensure this won't happen, and then we return a copy of the items that we need. using (await Locks.LockDataForReadAsync()) { // First we need to obtain the semester id var c = data.TableClasses.FirstOrDefault(i => i.Identifier == classId); if (c == null) { return(null); } semesterId = c.UpperIdentifier; } // We need all classes loaded, to know what time the end of day is var scheduleViewItemsGroup = await ScheduleViewItemsGroup.LoadAsync(data.LocalAccountId, semesterId, trackChanges : true, includeWeightCategories : false); var classViewItemsGroup = await ClassViewItemsGroup.LoadAsync( localAccountId : data.LocalAccountId, classId : classId, today : DateTime.SpecifyKind(todayAsUtc, DateTimeKind.Local), viewItemSemester : scheduleViewItemsGroup.Semester, includeWeights : false); classViewItemsGroup.LoadTasksAndEvents(); await classViewItemsGroup.LoadTasksAndEventsTask; List <ViewItemTaskOrEvent> copied; using (await classViewItemsGroup.DataChangeLock.LockForReadAsync()) { // Class view group sorts the items, so no need to sort copied = classViewItemsGroup.Class.TasksAndEvents.Where(i => i.Date.Date >= dateToStartDisplayingFrom).ToList(); } return(new ClassData() { Class = classViewItemsGroup.Class, AllUpcoming = copied }); }
protected override async Task LoadAsyncOverride() { try { ViewItemsGroupClass = await ClassViewItemsGroup.LoadAsync(_localAccountId, ClassId, _today, _semester); DetailsViewModel = new ClassDetailsViewModel(this); HomeworkViewModel = new ClassHomeworkOrExamsViewModel(this, ClassHomeworkOrExamsViewModel.ItemType.Homework); ExamsViewModel = new ClassHomeworkOrExamsViewModel(this, ClassHomeworkOrExamsViewModel.ItemType.Exams); TimesViewModel = new ClassTimesViewModel(this); GradesViewModel = new Class.ClassGradesViewModel(this); } catch (ClassViewItemsGroup.ClassNotFoundExcetion) { var parent = FindAncestor <PagedViewModel>(); parent.Replace(this, new ClassesViewModel(parent)); throw; } catch (Exception ex) { TelemetryExtension.Current?.TrackException(ex); RemoveViewModel(); } }