示例#1
0
        private async void ButtonPinSecondaryTile_Click(object sender, RoutedEventArgs e)
        {
            _tileId = "ScenarioBadgeControl";

            SecondaryTile tile = new SecondaryTile(_tileId, "Name 1", "args", new Uri("ms-appx:///Assets/DefaultSecondaryTileAssests/Medium.png"), TileSize.Default);

            tile.VisualElements.Square71x71Logo             = new Uri("ms-appx:///Assets/DefaultSecondaryTileAssests/Small.png");
            tile.VisualElements.Wide310x150Logo             = new Uri("ms-appx:///Assets/DefaultSecondaryTileAssests/Wide.png");
            tile.VisualElements.Square310x310Logo           = new Uri("ms-appx:///Assets/DefaultSecondaryTileAssests/Large.png");
            tile.VisualElements.ShowNameOnSquare150x150Logo = true;
            tile.VisualElements.ShowNameOnSquare310x310Logo = true;
            tile.VisualElements.ShowNameOnWide310x150Logo   = true;
            await tile.RequestCreateAsync();

            //Prepare for next Step:

            // Pop all the notifications
            ToastHelper.PopToast("Toast 1", "Content of Toast 1");
            ToastHelper.PopToast("Toast 2", "Content of Toast 2");
            ToastHelper.PopToast("Toast 3", "Content of Toast 3");

            //Update badge
            IReadOnlyList <ToastNotification> TNList = ToastNotificationManager.History.GetHistory();

            BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent((uint)TNList.Count);

            // Send the notification to the application’s tile.
            BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(_tileId).Update(badgeContent.CreateNotification());

            // Move the UI to the next step
            stepsControl.Step++;
            stepsControl.NextButtonVisibility = Visibility.Collapsed;
        }
示例#2
0
        //Set weather tile to disabled
        XmlDocument RenderTileWeatherDisabled()
        {
            try
            {
                //Reset secondary weather tile
                if (TileWeather_Pinned)
                {
                    Debug.WriteLine("Set weather tile to disabled.");

                    Tile_UpdateManager  = TileUpdateManager.CreateTileUpdaterForSecondaryTile("TimeMeWeatherTile");
                    Tile_PlannedUpdates = Tile_UpdateManager.GetScheduledTileNotifications();

                    foreach (ScheduledTileNotification Tile_Update in Tile_PlannedUpdates)
                    {
                        try { Tile_UpdateManager.RemoveFromSchedule(Tile_Update); } catch { }
                    }
                    BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile("TimeMeWeatherTile").Clear();

                    Tile_XmlContent.LoadXml("<tile><visual branding=\"none\"><binding template=\"TileSquareImage\"><image id=\"1\" src=\"ms-appx:///Assets/Tiles/SquareLogoWeatherDisabled.png\"/></binding><binding template=\"TileWideImage\"><image id=\"1\" src=\"ms-appx:///Assets/Tiles/WideLogoWeatherDisabled.png\"/></binding></visual></tile>");
                    Tile_UpdateManager.Update(new TileNotification(Tile_XmlContent));
                }
            }
            catch { }
            return(Tile_XmlContent);
        }
        /// <summary>
        /// 更新磁贴图标
        /// </summary>
        /// <param name="number"></param>
        public static void UpdateSecondaryBadgeWithGlyph(string tileId, int index)
        {
            BadgeGlyphNotificationContent badgeContent = new BadgeGlyphNotificationContent((GlyphValue)index);

            // Send the notification to the application’s tile.
            BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(tileId).Update(badgeContent.CreateNotification());
        }
示例#4
0
        public static void UpdateBadge(uint count, string Id)
        {
            BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent(count);

            // Send the notification to the application’s tile. Name taken from ScenarioPages.Toasts.HistoryChangedTrigger.BadgeControl
            BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(Id).Update(badgeContent.CreateNotification());
        }
        /// <summary>
        /// 更新磁贴数字
        /// </summary>
        /// <param name="number"></param>
        public static void UpdateSecondaryBadgeWithNumber(string tileId, int number)
        {
            BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent((uint)number);

            // Send the notification to the application’s tile.
            BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(tileId).Update(badgeContent.CreateNotification());
        }
