Esempio n. 1
0
        private void ToastGenerator()
        {
            const string title = "Click on time of Emergency!";

            var visual = new ToastVisual()
            {
                TitleText = new ToastText()
                {
                    Text = title
                }
            };

            const int conversationId = 177777;

            var toastContent = new ToastContent()
            {
                Visual = visual,
                Launch = new QueryString()
                {
                    { "conversationId", conversationId.ToString() }
                }.ToString()
            };

            var toast = new ToastNotification(toastContent.GetXml())
            {
                ExpirationTime = DateTime.Now.AddHours(5),
                SuppressPopup  = true,
                Tag            = "Friends"
            };

            if (ToastNotificationManager.History != null)
            {
                ToastNotificationManager.History.Remove("Friends");
            }

            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
Esempio n. 2
0
        public static void ShowToastNotification(string assetsImageFileName, string text, NotificationAudioNames audioName = NotificationAudioNames.Default)
        {
            // 1. 创建元素
            ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01;
            XmlDocument       toastXml      = ToastNotificationManager.GetTemplateContent(toastTemplate);

            // 2. 提供文本
            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");

            toastTextElements[0].AppendChild(toastXml.CreateTextNode(text));

            // 3. 提供图片
            XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image");

            ((XmlElement)toastImageAttributes[0]).SetAttribute("src", $"ms-appx:///{assetsImageFileName}");
            ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "logo");

            // 4. 持续时间
            IXmlNode toastNode = toastXml.SelectSingleNode("/toast");

            ((Windows.Data.Xml.Dom.XmlElement)toastNode).SetAttribute("duration", "short");

            // 5. 音频
            XmlElement audio = toastXml.CreateElement("audio");

            audio.SetAttribute("src", $"ms-winsoundevent:Notification.{audioName.ToString().Replace("_", ".")}");
            toastNode.AppendChild(audio);

            // 6. 应用程序启动参数
            //((XmlElement)toastNode).SetAttribute("launch", "{\"type\":\"toast\",\"param1\":\"12345\",\"param2\":\"67890\"}");

            // 7. 发送吐司
            ToastNotification toast = new ToastNotification(toastXml);

            ToastNotificationManager.CreateToastNotifier().Show(toast);
            toast.Activated += SavedPictures;
        }
Esempio n. 3
0
        public MainPage()
        {
            this.InitializeComponent();

            ApplicationView.PreferredLaunchViewSize      = new Size(770, 550);
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;


            //notification
            IToastImageAndText02 weather_notifications = ToastContentFactory.CreateToastImageAndText02();

            weather_notifications.TextHeading.Text  = "Aplikacja pogodowa załadowana poprawnie";
            weather_notifications.TextBodyWrap.Text = "WeatherApp";
            ScheduledToastNotification giveittime;

            giveittime    = new ScheduledToastNotification(weather_notifications.GetXml(), DateTime.Now.AddSeconds(2));
            giveittime.Id = "Any_ID";
            ToastNotificationManager.CreateToastNotifier().AddToSchedule(giveittime);


            //live tiles
            var template = TileContentFactory.CreateTileSquare150x150PeekImageAndText01();

            template.TextBody1.Text = "Aplikacja pogodowa";
            template.Image.Src      = "ms-appx:///Assets/pogoda.png";

            var wideTemlate = TileContentFactory.CreateTileWide310x150PeekImageAndText01();

            wideTemlate.TextBodyWrap.Text    = "Aplikacja pogodowa - szerszy tile";
            wideTemlate.Image.Src            = "ms-appx:///Assets/pogoda.png";
            wideTemlate.Square150x150Content = template;

            TileNotification wideNotification = wideTemlate.CreateNotification();
            TileUpdater      updater          = TileUpdateManager.CreateTileUpdaterForApplication();

            updater.Update(wideNotification);
        }
