コード例 #1
0
        public static void ToastNotificationManagerCompatOnOnActivated(ToastNotificationActivatedEventArgsCompat e)
        {
            MainWindow.DispatcherQueue.TryEnqueue(() =>
            {
                //Activate window
                MainWindow.Activate();

                //Handle toast action
                ToastArguments args = ToastArguments.Parse(e.Argument);
                if (!args.Contains(ToastAction))
                {
                    return;
                }

                switch (args[ToastAction])
                {
                case ToastActionConversation:
                    {
                        var chatId = args[ToastActionConversationChat];
                        if (ChatActivated != null)
                        {
                            ChatActivated.Invoke(null, chatId);
                        }
                        else
                        {
                            PendingChatId = chatId;
                        }

                        break;
                    }
                }
            });
        }
コード例 #2
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"));
         });
     };
 }
コード例 #3
0
        // Add any OnActivationCompleted customization here.
        private void OnActivatedByToast(ToastNotificationActivatedEventArgs toastActivationArgs)
        {
            ToastArguments toastArguments = ToastArguments.Parse(toastActivationArgs.Argument);
            ValueSet       userInput      = toastActivationArgs.UserInput;

            if (toastArguments.Contains("opcode"))
            {
                string opcode = toastArguments["opcode"];
                if ("device".Equals(opcode))
                {
                    sDeviceManager.HandleToast(toastArguments, userInput);
                }
            }

            // Close System Tray
            if (sAppServiceManager != null)
            {
                sAppServiceManager.Dispose();
                sAppServiceManager = null;
            }
        }
コード例 #4
0
 internal void HandleToast(ToastArguments toastArguments, ValueSet userInput)
 {
     if (toastArguments.Contains("action"))
     {
         string action = toastArguments["action"];
         if ("pair".Equals(action))
         {
             string device_id = toastArguments["deviceid"];
             PairWithMac(device_id);
         }
         else if ("unpair".Equals(action))
         {
             string device_id = toastArguments["deviceid"];
             UnpairWithMac(device_id);
         }
         else if ("connect".Equals(action))
         {
             string device_id = toastArguments["deviceid"];
             ConnectA2DP(device_id);
         }
     }
 }