示例#6
0
        //Set battery tile to disabled
        XmlDocument RenderTileBatteryDisabled()
        {
            try
            {
                //Reset secondary battery tile
                if (TileBattery_Pinned)
                {
                    Debug.WriteLine("Set battery tile to disabled.");

                    Tile_UpdateManager  = TileUpdateManager.CreateTileUpdaterForSecondaryTile("TimeMeBatteryTile");
                    Tile_PlannedUpdates = Tile_UpdateManager.GetScheduledTileNotifications();

                    foreach (ScheduledTileNotification Tile_Update in Tile_PlannedUpdates)
                    {
                        try { Tile_UpdateManager.RemoveFromSchedule(Tile_Update); } catch { }
                    }
                    BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile("TimeMeBatteryTile").Clear();

                    string TileImage         = "<group><subgroup><image src=\"ms-appx:///Assets/BatterySquare/BatteryVerNoBattery.png\"/></subgroup></group>";
                    string BatterySmallTile  = "<binding template=\"TileSmall\">" + TileBattery_BackgroundPhotoXml + TileImage + "</binding>";
                    string BatteryMediumTile = "<binding template=\"TileMedium\">" + TileBattery_BackgroundPhotoXml + TileImage + "</binding>";
                    string BatteryWideTile   = "<binding template=\"TileWide\">" + TileBattery_BackgroundPhotoXml + TileImage + "</binding>";

                    Tile_XmlContent.LoadXml("<tile><visual contentId=\"" + TileContentId + "\" branding=\"none\">" + BatterySmallTile + BatteryMediumTile + BatteryWideTile + "</visual></tile>");
                    Tile_UpdateManager.Update(new TileNotification(Tile_XmlContent));
                }
            }
            catch { }
            return(Tile_XmlContent);
        }
示例#7
0
        private async void BadgeToggleSwitch_Toggled(object sender, RoutedEventArgs e)
        {
            if (Badge.IsOn)
            {
                badgeTile = new SecondaryTile(
                    "BadgeTile",
                    "Badge",
                    "Arguments",
                    new Uri("ms-appx:///Assets/green.150x150.png", UriKind.Absolute),
                    TileSize.Square150x150);
                await badgeTile.RequestCreateAsync();

                tileXml   = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph);
                tileImage = tileXml.SelectSingleNode("/badge") as XmlElement;
                tileImage.SetAttribute("value", "alert");

                BadgeNotification badgeNotification = new BadgeNotification(tileXml);
                BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(badgeTile.TileId).Update(badgeNotification);

                tileXml   = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
                tileImage = tileXml.SelectSingleNode("/badge") as XmlElement;
                tileImage.SetAttribute("value", "31");
                badgeNotification = new BadgeNotification(tileXml);
                BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badgeNotification);
            }
            else
            {
                BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();
                await badgeTile.RequestDeleteAsync();
            }
        }
示例#8
0
        private async void ButtonUpdateBadgeNumber_Click(object sender, RoutedEventArgs e)
        {
            int num;

            if (!int.TryParse(TextBoxBadgeNumber.Text, out num))
            {
                await new MessageDialog("You must provide a valid integer.", "Error").ShowAsync();
                return;
            }

            // Get the blank badge XML payload for a badge number
            XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);

            // Set the value of the badge in the XML to our number
            XmlElement badgeElement = badgeXml.SelectSingleNode("/badge") as XmlElement;

            badgeElement.SetAttribute("value", num.ToString());

            // Create the badge notification
            BadgeNotification badge = new BadgeNotification(badgeXml);

            // Create the badge updater for our secondary tile, using our tile ID for the secondary tile
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(SECONDARY_TILE_ID);

            // And update the badge
            badgeUpdater.Update(badge);
        }
