Пример #1
0
        public static void SendBadge(uint count)
        {
            BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent(count);
            BadgeNotification notif = new BadgeNotification(badgeContent.GetXml());

            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(notif);
        }
Пример #2
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            var deferal = taskInstance.GetDeferral();

            if (taskInstance.TriggerDetails is RawNotification)
            {
                var details   = taskInstance.TriggerDetails as RawNotification;
                var arguments = details.Content.Split(':');

                if (arguments.Count() > 0)
                {
                    switch (arguments[0])
                    {
                    case "new_items":
                        if (arguments.Count() > 1)
                        {
                            XmlDocument badgeXml     = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
                            XmlElement  badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
                            badgeElement.SetAttribute("value", arguments[1]);
                            BadgeNotification badge = new BadgeNotification(badgeXml);
                            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
                        }
                        break;
                    }
                }
            }



            deferal.Complete();
        }
Пример #3
0
        public void UpdateCount(int count)
        {
            var badgeXml = TileHelper.CreateBadgeNumber(count);
            var badge    = new BadgeNotification(badgeXml);

            _badgeUpdater.Update(badge);
        }
Пример #4
0
        private static void UpdateBadgeGlyph(string badgeGlyphValue)
        {
            //https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-badges

            if (badgeGlyphValue.IsNullOrWhiteSpace())
            {
                badgeGlyphValue = "alert";
            }

            // 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 the application
            BadgeUpdater badgeUpdater =
                BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            // And update the badge
            badgeUpdater.Update(badge);
        }
Пример #5
0
        private void SetState(StateType state)
        {
            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();
            string badgeGlyphValue = "";

            switch (state)
            {
            case StateType.available:
                badgeGlyphValue = "available";
                break;

            case StateType.away:
                badgeGlyphValue = "away";
                break;

            case StateType.busy:
                badgeGlyphValue = "busy";
                break;

            default:
                break;
            }
            XmlDocument badgeXml     = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph);
            XmlElement  badgeElement = badgeXml.SelectSingleNode("/badge") as XmlElement;

            badgeElement.SetAttribute("value", badgeGlyphValue);
            BadgeNotification badge        = new BadgeNotification(badgeXml);
            BadgeUpdater      badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            badgeUpdater.Update(badge);
        }
Пример #6
0
        public static void UpdateBadgeGlyph(BadgeGlyph glyph)
        {
            // Create the badge updater for the application
            BadgeUpdater updater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            if (glyph == BadgeGlyph.None)
            {
                updater.Clear();
            }
            else
            {
                // Get the blank badge XML payload for a badge number
                XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph);

                // Set the value of the badge in the xml to our number
                XmlElement badgeElem = badgeXml.SelectSingleNode("/badge") as XmlElement;
                badgeElem.SetAttribute("value", glyph.DescriptionAttr());

                // Create the badge notification
                BadgeNotification badge = new BadgeNotification(badgeXml)
                {
                    ExpirationTime = DateTimeOffset.UtcNow.AddMinutes(10)
                };
                // And update the badge
                updater.Update(badge);
            }
        }
Пример #7
0
        static public void UpdateWatchedBadge(WhirlMonData.WhirlPoolAPIData.RootObject data)
        {
            try
            {
                int unread = data.totalUnread;

                if (unread == 0)
                {
                    BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();
                }
                else
                {
                    XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);

                    XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
                    badgeElement.SetAttribute("value", unread.ToString());

                    BadgeNotification badge = new BadgeNotification(badgeXml);
                    BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
                }
            }
            catch (Exception x)
            {
                ShowErrorToast("UpdateWatchedBadge", x);
            }
        }
Пример #8
0
 private void UpdateBadge(bool playing, bool paused)
 {
     try
     {
         string xmlstring;
         if (playing && !paused)
         {
             xmlstring = "<badge value=\"playing\"/>";
         }
         else
         if (paused)
         {
             xmlstring = "<badge value=\"paused\"/>";
         }
         else
         {
             xmlstring = "<badge value=\"stopped\"/>";
         }
         XmlDocument xdoc = new XmlDocument();
         xdoc.LoadXml(xmlstring);
         BadgeNotification bnotification = new BadgeNotification(xdoc);
         BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(bnotification);
     }
     catch (Exception ex)
     {
         NotifyUser(ex);
     }
 }
