Ejemplo n.º 1
0
        private void UpdatePausedTile()
        {
            if (CurrentTrack == null)
            {
                return;
            }

            if (App.IsDesktop || App.IsMobile)
            {
                try
                {
                    _tileUpdater.Clear();

                    var firstXml = new Windows.Data.Xml.Dom.XmlDocument();
                    firstXml.LoadXml("<tile><visual><binding template=\"TileMedium\" branding=\"nameAndLogo\"><image placement=\"peek\" src=\"" + ArtworkConverter.ConvertObjectToImage(CurrentTrack) + "\"/><text>Paused</text><text hint-style=\"captionsubtle\" hint-wrap=\"true\"><![CDATA[" + CurrentTrack.Title.Replace("&", "&amp;") + "]]></text></binding><binding template=\"TileLarge\" branding=\"nameAndLogo\"><image placement=\"peek\" src=\"" + ArtworkConverter.ConvertObjectToImage(CurrentTrack) + "\"/><text>Paused</text><text hint-style=\"captionsubtle\" hint-wrap=\"true\"><![CDATA[" + CurrentTrack.Title.Replace("&", "&amp;") + "]]></text></binding></visual></tile>", new Windows.Data.Xml.Dom.XmlLoadSettings {
                        ValidateOnParse = true
                    });
                    _tileUpdater.Update(new TileNotification(firstXml));
                }
                catch
                {
                    // ignored
                }
            }
        }
Ejemplo n.º 2
0
        public static void CreateTile(Post post)
        {
            TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication();

            updater.EnableNotificationQueue(true);
            updater.Clear();

            var tileLarge = TileContentFactory.CreateTileWide310x150PeekImage01();

            tileLarge.Image.Src = "ms-appx:///Assets/WideLogo.scale-240.png";
            string title = post.Title;

            //if (title.Length > 13)
            //{
            //    title = title.Substring(0, 12) + "…";
            //}
            tileLarge.TextBodyWrap.Text = post.Summary;
            tileLarge.TextHeading.Text  = title;

            var tileSmall = TileContentFactory.CreateTileSquare150x150PeekImageAndText02();

            tileSmall.Image.Src         = "ms-appx:///Assets/Logo.scale-240.png";
            tileSmall.TextHeading.Text  = post.BlogApp;
            tileSmall.TextBodyWrap.Text = post.Title;

            tileLarge.Square150x150Content = tileSmall;
            TileUpdateManager.CreateTileUpdaterForApplication().Update(tileLarge.CreateNotification());
        }
Ejemplo n.º 3
0
        internal static async Task UpdateTile(IDisposable CanvasDevice, BookItem Book, string TileId)
        {
            TileUpdater Updater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(TileId);

            Updater.EnableNotificationQueue(true);
            Updater.Clear();

            StringResources stx = StringResources.Load("Message");

            XmlDocument Template150 = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Text01);

            Template150.GetElementsByTagName("text").First().AppendChild(Template150.CreateTextNode(stx.Str("NewContent")));
            Updater.Update(new TileNotification(Template150));

            XmlDocument Template71 = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare71x71Image);
            IXmlNode    ImgSrc     = Template71.GetElementsByTagName("image")
                                     .FirstOrDefault()?.Attributes
                                     .FirstOrDefault(x => x.NodeName == "src");

            string SmallTile = await Image.LiveTileBadgeImage(CanvasDevice, Book, 150, 150, "\uEDAD");

            if (!string.IsNullOrEmpty(SmallTile))
            {
                ImgSrc.NodeValue = SmallTile;
                Updater.Update(new TileNotification(Template71));
            }
        }
