Example #1
0
        private void CreateToastButton_Click(object sender, EventArgs e)
        {
            var actionButton = new ToastButton();

            actionButton.AddArgument("action", "buttonAction");
            actionButton.SetContent("Action Button");

            var dismissButton = new ToastButton();

            dismissButton.SetContent("Dismiss Button");
            dismissButton.SetDismissActivation();

            var toast = new ToastContentBuilder();

            toast.AddAttributionText("Attribute Text");
            toast.AddText("Title");
            toast.AddText("Text 1");
            toast.AddText("Text 2");
            toast.AddButton(actionButton);
            toast.AddButton(dismissButton);
            toast.Show(toast =>
            {
                toast.ExpirationTime = DateTime.Now.AddSeconds(5);
                toast.Priority       = Windows.UI.Notifications.ToastNotificationPriority.High;
            });
        }
Example #2
0
        /// <summary>
        /// Show a toast notification by providing the Content, Purpose, and optionally Device IP and MAC (for device blocking handling scenarios).
        /// </summary>
        /// <param name="Content"></param>
        /// <param name="Purpose"></param>
        /// <param name="DeviceId"></param>
        public static void ShowPrompt(string Content, NotificationPurpose Purpose, string DeviceIP = "", string DeviceMAC = "")
        {
            var Toast = new ToastContentBuilder()
                        .AddArgument("Action", Purpose)
                        .AddArgument("DeviceIP", DeviceIP)
                        .AddArgument("DeviceMAC", DeviceMAC)
                        .AddText("NetStalker")
                        .AddText(Content);

            switch (Purpose)
            {
            case NotificationPurpose.NotificationsSuppression:
            {
                Toast.AddButton(new ToastButton()
                                .SetContent("Yes")
                                .AddArgument("Choice", NotificationChoice.Yes))
                .AddButton(new ToastButton()
                           .SetContent("No")
                           .AddArgument("Choice", NotificationChoice.No));

                break;
            }

            case NotificationPurpose.TargetDiscovery:
            {
                Toast.AddButton(new ToastButton()
                                .SetContent("Show")
                                .AddArgument("Choice", NotificationChoice.Show))
                .AddButton(new ToastButton()
                           .SetContent("Block")
                           .AddArgument("Choice", NotificationChoice.Block))
                .AddButton(new ToastButtonDismiss())
                .AddButton(new ToastButton()
                           .SetContent("Suppress Notifications")
                           .AddArgument("Choice", NotificationChoice.Suppress));

                break;
            }

            default:
            {
                Toast = null;
                return;
            }
            }

            Toast.Show();
        }
Example #3
0
        public void AddButtonTest_WithTextBoxId_ReturnSelfWithButtonAdded()
        {
            // Arrange
            string testInputTextBoxId = Guid.NewGuid().ToString();
            string testButtonContent  = "Test Button Content";
            ToastActivationType testToastActivationType = ToastActivationType.Background;
            string testButtonLaunchArgs = "Test Launch Args";
            Uri    testImageUriSrc      = new Uri("C:/justatesturi.jpg");

            ToastContentBuilder builder = new ToastContentBuilder();

            // Act
            ToastContentBuilder anotherReference = builder.AddButton(testInputTextBoxId, testButtonContent, testToastActivationType, testButtonLaunchArgs, testImageUriSrc);

            // Assert
            Assert.AreSame(builder, anotherReference);

            var button = (builder.Content.Actions as ToastActionsCustom).Buttons.First() as ToastButton;

            Assert.AreEqual(testInputTextBoxId, button.TextBoxId);
            Assert.AreEqual(testButtonContent, button.Content);
            Assert.AreEqual(testToastActivationType, button.ActivationType);
            Assert.AreEqual(testButtonLaunchArgs, button.Arguments);
            Assert.AreEqual(testImageUriSrc.OriginalString, button.ImageUri);
        }
