Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        // Initialize the app's tiles on the Start page. There are three different sizes of tiles users can
        // choose from.
        private void InitializeTiles()
        {
            tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
            var mediumSquareTile = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150PeekImageAndText01);
            var largeSquareTile  = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare310x310ImageAndText02);
            var wideTile         = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150PeekImage02);

            tileUpdater.EnableNotificationQueue(true);

            mediumSquareTile.GetElementsByTagName("text")[0].InnerText = "TicTacToe";
            largeSquareTile.GetElementsByTagName("text")[0].InnerText  = "TicTacToe";
            wideTile.GetElementsByTagName("text")[0].InnerText         = "TicTacToe";

            var node1 = wideTile.ImportNode(mediumSquareTile.GetElementsByTagName("binding")[0], true);

            wideTile.GetElementsByTagName("visual")[0].AppendChild(node1);

            var node2 = wideTile.ImportNode(largeSquareTile.GetElementsByTagName("binding")[0], true);

            wideTile.GetElementsByTagName("visual")[0].AppendChild(node2);

            var testNotification = new TileNotification(wideTile);

            testNotification.Tag = "Test";
            tileUpdater.Update(testNotification);

            badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
 /// <summary>
 /// Initialises a new instance of the Skycap.Notifications.EmailBadgeNotification class.
 /// </summary>
 static EmailBadgeNotification()
 {
     // Initialise local variables
     if (_badgeUpdater == null)
     {
         _badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
     }
 }
        public NotificationsImpl()
        {
            this.badgeUpdater  = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
            this.toastNotifier = ToastNotificationManager.CreateToastNotifier();

            this.badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
            this.badgeEl  = (XmlElement)this.badgeXml.SelectSingleNode("/badge");
        }
        private void OnSetBadgeClick(object sender, RoutedEventArgs e)
        {
            var template = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);

            (template.GetElementsByTagName("badge")[0] as XmlElement).SetAttribute("value", countTextBox.Text);
            BadgeUpdater updater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            updater.Update(new BadgeNotification(template));
        }
Exemplo n.º 10
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
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            int counter = 0;

            if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("ToastCounter"))
            {
                counter = 0;
            }
            else
            {
                counter = (int)ApplicationData.Current.LocalSettings.Values["ToastCounter"];
            }

            var details = taskInstance.TriggerDetails as ToastNotificationHistoryChangedTriggerDetail;

            switch (details.ChangeType)
            {
            case ToastHistoryChangedType.Cleared:
                counter = 0;
                break;

            case ToastHistoryChangedType.Removed:
                counter--;
                break;

            case ToastHistoryChangedType.Expired:
                counter--;
                break;

            case ToastHistoryChangedType.Added:
                counter++;
                break;
            }

            ApplicationData.Current.LocalSettings.Values["ToastCounter"] = counter;

            // 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", counter.ToString());

            // 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);
        }
Exemplo n.º 13
0
 public NotificationManager(IServiceProvider services,
                            IJobManager jobs,
                            ISettings settings,
                            IRepository repository)
 {
     this.toastNotifier = ToastNotificationManager.CreateToastNotifier();
     this.badgeUpdater  = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
     this.services      = services;
     this.jobs          = jobs;
     this.settings      = settings;
     this.repository    = repository;
 }
Exemplo n.º 14
0
        private void OnSendStandardToastClicked(object sender, RoutedEventArgs e)
        {
            string xml = @"<toast>
                              <visual>
                                <binding template=""ToastGeneric"">
                                  <image placement=""appLogoOverride"" src=""Assets/MicrosoftLogo.png"" />
                                  <text>Hello insiders!</text>
                                  <image placement=""inline"" src=""Assets/TRexInsider.png"" />
                                  <text>Check out this image. Isn’t it awesome?</text>
                                </binding>
                              </visual>
                            </toast>";

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);

            ToastNotification notification = new ToastNotification(doc);

            ToastNotificationManager.CreateToastNotifier().Show(notification);

            int badgeCounter;

            if (ApplicationData.Current.LocalSettings.Values.ContainsKey("ToastCounter"))
            {
                badgeCounter = (int)ApplicationData.Current.LocalSettings.Values["ToastCounter"];
            }
            else
            {
                badgeCounter = 0;
            }

            badgeCounter++;

            // 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", badgeCounter.ToString());

            // 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);

            ApplicationData.Current.LocalSettings.Values["ToastCounter"] = badgeCounter;
        }