示例#9
0
        //Set tile to failed update
        XmlDocument RenderTileLiveFailed(string TileId)
        {
            try
            {
                Debug.WriteLine("Set tile to failed: " + TileId);

                //Reset primary tile
                BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();
                TileUpdateManager.CreateTileUpdaterForApplication().Clear();

                Tile_UpdateManager  = TileUpdateManager.CreateTileUpdaterForSecondaryTile(TileId);
                Tile_PlannedUpdates = Tile_UpdateManager.GetScheduledTileNotifications();

                foreach (ScheduledTileNotification Tile_Update in Tile_PlannedUpdates)
                {
                    try { Tile_UpdateManager.RemoveFromSchedule(Tile_Update); } catch { }
                }
                BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(TileId).Clear();

                Tile_XmlContent.LoadXml("<tile><visual branding=\"none\"><binding template=\"TileSquareImage\"><image id=\"1\" src=\"ms-appx:///Assets/Tiles/SquareLogoFailed.png\"/></binding><binding template=\"TileWideImage\"><image id=\"1\" src=\"ms-appx:///Assets/Tiles/WideLogoFailed.png\"/></binding></visual></tile>");
                Tile_UpdateManager.Update(new TileNotification(Tile_XmlContent));
            }
            catch { }
            return(Tile_XmlContent);
        }