Example #4
0
        public void AddArgumentTest_Generic_ReturnSelfWithArgumentsAdded()
        {
            // Arrange
            const string userIdKey   = "userId";
            const int    userIdValue = 542;

            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder
                                                   .AddButton(new ToastButton()
                                                              .SetContent("Accept")
                                                              .AddArgument("action", "accept")
                                                              .SetBackgroundActivation())
                                                   .AddButton(new ToastButtonSnooze())
                                                   .AddButton("View", ToastActivationType.Protocol, "https://msn.com")

                                                   // Add generic arguments halfway through (should be applied to existing buttons and to any subsequent buttons added later)
                                                   .AddArgument(userIdKey, userIdValue)

                                                   .AddButton(new ToastButton()
                                                              .SetContent("Decline")
                                                              .AddArgument("action", "decline")
                                                              .SetBackgroundActivation())
                                                   .AddButton(new ToastButton()
                                                              .SetContent("Report")
                                                              .SetProtocolActivation(new Uri("https://microsoft.com")));

            // Assert
            Assert.AreSame(builder, anotherReference);

            // Top level arguments should be present
            Assert.AreEqual("userId=542", builder.Content.Launch);

            // All foreground/background activation buttons should have received generic arguments. Protocol and system activation buttons shouldn't have had any arguments changed.
            var actions = builder.Content.Actions as ToastActionsCustom;

            var button1 = actions.Buttons[0] as ToastButton;

            Assert.AreEqual("Accept", button1.Content);
            Assert.AreEqual("action=accept;userId=542", button1.Arguments);

            var button2 = actions.Buttons[1];

            Assert.IsInstanceOfType(button2, typeof(ToastButtonSnooze));

            var button3 = actions.Buttons[2] as ToastButton;

            Assert.AreEqual("View", button3.Content);
            Assert.AreEqual("https://msn.com", button3.Arguments);

            var button4 = actions.Buttons[3] as ToastButton;

            Assert.AreEqual("Decline", button4.Content);
            Assert.AreEqual("action=decline;userId=542", button4.Arguments);

            var button5 = actions.Buttons[4] as ToastButton;

            Assert.AreEqual("Report", button5.Content);
            Assert.AreEqual("https://microsoft.com/", button5.Arguments);
        }
Example #5
0
        private static XmlDocument GeneratePayload(AccountDataItem account, ViewItemSchedule s)
        {
            var c = s.Class;

            var builder = new ToastContentBuilder()
                          .AddToastActivationInfo(new ViewClassArguments()
            {
                LocalAccountId = account.LocalAccountId,
                ItemId         = c.Identifier,
                LaunchSurface  = LaunchSurface.Toast
            }.SerializeToString(), ToastActivationType.Foreground)
                          .SetToastScenario(ToastScenario.Reminder)
                          .AddText(c.Name)
                          .AddText(string.Format(_timeToTime, _timeFormatter.Format(s.StartTime), _timeFormatter.Format(s.EndTime)));

            if (!string.IsNullOrWhiteSpace(s.Room))
            {
                builder.AddText(s.Room);
            }

            builder.AddToastInput(new ToastSelectionBox("snoozeTime")
            {
                DefaultSelectionBoxItemId = "5",
                Items =
                {
                    new ToastSelectionBoxItem("5",  PowerPlannerResources.GetXMinutes(5)),
                    new ToastSelectionBoxItem("10", PowerPlannerResources.GetXMinutes(10)),
                    new ToastSelectionBoxItem("15", PowerPlannerResources.GetXMinutes(15)),
                    new ToastSelectionBoxItem("30", PowerPlannerResources.GetXMinutes(30)),
                    new ToastSelectionBoxItem("45", PowerPlannerResources.GetXMinutes(45))
                }
            });

            builder.AddButton(new ToastButtonSnooze()
            {
                SelectionBoxId = "snoozeTime"
            });

            builder.AddButton(new ToastButtonDismiss());

            return(builder.GetToastContent().GetXml());
        }
Example #6
0
        private void OnRafflesWon(object sender, RafflesWonArgs e)
        {
            bool enableToast = Properties.UserConfig.Default.ToastNotifications;

            if (enableToast)
            {
                string logo = Files.LogoFile;
                if (!File.Exists(logo))
                {
                    using (var http = new HttpClient())
                    {
                        string url  = string.Format("https://scrap.tf/apple-touch-icon.png?{0}", Guid.NewGuid());
                        byte[] data = http.GetByteArrayAsync(url).Result;
                        File.WriteAllBytes(logo, data);
                    }
                }

                string message    = e.Message;
                var    viewButton = new ToastButton();
                viewButton.AddArgument("action", "viewRafflesWonPage");
                viewButton.SetContent("View Won Raffles");

                var dismissButton = new ToastButton();
                dismissButton.SetContent("Dismiss");
                dismissButton.SetDismissActivation();

                var toast = new ToastContentBuilder();
                toast.AddAppLogoOverride(new Uri(logo), ToastGenericAppLogoCrop.Circle, null, false);
                toast.AddAttributionText(string.Format("Scraps {0}", Common.Constants.Version.Full));
                toast.AddText("Items Need Withdrawing");
                toast.AddText(message);
                toast.AddButton(viewButton);
                toast.AddButton(dismissButton);
                toast.Show();
            }
        }
Example #7
0
        public void AddButtonTest_WithTextOnlyButton_ReturnSelfWithButtonAdded()
        {
            // Arrange
            string testButtonContent = "Test Button Content";
            ToastActivationType testToastActivationType = ToastActivationType.Background;
            string testButtonLaunchArgs = "Test Launch Args";
            ToastContentBuilder builder = new ToastContentBuilder();

            // Act
            ToastContentBuilder anotherReference = builder.AddButton(testButtonContent, testToastActivationType, testButtonLaunchArgs);

            // Assert
            Assert.AreSame(builder, anotherReference);

            var button = (builder.Content.Actions as ToastActionsCustom).Buttons.First() as ToastButton;

            Assert.AreEqual(testButtonContent, button.Content);
            Assert.AreEqual(testToastActivationType, button.ActivationType);
            Assert.AreEqual(testButtonLaunchArgs, button.Arguments);
        }
