コード例 #1
0
        public ScheduleViewModel(Schedule schedule, WellknownData wellknown)
        {
            Weeks = schedule.Weeks.OrderBy(x => x.WeekNumber).Select(x => new ScheduleWeekViewModel(x, wellknown)).ToList();
            if (Weeks.Count > 1)
            {
                for (int i = 0; i < Weeks.Count - 1; i++)
                {
                    int insertCount = Weeks[i + 1].WeekNumber - Weeks[i].WeekNumber - 1;
                    for (int j = 0; j < insertCount; j++)
                    {
                        ScheduleWeekViewModel emptyWeek = new ScheduleWeekViewModel(new ScheduleWeek(Weeks[i].WeekNumber + j + 1), wellknown);
                        Weeks.Insert(i + j + 1, emptyWeek);
                    }
                    i += insertCount;
                }
            }
            int daysSinceTermStart = (int)(DateTimeOffset.Now.Date - wellknown.TermStartDate).TotalDays;
            int weekNumber         = daysSinceTermStart / 7;

            if (weekNumber < 0 || weekNumber >= Weeks.Count)
            {
                Today = new List <ScheduleEntryViewModel>();
            }
            else
            {
                int todayDayOfWeek = (int)DateTimeOffset.Now.DayOfWeek;
                todayDayOfWeek = todayDayOfWeek == 0 ? 7 : todayDayOfWeek;
                ScheduleDayViewModel day = Weeks[weekNumber].Days[todayDayOfWeek - 1];
                Today = day.Entries.Where(x => x.LocalEndTime > DateTimeOffset.Now).ToList() ?? new List <ScheduleEntryViewModel>();
            }
        }
コード例 #2
0
        public ExamViewModel(Exam exam, WellknownData schedule)
        {
            ShortName = exam.ShortName;
            StartTime = exam.StartTime.LocalDateTime;
            EndTime   = exam.EndTime.LocalDateTime;
            Countdown = (int)(StartTime.GetLocalDate() - DateTimeOffset.Now.Date).TotalDays;
            EquivalentStartSession = FindEqivalentSession(StartTime.TimeOfDay, schedule);
            EquivalentEndSession   = FindEqivalentSession(EndTime.TimeOfDay, schedule);
            Week          = exam.Week;
            DayOfWeek     = exam.DayOfWeek;
            ShortLocation = exam.ShortLocation;
            Seating       = exam.Seating;

            ILocalizationService locService = Application.Current.GetService <ILocalizationService>();

            TimeRangeDisplay = locService.Format("ScheduleSummaryTimeRangeFormat", StartTime.ToLocalTime().TimeOfDay, EndTime.ToLocalTime().TimeOfDay);
            if (Countdown < 0)
            {
                CountdownDisplay = locService.GetString("ScheduleSummaryExamCountdownEnded");
            }
            else if (Countdown < 3)
            {
                CountdownDisplay = locService.GetString($"ScheduleSummaryExamCountdown{Countdown}");
            }
            else
            {
                CountdownDisplay = locService.Format("ScheduleSummaryExamCountdownFormat", Countdown);
            }
        }
コード例 #3
0
        public ExamScheduleViewModel(ExamSchedule exams, WellknownData schedule)
        {
            Exams = exams.Exams.Select(x => new ExamViewModel(x, schedule)).ToList();
            int recentExamsThreshold = Application.Current.GetConfigurationValue("RecentExamsThreshold", 15);

            RecentExams = Exams.Where(x => x.EndTime > DateTimeOffset.Now && x.StartTime < DateTimeOffset.Now.AddDays(recentExamsThreshold)).OrderBy(x => x.Countdown).ToList();
        }
コード例 #4
0
 public WellknownDataViewModel(WellknownData data)
 {
     CurrentTerm   = data.CurrentTerm;
     TermStartDate = data.TermStartDate;
     TermEndDate   = data.TermEndDate.AddDays(-1);
     Schedule      = data.Schedule;
     Model         = data;
 }
コード例 #5
0
ファイル: WellknownData.cs プロジェクト: DL444/ucqu-ng
 public WellknownDataFunction(IWellknownDataService wellknown)
 {
     data = new WellknownData()
     {
         CurrentTerm   = wellknown.CurrentTerm,
         TermStartDate = wellknown.TermStartDate,
         TermEndDate   = wellknown.TermEndDate,
         Schedule      = wellknown.Schedule.ToList()
     };
 }
コード例 #6
0
        private async Task <List <ScheduleEntryViewModel> > GetTodayScheduleAsync()
        {
            IDataService dataService = Application.Current.GetService <IDataService>(x => x.DataSource == DataSource.LocalCache);
            Task <DataRequestResult <WellknownData> > wellknownDataTask = dataService.GetWellknownDataAsync();
            Task <DataRequestResult <Schedule> >      scheduleTask      = dataService.GetScheduleAsync();
            WellknownData  wellknown   = (await wellknownDataTask).Resource;
            Schedule       schedule    = (await scheduleTask).Resource;
            var            scheduleVm  = new ScheduleViewModel(schedule, wellknown);
            int            previewMins = Application.Current.GetConfigurationValue("Notification:NextSessionPreviewMinutes", 10);
            DateTimeOffset threshold   = DateTimeOffset.Now.AddMinutes(previewMins);

            return(scheduleVm.Today.Where(x => x.LocalEndTime > threshold).ToList());
        }