示例#10
0
        private async void CreateBadgeTile_Click(object sender, RoutedEventArgs e)
        {
            if (!SecondaryTile.Exists(BADGE_TILE_ID))
            {
                SecondaryTile secondTile = new SecondaryTile(
                    BADGE_TILE_ID,
                    "LockScreen CS - Badge only",
                    "BADGE_ARGS",
                    new Uri("ms-appx:///Assets/squareTile-sdk.png"),
                    TileSize.Square150x150
                    );
                secondTile.LockScreenBadgeLogo = new Uri("ms-appx:///Assets/badgelogo-sdk.png");

                bool isPinned = await secondTile.RequestCreateForSelectionAsync(GetElementRect((FrameworkElement)sender), Placement.Above);

                if (isPinned)
                {
                    BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent(2);
                    BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(BADGE_TILE_ID).Update(new BadgeNotification(badgeContent.GetXml()));
                    rootPage.NotifyUser("Secondary tile created and badge updated. Go to PC settings to add it to the lock screen.", NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser("Tile not created.", NotifyType.ErrorMessage);
                }
            }
            else
            {
                rootPage.NotifyUser("Badge secondary tile already exists.", NotifyType.ErrorMessage);
            }
        }
示例#11
0
        // 启动一个“轮询服务端以更新 badge 通知”的任务
        private void btnStartPeriodicUpdate_Click(object sender, RoutedEventArgs e)
        {
            // 启动一个循环更新 Badge 通知的任务,并指定 Badge 通知的数据源和轮询周期
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(TILEID);

            // 马上请求服务端获取数据,然后 45 分钟之后再次获取数据,最后再每半个小时获取一次数据
            badgeUpdater.StartPeriodicUpdate(new Uri("http://localhost:44914/api/BadgeContent", UriKind.Absolute), DateTimeOffset.UtcNow.AddMinutes(45), PeriodicUpdateRecurrence.HalfHour);

            // Badge 通知的数据源示例请参见 WebApi/Controllers/BadgeContentController.cs
        }
示例#12
0
        //Обновление индикатора событий
        private void BadgeUpdaterForSecondaryTile()
        {
            string badgeXmlString = "<badge value='" + SampleDataSource.GroupUncheckedItemsCount() + "'/>";

            Windows.Data.Xml.Dom.XmlDocument badgeDOM = new Windows.Data.Xml.Dom.XmlDocument();
            badgeDOM.LoadXml(badgeXmlString);
            BadgeNotification badge = new BadgeNotification(badgeDOM);

            BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(SecondaryTileID).Update(badge);
        }
示例#13
0
        private void SetBadge(XmlDocument template)
        {
            XmlElement textnode = (XmlElement)template.SelectSingleNode("/badge");

            textnode.SetAttribute("value", BadgeNumber);

            BadgeNotification badgeNotification = new BadgeNotification(template);

            BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile("tileId").Update(badgeNotification);
        }
示例#14
0
        private void SendBadgeNotification_Click(object sender, RoutedEventArgs e)
        {
            if (VerifyTileIsPinned())
            {
                BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent(6);

                // Send the notification to the secondary tile
                BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(MainPage.dynamicTileId).Update(new BadgeNotification(badgeContent.GetXml()));

                rootPage.NotifyUser("Badge notification sent to " + MainPage.dynamicTileId, NotifyType.StatusMessage);
            }
        }
示例#15
0
        private void SendBadgeNotificationWithStringManipulation_Click(object sender, RoutedEventArgs e)
        {
            if (VerifyTileIsPinned())
            {
                string badgeXmlString = "<badge value='9'/>";
                var    badgeDOM       = new Windows.Data.Xml.Dom.XmlDocument();
                badgeDOM.LoadXml(badgeXmlString);
                BadgeNotification badge = new BadgeNotification(badgeDOM);

                // Send the notification to the secondary tile
                BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(MainPage.dynamicTileId).Update(badge);

                rootPage.NotifyUser("Badge notification sent to " + MainPage.dynamicTileId, NotifyType.StatusMessage);
            }
        }
示例#16
0
        /// <summary>
        /// 通过Xml磁贴模版文件更新磁贴数字
        /// </summary>
        /// <param name="number"></param>
        public static void UpdateSecondaryBadgeWithNumberWithByXml(string tileId, int number)
        {
            // Create a string with the badge template xml.
            string badgeXmlString = "<badge value='" + number + "'/>";

            Windows.Data.Xml.Dom.XmlDocument badgeDOM = new Windows.Data.Xml.Dom.XmlDocument();
            // Create a DOM.
            badgeDOM.LoadXml(badgeXmlString);

            // Load the xml string into the DOM, catching any invalid xml characters.
            BadgeNotification badge = new BadgeNotification(badgeDOM);

            // Create a badge notification and send it to the application’s tile.
            BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(tileId).Update(badge);
        }
示例#17
0
        private async void IconicTile_Toggled(object sender, RoutedEventArgs e)
        {
            if (IconicTile.IsOn)
            {
                iconicTile = new SecondaryTile(
                    "IconicTile",
                    "Iconic",
                    "Arguments",
                    new Uri("ms-appx:///Assets/yellow.150x150.png", UriKind.Absolute),
                    TileSize.Square150x150);
                await iconicTile.RequestCreateAsync();

                tileXml   = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
                tileImage = tileXml.SelectSingleNode("/badge") as XmlElement;
                tileImage.SetAttribute("value", "31");

                BadgeNotification badgeNotification = new BadgeNotification(tileXml);
                BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(iconicTile.TileId).Update(badgeNotification);

                tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150IconWithBadge);

                tileImage = tileXml.GetElementsByTagName("image")[0] as XmlElement;
                tileImage.SetAttribute("src", "ms-appx:///Assets/icon.130x202.png");

                notif = new TileNotification(tileXml);
                TileUpdateManager.CreateTileUpdaterForSecondaryTile(iconicTile.TileId).Update(notif);

                tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150IconWithBadgeAndText);

                tileImage = tileXml.GetElementsByTagName("image")[0] as XmlElement;
                tileImage.SetAttribute("src", "ms-appx:///Assets/icon.70x110.png");

                tileList = tileXml.GetElementsByTagName("text");
                (tileList[0] as XmlElement).InnerText = "Header text";
                (tileList[1] as XmlElement).InnerText = "First line of text";
                (tileList[2] as XmlElement).InnerText = "Second line of text";

                notif = new TileNotification(tileXml);
                TileUpdateManager.CreateTileUpdaterForApplication().Update(notif);
            }
            else
            {
                TileUpdateManager.CreateTileUpdaterForApplication().Clear();
                await iconicTile.RequestDeleteAsync();
            }
        }
        // 发送 secondary tile 的 Badge 通知
        private void btnBadgeNotification_Click(object sender, RoutedEventArgs e)
        {
            // 用于描述 badge 通知的 xml 字符串(数字在 1 - 99 之间,如果大于 99 则会显示 99+ ,如果是 0 则会移除 badge,如果小于 0 则无效)
            string badgeXml = "<badge value='3'/>";

            // 将 xml 字符串转换为 Windows.Data.Xml.Dom.XmlDocument 对象
            XmlDocument badgeDoc = new XmlDocument();

            badgeDoc.LoadXml(badgeXml);

            // 实例化 BadgeNotification 对象
            BadgeNotification badgeNotification = new BadgeNotification(badgeDoc);

            // 将指定的 BadgeNotification 对象更新到指定的 secondary tile 磁贴
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(TILEID);

            badgeUpdater.Update(badgeNotification);
        }
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            var details = taskInstance.TriggerDetails as ToastNotificationHistoryChangedTriggerDetail;

            if (details == null)
            {
                return;
            }

            //Update the badge by taking the counter and deleting one
            IReadOnlyList <ToastNotification> TNList = ToastNotificationManager.History.GetHistory();

            BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent((uint)TNList.Count);

            // Send the notification to the application’s tile. Name taken from ScenarioPages.Toasts.HistoryChangedTrigger.BadgeControl
            BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile("ScenarioBadgeControl").Update(badgeContent.CreateNotification());

            // We send back the change type, the UI listens to the progress and parses the change type
            taskInstance.Progress = (uint)details.ChangeType;
        }