Esempio n. 4
0
        /*********************************************************************************************************/

        private void MakingToastNotification(string ToastTitle, string ToastBody, string strTag,
                                             string strGroup, bool IsToastPopUpRequired)
        {
            // Using the ToastText02 toast template.This template contains a maximum of two text elements. The first text element is treated as a header text and is always bold.
            ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;

            // Retrieve the content part of the toast so we can change the text.
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

            //Find the text component of the content
            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");

            // Set the text on the toast.
            // The first line of text in the ToastText02 template is treated as header text, and will be bold.
            toastTextElements[0].AppendChild(toastXml.CreateTextNode(ToastTitle));                                                  //Toast notification title
            toastTextElements[1].AppendChild(toastXml.CreateTextNode(ToastBody + " (Tag:" + strTag + ", Group:" + strGroup + ")")); //Toast notification body

            // Set the duration on the toast
            IXmlNode toastNode = toastXml.SelectSingleNode("/toast");

            ((XmlElement)toastNode).SetAttribute("duration", "long");
            ToastNotification toast = new ToastNotification(toastXml);

            toast.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(10);

            //Check Toast popup required to display
            if (!IsToastPopUpRequired)
            {
                toast.SuppressPopup = true;//to send notification directly to action center without displaying a popup on phone.
            }

            //Note: Tag & Group properties are optional,but these are userful for delete/update particular notification from app
            toast.Tag   = strTag;
            toast.Group = strGroup;

            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
        private void SampleToastClick(object sender, RoutedEventArgs e)
        {
            try
            {
                var title      = "Unearthed Arcana: Subclasses, Part 3";
                var message    = "Three new subclasses for you to playtest: the Armorer for the artificer, the Circle of the Stars for the druid, and the Fey Wanderer for the ranger.";
                var message2   = "Aurora";
                var productUrl = "https://aurorabuilder.com/wp-content/uploads/2019/07/unearthed-arcana-banner-1024x267.jpg";

                string timeString = $"{DateTime.Now:HH:mm:ss}";
                string image      = productUrl; //Package.Current.Logo.ToString();//"https://avatars3.githubusercontent.com/u/34661065?s=200&v=4";



                string toastXmlString =
                    $@"<toast launch='action=toastAction&amp;id=1&amp;id2=2'><visual>
                               <binding template='ToastGeneric'>
                            <text>{title}</text>
                            <text>{message}</text>
                            <text placement='attribution'>{message2}</text>
                            <image src='{productUrl}' placement='hero'/>                        
                        </binding>
                       </visual></toast>";

                var xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(toastXmlString);

                var toastNotification = new ToastNotification(xmlDoc);

                var toastNotifier = ToastNotificationManager.CreateToastNotifier();
                toastNotifier.Show(toastNotification);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Esempio n. 6
0
        void ShowToast(DetailPageViewModel detailPageViewModel)
        {
            var data  = detailPageViewModel.Value;
            var image = "https://raw.githubusercontent.com/Windows-XAML/Template10/master/Assets/Template10.png";

            var content = new ToastContent()
            {
                Launch = data,
                Visual = new ToastVisual()
                {
                    TitleText = new ToastText()
                    {
                        Text = "Secondary tile pinned"
                    },

                    BodyTextLine1 = new ToastText()
                    {
                        Text = detailPageViewModel.Value
                    },

                    AppLogoOverride = new ToastAppLogo()
                    {
                        Crop   = ToastImageCrop.Circle,
                        Source = new ToastImageSource(image)
                    }
                },
                Audio = new ToastAudio()
                {
                    Src = new Uri("ms-winsoundevent:Notification.IM")
                }
            };

            var notification = new ToastNotification(content.GetXml());
            var notifier     = ToastNotificationManager.CreateToastNotifier();

            notifier.Show(notification);
        }
Esempio n. 7
0
        private static void ShowMergeCompleteNotification()
        {
            try
            {
                ToastNotificationManager.History.Remove("MergeVideoNotification");

                ToastContent Content = new ToastContent()
                {
                    Scenario = ToastScenario.Default,
                    Launch   = "Transcode",
                    Visual   = new ToastVisual()
                    {
                        BindingGeneric = new ToastBindingGeneric()
                        {
                            Children =
                            {
                                new AdaptiveText()
                                {
                                    Text = Globalization.GetString("Merge_Toast_Complete_Text")
                                },

                                new AdaptiveText()
                                {
                                    Text = Globalization.GetString("Toast_ClickToClear_Text")
                                }
                            }
                        }
                    },
                };

                ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(Content.GetXml()));
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex, "Toast notification could not be sent");
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a reminder at specific time (system reminder on win phone, scheduled notification toast on win 8)
        /// </summary>
        public static void RegisterReminder(string id, string title, string content, DateTime triggerTime)
        {
            if (triggerTime <= DateTime.Now)
            {
                return;                              // Trigger time has passed
            }
            // ensure we respect the user's settings for reminders
            if (!AreRemindersEnabled())
            {
                return;
            }

#if NETFX_CORE
            var notifier         = ToastNotificationManager.CreateToastNotifier();
            var reminders        = notifier.GetScheduledToastNotifications();
            var existingReminder = reminders.FirstOrDefault(n => n.Id == id);
            if (existingReminder != null)
            {
                notifier.RemoveFromSchedule(existingReminder);
            }

            ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText02;
            XmlDocument       toastXml      = ToastNotificationManager.GetTemplateContent(toastTemplate);

            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
            toastTextElements[0].AppendChild(toastXml.CreateTextNode(title));
            toastTextElements[1].AppendChild(toastXml.CreateTextNode(content));

            XmlNodeList toastImageElements = toastXml.GetElementsByTagName("image");

            ((XmlElement)toastImageElements[0]).SetAttribute("src", "ms-appx:///Assets/Logo.png");

            ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, triggerTime);
            scheduledToast.Id = id;
            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);
#endif
        }
Esempio n. 9
0
        // 弹出 toast 通知(设置 toast 的过期时间)
        private void buttonShowToast2_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的之前的全部 toast 通知
            // ToastNotificationManager.History.Clear();

            string toastXml = $@"
                <toast activationType='foreground' launch='Notification-Toast-Basic-Arguments 2'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>toast - title</text>
                            <text>toast - content 2 {DateTime.Now.ToString("mm:ss")}</text>
                        </binding>
                    </visual>
                </toast>";

            XmlDocument toastDoc = new XmlDocument();

            toastDoc.LoadXml(toastXml);

            ToastNotification toast          = new ToastNotification(toastDoc);
            DateTimeOffset    expirationTime = DateTimeOffset.UtcNow.AddSeconds(30);

            toast.ExpirationTime = expirationTime; // 30 秒后 toast 通知将从操作中心中移除

            // 系统会将所用未指定 group 的 toast 视为同 group
            // 系统会将所用未指定 tag 的 toast 视为不同 tag(此时虽然获取 tag 时其为空字符串,但是系统会认为其是一个随机值)
            // 每次弹出此 toast 时都会被认为是一个全新的 toast
            // toast.Tag = "2";

            toast.Activated += Toast_Activated;
            toast.Dismissed += Toast_Dismissed;
            toast.Failed    += Toast_Failed;

            ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();

            toastNotifier.Show(toast);
        }
        void DisplayLongToastWithStringManipulation(bool loopAudio)
        {
            string toastXmlString = String.Empty;

            if (loopAudio)
            {
                toastXmlString = "<toast duration='long'>"
                                 + "<visual version='1'>"
                                 + "<binding template='ToastText02'>"
                                 + "<text id='1'>Long Duration Toast</text>"
                                 + "<text id='2'>Looping audio</text>"
                                 + "</binding>"
                                 + "</visual>"
                                 + "<audio loop='true' src='ms-winsoundevent:Notification.Looping.Alarm'/>"
                                 + "</toast>";
            }
            else
            {
                toastXmlString = "<toast duration='long'>"
                                 + "<visual version='1'>"
                                 + "<binding template='ToastText02'>"
                                 + "<text id='1'>Long Toast</text>"
                                 + "</binding>"
                                 + "</visual>"
                                 + "<audio loop='true' src='ms-winsoundevent:Notification.IM'/>"
                                 + "</toast>";
            }

            Windows.Data.Xml.Dom.XmlDocument toastDOM = new Windows.Data.Xml.Dom.XmlDocument();
            toastDOM.LoadXml(toastXmlString);

            // Create a toast, then create a ToastNotifier object to show
            // the toast
            scenario6Toast = new ToastNotification(toastDOM);
            ToastNotificationManager.CreateToastNotifier().Show(scenario6Toast);
            rootPage.NotifyUser(toastDOM.GetXml(), NotifyType.StatusMessage);
        }