コード例 #5
0
        private static bool IsSame(ToastArguments expected, ToastArguments actual)
        {
            if (expected.Count != actual.Count)
            {
                return(false);
            }

            foreach (var pair in expected)
            {
                if (!actual.Contains(pair.Key))
                {
                    return(false);
                }

                if (actual.Get(pair.Key) != pair.Value)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #6
0
        protected override void OnActivated(IActivatedEventArgs e)
        {
            if (e.GetType() == typeof(ToastNotificationActivatedEventArgs))
            {
                Console.WriteLine(e is ToastNotificationActivatedEventArgs);
                var            toastActivationArgs = (ToastNotificationActivatedEventArgs)e;
                ToastArguments args = ToastArguments.Parse(toastActivationArgs.Argument);

                var JsonString = args.Contains("lesson") ? args["lesson"] : null;
                if (JsonString != null)
                {
                    var lesson = JsonConvert.DeserializeObject <Lesson>(JsonString,
                                                                        new JsonSerializerSettings()
                    {
                        TypeNameHandling = TypeNameHandling.Auto
                    });
                    lesson.EnterClass(new StudentInfo()
                    {
                        Name = Settings.UserName
                    });
                }
            }
        }
コード例 #7
0
        public void TestContains()
        {
            ToastArguments qs = new ToastArguments();

            Assert.IsFalse(qs.Contains("name"));
            Assert.IsFalse(qs.Contains("name", "Andrew"));

            qs.Add("isBook");

            Assert.IsFalse(qs.Contains("name"));
            Assert.IsFalse(qs.Contains("name", "Andrew"));

            Assert.IsTrue(qs.Contains("isBook"));
            Assert.IsTrue(qs.Contains("isBook", null));
            Assert.IsFalse(qs.Contains("isBook", "True"));

            qs.Add("isBook", "True");

            Assert.IsTrue(qs.Contains("isBook"));
            Assert.IsFalse(qs.Contains("isBook", null));
            Assert.IsTrue(qs.Contains("isBook", "True"));

            qs.Add("name", "Andrew");

            Assert.IsTrue(qs.Contains("name"));
            Assert.IsFalse(qs.Contains("name", null));     // Value doesn't exist
            Assert.IsTrue(qs.Contains("name", "Andrew"));
            Assert.IsFalse(qs.Contains("Name", "Andrew")); // Wrong case on name
            Assert.IsFalse(qs.Contains("name", "andrew")); // Wrong case on value
            Assert.IsFalse(qs.Contains("Name"));           // Wrong case on name
        }
コード例 #8
0
ファイル: ToastAPI.cs プロジェクト: hmz777/NetStalker
        private async static void Notifications_OnActivated(ToastNotificationActivatedEventArgsCompat e)
        {
            ToastArguments args     = ToastArguments.Parse(e.Argument);
            var            MainForm = Application.OpenForms["Main"] as Main;

            if (ToastNotificationManagerCompat.WasCurrentProcessToastActivated())
            {
                if (MainForm.InvokeRequired)
                {
                    MainForm.BeginInvoke(new Action(() =>
                    {
                        MetroFramework.MetroMessageBox.Show(MainForm,
                                                            "Process has been activated by toast notification trigger.",
                                                            "Information",
                                                            MessageBoxButtons.OK,
                                                            MessageBoxIcon.Information);
                    }));
                }
                else
                {
                    MetroFramework.MetroMessageBox.Show(MainForm,
                                                        "Process has been activated by toast notification trigger.",
                                                        "Information",
                                                        MessageBoxButtons.OK,
                                                        MessageBoxIcon.Information);
                }

                return;
            }

            if (!args.Contains("Choice"))
            {
                return; //No choice to select then no action required e.g. body tapped
            }

            NotificationChoice NotificationChoice = NotificationChoice.None;

            if (!Enum.TryParse <NotificationChoice>(args["Choice"], out NotificationChoice))
            {
                return; //No valid choice, we return
            }

            switch (Enum.Parse(typeof(NotificationPurpose), args["Action"]))
            {
            case NotificationPurpose.NotificationsSuppression:
            {
                switch (NotificationChoice)
                {
                case NotificationChoice.Yes:
                    Properties.Settings.Default.SuppressNotifications = 2;
                    break;

                case NotificationChoice.No:
                    Properties.Settings.Default.SuppressNotifications = 1;
                    break;

                default: return;
                }

                Properties.Settings.Default.Save();

                break;
            }

            case NotificationPurpose.TargetDiscovery:
            {
                switch (NotificationChoice)
                {
                case NotificationChoice.Show:
                {
                    if (MainForm.InvokeRequired)
                    {
                        MainForm.BeginInvoke(new Action(() =>
                                {
                                    MainForm.Show();
                                    MainForm.WindowState = FormWindowState.Normal;

                                    if (MainForm.TrayIcon.Visible)
                                    {
                                        MainForm.TrayIcon.Visible = false;
                                    }
                                }));
                    }
                    else
                    {
                        MainForm.Show();
                        MainForm.WindowState = FormWindowState.Normal;

                        if (MainForm.TrayIcon.Visible)
                        {
                            MainForm.TrayIcon.Visible = false;
                        }
                    }

                    break;
                }

                case NotificationChoice.Block:
                {
                    if (!string.IsNullOrEmpty(args["DeviceIP"]) && !string.IsNullOrEmpty(args["DeviceMAC"]))
                    {
                        if (MainForm.InvokeRequired)
                        {
                            MainForm.BeginInvoke(new Action(async() =>
                                    {
                                        await MainForm.BlockDevice(args["DeviceIP"], args["DeviceMAC"]);
                                    }));
                        }
                        else
                        {
                            await MainForm.BlockDevice(args["DeviceIP"], args["DeviceMAC"]);
                        }
                    }

                    break;
                }

                case NotificationChoice.Suppress:
                {
                    Properties.Settings.Default.SuppressNotifications = 1;
                    Properties.Settings.Default.Save();
                    break;
                }

                default: return;
                }

                break;
            }

            default: return;
            }
        }