示例#20
0
        private void ButtonUpdateBadgeGlyph_Click(object sender, RoutedEventArgs e)
        {
            string badgeGlyphValue = ComboBoxBadgeGlyph.SelectedItem as string;

            // Get the blank badge XML payload for a badge glyph
            XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph);

            // Set the value of the badge in the XML to our glyph value
            XmlElement badgeElement = badgeXml.SelectSingleNode("/badge") as XmlElement;

            badgeElement.SetAttribute("value", badgeGlyphValue);

            // Create the badge notification
            BadgeNotification badge = new BadgeNotification(badgeXml);

            // Create the badge updater for our secondary tile, using our tile ID for the secondary tile
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(SECONDARY_TILE_ID);

            // And update the badge
            badgeUpdater.Update(badge);
        }
        /// <summary>
        /// This is the click handler for the 'Other' button.  You would replace this with your own handler
        /// if you have a button or buttons on this page.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SendBadgeNotification_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;

            if (button != null)
            {
                if (SecondaryTile.Exists(MainPage.dynamicTileId))
                {
                    BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent(6);

                    // Send the notification to the secondary tile
                    BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(MainPage.dynamicTileId).Update(badgeContent.CreateNotification());

                    rootPage.NotifyUser("Badge notification sent to " + MainPage.dynamicTileId, NotifyType.StatusMessage);
                }
                else
                {
                    ToggleButtons(false);
                    rootPage.NotifyUser(MainPage.dynamicTileId + " not pinned.", NotifyType.ErrorMessage);
                }
            }
        }
        // 以数字的方式更新指定的 Secondary Tile 的 Badge 通知
        private void btnUpdateBadgeWidthNumber_Click(object sender, RoutedEventArgs e)
        {
            // 用于描述 badge 通知的 xml 字符串(数字在 1 - 99 之间,如果大于 99 则会显示 99+ ,如果是 0 则会移除 badge,如果小于 0 则无效)
            string badgeXml = "<badge value='6'/>";

            // 将 xml 字符串转换为 Windows.Data.Xml.Dom.XmlDocument 对象
            XmlDocument badgeDoc = new XmlDocument();

            badgeDoc.LoadXml(badgeXml);
            // 获取此 badge 的 xml
            // lblMsg.Text = badgeXml.GetXml();

            // 实例化 BadgeNotification 对象
            BadgeNotification badgeNotification = new BadgeNotification(badgeDoc);
            DateTimeOffset    expirationTime    = DateTimeOffset.UtcNow.AddSeconds(30);

            badgeNotification.ExpirationTime = expirationTime; // 30 秒后清除这个 badge

            // 将指定的 BadgeNotification 对象更新到指定的 secondary tile 磁贴
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(TILEID);

            badgeUpdater.Update(badgeNotification);
        }
        // 以图标的方式更新指定的 Secondary Tile 的 Badge 通知
        private void btnUpdateBadgeWidthIcon_Click(object sender, RoutedEventArgs e)
        {
            // 用于描述 badge 通知的 xml 字符串
            string badgeXml = $"<badge value='{((ComboBoxItem)cmbBadgeValue.SelectedItem).Content}'/>";

            // 将 xml 字符串转换为 Windows.Data.Xml.Dom.XmlDocument 对象
            XmlDocument badgeDoc = new XmlDocument();

            badgeDoc.LoadXml(badgeXml);
            // 获取此 badge 的 xml
            // lblMsg.Text = badgeXml.GetXml();

            // 实例化 BadgeNotification 对象
            BadgeNotification badgeNotification = new BadgeNotification(badgeDoc);
            DateTimeOffset    expirationTime    = DateTimeOffset.UtcNow.AddSeconds(30);

            badgeNotification.ExpirationTime = expirationTime; // 30 秒后清除这个 badge

            // 将指定的 BadgeNotification 对象更新到指定的 secondary tile 磁贴
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(TILEID);

            badgeUpdater.Update(badgeNotification);
        }
        // 清除指定的 Secondary Tile 的 Badge 通知
        private void btnClearBadge_Click(object sender, RoutedEventArgs e)
        {
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(TILEID);

            badgeUpdater.Clear();
        }