Esempio n. 11
0
        public static void ToastNotifications(string artists, string tracks)
        {
            artists = artists.Replace("&", "and");
            tracks  = tracks.Replace("&", "and");
            string toastXmlString = "<toast>"
                                    + "<visual version='2'>"
                                    + "<binding template='ToastImageAndText04'>"
                                    + "<text id='1'>" + "Downloaded: " + tracks + "</text>"
                                    + "<text id='2'>" + "By: " + artists + "</text>"
                                    + "</binding>"
                                    + "</visual>"
                                    + "</toast>";

            Windows.Data.Xml.Dom.XmlDocument toastDOM = new Windows.Data.Xml.Dom.XmlDocument();
            toastDOM.LoadXml(toastXmlString);

            // Create a toast, then create a ToastNotifier object to show
            // the toast
            try
            {
                ToastNotification toast = new ToastNotification(toastDOM);
                ToastNotificationManager.CreateToastNotifier().Show(toast);
            }
            catch (Exception)
            {
                toastXmlString = "<toast>"
                                 + "<visual version='2'>"
                                 + "<binding template='ToastImageAndText04'>"
                                 + "<text id='1'>" + "Downloaded: " + tracks + "</text>"
                                 + "<text id='2'>" + "By: " + artists + "</text>"
                                 + "</binding>"
                                 + "</visual>"
                                 + "</toast>";
                ToastNotification toast = new ToastNotification(toastDOM);
                ToastNotificationManager.CreateToastNotifier().Show(toast);
            }
        }