Exemplo n.º 15
0
        public static void SetBadgeNum(double num)
        {
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            badgeUpdater.Clear();
            if (num != 0)
            {
                XmlDocument xml = new XmlDocument();
                xml.LoadXml($"<badge value=\"{num}\"/>");
                badgeUpdater.Update(new BadgeNotification(xml));
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Creates and initializes a new instance of the BadgeUpdater, which lets you change the appearance or content of the badge on the calling app's tile.
        /// </summary>
        /// <returns>The object you will use to send changes to the app tile's badge.</returns>
        public static BadgeUpdater CreateBadgeUpdaterForApplication()
        {
            if(_updater == null)
            {
#if __UNIFIED__ || TIZEN
                _updater = new BadgeUpdater();
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
                _updater = new BadgeUpdater(Windows.UI.Notifications.BadgeUpdateManager.CreateBadgeUpdaterForApplication());
#endif
            }

            return _updater;
        }
Exemplo n.º 17
0
 public static async void UpdateBadge(int count)
 {
     await Task.Run(() => {
         Debug.WriteLine("更新 badge 数量 开始");
         XmlDocument badgeXml    = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
         XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
         badgeElement.SetAttribute("value", count.ToString());
         BadgeNotification badgeNotification = new BadgeNotification(badgeXml);
         BadgeUpdater badgeUpdater           = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
         badgeUpdater.Update(badgeNotification);
         Debug.WriteLine(string.Format("更新 badge 数量 {0} 结束", count));
     });
 }
Exemplo n.º 18
0
        /// <summary>
        /// Creates and initializes a new instance of the <see cref="BadgeUpdater"/>, which lets you change the appearance or content of the badge on the calling app's tile.
        /// </summary>
        /// <returns>The object you will use to send changes to the app tile's badge.</returns>
        public static BadgeUpdater CreateBadgeUpdaterForApplication()
        {
            if (_updater == null)
            {
#if __UNIFIED__ || TIZEN
                _updater = new BadgeUpdater();
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
                _updater = new BadgeUpdater(Windows.UI.Notifications.BadgeUpdateManager.CreateBadgeUpdaterForApplication());
#endif
            }

            return(_updater);
        }
Exemplo n.º 19
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            Random randomizer = new Random();
            var    template   = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);

            (template.GetElementsByTagName("badge")[0] as XmlElement).SetAttribute("value", randomizer.Next(1, 99).ToString());
            BadgeUpdater updater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            updater.Update(new BadgeNotification(template));

            deferral.Complete();
        }
Exemplo n.º 20
0
        private void CreateBadge(object sender, RoutedEventArgs e)
        {
            const BadgeTemplateType badgeTemplateType = BadgeTemplateType.BadgeGlyph;
            XmlDocument             templateContent   = BadgeUpdateManager.GetTemplateContent(badgeTemplateType);

            (templateContent.GetElementsByTagName("badge").FirstOrDefault() as XmlElement)?.SetAttribute("value", "alarm");

            BadgeUpdater badgeUpdater      = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
            var          badgeNotification = new BadgeNotification(templateContent)
            {
                ExpirationTime = new DateTimeOffset(DateTime.UtcNow + TimeSpan.FromSeconds(10))
            };

            badgeUpdater.Update(badgeNotification);
        }
Exemplo n.º 21
0
        private void setBadgeNumber(int num)
        {
            // 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 the application
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            // And update the badge
            badgeUpdater.Update(badge);
        }
Exemplo n.º 22
0
        void UpdateBadge()
        {
            Debug.WriteLine("更新 badge 数量 开始");
            int count = GetNoticeCountFromNoticeToastTempData();

            count += GetPmCountFromPmToastTempData();

            XmlDocument badgeXml     = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
            XmlElement  badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");

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

            badgeUpdater.Update(badgeNotification);
            Debug.WriteLine(string.Format("更新 badge 数量 {0} 结束", count));
        }
        // 发送 Application 的 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 对象更新到 application
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            badgeUpdater.Update(badgeNotification);
        }
Exemplo n.º 24
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);
        }
Exemplo n.º 25
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 the application
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            // And update the badge
            badgeUpdater.Update(badge);
        }
