private static async Task UpdateScheduleTile(string tileId, AccountDataItem account, AccountDataStore data)
        {
            try
            {
                if (!SecondaryTile.Exists(tileId))
                {
                    return;
                }

                Debug.WriteLine("Updating Secondary Schedule Tile");

                TileUpdater updater;

                try
                {
                    updater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(tileId);
                }

                catch
                {
                    return;
                }

                TileHelper.ClearScheduledNotifications(updater);

                bool sentNotification = false;

                var notifications = await GenerateTileNotificationContentsAsync(account);

                foreach (var n in notifications)
                {
                    Schedule(updater, n.Content, n.DeliveryTime ?? DateTime.Now, n.ExpirationTime);
                    sentNotification = true;
                }

                if (!sentNotification)
                {
                    updater.Clear();
                }
            }

            catch (Exception ex)
            {
                if (!UWPExceptionHelper.TrackIfNotificationsIssue(ex, "Tiles") && !UWPExceptionHelper.TrackIfElementNotFound(ex, "Tiles"))
                {
                    throw ex;
                }
            }
        }
        private static IEnumerable <TileNotificationContentAndData> GenerateTileNotificationContents(ScheduleTileDataHelper scheduleTileData)
        {
            // If no semester
            if (!scheduleTileData.HasSemester)
            {
                yield return(new TileNotificationContentAndData()
                {
                    Content = CreateBasicTileNotificationContent(PowerPlannerResources.GetString("String_NoSemester"))
                });

                yield break;
            }

            bool            createdContent = false;
            DateTime        now            = DateTime.Now.AddSeconds(30); // Use now as 30 secs in advance to prevent scheduling notifications that already passed
            List <DateTime> previousTimes  = new List <DateTime>();

            foreach (var dayData in scheduleTileData.GetDataForAllDays())
            {
                // If nothing on this day
                if (!dayData.Schedules.Any() && !dayData.Holidays.Any())
                {
                    // Add that we skipped this day, and continue to next
                    previousTimes.Add(dayData.Date);
                    continue;
                }

                // Handle previously skipped days
                if (previousTimes.Count > 0)
                {
                    foreach (var dateSkipped in previousTimes)
                    {
                        XmlDocument xmlForSkipped;

                        if (dayData.Holidays.Any())
                        {
                            xmlForSkipped = GenerateHolidayTileNotification(dayData.Holidays, TileHelper.ToFriendlyDate(dayData.Date, dateSkipped), dayData.Date);
                        }
                        else
                        {
                            xmlForSkipped = GenerateTileNotification(dayData.Schedules, TileHelper.ToFriendlyDate(dayData.Date, dateSkipped), dayData.Date, dateSkipped);
                        }

                        yield return(new TileNotificationContentAndData()
                        {
                            Content = xmlForSkipped,
                            DeliveryTime = dateSkipped,
                            ExpirationTime = dateSkipped.AddDays(1)
                        });

                        createdContent = true;
                    }

                    previousTimes.Clear();
                }

                // First one starts displaying exactly at the start of the day
                DateTime deliveryTime = dayData.Date;

                if (dayData.Holidays.Any())
                {
                    XmlDocument xml = GenerateHolidayTileNotification(dayData.Holidays, "Today", dayData.Date);

                    var expirationTime = dayData.Date.AddHours(15); // Switches at 3 PM
                    if (expirationTime > now)
                    {
                        yield return(new TileNotificationContentAndData()
                        {
                            Content = xml,
                            DeliveryTime = deliveryTime,
                            ExpirationTime = expirationTime
                        });

                        createdContent = true;
                    }

                    // We always add this, so that the next day's content will start appearing after the last item
                    previousTimes.Add(expirationTime);
                }
                else
                {
                    var schedulesOnDate = dayData.Schedules.ToList();
                    while (schedulesOnDate.Count > 0)
                    {
                        DateTime expirationTime = dayData.Date.Add(schedulesOnDate.First().EndTime.TimeOfDay);

                        // If it hasn't expired yet
                        if (expirationTime > now)
                        {
                            XmlDocument xml = GenerateTileNotification(schedulesOnDate, "Today", dayData.Date, dayData.Date);

                            // If the class is 10 mins or longer, we'll switch it 5 mins before the class ends, so that user can see their next class
                            if ((schedulesOnDate.First().EndTime.TimeOfDay - schedulesOnDate.First().StartTime.TimeOfDay).TotalMinutes >= 10)
                            {
                                expirationTime = expirationTime.AddMinutes(-5);
                            }

                            yield return(new TileNotificationContentAndData()
                            {
                                Content = xml,
                                DeliveryTime = deliveryTime,
                                ExpirationTime = expirationTime
                            });

                            createdContent = true;
                        }

                        deliveryTime = expirationTime;

                        schedulesOnDate.RemoveAt(0);
                    }

                    // We always add this, so that the next day's content will start appearing after the last item
                    previousTimes.Add(deliveryTime);
                }
            }

            if (!createdContent)
            {
                yield return(new TileNotificationContentAndData()
                {
                    Content = CreateBasicTileNotificationContent(PowerPlannerResources.GetString("String_NoClassesThisWeek"))
                });
            }
        }