public static string GenerateIcs(Model.Schedule schedule) { int dayCount = schedule.Count * 7; DateTime firstDay = RuntimeData.StartDate; Calendar calendar = new Calendar(); for (int i = 0; i < dayCount; i++) { DateTime date = firstDay.AddDays(i); foreach (Model.ScheduleEntry e in schedule.GetDaySchedule(i)) { (var start, var end) = SessionTimeConverter.ConvertShort(e.SessionSpan, CampusSelector.IsCampusD(e.Room)); CalendarEvent calEvent = new CalendarEvent() { DtStart = new CalDateTime(new DateTime(date.Year, date.Month, date.Day, start.Hour, start.Minute, 0)), DtEnd = new CalDateTime(new DateTime(date.Year, date.Month, date.Day, end.Hour, end.Minute, 0)), Location = e.Room, Summary = e.Name, Description = $"教师: {e.Lecturer}", Alarms = { new Alarm() { Trigger = new Trigger(new TimeSpan(0, -15, 0)) } } }; calendar.Events.Add(calEvent); } } var serializer = new Ical.Net.Serialization.CalendarSerializer(); return(serializer.SerializeToString(calendar)); }
public MainPageNavigationParameter(string userId, string token, Model.StudentInfo studentInfo, Model.Score score, Model.Schedule schedule) { UserId = userId; Token = token; StudentInfo = studentInfo; Score = score; Schedule = schedule; }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); this.schedule = RuntimeData.Schedule; for (int i = 0; i < schedule.Count; i++) { ScheduleFrame frame = new ScheduleFrame(); frame.Week = schedule.Weeks[i].WeekNumber; frame.WeekSchedule = schedule.Weeks[i]; WeekFlip.Items.Add(frame); } int elapsedWeeks = (DateTime.Today - RuntimeData.StartDate).Days / 7; if (elapsedWeeks > schedule.Count - 1) { WeekFlip.SelectedIndex = schedule.Count - 1; } else { WeekFlip.SelectedIndex = elapsedWeeks; } }
public static async Task UpdateTile(Model.Schedule schedule) { TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication(); if (schedule == null) { updater.Clear(); return; } //Windows.Foundation.Diagnostics.LoggingChannel lc = new Windows.Foundation.Diagnostics.LoggingChannel("UCQU_BackgroundTaskPayload", null, new Guid("4bd2826e-54a1-4ba9-bf63-92b73ea1ac4a")); //lc.LogMessage("Entered Payload Method."); //lc.LogMessage("Tile Updated Created."); string id = "", pwdHash = ""; if (Login.LoadCredentials(out id, out pwdHash) == false) { //lc.LogMessage("Credential Load Failed. Clearing tile and exiting..."); updater.Clear(); return; } TileContent content = null; //lc.LogMessage("Obtaining Schedule."); //lc.LogMessage("Getting Schedule of Today."); List <Model.ScheduleEntry> entries = schedule.GetDaySchedule((DateTime.Today /*CommonResources.TestDate*/ - RuntimeData.StartDate).Days).ToList(); entries.RemoveAll(x => { (_, var endTime) = SessionTimeConverter.ConvertShort(x.SessionSpan, CampusSelector.IsCampusD(x.Room)); return(endTime.GetDateTime() < DateTime.Now); }); entries.Sort((x, y) => x.StartSlot - y.StartSlot); //lc.LogMessage("Constructing Tile Content."); TileBindingContentAdaptive midTileContent = new TileBindingContentAdaptive(); TileBindingContentAdaptive wideTileContent = new TileBindingContentAdaptive(); TileBindingContentAdaptive largeTileContent = new TileBindingContentAdaptive(); if (entries.Count > 0) { if (!IsToastScheduled) { try { ScheduleToast(entries); } catch (Exception ex) { } IsToastScheduled = true; } //lc.LogMessage("Course Detected. Creating daily schedule tile."); foreach (Model.ScheduleEntry e in entries) { (var start, var end) = SessionTimeConverter.ConvertShort(e.SessionSpan, CampusSelector.IsCampusD(e.Room)); AdaptiveGroup midGroup = new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = e.Name, HintStyle = AdaptiveTextStyle.Caption, HintWrap = true }, new AdaptiveText() { Text = $"{start}-{end} {e.Room}", HintStyle = AdaptiveTextStyle.CaptionSubtle }, } } } }; AdaptiveGroup wideGroup = new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = e.Name, HintStyle = AdaptiveTextStyle.Caption, }, new AdaptiveText() { Text = $"{start}-{end} {e.Room}", HintStyle = AdaptiveTextStyle.CaptionSubtle }, } } } }; AdaptiveGroup largeGroup = new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = e.Name, HintStyle = AdaptiveTextStyle.Base, HintWrap = true }, new AdaptiveText() { Text = $"{start}-{end} {e.Room}", HintStyle = AdaptiveTextStyle.CaptionSubtle }, new AdaptiveText() { HintStyle = AdaptiveTextStyle.Caption } } } } }; midTileContent.Children.Add(midGroup); wideTileContent.Children.Add(wideGroup); largeTileContent.Children.Add(largeGroup); } //lc.LogMessage("Assigning Tile Content."); content = new TileContent() { Visual = new TileVisual() { Branding = TileBranding.Name, TileLarge = new TileBinding() { Content = largeTileContent }, TileMedium = new TileBinding() { Content = midTileContent }, TileWide = new TileBinding() { Content = wideTileContent }, } }; } else { //lc.LogMessage("No Course Detected. Creating image tile."); //lc.LogMessage("Getting Image Entries Metadata."); List <HuxiImgEntry> huxiImgEntries = await HuxiImg.GetEntries(); //lc.LogMessage("Creating Randomizer."); Random randomizer = new Random((int)DateTime.Now.Ticks); int index = randomizer.Next(0, huxiImgEntries.Count); if (!IsToastScheduled) { try { ScheduleToast(huxiImgEntries[index]); } catch (Exception ex) { } IsToastScheduled = true; } //lc.LogMessage("Randomly Selected Index: " + index); //lc.LogMessage("Constructing Image Tile."); largeTileContent.BackgroundImage = new TileBackgroundImage() { Source = huxiImgEntries[index].Uri, HintOverlay = 40 }; largeTileContent.Children.Add ( new AdaptiveText() { Text = huxiImgEntries[index].Title, HintStyle = AdaptiveTextStyle.Base } ); largeTileContent.Children.Add ( new AdaptiveText() { Text = huxiImgEntries[index].Author, HintStyle = AdaptiveTextStyle.CaptionSubtle } ); //lc.LogMessage("Assigning Tile Content."); content = new TileContent() { Visual = new TileVisual() { Branding = TileBranding.Name, TileLarge = new TileBinding() { Content = largeTileContent }, TileMedium = new TileBinding() { Content = largeTileContent }, TileWide = new TileBinding() { Content = largeTileContent }, } }; } //lc.LogMessage("Creating Tile Notification."); var notification = new TileNotification(content.GetXml()); //lc.LogMessage("Setting Expiry Time."); notification.ExpirationTime = DateTimeOffset.UtcNow.AddMinutes(60); //lc.LogMessage("Clearing Existing Tiles"); updater.Clear(); //lc.LogMessage("Updating Tiles"); TileUpdateManager.CreateTileUpdaterForApplication().Update(notification); //lc.LogMessage("Payload Method Complete."); }