protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); dayEntries = RuntimeData.Schedule.GetDaySchedule((DateTime.Today - RuntimeData.StartDate).Days).ToList(); if (dayEntries.Count != 0) { dayEntries.Sort(); TodayScheduleList.ItemsSource = dayEntries; TodayScheduleList.Visibility = Visibility.Visible; } if (huxiImgEntries == null) { huxiImgEntries = await HuxiImg.GetEntries(); } if (huxiImgEntries.Count == 0) { HuxiImgGrid.Visibility = Visibility.Collapsed; } else { HuxiImgGrid.ItemsSource = huxiImgEntries; } }
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."); }