示例#25
0
 private void ButtonClearBadge_Click(object sender, RoutedEventArgs e)
 {
     // Clear the badge from the secondary tile
     BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(SECONDARY_TILE_ID).Clear();
 }
示例#26
0
        public void UpdateTiles()
        {
            try
            {
                // update main tile
                var todayView = this.workbook.Views.FirstOrDefault(v => v.ViewKind == ViewKind.Today);
                if (todayView != null)
                {
                    var todayTasks = this.PickTasks(todayView);
                    this.SetTileContent(StringResources.SystemView_TitleToday, todayTasks, TileUpdateManager.CreateTileUpdaterForApplication());

                    bool   badgeSet         = false;
                    string badgeFolderValue = this.workbook.Settings.GetValue <string>(CoreSettings.BadgeValue);
                    if (!string.IsNullOrWhiteSpace(badgeFolderValue))
                    {
                        var descriptor = LaunchArgumentsHelper.GetDescriptorFromArgument(this.workbook, badgeFolderValue);
                        if (descriptor != null && descriptor.Folder != null)
                        {
                            var folder = descriptor.Folder;
                            this.SetBadgeValue(BadgeUpdateManager.CreateBadgeUpdaterForApplication(), this.PickTasks(folder).Count);
                            badgeSet = true;
                        }
                    }

                    if (!badgeSet)
                    {
                        this.SetBadgeValue(BadgeUpdateManager.CreateBadgeUpdaterForApplication(), 0);
                    }
                }
                else
                {
                    this.TrackEvent("Update main tile", "Could not find view today");
                }
            }
            catch (Exception ex)
            {
                TrackingManagerHelper.Exception(ex, "Error while updating main tile");
            }

            if (this.secondaryTiles == null)
            {
                this.TrackEvent("Update secondary tiles", "Secondary tiles are not loaded, skipping update");
                return;
            }

            foreach (var secondaryTile in this.secondaryTiles)
            {
                try
                {
                    TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(secondaryTile.TileId);

                    IAbstractFolder folder = LaunchArgumentsHelper.GetDescriptorFromArgument(this.workbook, secondaryTile.TileId).Folder;
                    ITask           task   = LaunchArgumentsHelper.GetDescriptorFromArgument(this.workbook, secondaryTile.TileId).Task;

                    if (folder != null)
                    {
                        var title       = folder.Name;
                        var folderTasks = this.PickTasks(folder);

                        this.SetTileContent(title, folderTasks, tileUpdater, folder);
                        this.SetBadgeValue(BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(secondaryTile.TileId), folderTasks.Count);
                    }
                    else if (task != null)
                    {
                        this.SetTileContent(task, tileUpdater);
                    }
                    else if (secondaryTile.TileId != quickAddTaskTileId)
                    {
                        // task that is linked to no folder and no task...
                        this.SetTileContent(StringResources.Message_LiveTileRemoveMe, new List <ITask>(), tileUpdater);
                    }
                }
                catch (Exception ex)
                {
                    TrackingManagerHelper.Exception(ex, "Update secondary tiles");
                }
            }
        }