Esempio n. 12
0
        private void ShowToastNotification()
        {
            var notificationManager = ToastNotificationManager.GetDefault();
            var toastContent        = new ToastContent
            {
                Visual = new ToastVisual
                {
                    BindingGeneric = new ToastBindingGeneric
                    {
                        Children =
                        {
                            new AdaptiveText
                            {
                                Text = _input.Text ?? "Hest er best på fest"
                            }
                        }
                    }
                },
                Actions = new ToastActionsCustom
                {
                    Buttons =
                    {
                        new ToastButton("Ingen protest!", "action=NoProtest")
                        {
                            ActivationType = ToastActivationType.Foreground
                        }
                    }
                }
            };

            var doc = new Windows.Data.Xml.Dom.XmlDocument();

            doc.LoadXml(toastContent.GetContent());
            var toast = new ToastNotification(doc);

            notificationManager.CreateToastNotifier().Show(toast);
        }
Esempio n. 13
0
        private void Button_Test_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            System.Diagnostics.Process pro = System.Diagnostics.Process.GetCurrentProcess();

            Debug.WriteLine(pro.Id.ToString() + " / " + pro.ProcessName + " / " + pro.ToString());

            // Get a toast XML template
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);

            Debug.WriteLine(toastXml.GetXml());

            // Fill in the text elements
            XmlNodeList stringElements = toastXml.GetElementsByTagName("text");

            for (int i = 0; i < stringElements.Length; i++)
            {
                stringElements[i].AppendChild(toastXml.CreateTextNode("Line " + i));
            }

            // Specify the absolute path to an image
            String imagePath = "file:///" + Path.GetFullPath("./Resources/Wopal_Beach.png");
            //String imagePath = "ms-appx:///Wopal_Beach.png";
            XmlNodeList imageElements = toastXml.GetElementsByTagName("image");

            imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath;

            Debug.WriteLine(imagePath);
            // Create the toast and attach event listeners
            ToastNotification toast = new ToastNotification(toastXml);

            toast.Activated += ToastActivated;
            toast.Dismissed += ToastDismissed;
            toast.Failed    += ToastFailed;

            // Show the toast. Be sure to specify the AppUserModelId on your application's shortcut!
            ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);
        }
Esempio n. 14
0
        /// <summary>
        /// Show toast alert notification with a warning icon.
        /// </summary>
        /// <param name="title">Title to show in the notification.</param>
        /// <param name="text">Text to show in the notification.</param>
        public static void ShowAlertNotification(string title, string text)
        {
            var visual = new ToastVisual
            {
                BindingGeneric = new ToastBindingGeneric
                {
                    Children =
                    {
                        new AdaptiveText {
                            Text = title
                        },
                        new AdaptiveText {
                            Text = text
                        }
                    },

                    AppLogoOverride = new ToastGenericAppLogo
                    {
                        Source   = WarningUri,
                        HintCrop = ToastGenericAppLogoCrop.Circle
                    }
                }
            };

            var toastContent = new ToastContent
            {
                Visual = visual,
                Audio  = new ToastAudio()
                {
                    Silent = false
                },
            };

            var toast = new ToastNotification(toastContent.GetXml());

            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            handler = new ConsoleEventDelegate(ConsoleEventCallback);
            SetConsoleCtrlHandler(handler, true);

            var appId         = "Felix.Lol.Test";
            var toastTemplate = @"
            <toast launch=""developer-defined-string"">
                <visual>
                <binding template=""ToastGeneric"">
                    <text>Andrew B.</text>
                    <text>Shall we meet up at 8?</text>
                    <image placement=""appLogoOverride"" src=""https://unsplash.it/64?image=883"" hint-crop=""circle"" />
                </binding>
                </visual>
                <actions>
                <input id=""message"" type=""text"" placeHolderContent=""Type a reply"" />
                <action activationType=""background"" content=""Reply"" arguments=""reply"" />
                <action activationType=""foreground"" content=""Video call"" arguments=""video"" />
                </actions>
            </toast>";

            CRegisterForNotificationSupport();
            CRegisterActivator();

            XmlDocument toastXml = new XmlDocument();

            toastXml.LoadXml(toastTemplate);

            ToastNotification toast = new ToastNotification(toastXml);

            ToastNotificationManager.CreateToastNotifier(appId).Show(toast);


            Console.WriteLine("Waiting...");
            var name = Console.ReadLine();
        }