Example #8
0
        public void AddArgumentTest_ReplacingWithinButton_ReturnSelfWithArgumentsAdded()
        {
            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder
                                                   .AddButton(new ToastButton()
                                                              .SetContent("Accept")
                                                              .AddArgument("action", "accept")
                                                              .AddArgument("userId", 601)
                                                              .SetBackgroundActivation())

                                                   // Add generic arguments halfway through (in this case shouldn't overwrite anything)
                                                   .AddArgument("userId", 542)

                                                   .AddButton(new ToastButton()
                                                              .SetContent("Decline")
                                                              .AddArgument("action", "decline")
                                                              .AddArgument("userId", 601)
                                                              .SetBackgroundActivation());

            // Assert
            Assert.AreSame(builder, anotherReference);

            // Top level arguments should be present
            Assert.AreEqual("userId=542", builder.Content.Launch);

            // Buttons should have overridden the generic userId
            var actions = builder.Content.Actions as ToastActionsCustom;

            var button1 = actions.Buttons[0] as ToastButton;

            Assert.AreEqual("Accept", button1.Content);
            Assert.AreEqual("action=accept;userId=601", button1.Arguments);

            var button2 = actions.Buttons[1] as ToastButton;

            Assert.AreEqual("Decline", button2.Content);
            Assert.AreEqual("action=decline;userId=601", button2.Arguments);
        }
Example #9
0
        public void SetProtocolActivationTest_ReturnSelfWithArgumentsAdded()
        {
            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder
                                                   .AddButton(new ToastButton()
                                                              .SetContent("Accept")
                                                              .AddArgument("action", "accept")
                                                              .SetBackgroundActivation())

                                                   .AddArgument("userId", 542)

                                                   .SetProtocolActivation(new Uri("https://msn.com/"))

                                                   .AddArgument("name", "Andrew")

                                                   .AddButton(new ToastButton()
                                                              .SetContent("Decline")
                                                              .AddArgument("action", "decline")
                                                              .SetBackgroundActivation());

            // Assert
            Assert.AreSame(builder, anotherReference);
            Assert.AreEqual("https://msn.com/", builder.Content.Launch);
            Assert.AreEqual(ToastActivationType.Protocol, builder.Content.ActivationType);

            var actions = builder.Content.Actions as ToastActionsCustom;

            var button1 = actions.Buttons[0] as ToastButton;

            Assert.AreEqual("Accept", button1.Content);
            Assert.AreEqual("action=accept;userId=542;name=Andrew", button1.Arguments);

            var button2 = actions.Buttons[1] as ToastButton;

            Assert.AreEqual("Decline", button2.Content);
            Assert.AreEqual("action=decline;userId=542;name=Andrew", button2.Arguments);
        }
Example #10
0
 public IUwpExtension AddButton(string content, ToastActivationType activationType, string arguments, Uri?imageUri = null)
 {
     tbc.AddButton(content, activationType, arguments, imageUri);
     return(this);
 }
        private static XmlDocument GenerateXml(Notification notification)
        {
#if NETSTANDARD
            var sw = new StringWriter();
            var xw = XmlWriter.Create(sw, new XmlWriterSettings
            {
                OmitXmlDeclaration = true,
                Indent             = true
            });

            xw.WriteStartElement("toast");

            xw.WriteStartElement("visual");

            xw.WriteStartElement("binding");

            xw.WriteAttributeString("template", "ToastGeneric");

            xw.WriteStartElement("text");
            xw.WriteString(notification.Title ?? string.Empty);
            xw.WriteEndElement();

            xw.WriteStartElement("text");
            xw.WriteString(notification.Body ?? string.Empty);
            xw.WriteEndElement();

            xw.WriteEndElement();

            xw.WriteEndElement();

            xw.WriteStartElement("actions");

            foreach (var(title, actionId) in notification.Buttons)
            {
                xw.WriteStartElement("action");
                xw.WriteAttributeString("content", title);
                xw.WriteAttributeString("activationType", "foreground");
                xw.WriteAttributeString("arguments", actionId);
                xw.WriteEndElement();
            }

            xw.WriteEndElement();

            xw.WriteEndElement();
            xw.Flush();

            var xmlStr = sw.ToString();
            var xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(xmlStr);

            return(xmlDoc);
#else
            var builder = new ToastContentBuilder();

            builder.AddText(notification.Title);
            builder.AddText(notification.Body);

            foreach (var(title, actionId) in notification.Buttons)
            {
                builder.AddButton(title, ToastActivationType.Foreground, actionId);
            }

            return(builder.GetXml());
#endif
        }