Пример #9
0
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--
        public static void IncBadgeCount()
        {
            // 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;
            string     value        = null;

            try
            {
                value = badgeElement.GetAttribute("value");
            }
            catch (Exception) { Logger.Debug("Failed to retrieve badge count value node."); }

            if (int.TryParse(value, out int count))
            {
                badgeElement.SetAttribute("value", (count + 1).ToString());
            }
            else
            {
                badgeElement.SetAttribute("value", "1");
            }

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

            // Create the badge updater for the application
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            // And update the badge
            badgeUpdater.Update(badge);
        }
Пример #10
0
        /// <summary>
        /// Applies a change to the badge's number.
        /// </summary>
        /// <param name="notification">The object that supplies the new XML definition for the badge.</param>
        public void Update(BadgeNotification notification)
        {
#if __IOS__ || __TVOS__
            UIApplication.SharedApplication.InvokeOnMainThread(() =>
            {
                UIApplication.SharedApplication.ApplicationIconBadgeNumber = notification.Value;
            });
#elif __MAC__
            if (notification.Glyph != char.MinValue)
            {
                NSApplication.SharedApplication.DockTile.BadgeLabel = notification.Glyph.ToString();
            }
            else
            {
                if (notification.Value < 1)
                {
                    Clear();
                    return;
                }

                NSApplication.SharedApplication.DockTile.BadgeLabel = notification.Value.ToString();
            }
#elif TIZEN
            Tizen.Applications.BadgeControl.Update(Tizen.Applications.Application.Current.ApplicationInfo.ApplicationId, notification.Value);
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
            _updater.Update(notification._notification);
#endif
        }
Пример #11
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();
            }
        }
Пример #12
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);
        }
        void UpdateBadgeWithGlyphWithStringManipulation()
        {
            // Create a string with the badge template xml.
            string badgeXmlString = "<badge value='" + ((TileGlyph)GlyphList.SelectedItem).Name.ToString() + "'/>";

            Windows.Data.Xml.Dom.XmlDocument badgeDOM = new Windows.Data.Xml.Dom.XmlDocument();
            try
            {
                // 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.CreateBadgeUpdaterForApplication().Update(badge);

                OutputTextBlock.Text = badgeDOM.GetXml();
                rootPage.NotifyUser("Badge sent", NotifyType.StatusMessage);
            }
            catch (Exception)
            {
                OutputTextBlock.Text = string.Empty;
                rootPage.NotifyUser("Error loading the xml, check for invalid characters in the input", NotifyType.ErrorMessage);
            }
        }
Пример #14
0
        public static void UpdateTile(int value)
        {
            var type     = BadgeTemplateType.BadgeNumber;
            var xml      = BadgeUpdateManager.GetTemplateContent(type);
            var elements = xml.GetElementsByTagName("badge");
            var element  = elements[0] as XmlElement;

            element.SetAttribute("value", value.ToString());

            var updater      = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
            var notification = new BadgeNotification(xml);

            updater.Update(notification);

            Debug.WriteLine("Background task badge updated: " + value.ToString());

            var template = ToastTemplateType.ToastText01;

            xml = ToastNotificationManager.GetTemplateContent(template);
            var text = xml.CreateTextNode(string.Format("Badge updated to {0}", value));

            elements = xml.GetElementsByTagName("text");
            elements[0].AppendChild(text);

            var toast    = new ToastNotification(xml);
            var notifier = ToastNotificationManager.CreateToastNotifier();

            notifier.Show(toast);

            Debug.WriteLine("Background task toast shown: " + value.ToString());
        }
Пример #15
0
        static public void UpdateTile(int nbr)
        {
            XmlDocument badgeDOM = new XmlDocument();

            badgeDOM.LoadXml(string.Format("<badge value='{0}'/>", nbr));
            BadgeNotification badge = new BadgeNotification(badgeDOM);

            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
        }
Пример #16
0
        private static void UpdateBadge()
        {
            XmlDocument badgeXml     = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph);
            XmlElement  badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");

            badgeElement.SetAttribute("value", "1");
            BadgeNotification badge = new BadgeNotification(badgeXml);

            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
        }
Пример #17
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);
        }
Пример #18
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);
        }
