public static void CreateDefferedToast() { // Construct the visuals of the toast (using Notifications library) ToastContent toastContent = new ToastContent() { // Arguments when the user taps body of toast Launch = "action=viewConversation&conversationId=5", Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Hello world!" } } } } }; // Create the XML document (BE SURE TO REFERENCE WINDOWS.DATA.XML.DOM) var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); // And create the toast notification var toast = new ScheduledToastNotification(toastContent.GetXml(), DateTime.Now.AddSeconds(10)); // And then show it DesktopNotificationManagerCompat.CreateToastNotifier().AddToSchedule(toast); }
public void CreateAndShowMessage(string message) { ToastContent toastContent = new ToastContent() { Launch = "bodyTapped", Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = message }, } } }, Header = new ToastHeader("header", "NetStalker", "header") }; var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); var messageNotification = new ToastNotification(doc); DesktopNotificationManagerCompat.CreateToastNotifier().Show(messageNotification); }
public void notify(string title, string description) { // Construct the visuals of the toast (using Notifications library) ToastContent toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title }, new AdaptiveText() { Text = description } } } } }; var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); var toast = new ToastNotification(doc); DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
private void Toast(ToastContent toastContent, string identifier, bool handleActivated) { var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); var toast = new ToastNotification(doc); if (!string.IsNullOrWhiteSpace(identifier)) { toast.Tag = identifier; toast.SuppressPopup = ShouldSuppressPopup(toast); } if (handleActivated) { toast.Activated += Toast_Activated; } ToastNotifier notifier; if (Utils.IsRunningAsUWP) { notifier = ToastNotificationManager.CreateToastNotifier(); } else { notifier = ToastNotificationManager.CreateToastNotifier(AumID); } notifier.Show(toast); }
public void DisplayWin10Message(string message) { var binding = new ToastBindingGeneric(); binding.Children.Add(new AdaptiveText { Text = message, HintWrap = true }); var content = new ToastContent { Launch = "", Visual = new ToastVisual { BindingGeneric = binding } }; var xml = content.GetContent(); var doc = new XmlDocument(); doc.LoadXml(xml); var n = ToastNotificationManager.CreateToastNotifier(Constants.ApplicationId); n.Show(new ToastNotification(doc)); }
private async Task showToast(ToastMessageModel input) => await Task.Factory.StartNew(() => { var visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "File Watcher Notification" }, new AdaptiveText() { Text = input.Message } } } }; var actions = new ToastActionsCustom(); var toastContent = new ToastContent() { Visual = visual, Actions = actions }; var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(toastContent.GetContent()); var toastNotification = new ToastNotification(xmlDoc); ToastNotificationManager.CreateToastNotifier(applicationId).Show(toastNotification); });
public static void SendToast(string text) { // Construct the visuals of the toast (using Notifications library) ToastContent toastContent = new ToastContent() { // Arguments when the user taps body of toast Launch = "action=viewConversation&conversationId=5", Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = text } } } } }; // Create the XML document (BE SURE TO REFERENCE WINDOWS.DATA.XML.DOM) var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); // And create the toast notification var toast = new ToastNotification(doc); // And then show it DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
public ToastNotification BuildToast(string text) { ToastContent toastContent = new ToastContent() { // Arguments when the user taps body of toast Launch = "action=viewConversation&conversationId=5", Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = text } } } } }; // Create the XML document (BE SURE TO REFERENCE WINDOWS.DATA.XML.DOM) var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); // And create the toast notification var toast = new ToastNotification(doc); return(toast); }
private void SendToastNotification() { ToastContent content = new ToastContent() { Launch = "lei", Visual = new ToastVisual() { TitleText = new ToastText() { Text = "Connecting...." }, BodyTextLine1 = new ToastText() { Text = "Sending new command to heater" }, }, }; DataPackage dp = new DataPackage(); dp.SetText(content.GetContent()); ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(content.GetXml())); }
static void ShowModernNotification(string?title, string message, Uri?navigateTo, TimeSpan?duration = null) { var content = new ToastContent { Launch = navigateTo?.ToString(), Header = title == null ? null : new ToastHeader(title, title, navigateTo?.ToString()), Visual = new ToastVisual { BindingGeneric = new ToastBindingGeneric { Children = { new AdaptiveText { Text = message } }, } } }; var contentXml = new XmlDocument(); contentXml.LoadXml(content.GetContent()); var toast = new ToastNotification(contentXml) { // DTO + null == null ExpirationTime = DateTimeOffset.Now + duration, }; try { ToastNotificationManagerCompat.CreateToastNotifier().Show(toast); } catch (Exception e) { WarningsService.Default.ReportAsWarning(e, prefix: $"Notification failed"); } }
private static void SendToastNotification(string text) { ToastContent content = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Fina Reminder", HintMaxLines = 1 }, new AdaptiveText() { Text = text }, }, } }, Duration = ToastDuration.Long }; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(content.GetContent()); var tstVisual = new ToastNotification(xmlDoc); ToastNotificationManager.CreateToastNotifier(APP_ID).Show(tstVisual); }
private static void AssertAdaptiveChildInToast(string expectedAdaptiveChildXml, IAdaptiveChild child) { var binding = new ToastBindingGeneric(); // If the child isn't text, we need to add a text element so notification is valid if (!(child is AdaptiveText)) { binding.Children.Add(new AdaptiveText() { Text = "Required text element" }); expectedAdaptiveChildXml = "<text>Required text element</text>" + expectedAdaptiveChildXml; } binding.Children.Add(child); var content = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = binding } }; AssertHelper.AssertXml( "<toast><visual><binding template='ToastGeneric'>" + expectedAdaptiveChildXml + "</binding></visual></toast>", content.GetContent()); }
public string GetOfficialReplyToast(Channel channel, Feedback feedback, Comment comment) { ToastContent content = new ToastContent() { Launch = "app-defined-string", Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = $"Phản hồi từ {channel.Name}", HintMaxLines = 1 }, new AdaptiveText() { Text = feedback.Content, }, new AdaptiveText() { Text = comment.Content, }, }, Attribution = new ToastGenericAttributionText() { Text = "qua Complainer" }, } }, }; return(content.GetContent()); }
private string ComposeInteractiveToast() { var toastVisual = new ToastVisual { BindingGeneric = new ToastBindingGeneric { Children = { new AdaptiveText { Text = "Lucy" }, // Title new AdaptiveText { Text = "이전에 로그인을 시도했던 사람이 있어요." }, // Body } } }; var toastContent = new ToastContent { Visual = toastVisual, Duration = ToastDuration.Long }; return(toastContent.GetContent()); }
private void ShowToast(string msg) { // Construct the visuals of the toast ToastContent toastContent = new ToastContent() { // Arguments when the user taps body of toast Launch = "action=ok", Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = msg } } } } }; var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); // And create the toast notification var toast = new ToastNotification(doc); // And then show it DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
static void Main() { ToastVisual visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Give your eyes a break" }, new AdaptiveProgressBar() { Title = "Focus on something 20 feet away", Value = new BindableProgressBarValue("progressValue"), ValueStringOverride = new BindableString("progressValueString"), Status = "Keep looking" } } } }; ToastContent content = new ToastContent() { Visual = visual }; XmlDocument document = new XmlDocument(); document.LoadXml(content.GetContent()); while (true) { Thread.Sleep(20 * 60 * 1000); ToastNotification toast = new ToastNotification(document); toast.Tag = "refocus"; toast.Data = new NotificationData(); toast.Data.Values["progressValue"] = "0"; toast.Data.Values["progressValueString"] = "0/20 seconds"; ToastNotificationManager.CreateToastNotifier().Show(toast); for (uint seconds = 0; seconds <= 20; seconds++) { var data = new NotificationData { SequenceNumber = seconds }; data.Values["progressValue"] = (seconds / 20f).ToString(); data.Values["progressValueString"] = $"{seconds}/20 seconds"; if (ToastNotificationManager.CreateToastNotifier().Update(data, "refocus") != NotificationUpdateResult.Succeeded) { break; } Thread.Sleep(1000); } ToastNotificationManager.History.Remove("refocus"); } }
private void SendToastNotification() { ToastContent content = new ToastContent() { Launch = "lei", Visual = new ToastVisual() { TitleText = new ToastText() { Text = "New message from Lei" }, BodyTextLine1 = new ToastText() { Text = "NotificationsExtensions is great!" }, AppLogoOverride = new ToastAppLogo() { Crop = ToastImageCrop.Circle, Source = new ToastImageSource("http://messageme.com/lei/profile.jpg") } }, Actions = new ToastActionsCustom() { Inputs = { new ToastTextBox("tbReply") { PlaceholderContent = "Type a response" } }, Buttons = { new ToastButton("reply", "reply") { ActivationType = ToastActivationType.Background, ImageUri = "Assets/QuickReply.png", TextBoxId = "tbReply" } } }, Audio = new ToastAudio() { Src = new Uri("ms-winsoundevent:Notification.IM") } }; DataPackage dp = new DataPackage(); dp.SetText(content.GetContent()); Clipboard.SetContent(dp); ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(content.GetXml())); }
private XmlDocument GetXml(ToastContent toastContent) { XmlDocument doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); return(doc); }
//public static void AssertXml(string expected, string actual) //{ // XmlDocument expectedDoc = new XmlDocument(); // expectedDoc.LoadXml(expected); // XmlDocument actualDoc = new XmlDocument(); // actualDoc.LoadXml(actual); // AssertXmlElement(expectedDoc.DocumentElement, actualDoc.DocumentElement); //} //private static void AssertXmlElement(XmlElement expected, XmlElement actual) //{ // // If both null, good, done // if (expected == null && actual == null) // return; // // If one is null and other isn't, bad // if (expected == null) // Assert.Fail("Expected XML element was null, while actual was initialized"); // if (actual == null) // Assert.Fail("Actual XML element was null, while expected was initialized"); // // If name doesn't match // Assert.AreEqual(expected.Name, actual.Name, "Element names did not match."); // // If attribute count doesn't match // Assert.AreEqual(expected.Attributes.Count, actual.Attributes.Count, "Element attributes counts didn't match"); // // Make sure attributes match (order does NOT matter) // foreach (XmlAttribute expectedAttr in expected.Attributes) // { // var actualAttr = actual.Attributes.GetNamedItem(expectedAttr.Name); // // If didn't find the attribute // if (actualAttr == null) // Assert.Fail("Expected element to have attribute " + expectedAttr.Name + " but it didn't."); // // Make sure value matches // Assert.AreEqual(expectedAttr.Value, actualAttr.Value, $@"Attribute values for ""{expectedAttr.Name}"" didn't match."); // } // // Make sure children elements match (order DOES matter) // // Obtain the child elements (ignore any comments, w // XmlElement[] expectedChildren = expected.ChildNodes.OfType<XmlElement>().ToArray(); // XmlElement[] actualChildren = actual.ChildNodes.OfType<XmlElement>().ToArray(); // Assert.AreEqual(expectedChildren.Length, actualChildren.Length, "Number of child elements did not match."); // // If no elements, compare inner text // if (expectedChildren.Length == 0) // { // Assert.AreEqual(expected.InnerText, actual.InnerText, "Inner text did not match."); // } // // Otherwise compare elements // else // { // for (int i = 0; i < expectedChildren.Length; i++) // { // AssertXmlElement(expectedChildren[i], actualChildren[i]); // } // } //} public static void AssertToast(string expected, ToastContent toast) { AssertHelper.AssertXml(expected, toast.GetContent()); #if WINDOWS_UWP // For WinRT, we'll test the XmlDocument method too, make sure it works. AssertHelper.AssertXml(expected, toast.GetXml().GetXml()); #endif }
public void ShowToastNotificationSample() { // Create the toast content var content = new ToastContent() { // More about the Launch property at https://docs.microsoft.com/dotnet/api/microsoft.toolkit.uwp.notifications.toastcontent Launch = "ToastContentActivationParams", Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Sample Toast Notification" }, new AdaptiveText() { Text = @"Click OK to see how activation from a toast notification can be handled in the ToastNotificationService." } } } }, Actions = new ToastActionsCustom() { Buttons = { // More about Toast Buttons at https://docs.microsoft.com/dotnet/api/microsoft.toolkit.uwp.notifications.toastbutton new ToastButton("OK", "ToastButtonActivationArguments") { ActivationType = ToastActivationType.Foreground }, new ToastButtonDismiss("Cancel") } } }; // Add the content to the toast var doc = new XmlDocument(); doc.LoadXml(content.GetContent()); var toast = new ToastNotification(doc) { // TODO WTS: Set a unique identifier for this notification within the notification group. (optional) // More details at https://docs.microsoft.com/uwp/api/windows.ui.notifications.toastnotification.tag Tag = "ToastTag" }; // And show the toast ShowToastNotification(toast); }
public static void SendStartupMessage( ToastNotifier notifier, ISMTPImpostorWorkerSettings settings) { var content = new ToastContent { Actions = new ToastActionsCustom { Buttons = { new ToastButtonDismiss(), new ToastButton("Open UI", OPEN_UI_ACTION) } }, Visual = new ToastVisual { BindingGeneric = new ToastBindingGeneric { Children = { new AdaptiveText { Text = "Worker is running" }, new AdaptiveText { Text = settings.StartupMessageLink } } } } }; var doc = new XmlDocument(); doc.LoadXml(content.GetContent()); var notification = new ToastNotification(doc); notification.Tag = START_NOTIFICATION_ID; notification.ExpiresOnReboot = true; notification.ExpirationTime = DateTimeOffset.Now.AddMinutes(1); notification.Activated += async(_, o) => { var args = o as ToastActivatedEventArgs; if (args.Arguments == OPEN_UI_ACTION) { await LaunchLink(settings.StartupMessageLink); } }; notifier.Show(notification); //Schedule(notifier, doc); }
private void ShowToastWithButton_Click(object sender, RoutedEventArgs e) { // Construct the visuals of the toast ToastVisual visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Title" }, new AdaptiveText() { Text = "Desription" } } } }; ToastActionsCustom actions = new ToastActionsCustom() { Buttons = { new ToastButton("Reply", new QueryString() { { "action", "reply" } }.ToString()), new ToastButton("View", new QueryString() { { "action", "viewImage" } }.ToString()) } }; // Now we can construct the final toast content ToastContent toastContent = new ToastContent() { Visual = visual, Actions = actions }; // And create the toast notification XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(toastContent.GetContent()); ToastNotification notification = new ToastNotification(xmlDoc); // And then send the toast ToastNotificationManager.CreateToastNotifier(APP_ID).Show(notification); }
private string ComposeInteractiveToast() { var toastVisual = new ToastVisual { BindingGeneric = new ToastBindingGeneric { Children = { new AdaptiveText { Text = "DesktopToast WPF Sample" }, // Title new AdaptiveText { Text = "This is an interactive toast test." }, // Body }, AppLogoOverride = new ToastGenericAppLogo { Source = string.Format("file:///{0}", Path.GetFullPath("Resources/toast128.png")), AlternateText = "Logo" } } }; var toastAction = new ToastActionsCustom { Inputs = { new ToastTextBox(id: MessageId) { PlaceholderContent = "Input a message" } }, Buttons = { new ToastButton(content: "Reply", arguments: "action=Replied") { ActivationType = ToastActivationType.Background }, new ToastButton(content: "Ignore", arguments: "action=Ignored") } }; var toastContent = new ToastContent { Visual = toastVisual, Actions = toastAction, Duration = ToastDuration.Long, Audio = new NotificationsExtensions.Toasts.ToastAudio { Loop = true, Src = new Uri("ms-winsoundevent:Notification.Looping.Alarm4") } }; return(toastContent.GetContent()); }
public void Toast(string message1, string message2) { if (string.IsNullOrEmpty(message1)) { throw new ArgumentNullException(nameof(message1)); } if (string.IsNullOrEmpty(message2)) { throw new ArgumentNullException(nameof(message2)); } var toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = message1 }, new AdaptiveText() { Text = message2 } } } }, Actions = new ToastActionsCustom() { Buttons = { new ToastButtonDismiss() } }, Scenario = ToastScenario.Alarm, Duration = ToastDuration.Long, Audio = new ToastAudio { Loop = true, Src = new Uri("ms-winsoundevent:Notification.Looping.Alarm4") } }; var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); Show(doc); }
private void ShowNotification(string title, string message, bool retry, bool changePort) { ToastContent toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title }, new AdaptiveText() { Text = message } } } } }; ToastActionsCustom buttons = new ToastActionsCustom(); buttons.Buttons.Add(new ToastButton("Stop", "stop")); if (retry) { buttons.Buttons.Add(new ToastButton("Retry", "retry")); } if (changePort) { buttons.Buttons.Add(new ToastButton("Change Port", "changePort")); ToastSelectionBox portBox = new ToastSelectionBox("portBox"); foreach (var port in SerialPort.GetPortNames()) { portBox.Items.Add(new ToastSelectionBoxItem(port, port)); } buttons.Inputs.Add(portBox); } toastContent.Actions = buttons; var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); var toast = new ToastNotification(doc); DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
private WindowsPushNotification GetNotification(ScoreDiffItem diff) { string title = GetNotificationTitle(diff); string primaryDescription = GetNotificationPrimaryDescription(diff); string secondaryDescription = GetNotificationSecondaryDescription(diff); string emojiUri = GetNotificationEmojiUri(diff); ToastContent toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title, HintStyle = AdaptiveTextStyle.Title }, new AdaptiveText() { Text = primaryDescription, HintMaxLines = 2 }, new AdaptiveText() { Text = secondaryDescription, HintStyle = AdaptiveTextStyle.CaptionSubtle } }, AppLogoOverride = new ToastGenericAppLogo() { Source = emojiUri, } } }, Actions = new ToastActionsCustom() { ContextMenuItems = { new ToastContextMenuItem("ms-resource:ScoreChangedToastNeverShow", "NeverShowScoreChanged") { ActivationType = ToastActivationType.Background } } }, Launch = "ScoreChanged" }; return(new WindowsPushNotification(WindowsNotificationType.Toast, toastContent.GetContent())); }
private void Show(ToastContent content) { try { Debug.WriteLine(content.GetContent()); ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(content.GetXml())); } catch (Exception ex) { var dontWait = new MessageDialog(ex.ToString()).ShowAsync(); } }
/// <summary> /// Send toast notification. /// </summary> /// <param name="toastContent">XML document of the toast notification</param> private static void SendNotification(ToastContent toastContent) { // Make sure to use Windows.Data.Xml.Dom XmlDocument doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); // And create the toast notification ToastNotification toast = new ToastNotification(doc); // And then show it DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
private static string ComposeInteractiveToast(string title, string body, Slot slot) { // なぜか、 image タグが反映されない。 var toastVisual = new ToastVisual { BindingGeneric = new ToastBindingGeneric { Children = { new AdaptiveText { Text = title }, new AdaptiveText { Text = body } } } }; var toastAction = new ToastActionsCustom { Buttons = { new ToastButton(Resources.View, $"action=View&channelId={slot?.Channel.ChannelId}") { ActivationType = ToastActivationType.Background }, new ToastButton(Resources.Ignore, "action=Ignored") } }; var toastContent = new ToastContent { Visual = toastVisual, Actions = toastAction, Duration = ToastDuration.Long }; Debug.WriteLine(toastContent.GetContent()); return(toastContent.GetContent()); }
public string GetActionChangedToast(Channel channel, Feedback feedback, Comment comment) { string action = ""; switch (feedback.Action) { case 0: action = "đang được xem xét"; break; case 1: action = "đã được giải quyết"; break; default: return(null); } ToastContent content = new ToastContent() { Launch = "app-defined-string", Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = $"Phản hồi từ {channel.Name}", HintMaxLines = 1 }, new AdaptiveText() { Text = feedback.Content, }, new AdaptiveText() { Text = $"Phản hồi của bạn {action}", }, }, Attribution = new ToastGenericAttributionText() { Text = "qua Complainer" }, } }, }; return(content.GetContent()); }