コード例 #7
0
 private static int FindEqivalentSession(TimeSpan time, WellknownData schedule)
 {
     if (schedule.Schedule == null)
     {
         return(0);
     }
     for (int i = 0; i < schedule.Schedule.Count; i++)
     {
         if (time <= schedule.Schedule[i].StartOffset)
         {
             return(i);
         }
     }
     return(schedule.Schedule.Count);
 }
コード例 #8
0
        public ScheduleEntryViewModel(ScheduleEntry entry, DateTimeOffset date, WellknownData schedule)
        {
            Name         = entry.Name;
            Lecturer     = entry.Lecturer;
            Room         = entry.Room;
            DayOfWeek    = entry.DayOfWeek;
            StartSession = Math.Min(entry.StartSession, schedule.Schedule.Count);
            EndSession   = Math.Min(entry.EndSession, schedule.Schedule.Count);

            TimeSpan startTime = schedule.Schedule[StartSession - 1].StartOffset;
            TimeSpan endTime   = schedule.Schedule[EndSession - 1].EndOffset;

            LocalStartTime = date.Add(startTime);
            LocalEndTime   = date.Add(endTime);
            ILocalizationService locService = Application.Current.GetService <ILocalizationService>();

            TimeRangeDisplay     = locService.Format("ScheduleSummaryTimeRangeFormat", LocalStartTime.TimeOfDay, LocalEndTime.TimeOfDay);
            TimeRangeRoomDisplay = locService.Format("ScheduleSummaryTimeRangeRoomFormat", LocalStartTime.TimeOfDay, LocalEndTime.TimeOfDay, Room);
        }
コード例 #9
0
        public ScheduleWeekViewModel(ScheduleWeek week, WellknownData wellknown)
        {
            WeekNumber        = week.WeekNumber;
            WeekNumberDisplay = Application.Current.GetService <ILocalizationService>().Format("ScheduleTableWeekNumberHeaderFormat", week.WeekNumber);
            Days = new ScheduleDayViewModel[7];
            DateTimeOffset weekStartDate = wellknown.TermStartDate.GetLocalDate().AddDays((week.WeekNumber - 1) * 7);

            foreach (var group in week.Entries.GroupBy(x => x.DayOfWeek))
            {
                int            dayOfWeek = group.Key;
                DateTimeOffset day       = weekStartDate.AddDays(dayOfWeek - 1);
                Days[dayOfWeek - 1] = new ScheduleDayViewModel(WeekNumber, day, group, wellknown);
            }
            for (int i = 0; i < 7; i++)
            {
                if (!Days[i].Initialized)
                {
                    DateTimeOffset day = weekStartDate.AddDays(i);
                    Days[i] = new ScheduleDayViewModel(WeekNumber, day, Array.Empty <ScheduleEntry>(), wellknown);
                }
            }
        }
コード例 #10
0
 public Task SetWellknownDataAsync(WellknownData data) => SetRecordDataAsync(RecordType.Wellknown, data);
コード例 #11
0
        public ScheduleDayViewModel(int weekNumber, DateTimeOffset date, IEnumerable <ScheduleEntry> entries, WellknownData schedule)
        {
            ILocalizationService locService = Application.Current.GetService <ILocalizationService>();

            LocalDate        = date;
            LocalDateDisplay = locService.Format("ScheduleTableDayDisplayFormat", date);
            WeekNumber       = weekNumber;
            DayOfWeek        = date.DayOfWeek == System.DayOfWeek.Sunday ? 7 : (int)date.DayOfWeek;
            DayOfWeekDisplay = locService.GetString($"ScheduleTableDayOfWeek{DayOfWeek}Header");
            IsToday          = date == DateTimeOffset.Now.GetLocalDate();
            Entries          = entries.OrderBy(x => x.StartSession).Select(x => new ScheduleEntryViewModel(x, date, schedule)).ToList();
            Initialized      = true;

            ConsolidatedEntries = new List <ScheduleConsolidationViewModel>();
            for (int i = 0; i < Entries.Count; i++)
            {
                ScheduleEntryViewModel         currentEntry  = Entries[i];
                ScheduleConsolidationViewModel consolidation = new ScheduleConsolidationViewModel(currentEntry);
                for (int j = i; j < Entries.Count; j++)
                {
                    ScheduleEntryViewModel potentialConflict = Entries[j];
                    if (potentialConflict.StartSession > currentEntry.EndSession)
                    {
                        break;
                    }
                    else
                    {
                        consolidation.Conflicts.Add(potentialConflict);
                    }
                }
                if (consolidation.ConflictCount > 1)
                {
                    consolidation.ConflictCountDisplay = locService.Format("ScheduleTableConflictDescriptionFormat", consolidation.ConflictCount - 1);
                }
                ConsolidatedEntries.Add(consolidation);
                i += consolidation.ConflictCount;
            }
        }