Пример #19
0
        public static void UpdateBadge(int count)
        {
            XmlDocument badgeXml     = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
            XmlElement  badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");

            badgeElement.SetAttribute("value", count.ToString());
            BadgeNotification badge = new BadgeNotification(badgeXml);

            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
        }
Пример #20
0
        //バッジ通知を表示
        public static void SendBasicBadge(int number)
        {
            var template = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);

            Debug.WriteLine(template.GetXml());
            template.FirstChild.Attributes.First(q => q.NodeName == "value").InnerText = number.ToString();

            var notification = new BadgeNotification(template);

            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(notification);
        }
        private void ButtonSetLockScreenClick(object sender, RoutedEventArgs e)
        {
            var lockscreen = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
            var template   = lockscreen.GetElementsByTagName("badge");

            ((XmlElement)template[0]).SetAttribute("value", TextboxLockScreen.Text);

            BadgeNotification badge = new BadgeNotification(lockscreen);

            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
        }
        public static void SetBadgeCount(int c)
        {
            XmlDocument badgeXml        = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
            var         badgeAttributes = (XmlElement)badgeXml.GetElementsByTagName("badge")[0];

            badgeAttributes.SetAttribute("value", c.ToString());

            var badgeNotification = new BadgeNotification(badgeXml);

            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badgeNotification);
        }
Пример #23
0
        private void DisplayBadge_Click(object sender, RoutedEventArgs e)
        {
            Windows.Data.Xml.Dom.XmlDocument doc = new Windows.Data.Xml.Dom.XmlDocument();
            string xml = File.ReadAllText("Templates/Badge.xml");

            doc.LoadXml(xml);

            BadgeNotification badge = new BadgeNotification(doc);

            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
        }
Пример #24
0
        private void SendBadgeWithStringManipulation_Click(object sender, RoutedEventArgs e)
        {
            string badgeXmlString = "<badge value='6'/>";

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

            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
            rootPage.NotifyUser("Badge notification sent", NotifyType.StatusMessage);
        }
Пример #25
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();
        }
Пример #26
0
        private void setBadgeNumber(int num)
        {
            XmlDocument badgeXml     = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
            XmlElement  badgeElement = badgeXml.SelectSingleNode("/badge") as XmlElement;

            badgeElement.SetAttribute("value", num.ToString());
            BadgeNotification badge        = new BadgeNotification(badgeXml);
            BadgeUpdater      badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            badgeUpdater.Update(badge);
        }
Пример #27
0
        private void btnBadge_Click(object sender, RoutedEventArgs e)
        {
            XmlDocument badgeXml     = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph);
            XmlElement  badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");

            badgeElement.SetAttribute("value", "alarm");
            BadgeNotification badge = new BadgeNotification(badgeXml);

            badge.ExpirationTime = DateTimeOffset.Now.AddMinutes(1);
            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
        }
Пример #28
0
        private void btnCleraBadge_Click(object sender, RoutedEventArgs e)
        {
            XmlDocument badgeXml =
                BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
            XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");

            badgeElement.SetAttribute("value", "0");
            BadgeNotification badge = new BadgeNotification(badgeXml);

            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
        }
Пример #29
0
        /// <summary>
        /// Sets the badge.
        /// </summary>
        /// <param name="badgeNumber">The badge number.</param>
        /// <param name="title">The title. Used only by Android</param>
        public void SetBadge(int badgeNumber, string title = null)
        {
            var badgeXml     = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
            var badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");

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

            var badge = new BadgeNotification(badgeXml);

            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
        }
Пример #30
0
Файл: Help.cs Проект: fffweb/wp
        public static void UpdateBadge(int wordCount)

        {
            XmlDocument xdoc   = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
            XmlElement  xBadge = (XmlElement)xdoc.SelectSingleNode("/badge");

            xBadge.SetAttribute("value", wordCount.ToString());
            BadgeNotification notifi = new BadgeNotification(xdoc);

            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(notifi);
        }
Пример #31
0
        private void ClearBadgeNotification_Click(object sender, RoutedEventArgs e)
        {
            string xmlContent = "<badge version='1' value='0'/>";

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xmlContent);

            BadgeNotification notification = new BadgeNotification(xmlDoc);

            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(notification);
        }