コード例 #1
0
 protected override void OnStartup(StartupEventArgs e)
 {
     base.OnStartup(e);
     ToastNotificationManagerCompat.OnActivated += t =>
     {
         ToastArguments args = ToastArguments.Parse(t.Argument);
         //t.Use
         Current.Dispatcher.Invoke(delegate
         {
             if (!args.Contains("action"))
             {
                 return;
             }
             else
             {
                 int state = args.GetInt("action");
                 if (state == 0)
                 {
                     Modetor.Net.Server.Core.HttpServers.BaseServer.Servers[args.Get("si")].Suspend();
                 }
                 else if (state == 1)
                 {
                     Modetor.Net.Server.Core.HttpServers.BaseServer.Servers[args.Get("si")].Resume();
                 }
                 else if (state == 2)
                 {
                     // Started....
                 }
             }
             //MessageBox.Show(args.Get("action"));
         });
     };
 }
コード例 #2
0
        public void TestStronglyTyped()
        {
            ToastArguments args = new ToastArguments()
                                  .Add("isAdult", true)
                                  .Add("isPremium", false)
                                  .Add("age", 22)
                                  .Add("level", 0)
                                  .Add("gpa", 3.97)
                                  .Add("percent", 97.3f);

#if !WINRT
            args.Add("activationKind", ToastActivationType.Background);
#endif

            AssertEqual(
                new ToastArguments()
            {
                { "isAdult", "1" },
                { "isPremium", "0" },
                { "age", "22" },
                { "level", "0" },
                { "gpa", "3.97" },
                { "percent", "97.3" },
#if !WINRT
                { "activationKind", "1" }
#endif
            }, args);

            Assert.AreEqual(true, args.GetBool("isAdult"));
            Assert.AreEqual("1", args.Get("isAdult"));

            Assert.AreEqual(false, args.GetBool("isPremium"));
            Assert.AreEqual("0", args.Get("isPremium"));

            Assert.AreEqual(22, args.GetInt("age"));
            Assert.AreEqual(22d, args.GetDouble("age"));
            Assert.AreEqual(22f, args.GetFloat("age"));
            Assert.AreEqual("22", args.Get("age"));

            Assert.AreEqual(0, args.GetInt("level"));

            Assert.AreEqual(3.97d, args.GetDouble("gpa"));

            Assert.AreEqual(97.3f, args.GetFloat("percent"));

#if !WINRT
            Assert.AreEqual(ToastActivationType.Background, args.GetEnum <ToastActivationType>("activationKind"));

            if (args.TryGetValue("activationKind", out ToastActivationType activationType))
            {
                Assert.AreEqual(ToastActivationType.Background, activationType);
            }
            else
            {
                Assert.Fail("TryGetValue as enum failed");
            }

            // Trying to get enum that isn't an enum should return false
            Assert.IsFalse(args.TryGetValue("percent", out activationType));
#endif

            // After serializing and deserializing, the same should work
            args = ToastArguments.Parse(args.ToString());

            Assert.AreEqual(true, args.GetBool("isAdult"));
            Assert.AreEqual("1", args.Get("isAdult"));

            Assert.AreEqual(false, args.GetBool("isPremium"));
            Assert.AreEqual("0", args.Get("isPremium"));

            Assert.AreEqual(22, args.GetInt("age"));
            Assert.AreEqual(22d, args.GetDouble("age"));
            Assert.AreEqual(22f, args.GetFloat("age"));
            Assert.AreEqual("22", args.Get("age"));

            Assert.AreEqual(0, args.GetInt("level"));

            Assert.AreEqual(3.97d, args.GetDouble("gpa"));

            Assert.AreEqual(97.3f, args.GetFloat("percent"));

#if !WINRT
            Assert.AreEqual(ToastActivationType.Background, args.GetEnum <ToastActivationType>("activationKind"));

            if (args.TryGetValue("activationKind", out activationType))
            {
                Assert.AreEqual(ToastActivationType.Background, activationType);
            }
            else
            {
                Assert.Fail("TryGetValue as enum failed");
            }

            // Trying to get enum that isn't an enum should return false
            Assert.IsFalse(args.TryGetValue("percent", out activationType));
#endif
        }
コード例 #3
0
        private void ToastNotificationManagerCompat_OnActivated(ToastNotificationActivatedEventArgsCompat e)
        {
            Dispatcher.Invoke(() =>
            {
                // If arguments are empty, that means the app title within Action Center was clicked.
                if (e.Argument.Length == 0)
                {
                    OpenWindowIfNeeded();
                    return;
                }

                // Parse the toast arguments
                ToastArguments args = ToastArguments.Parse(e.Argument);

                int conversationId = args.GetInt("conversationId");

                // If no specific action, view the conversation
                if (args.TryGetValue("action", out MyToastActions action))
                {
                    switch (action)
                    {
                    // View conversation
                    case MyToastActions.ViewConversation:

                        // Make sure we have a window open and in foreground
                        OpenWindowIfNeeded();

                        // And then show the conversation
                        (Current.Windows[0] as MainWindow).ShowConversation(conversationId);

                        break;

                    // Open the image
                    case MyToastActions.ViewImage:

                        // The URL retrieved from the toast args
                        string imageUrl = args["imageUrl"];

                        // Make sure we have a window open and in foreground
                        OpenWindowIfNeeded();

                        // And then show the image
                        (Current.Windows[0] as MainWindow).ShowImage(imageUrl);

                        break;

                    // Background: Quick reply to the conversation
                    case MyToastActions.Reply:

                        // Get the response the user typed
                        string msg = e.UserInput["tbReply"] as string;

                        // And send this message
                        ShowToast("Message sent: " + msg + "\nconversationId: " + conversationId);

                        // If there's no windows open, exit the app
                        if (Current.Windows.Count == 0)
                        {
                            Current.Shutdown();
                        }

                        break;

                    // Background: Send a like
                    case MyToastActions.Like:

                        ShowToast($"Like sent to conversation {conversationId}!");

                        // If there's no windows open, exit the app
                        if (Current.Windows.Count == 0)
                        {
                            Current.Shutdown();
                        }

                        break;

                    default:

                        OpenWindowIfNeeded();

                        break;
                    }
                }
            });
        }