Esempio n. 16
0
        // 弹出 toast 通知
        private void buttonShowToast1_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的之前的全部 toast 通知
            // ToastNotificationManager.History.Clear();

            // 用于描述 toast 通知的 xml 字符串
            string toastXml = $@"
                <toast activationType='foreground' launch='Notification-Toast-Basic-Arguments 1'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>toast - title</text>
                            <text>toast - content 1 {DateTime.Now.ToString("mm:ss")}</text>
                        </binding>
                    </visual>
                </toast>";

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

            toastDoc.LoadXml(toastXml);

            // 实例化 ToastNotification 对象
            ToastNotification toast = new ToastNotification(toastDoc);

            // 系统会将所用未指定 group 的 toast 视为同 group
            // 同 group 且同 tag 则视为同一 toast,即新 toast 会更新旧 toast
            toast.Tag = "1";

            toast.Activated += Toast_Activated;
            toast.Dismissed += Toast_Dismissed;
            toast.Failed    += Toast_Failed;

            // 弹出 toast 通知
            ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();

            toastNotifier.Show(toast);
        }
Esempio n. 17
0
        public static void ScheduleToast(string updateString, int eventID, DateTime dueTime, bool RepeatToast = false)
        {
            if (dueTime < DateTime.Now)
            {
                return;
            }
            //Random rand = new Random();
            //int idNumber = rand.Next(0, 10000000);
            // Scheduled toasts use the same toast templates as all other kinds of toasts.
            //ToastContent toastContent = To
            IToastText02 toastContent = ToastContentFactory.CreateToastText02();

            toastContent.TextHeading.Text = updateString;
            //toastContent.TextBodyWrap.Text = "Received: " + dueTime.ToLocalTime();

            ScheduledToastNotification toast;

            //Этот код нужен если отложить напоминайку
            if (RepeatToast == true)
            {
                toast = new ScheduledToastNotification(toastContent.GetXml(), dueTime, TimeSpan.FromSeconds(60), 5);

                // You can specify an ID so that you can manage toasts later.
                // Make sure the ID is 15 characters or less.
                //toast.Id = "Repeat" + eventID;
            }
            else
            {
                toast = new ScheduledToastNotification(toastContent.GetXml(), dueTime);
            }
            toast.Id = eventID.ToString();
            //Everyday.listNotrfications.Add(toast.Id);
            ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();

            notifier.AddToSchedule(toast);
            //NotifyUser("Event scheduled on " + dueTime + ", a toast with ID: " + toast.Id, NotifyType.StatusMessage);
        }
Esempio n. 18
0
        static void Main(string[] args)
        {
            string content, title;

            if (args.Length == 2)
            {
                title   = args[0];
                content = args[1];
            }
            else
            {
                Console.Write("\nPlease enter the content for you notification: ");
                content = Console.ReadLine();
                Console.Write("Please enter the title for your notification: ");
                title = Console.ReadLine();
            }

            Console.Write("\nSending notification...");

            ToastNotifier notifier   = ToastNotificationManager.CreateToastNotifier();
            XmlDocument   toastXDoc  = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
            XmlNodeList   toastNodes = toastXDoc.GetElementsByTagName("text");

            toastNodes.Item(0).AppendChild(toastXDoc.CreateTextNode(title));
            toastNodes.Item(1).AppendChild(toastXDoc.CreateTextNode(content));
            IXmlNode   toastNode = toastXDoc.SelectSingleNode("/toast");
            XmlElement audioElem = toastXDoc.CreateElement("audio");

            audioElem.SetAttribute("src", "ms-winsoundevent:Notification.Reminder");

            ToastNotification toast = new ToastNotification(toastXDoc);

            notifier.Show(toast);

            Console.WriteLine("Notification sent!");
            Console.ReadKey();
        }