示例#27
0
        /// <summary>
        /// 通过Xml磁贴模版文件更新磁贴图标
        /// </summary>
        /// <param name="TileGlyph"></param>
        public static void UpdateBadgeWithGlyphByXml(string tileId, string TileGlyph)
        {
            /*
             *              public class TileGlyph
             *  {
             *      public string Name { get; private set; }
             *      public bool IsAvailable { get; private set; }
             *      public TileGlyph(string name, bool isAvailable)
             *      {
             *          this.Name = name;
             *          this.IsAvailable = isAvailable;
             *      }
             *      public override string ToString()
             *      {
             *          return Name;
             *      }
             *  }
             *
             *  public class TileGlyphCollection : ObservableCollection<TileGlyph>
             *  {
             *
             *      public TileGlyphCollection()
             *      {
             *          // Some glyphs are only available on Windows
             #if WINDOWS_PHONE_APP
             *          const bool windows = false;
             *          const bool phone = true;
             #else
             *          const bool windows = true;
             *          const bool phone = false;
             #endif
             *
             *          Add(new TileGlyph("none", windows | phone));
             *          Add(new TileGlyph("activity", windows));
             *          Add(new TileGlyph("alert", windows | phone));
             *          Add(new TileGlyph("available", windows));
             *          Add(new TileGlyph("away", windows));
             *          Add(new TileGlyph("busy", windows));
             *          Add(new TileGlyph("newMessage", windows));
             *          Add(new TileGlyph("paused", windows));
             *          Add(new TileGlyph("playing", windows));
             *          Add(new TileGlyph("unavailable", windows));
             *          Add(new TileGlyph("error", windows));
             *          Add(new TileGlyph("attention", windows | phone));
             *          Add(new TileGlyph("alarm", windows));
             *      }
             *  }
             * */

            // Create a string with the badge template xml.
            string badgeXmlString = "<badge value='" + TileGlyph + "'/>";

            Windows.Data.Xml.Dom.XmlDocument badgeDOM = new Windows.Data.Xml.Dom.XmlDocument();

            // Create a DOM.
            badgeDOM.LoadXml(badgeXmlString);

            // Load the xml string into the DOM, catching any invalid xml characters.
            BadgeNotification badge = new BadgeNotification(badgeDOM);

            // Create a badge notification and send it to the application’s tile.
            BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(tileId).Update(badge);
        }
示例#28
0
 /// <summary>
 /// Set secondary tile
 /// </summary>
 /// <param name="secondaryId">Identifier of the secondary tile</param>
 public void SetSecondary(string secondaryId)
 {
     BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(secondaryId).Update(new BadgeNotification(this.xml));
 }
示例#29
0
 public BadgeUpdater GetBadgeUpdaterForSecondaryTile(string tileId)
 {
     return(BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(tileId));
 }