Exemplo n.º 26
0
        private void SetBadgeValue(BadgeUpdater badgeUpdater, int value)
        {
            // create a string with the badge template xml
            string      badgeXmlString = string.Format("<badge value='{0}'/>", value);
            XmlDocument badgeDOM       = new 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
                badgeUpdater.Update(badge);
            }
            catch (Exception ex)
            {
                TrackingManagerHelper.Exception(ex, $"Set badge error loading xml: {badgeXmlString}");
            }
        }
Exemplo n.º 27
0
        // 以数字的方式更新 Application 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 对象更新到 application
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            badgeUpdater.Update(badgeNotification);
        }
Exemplo n.º 28
0
        // 以图标的方式更新 Application 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 对象更新到 application
            BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            badgeUpdater.Update(badgeNotification);
        }
Exemplo n.º 29
0
 public BadgeManager(DiscordClient client)
 {
     _discord            = client;
     _badgeUpdateManager = BadgeUpdateManager.CreateBadgeUpdaterForApplication("App");
 }
Exemplo n.º 30
0
        /// <summary>
        /// Creates or updates one or multiple live tiles on the executing platform. How it is manifests itself is determined by the class that
        /// implements this interface. If the platform does not support this feature, then the implementation should do nothing.
        /// </summary>
        /// <param name="model">Model which contains the data necessary to create a new tile or to find the tile to update</param>
        public override async Task <bool> CreateOrUpdateTileAsync(IModel model)
        {
            if (model == null)
            {
                return(false);
            }

            // Do custom tile creation based on the type of the model passed into this method.
            if (model is MainViewModel || model is ModelList <ItemModel> )
            {
                var list = (model as MainViewModel)?.Items ?? model as ModelList <ItemModel>;

                // 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", list?.Count.ToString());

                // 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);
            }
            else if (model is ItemModel)
            {
                var item = model as ItemModel;

                var tile = new SecondaryTile();
                tile.TileId      = Platform.Current.GenerateModelTileID(item);
                tile.Arguments   = Platform.Current.GenerateModelArguments(model);
                tile.DisplayName = item.LineOne;
                var status = await this.CreateOrUpdateSecondaryTileAsync(tile, new TileVisualOptions());

                if (status)
                {
                    #region Create ItemModel TileContent

                    // Construct the tile content
                    TileContent content = new TileContent()
                    {
                        Visual = new TileVisual()
                        {
                            TileMedium = new TileBinding()
                            {
                                Content = new TileBindingContentAdaptive()
                                {
                                    Children =
                                    {
                                        new TileText()
                                        {
                                            Text = item.LineOne
                                        },
                                        new TileText()
                                        {
                                            Text = item.LineTwo, Style = TileTextStyle.CaptionSubtle
                                        },
                                        new TileText()
                                        {
                                            Text = item.LineThree, Style = TileTextStyle.CaptionSubtle
                                        }
                                    }
                                }
                            },

                            TileWide = new TileBinding()
                            {
                                Content = new TileBindingContentAdaptive()
                                {
                                    Children =
                                    {
                                        new TileText()
                                        {
                                            Text = item.LineOne, Style = TileTextStyle.Subtitle
                                        },
                                        new TileText()
                                        {
                                            Text = item.LineTwo, Style = TileTextStyle.CaptionSubtle
                                        },
                                        new TileText()
                                        {
                                            Text = item.LineThree, Style = TileTextStyle.CaptionSubtle
                                        }
                                    }
                                }
                            },

                            TileLarge = new TileBinding()
                            {
                                Content = new TileBindingContentAdaptive()
                                {
                                    Children =
                                    {
                                        new TileText()
                                        {
                                            Text = item.LineOne, Style = TileTextStyle.Subtitle
                                        },
                                        new TileText()
                                        {
                                            Text = item.LineTwo, Style = TileTextStyle.CaptionSubtle
                                        },
                                        new TileText()
                                        {
                                            Text = item.LineThree, Style = TileTextStyle.CaptionSubtle
                                        }
                                    }
                                }
                            }
                        }
                    };

                    #endregion

                    var notification = new TileNotification(content.GetXml());
                    notification.ExpirationTime = DateTimeOffset.UtcNow.AddMinutes(10);
                    TileUpdateManager.CreateTileUpdaterForSecondaryTile(tile.TileId).Update(notification);
                }

                return(status);
            }

            return(false);
        }
Exemplo n.º 31
0
 public NotificationsImpl()
 {
     this.badgeUpdater  = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
     this.toastNotifier = ToastNotificationManager.CreateToastNotifier();
 }