Esempio n. 19
0
        private void ShowToast(ITracer tracer, NamedPipeMessages.Notification.Request request)
        {
            ToastData toastData = new ToastData();

            toastData.Visual = new VisualData();

            BindingData binding = new BindingData();

            toastData.Visual.Binding = binding;

            binding.Template = "ToastGeneric";
            binding.Items    = new XmlList <BindingItem>();
            binding.Items.Add(new BindingItem.TextData(request.Title));
            binding.Items.AddRange(request.Message.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Select(t => new BindingItem.TextData(t)));

            XmlDocument toastXml = new XmlDocument();

            using (StringWriter stringWriter = new StringWriter())
                using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings {
                    OmitXmlDeclaration = true
                }))
                {
                    XmlSerializer           serializer = new XmlSerializer(toastData.GetType());
                    XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
                    namespaces.Add(string.Empty, string.Empty);

                    serializer.Serialize(xmlWriter, toastData, namespaces);

                    toastXml.LoadXml(stringWriter.ToString());
                }

            ToastNotification toastNotification = new ToastNotification(toastXml);

            ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(ServiceAppId);

            toastNotifier.Show(toastNotification);
        }
Esempio n. 20
0
        private void OnSoundToast(object sender, RoutedEventArgs e)
        {
            XmlDocument toast_xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
            var         text_node = toast_xml.DocumentElement.GetElementsByTagName("text").FirstOrDefault() as XmlElement;

            text_node.AppendChild(toast_xml.CreateTextNode("custom sound notification"));


            //add a custom audio sound to the notification (in this case it is the new mail sound)

            /**
             * it can also be:
             * ms-winsoundevent:Notification.Default
             * ms-winsoundevent:Notification.SMS
             * ms-winsoundevent:Notification.IM
             * ms-winsoundevent:Notification.Reminder
             * Silent
             *
             * */
            var audio_node = toast_xml.CreateElement("audio");

            audio_node.SetAttribute("src", "ms-winsoundevent:Notification.IM");
            audio_node.SetAttribute("loop", "true");
            IXmlNode toastNode = toast_xml.SelectSingleNode("/toast");

            toastNode.AppendChild(audio_node);

            var v = toast_xml.GetXml();

            if (v != null)
            {
            }
            ToastNotification toast = new ToastNotification(toast_xml);
            var notifier            = ToastNotificationManager.CreateToastNotifier();

            notifier.Show(toast);
        }
        public void ShowToast(INotification notification)
        {
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);

            // Fill in the text elements
            XmlNodeList stringElements = toastXml.GetElementsByTagName("text");

            stringElements[0].AppendChild(toastXml.CreateTextNode(notification.Type));
            var dt = DateUtil.FromUnixTime(notification.Date);

            stringElements[1].AppendChild(toastXml.CreateTextNode(dt.ToLongDateString()));

            //for (int i = 0; i < stringElements.Length; i++)
            //{
            //	stringElements[i].AppendChild(toastXml.CreateTextNode("Line " + i));
            //}

            // Specify the absolute path to an image
            String      imagePath     = "file:///" + Environment.CurrentDirectory + @"\Resources\Images\so-icon.png";
            XmlNodeList imageElements = toastXml.GetElementsByTagName("image");

            imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath;

            string paramString = notification.Link;

            ((XmlElement)toastXml.SelectSingleNode("/toast")).SetAttribute("launch", paramString);

            // Create the toast and attach event listeners
            ToastNotification toast = new ToastNotification(toastXml);

            toast.Activated += ToastActivated;
            toast.Dismissed += ToastDismissed;
            toast.Failed    += ToastFailed;

            // Show the toast. Be sure to specify the AppUserModelId on your application's shortcut!
            ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);
        }