Ejemplo n.º 4
0
        private static async Task UpdatePrimaryTileNotificationsBlocking(AccountDataItem account, AccountDataStore data)
        {
            try
            {
                Debug.WriteLine("Updating Primary Tile");

                TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();


                if (account == null || account.MainTileSettings.IsDisabled())
                {
                    ClearScheduledNotifications(tileUpdater);
                    tileUpdater.Clear();
                    return;
                }

                DateTime todayInLocal = DateTime.Today;

                var allUpcoming = await getAllUpcomingBlocking(account, data, DateTime.SpecifyKind(todayInLocal, DateTimeKind.Utc), account.MainTileSettings);

                UpdateUpcomingTile(tileUpdater, allUpcoming, todayInLocal, UpcomingTileType.PrimaryTile, account.MainTileSettings);
            }

            catch (Exception ex)
            {
                if (!UWPExceptionHelper.TrackIfNotificationsIssue(ex, "Tiles"))
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 5
0
 private static void InitLiveTitleState(TileUpdater updater)
 {
     updater.EnableNotificationQueueForWide310x150(true);
     updater.EnableNotificationQueueForSquare150x150(true);
     updater.EnableNotificationQueueForSquare310x310(true);
     updater.EnableNotificationQueue(true);
     updater.Clear();
 }
Ejemplo n.º 6
0
        public MainPage()
        {
            InitializeComponent();

            _tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
            _tileUpdater.Clear();
            _tileUpdater.EnableNotificationQueue(false);
        }
Ejemplo n.º 7
0
        public void ClearSecondaryTile(string tileID)
        {
            if (!SecondaryTile.Exists(tileID))
            {
                return;
            }
            TileUpdater updater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(tileID);

            updater.Clear();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 初始化单一实例应用程序对象。这是执行的创作代码的第一行,
        /// 已执行,逻辑上等同于 main() 或 WinMain()。
        /// </summary>
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;
            Global.Store.getInstance().Initialize();
            TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();

            tileUpdater.Clear();
            TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);
        }
Ejemplo n.º 9
0
        public static void Clear()
        {
            XmlDocument       badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
            BadgeNotification badge    = new BadgeNotification(badgeXml);

            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);

            TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();

            tileUpdater.Clear();
        }
Ejemplo n.º 10
0
        private static void ClearNotifications(TileUpdater updater)
        {
            var scheduledNotifications = updater.GetScheduledTileNotifications();

            foreach (var notificaton in scheduledNotifications)
            {
                updater.RemoveFromSchedule(notificaton);
            }

            updater.Clear();
        }
Ejemplo n.º 11
0
        private void Update()
        {
            _tileUpdater.EnableNotificationQueue(true);
            _tileUpdater.Clear();

            foreach (var message in _currentUnreads.Take(5))
            {
                var tileContent = NotificationUtils.CreateTileNotificationForMessage(message);
                _tileUpdater.Update(tileContent);
            }
        }
Ejemplo n.º 12
0
        public static void run(List <Site> sites)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(File.ReadAllText("Assets/Tile.xml"));
            TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication();

            updater.Clear();
            TileNotification titleNotification = new TileNotification(doc);

            updater.Update(titleNotification);
            sites.ForEach(site => updater.Update(changeSite(doc, site)));
            updater.EnableNotificationQueue(true);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Create the application tile
        /// </summary>
        public async Task CreateAsync()
        {
            TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication();

            updater.EnableNotificationQueue(true);

            // Clear tile notifications
            updater.Clear();

            // Add new notifications
            updater.Update(await AddConferencesToTileAsync());
            updater.Update(await AddNewsToTileAsync());
            updater.Update(await AddShowsToTileAsync());
            updater.Update(await AddNewsToTileAsync());
        }