Esempio n. 22
0
        public static void AddToastNotification(TaskModel task)
        {
            if (task.Notification < DateTime.Now)
            {
                return;
            }
            string      source   = $@"
<toast launch='action=viewtasks'>
    <visual>
        <binding template='ToastGeneric'>
            <text>{task.Subject}</text>
            <text>{task.Description}</text>
        </binding>  
    </visual>

    <actions>
        <action
            content='Done'
            arguments='action=done&amp;task={task.Id}'
            activationType='background'/>

        <action
            content='Remind me later'
            arguments='action=remindlater&amp;task={task.Id}'
            activationType='background'/>
    </actions>
</toast>";
            XmlDocument xmlToast = new XmlDocument();

            xmlToast.LoadXml(source);
            ScheduledToastNotification toast = new ScheduledToastNotification(xmlToast, task.Notification, TimeSpan.FromMinutes(60), 5); //TODO odhalit

            toast.Tag   = task.Id.ToString();
            toast.Group = task.Id.ToString();
            toast.Id    = task.Id.ToString();
            ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
        }
Esempio n. 23
0
        public NewToastNotification(string title, string content, int type)
        {
            ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01;
            XmlDocument       toastXml      = ToastNotificationManager.GetTemplateContent(toastTemplate);

            var uri = @"https://docs.microsoft.com/en-us/dotnet/standard/data/xml/reading-an-xml-document-into-the-dom";

            XmlNodeList bindingAttributes = toastXml.GetElementsByTagName("binding");

            ((XmlElement)bindingAttributes[0]).SetAttribute("baseUri", uri);

            XmlNodeList visualAttributes = toastXml.GetElementsByTagName("visual");

            ((XmlElement)visualAttributes[0]).SetAttribute("baseUri", uri);

            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");

            toastTextElements[0].AppendChild(toastXml.CreateTextNode($"{content}"));

            XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image");

            ((XmlElement)toastImageAttributes[0]).SetAttribute("src", "C:\\Users\\IsaoTakashi\\Desktop\\desktop-toasts-master\\CS\\DesktopToastsApp\\Images\\883-364x202.jpg");
            ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "red graphic");

            IXmlNode toastNode = toastXml.SelectSingleNode("/toast");

            ((XmlElement)toastNode).SetAttribute("duration", "long");
            ((XmlElement)toastNode).SetAttribute("launch", "{\"type\":\"toast\",\"param1\":\"12345\",\"param2\":\"67890\"}");

            ToastNotification toast = new ToastNotification(toastXml);

            toast.Activated += Toast_Activated;
            //toast.Failed += Toast_Failed;
            //toast.Dismissed += Toast_Dismissed;

            ToastNotificationManager.CreateToastNotifier($"{title}").Show(toast);
        }
Esempio n. 24
0
        // 弹出 toast 通知(点击 toast 框或点击 toast 中的按钮则可激活后台任务)
        private void buttonShowToast_Click(object sender, RoutedEventArgs e)
        {
            string toastXml = @"
                <toast activationType='background' launch='launch arguments'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>toast - title</text>
                            <text>toast - content</text>
                        </binding>
                    </visual>
                    <actions>
                        <input type='text' id='message1' title='title1' />
                        <action content='确认' activationType='background' arguments='action arguments'/>
                    </actions>
                </toast>";

            XmlDocument toastDoc = new XmlDocument();

            toastDoc.LoadXml(toastXml);

            ToastNotification toast = new ToastNotification(toastDoc);

            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
Esempio n. 25
0
        public static void SendToast(string message)
        {
            var xmlToastTemplate = "<toast launch=\"app-defined-string\">" +
                                   "<visual>" +
                                   "<binding template =\"ToastGeneric\">" +
                                   "<text>Sample Notification</text>" +
                                   "<text>" +
                                   message +
                                   "</text>" +
                                   "</binding>" +
                                   "</visual>" +
                                   "</toast>";

            // load the template as XML document
            var xmlDocument = new Windows.Data.Xml.Dom.XmlDocument();

            xmlDocument.LoadXml(xmlToastTemplate);

            // create the toast notification and show to user
            var toastNotification = new ToastNotification(xmlDocument);
            var notification      = ToastNotificationManager.CreateToastNotifier();

            notification.Show(toastNotification);
        }
Esempio n. 26
0
        public static ToastNotification PopCustomToast(XmlDocument doc, string tag, string group)
        {
            var toast = new ToastNotification(doc);

            if (tag != null)
            {
                toast.Tag = tag;
            }

            if (group != null)
            {
                toast.Group = group;
            }

            // edetoc : see https://docs.microsoft.com/en-gb/uwp/api/windows.ui.notifications.toastnotificationpriority
            // High :: The notification should be treated as high priority. For desktop PCs, this means during connected standby mode the incoming notification can turn on the screen for Surface-like devices if it doesn’t have a closed lid detected.
            // The priority setting provides hints on how and at what urgency level a notification should be presented to the user (whether to wake up the screen, etc). Whether the notification is displayed in high priority is based on the state and power management policy of the device.

            toast.Priority = ToastNotificationPriority.High;

            ToastNotificationManager.CreateToastNotifier().Show(toast);

            return(toast);
        }
Esempio n. 27
0
        // Remove the notification by checking the list of scheduled notifications for a notification with matching ID.
        // While it would be possible to manage the notifications by storing a reference to each notification, such practice
        // causes memory leaks by not allowing the notifications to be collected once they have shown.
        // It's important to create unique IDs for each notification if they are to be managed later.
        void Remove_Click(object sender, RoutedEventArgs e)
        {
            IList <Object> items = ItemGridView.SelectedItems;

            for (int i = 0; i < items.Count; i++)
            {
                NotificationData item   = (NotificationData)items[i];
                String           itemId = item.ItemId;
                if (item.IsTile)
                {
                    TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication();
                    IReadOnlyList <ScheduledTileNotification> scheduled = updater.GetScheduledTileNotifications();
                    for (int j = 0; j < scheduled.Count; j++)
                    {
                        if (scheduled[j].Id == itemId)
                        {
                            updater.RemoveFromSchedule(scheduled[j]);
                        }
                    }
                }
                else
                {
                    ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();
                    IReadOnlyList <ScheduledToastNotification> scheduled = notifier.GetScheduledToastNotifications();
                    for (int j = 0; j < scheduled.Count; j++)
                    {
                        if (scheduled[j].Id == itemId)
                        {
                            notifier.RemoveFromSchedule(scheduled[j]);
                        }
                    }
                }
            }
            rootPage.NotifyUser("Removed selected scheduled notifications", NotifyType.StatusMessage);
            RefreshListView();
        }
Esempio n. 28
0
        private static void ShowToast(Notification notification)
        {
            try
            {
                var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText02);

                var stringElements = toastXml.GetElementsByTagName("text");
                stringElements[0].AppendChild(toastXml.CreateTextNode(notification.Header));
                stringElements[1].AppendChild(toastXml.CreateTextNode(notification.Content));

                var imagePath = "file:///" + Path.GetFullPath("Resources/Images/elite-dangerous-clean.png");

                var imageElements = toastXml.GetElementsByTagName("image");
                imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath;

                var toast = new ToastNotification(toastXml);
                var id    = Assembly.GetExecutingAssembly().GetType().GUID.ToString();
                ToastNotificationManager.CreateToastNotifier(id).Show(toast);
            }
            catch (Exception)
            {
                // silently fail for platforms not supporting toasts
            }
        }
Esempio n. 29
0
        private static void ShowTextToast(string appId, string title, string message)
        {
            var toastXml = ToastNotificationManager.GetTemplateContent(
                ToastTemplateType.ToastText02);

            // Fill in the text elements
            var stringElements = toastXml.GetElementsByTagName("text");

            stringElements[0].AppendChild(toastXml.CreateTextNode(title));
            stringElements[1].AppendChild(toastXml.CreateTextNode(message));

            // Create the toast and attach event listeners
            var toast = new ToastNotification(toastXml);

            var events = new ToastEvents();

            toast.Activated += events.ToastActivated;
            toast.Dismissed += events.ToastDismissed;
            toast.Failed    += events.ToastFailed;

            // Show the toast. Be sure to specify the AppUserModelId
            // on your application's shortcut!
            ToastNotificationManager.CreateToastNotifier(appId).Show(toast);
        }
        // Create and show the toast.
        // See the "Toasts" sample for more detail on what can be done with toasts
        public void ShowToast()
        {
            // Get a toast XML template
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);

            // Fill in the text elements
            XmlNodeList stringElements = toastXml.GetElementsByTagName("text");

            stringElements[1].AppendChild(toastXml.CreateTextNode("Hey, I found something!"));

            // Specify the absolute path to an image
            String      imagePath     = "file:///" + Path.GetFullPath("ToastIcon.png");
            XmlNodeList imageElements = toastXml.GetElementsByTagName("image");

            imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath;

            // Create the toast and attach event listeners
            ToastNotification toast = new ToastNotification(toastXml);

            toast.Activated += ToastActivated;

            // Show the toast. Be sure to specify the AppUserModelId on your application's shortcut!
            ToastNotificationManager.CreateToastNotifier("Click to Open").Show(toast);
        }