Ejemplo n.º 14
0
 private void UpdateTile(IList <string> UserInfo)
 {
     try
     {
         updater.EnableNotificationQueue(true);
         updater.Clear();
         foreach (string iter_string in UserInfo)
         {
             updater.Update(new TileNotification(AddToDoc(iter_string)));
         }
     }
     catch (Exception)
     {
         // ignored
     }
 }
        /// <summary>
        /// Update the pin tile of a visit.
        /// </summary>
        /// <param name="visitItem">Visit item</param>
        /// <param name="tile">Tile</param>
        public async void UpdatePinTile(VisitItem visitItem, SecondaryTile tile)
        {
            try
            {
                tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(tile.TileId);
                tileUpdater.Clear();
                tileUpdater.EnableNotificationQueue(true);

                await CreateTile(visitItem, IMAGE_FILENAME + tile.TileId + IMAGE_FORMAT);

                CreateImageTile(visitItem, IMAGE_FILENAME + tile.TileId + IMAGE_FORMAT);
            }
            catch (Exception)
            {
            }
        }
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            TileUpdater tileUpdate = TileUpdateManager.CreateTileUpdaterForApplication();

            tileUpdate.EnableNotificationQueue(true);
            tileUpdate.Clear();
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif
            SQLiteService.LoadDatabase();

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing required information as a navigation
                    // parameter
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                }
                // Ensure the current window is active
                Window.Current.Activate();
            }
        }
        void UpdateTile(string printerName, string bidiMessage)
        {
            TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();

            tileUpdater.Clear();

            XmlDocument tileXml            = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideText09);
            XmlNodeList tileTextAttributes = tileXml.GetElementsByTagName("text");

            tileTextAttributes[0].InnerText = printerName;
            tileTextAttributes[1].InnerText = bidiMessage;

            TileNotification tileNotification = new TileNotification(tileXml);

            tileNotification.Tag = "tag01";
            tileUpdater.Update(tileNotification);
        }
        protected override Task Execute(CancellationToken cancellationToken)
        {
            return(Task.Run(async delegate
            {
                TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication();
                cancellationToken.ThrowIfCancellationRequested();

                TileHelper.ClearScheduledNotifications(updater);
                cancellationToken.ThrowIfCancellationRequested();

                var desiredTileNotifications = await GenerateDesiredTileNotifications(cancellationToken);
                cancellationToken.ThrowIfCancellationRequested();

                if (desiredTileNotifications.Count == 0)
                {
                    // Only call clear if we're not updating with anything else.
                    // Because there's a good chance the tile is actually already up-to-date, and the notification that we
                    // place there is just going to be a duplicate of the existing. If you called clear, then the UI would clear
                    // the tile and then animate to display the new (same) content. Skipping the call to clear, the UI notices that the
                    // new notification is the same and doesn't display it, leading to a better experience.
                    updater.Clear();
                }

                else
                {
                    foreach (var desired in desiredTileNotifications)
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        // If it's set to be displayed in the past, or now (or super soon), we'll update immediately, since scheduling something
                        // for a time that has already passed throws an exception
                        if (desired.DeliveryTime < DateTimeOffset.Now.AddSeconds(5))
                        {
                            updater.Update(new TileNotification(desired.Content));
                        }

                        else
                        {
                            updater.AddToSchedule(new ScheduledTileNotification(desired.Content, desired.DeliveryTime));
                        }
                    }
                }
            }));
        }
Ejemplo n.º 19
0
        public void ClearTileStatus(string Id)
        {
            XParameter TileParam = XReg.Parameter(Id);

            if (TileParam == null)
            {
                return;
            }

            string TileId = TileParam.GetValue("tileId");

            try
            {
                TileUpdater Updater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(TileId);
                Updater.Clear();
                Updater.EnableNotificationQueue(false);
            }
            catch (Exception) { }
        }
        /// <summary>
        /// Update the main tile with next visits.
        /// </summary>
        /// <param name="visits">Visits collection.</param>
        public async void UpdateMainTile(IList <Visit> visits)
        {
            if (visits.Any())
            {
                tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
                tileUpdater.Clear();
                tileUpdater.EnableNotificationQueue(true);
                var i = 0;

                foreach (var visit in visits)
                {
                    var visitItem = new VisitItem(visit, 0);

                    await CreateTile(visitItem, string.Format("mainTile_{0}.jpg", i.ToString()));

                    i++;
                }
            }
        }
Ejemplo n.º 21
0
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            tileUpdate = GetTileUpdater();
            tileUpdate.EnableNotificationQueue(true);
            tileUpdate.Clear();

            Frame rootFrame = Window.Current.Content as Frame;

            Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += BackRequested;

            // 不要在窗口已包含内容时重复应用程序初始化,
            // 只需确保窗口处于活动状态
            if (rootFrame == null)
            {
                // 创建要充当导航上下文的框架,并导航到第一页
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: 从之前挂起的应用程序加载状态
                }

                // 将框架放在当前窗口中
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    // 当导航堆栈尚未还原时,导航到第一页,
                    // 并通过将所需信息作为导航参数传入来配置
                    // 参数
                    rootFrame.Navigate(typeof(LoginPage), e.Arguments);
                }
                // 确保当前窗口处于活动状态
                Window.Current.Activate();
                rootFrame.Navigated += OnNavigated;
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Opdaterer applikationstile med nyheder til finansstyring.
        /// </summary>
        /// <param name="nyheder">Nyheder til finansstyring.</param>
        private static void UpdateTile(IEnumerable <INyhedModel> nyheder)
        {
            if (nyheder == null)
            {
                throw new ArgumentNullException(nameof(nyheder));
            }

            TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();

            tileUpdater.EnableNotificationQueue(true);
            tileUpdater.Clear();
            foreach (IGrouping <DateTime, INyhedModel> nyhedsgruppe in nyheder.Where(m => string.IsNullOrEmpty(m.Nyhedsinformation) == false).OrderByDescending(m => m.Nyhedsudgivelsestidspunkt.Date).Take(5).GroupBy(m => m.Nyhedsudgivelsestidspunkt.Date))
            {
                foreach (INyhedModel nyhed in nyhedsgruppe.OrderByDescending(m => m.Nyhedsaktualitet))
                {
                    tileUpdater.Update(UpdateTile(nyhed, TileTemplateType.TileSquare150x150Text04));
                    tileUpdater.Update(UpdateTile(nyhed, TileTemplateType.TileWide310x150BlockAndText02));
                }
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Método que configura a URL das live tiles do aplicativo.
        /// </summary>
        public static void CreateTile()
        {
            var uris = new List <Uri>();

            for (int i = 0; i < 5; i++)
            {
                uris.Add(new Uri("http://" + backendUrl + "notifications/tiles/tile.php" + finalUrl + "&tile=" + i));
            }

            TileUpdater LiveTileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();

            LiveTileUpdater.Clear();
            LiveTileUpdater.EnableNotificationQueue(true);
            LiveTileUpdater.StartPeriodicUpdateBatch(uris, PeriodicUpdateRecurrence.Daily);

            BadgeUpdater BadgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            BadgeUpdater.Clear();
            BadgeUpdater.StartPeriodicUpdate(new Uri("http://" + backendUrl + "notifications/tiles/badge.php" + finalUrl), PeriodicUpdateRecurrence.Daily);
        }
Ejemplo n.º 24
0
        private void UpdatePrimaryTile(List <string> xmls)
        {
            if (xmls == null || !xmls.Any())
            {
                return;
            }

            try
            {
                _tileUpdater.Clear();
                foreach (var xml in xmls)
                {
                    var doc = new XmlDocument();
                    doc.LoadXml(WebUtility.HtmlDecode(xml));
                    _tileUpdater.Update(new TileNotification(doc));
                }
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 25
0
        public static void UpdateTile()
        {
            TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication();

            updater.EnableNotificationQueue(true);
            updater.Clear();
            SetBadgeCountOnTile(MainPage.ViewModel1.AllItems.Count);
            int count = 0;

            foreach (var item in MainPage.ViewModel1.AllItems)
            {
                count++;
                XmlDocument      xmlDoc       = CreateTiles(item);
                TileNotification notification = new TileNotification(xmlDoc);
                updater.Update(notification);
                if (count == 5)
                {
                    break;
                }
            }
        }
Ejemplo n.º 26
0
        public static void CreateTile(Post post)
        {
            TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication();

            updater.EnableNotificationQueue(true);
            updater.Clear();

            var tileLarge = TileContentFactory.CreateTileWide310x150PeekImage01();

            tileLarge.Image.Src = "ms-appx:///Assets/TileUpdateBG_Wide_310x150.png";
            string title = post.Title;

            tileLarge.TextBodyWrap.Text = post.Summary;
            tileLarge.TextHeading.Text  = title;

            var tileSmall = TileContentFactory.CreateTileSquare150x150PeekImageAndText02();

            tileSmall.Image.Src         = "ms-appx:///Assets/TileUpdateBG_Square_150x150.png";
            tileSmall.TextHeading.Text  = post.BlogApp;
            tileSmall.TextBodyWrap.Text = post.Title;

            tileLarge.Square150x150Content = tileSmall;
            TileUpdateManager.CreateTileUpdaterForApplication().Update(tileLarge.CreateNotification());
        }
Ejemplo n.º 27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="updater"></param>
        /// <param name="allUpcoming">This list will be manipulated. Should already be sorted.</param>
        /// <param name="todayInLocal"></param>
        /// <param name="type"></param>
        internal static void UpdateUpcomingTile(TileUpdater updater, List <BaseViewItemHomeworkExam> allUpcoming, DateTime todayInLocal, UpcomingTileType type, BaseUpcomingTileSettings tileSettings)
        {
            try
            {
                // Clear all scheduled notifications
                ClearScheduledNotifications(updater);

                List <ItemsOnDay> groupedByDay = GroupByDay(allUpcoming);

                bool      veryFirst     = true;
                DateTime  today         = todayInLocal;
                const int daysInAdvance = 5;
                for (int i = 0; i < daysInAdvance; i++, today = today.AddDays(1))
                {
                    DateTime todayAsUtc = DateTime.SpecifyKind(today, DateTimeKind.Utc);

                    // Remove any exams that are past "today"
                    for (int x = 0; x < groupedByDay.Count; x++)
                    {
                        groupedByDay[x].Items.RemoveAll(item => item is ViewItemExam && item.Date < today);
                        if (groupedByDay[x].Items.Count == 0)
                        {
                            groupedByDay.RemoveAt(x);
                            x--;
                        }
                    }

                    DateTime dateToStartFrom = tileSettings.GetDateToStartDisplayingOn(todayAsUtc);

                    // Remove any day groups that are older than the user's chosen max date range to display
                    while (groupedByDay.Count > 0 && groupedByDay[0].DateInUtc < dateToStartFrom)
                    {
                        groupedByDay.RemoveAt(0);
                    }

                    // If there's a today group
                    Dictionary <Guid, DateTime> identifiersAndEndTimes = new Dictionary <Guid, DateTime>();
                    var todayGroup = groupedByDay.FirstOrDefault(g => g.DateInUtc == todayAsUtc);
                    if (todayGroup != null)
                    {
                        // That means we'll need to check if there's exams/events, and if so, we need to update the tile
                        // after the event is over, rather than waiting till the day is over

                        // First we need to create a mapping of the item end times and their indexes, because we need to make sure that we're removing
                        // in order of the earliest end times (right now items are sorted by their start times, so not necessarily correct order based on end times)
                        // We also need to be aware that an event could potentially span multiple days...
                        foreach (var item in todayGroup.Items)
                        {
                            // We ignore "all day" items which end at 11:59:59
                            DateTime endTime;
                            if (item is ViewItemExam && item.TryGetEndDateWithTime(out endTime) && endTime.TimeOfDay != new TimeSpan(23, 59, 59))
                            {
                                identifiersAndEndTimes[item.Identifier] = endTime;
                            }
                        }

                        // Remove any events that have already expired (so that the first update doesn't include them)
                        //if (veryFirst)
                        //{
                        //    while (true)
                        //    {
                        //        if (identifiersAndEndTimes.Count > 0)
                        //        {
                        //            DateTime minEndTime = identifiersAndEndTimes.Values.Min();

                        //            // If it's already expired, we remove it
                        //            if (minEndTime < DateTime.Now)
                        //            {
                        //                Guid[] identifiersToRemove = identifiersAndEndTimes.Where(p => p.Value == minEndTime).Select(p => p.Key).ToArray();
                        //                foreach (var id in identifiersToRemove)
                        //                {
                        //                    identifiersAndEndTimes.Remove(id);
                        //                }

                        //                // Remove those events
                        //                todayGroup.Items.RemoveAll(x => identifiersToRemove.Contains(x.Identifier));

                        //                // If we've removed all for that day
                        //                if (todayGroup.Items.Count == 0)
                        //                {
                        //                    // Remove the group
                        //                    groupedByDay.Remove(todayGroup);
                        //                }
                        //            }
                        //        }

                        //        break;
                        //    }
                        //}
                    }

                    DateTime deliveryTime = today;

                    do
                    {
                        if (deliveryTime.Date != today.Date)
                        {
                            // If an event ended up spanning multiple days causing delivery time to be past today, we just won't add it.
                            // In the future when we add support for multiple day events, we'll have to actually handle this... otherwise when the
                            // event expires, the tile won't update correctly on that future day.
                            break;
                        }

                        // On all items but the last, we use the friendly date
                        XmlDocument tile = GenerateUpcomingTileNotificationContent(
                            groupedByDay: groupedByDay,
                            todayAsUtc: todayAsUtc,
                            useFriendlyDates: i != daysInAdvance - 1,
                            type: type);

                        if (tile == null)
                        {
                            if (veryFirst)
                            {
                                updater.Clear();
                            }
                            return;
                        }

                        DateTime thisDeliveryTime = deliveryTime;

                        DateTime expirationTime = today.AddDays(1);

                        bool hasAdditionalOnThisDay = false;

                        // Pick off earliest ending time if there are any left
                        if (identifiersAndEndTimes.Count > 0)
                        {
                            DateTime minEndTime          = identifiersAndEndTimes.Values.Min();
                            Guid[]   identifiersToRemove = identifiersAndEndTimes.Where(p => p.Value == minEndTime).Select(p => p.Key).ToArray();
                            foreach (var id in identifiersToRemove)
                            {
                                identifiersAndEndTimes.Remove(id);
                            }

                            // Assign the expiration time and the next delivery time to be this end time
                            if (minEndTime > deliveryTime)
                            {
                                expirationTime = minEndTime;
                                deliveryTime   = minEndTime; // Setting this for the NEXT notification
                            }

                            // Remove those events
                            todayGroup.Items.RemoveAll(x => identifiersToRemove.Contains(x.Identifier));

                            // If we've removed all for that day
                            if (todayGroup.Items.Count == 0)
                            {
                                // Remove the group
                                groupedByDay.Remove(todayGroup);
                            }

                            // Otherwise
                            else
                            {
                                // We have more on this day that we'll have to repeat the loop for
                                hasAdditionalOnThisDay = true;
                            }
                        }

                        // If we don't have additional on this day, we can remove today since we're done with it,
                        // which will ensure we correctly set expiration time if there's nothing else left
                        if (!hasAdditionalOnThisDay && todayGroup != null)
                        {
                            groupedByDay.Remove(todayGroup);
                        }

                        if (veryFirst || thisDeliveryTime < DateTime.Now.AddSeconds(5))
                        {
                            TileNotification currNotif = new TileNotification(tile);

                            // Only assign expiration time if we have no items left
                            if (groupedByDay.Count == 0)
                            {
                                currNotif.ExpirationTime = expirationTime;
                            }

                            updater.Update(currNotif);

                            veryFirst = false;
                        }
                        else
                        {
                            ScheduledTileNotification s = new ScheduledTileNotification(tile, thisDeliveryTime);

                            // Only assign expiration time if we have no items left
                            if (groupedByDay.Count == 0)
                            {
                                s.ExpirationTime = expirationTime;
                            }

                            updater.AddToSchedule(s);
                        }

                        if (!hasAdditionalOnThisDay)
                        {
                            break;
                        }
                    } while (true);
                }
            }

            catch (Exception ex)
            {
                if (!UWPExceptionHelper.TrackIfNotificationsIssue(ex, "Tiles"))
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 28
0
        // 清除 application tile 的数据
        private void btnClearTile_Click(object sender, RoutedEventArgs e)
        {
            TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();

            tileUpdater.Clear();
        }
Ejemplo n.º 29
0
        public void ClearMainTile()
        {
            TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication();

            updater.Clear();
        }
Ejemplo n.º 30
0
 public static void ClearLiveTile()
 {
     lastTileUpdateHash = null;
     tileUpdater.Clear();
 }