Example #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;
                    }
                }
            });
        }
        public void Setup()
        {
            // Listen to notification activation
            ToastNotificationManagerCompat.OnActivated += toastArgs =>
            {
                // Obtain the arguments from the notification
                ToastArguments args = ToastArguments.Parse(toastArgs.Argument);

                // Obtain any user input (text boxes, menu selections) from the notification
                ValueSet userInput = toastArgs.UserInput;

                // Need to dispatch to UI thread if performing UI operations
                Application.Current.Dispatcher.Invoke(delegate
                {
                    if (args.TryGetValue(_ActionTypeCode, out string value))
                    {
                        switch (value)
                        {
                        case _ActionTypeStartTask:
                            userInput.TryGetValue(_SelectionTaskKey, out object key);
                            StartSelectedWorkTask(key?.ToString());
                            break;

                        case _ActionTypeStartLunch:
                            StartBreak();
                            break;
                        }
                    }
                    else
                    {
                        ((MainWindow)Application.Current.MainWindow).ShowWindow();
                    }
                });
            };
Example #3
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"));
         });
     };
 }
Example #4
0
 public static void HandleToastAction(ToastNotificationActivatedEventArgsCompat toastArgs)
 {
     try
     {
         // Obtain the arguments from the notification
         ToastArguments args = ToastArguments.Parse(toastArgs.Argument);
         // Obtain any user input (text boxes, menu selections) from the notification
         ValueSet userInput = toastArgs.UserInput;
         if (toastArgs.Argument.Length == 0)
         {
             return;
         }
         Logger.Debug("toast called with args: " + toastArgs.Argument);
         string[] arguments = toastArgs.Argument.Split(";");
         foreach (string argumentString in arguments)
         {
             string[] argument = argumentString.Split("=");
             if (argument[0] == "action" && argument[1] == "update")
             {
                 Logger.Info("updating app, caller toast");
                 Task.Run(() => UpdateHandler.Update(overrideSilent: true)).Wait();
             }
             else if (argument[0] == "action" && argument[1] == "postpone")
             {
                 Logger.Debug("update postponed");
                 return;
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Error(ex, "updater failed, caller toast:");
     }
 }
        private static void AssertEqual(ToastArguments expected, ToastArguments actual)
        {
            Assert.IsTrue(IsSame(expected, actual), "Expected: " + expected + "\nActual: " + actual);

            Assert.IsTrue(IsSame(expected, ToastArguments.Parse(actual.ToString())), "After serializing and parsing actual, result changed.\n\nExpected: " + expected + "\nActual: " + ToastArguments.Parse(actual.ToString()));
            Assert.IsTrue(IsSame(ToastArguments.Parse(expected.ToString()), actual), "After serializing and parsing expected, result changed.\n\nExpected: " + ToastArguments.Parse(expected.ToString()) + "\nActual: " + actual);
            Assert.IsTrue(IsSame(ToastArguments.Parse(expected.ToString()), ToastArguments.Parse(actual.ToString())), "After serializing and parsing both, result changed.\n\nExpected: " + ToastArguments.Parse(expected.ToString()) + "\nActual: " + ToastArguments.Parse(actual.ToString()));
        }
Example #6
0
        private void ToastNotificationManagerCompat_OnActivated(ToastNotificationActivatedEventArgsCompat e)
        {
            var args = ToastArguments.Parse(e.Argument);

            Activator.Activate(
                args["type"],
                args.Contains("receivedAt") ? args["receivedAt"] : null,
                args.Contains("startedAt") ? args["startedAt"] : null
                );
        }
Example #7
0
        private void Toast_OnActivated(ToastNotificationActivatedEventArgsCompat e)
        {
            var parsed = ToastArguments.Parse(e.Argument);

            switch (parsed["action"])
            {
            case "viewRafflesWonPage":
                Process.Start("explorer.exe", "https://scrap.tf/raffles/won");
                break;
            }
        }
        public void TestEnumerator()
        {
            KeyValuePair <string, string>[] parameters = ToastArguments.Parse("name=Andrew;age=22;isOld").ToArray();

            Assert.AreEqual(3, parameters.Length);
            Assert.AreEqual(1, parameters.Count(i => i.Key.Equals("name")));
            Assert.AreEqual(1, parameters.Count(i => i.Key.Equals("age")));
            Assert.AreEqual(1, parameters.Count(i => i.Key.Equals("isOld")));
            Assert.IsTrue(parameters.Any(i => i.Key.Equals("name") && i.Value.Equals("Andrew")));
            Assert.IsTrue(parameters.Any(i => i.Key.Equals("age") && i.Value.Equals("22")));
            Assert.IsTrue(parameters.Any(i => i.Key.Equals("isOld") && i.Value == null));
        }
        private static void OnEntryWritten()
        {
            List <EventRecord> filteredEntries  = new List <EventRecord>();
            string             eventFilterQuery = "*[System[(EventID=5152 or EventID=5157) and TimeCreated[timediff(@SystemTime) <= 6000]]]";
            EventLogQuery      eventsQuery      = new EventLogQuery("Security", PathType.LogName, eventFilterQuery);

            try
            {
                EventLogReader logReader = new EventLogReader(eventsQuery);
                for (EventRecord eventdetail = logReader.ReadEvent(); eventdetail != null; eventdetail = logReader.ReadEvent())
                {
                    filteredEntries.Add(eventdetail);
                }
            }
            catch (EventLogNotFoundException)
            {
            }
            var query = filteredEntries.OrderByDescending(x => x.TimeCreated).FirstOrDefault();

            if (query != null && query.Properties[2].Value.ToString() == @"%%14593")
            {
                var filePath             = GetFriendlyPath(query.Properties[1].Value.ToString());
                var preRuleNameComponent = filePath.Split('\\');
                if (preRuleNameComponent.Length >= 2)
                {
                    var ruleNameComponent = preRuleNameComponent[preRuleNameComponent.Length - 1];

                    var existRule = filteredRules.Any(x => x.Name.EndsWith(ruleNameComponent + " 出站连接"));
                    if (existRule == false)
                    {
                        if (displayNotification)
                        {
                            new ToastContentBuilder()
                            .AddText("发现新的出站连接请求")
                            .AddText(filePath)
                            .AddText("请求建立出站连接")
                            .AddButton(new ToastButton().SetContent("允许").AddArgument("action", "AllowConnection"))
                            .AddButton(new ToastButton().SetContent("阻止").AddArgument("action", "BlockConnection"))
                            .Show();
                            displayNotification = false;
                            ToastNotificationManagerCompat.OnActivated += toastArgs =>
                            {
                                ToastArguments args = ToastArguments.Parse(toastArgs.Argument);

                                FirewallActions(args, filePath, ruleNameComponent);
                                args = null;
                            };
                        }
                    }
                }
            }
        }
Example #10
0
        protected override async void OnActivated(IActivatedEventArgs e)
        {
            if (e is ToastNotificationActivatedEventArgs toastActivationArgs)
            {
                // Obtain the arguments from the notification
                ToastArguments args = ToastArguments.Parse(toastActivationArgs.Argument);

                if (args.Get("action") is "Settings")
                {
                    await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location"));
                }
            }
        }
Example #11
0
        protected override void OnActivated(IActivatedEventArgs e)
        {
            // Handle notification activation
            if (e is ToastNotificationActivatedEventArgs toastActivationArgs)
            {
                // Obtain the arguments from the notification
                ToastArguments args = ToastArguments.Parse(toastActivationArgs.Argument);

                // Obtain any user input (text boxes, menu selections) from the notification
                ValueSet userInput = toastActivationArgs.UserInput;

                // TODO: Show the corresponding content
            }
        }
Example #12
0
        private void OnToastNotificationUserAction(ToastNotificationActivatedEventArgsCompat e)
        {
            ToastArguments args = ToastArguments.Parse(e.Argument);

            Application.Current.Dispatcher.Invoke(delegate
            {
                NotificationUserAction data = new()
                {
                    Arguments  = args.ToDictionary(p => p.Key, p => p.Value),
                    UserInputs = e.UserInput.ToDictionary(p => p.Key, p => p.Value)
                };
                _bootstrapper.OnToastNotificationUserAction(data);
            });
        }
    }
Example #13
0
        private void Setup()
        {
            bool encode = this.userSettingService.GetUserSetting <bool>(UserSettingConstants.NotifyOnEncodeDone);
            bool queue  = this.userSettingService.GetUserSetting <bool>(UserSettingConstants.NotifyOnQueueDone);

            if (encode || queue)
            {
                if (isInitialised)
                {
                    return;
                }

                this.notifier = ToastNotificationManagerCompat.CreateToastNotifier();

                isInitialised = true;

                ToastNotificationManagerCompat.OnActivated += toastArgs =>
                {
                    // Obtain the arguments from the notification
                    ToastArguments args = ToastArguments.Parse(toastArgs.Argument);

                    // Remove any notifications that are clicked
                    System.Collections.Generic.KeyValuePair <string, string> tag = args.FirstOrDefault();
                    if (!string.IsNullOrEmpty(tag.Value))
                    {
                        try
                        {
                            ToastNotificationManagerCompat.History.Remove(tag.Value);
                        }
                        catch (Exception exc)
                        {
                            Debug.WriteLine(exc);
                        }
                    }

                    // Need to dispatch to UI thread if performing UI operations
                    Application.Current.Dispatcher.Invoke(delegate
                    {
                        Window w = Application.Current.MainWindow;
                        if (w != null)
                        {
                            w.WindowState = WindowState.Normal;
                            w.BringIntoView();
                        }
                    });
                };
            }
        }
Example #14
0
        public Form1()
        {
            InitializeComponent();

            // Listen to notification activation
            ToastNotificationManagerCompat.OnActivated += toastArgs =>
            {
                // Obtain the arguments from the notification
                ToastArguments args = ToastArguments.Parse(toastArgs.Argument);

                // Obtain any user input (text boxes, menu selections) from the notification
                ValueSet userInput = toastArgs.UserInput;

                // Need to dispatch to UI thread if performing UI operations
                Console.WriteLine("URL: " + args["url"]);
                System.Diagnostics.Process.Start(args["url"]);
            };
        }
Example #15
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;
            }
        }
Example #16
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
                    });
                }
            }
        }
 private static void AssertParse(ToastArguments expected, string inputQueryString)
 {
     Assert.IsTrue(IsSame(expected, ToastArguments.Parse(inputQueryString)), "Expected: " + expected + "\nActual: " + inputQueryString);
 }
 private static void AssertDecode(string expected, string encoded)
 {
     Assert.AreEqual(expected, ToastArguments.Parse("message=" + encoded).Get("message"));
 }
        private static void AssertIndexer(string expected, string queryString, string paramName)
        {
            ToastArguments q = ToastArguments.Parse(queryString);

            Assert.AreEqual(expected, q[paramName]);
        }
        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
        }
Example #21
0
 private void ToastNotificationManagerCompat_OnActivated(ToastNotificationActivatedEventArgsCompat e)
 {
     var args = ToastArguments.Parse(e.Argument);
     var path = args.ToString()[18..];
        protected override void OnStartup(StartupEventArgs e)
        {
            // Listen to notification activation
            ToastNotificationManagerCompat.OnActivated += toastArgs => {
                Logger.Trace("Toast activated {Arguments}", toastArgs.Argument);
                // Obtain the arguments from the notification
                ToastArguments args = ToastArguments.Parse(toastArgs.Argument);

                // Obtain any user input (text boxes, menu selections) from the notification
                ValueSet userInput = toastArgs.UserInput;

                // Need to dispatch to UI thread if performing UI operations
                Application.Current.Dispatcher.Invoke(delegate {
                    Logger.Trace("Handling action {Arguments} {UserInput}", toastArgs.Argument, userInput);
                    switch (args["action"])
                    {
                    case "viewRemove":
                        ShowRemoved(Guid.Parse(args["id"]));
                        break;

                    case "revertRemove":
                        RevertRemove(Guid.Parse(args["id"]));
                        break;

                    case "confirmRemove":
                        ConfirmRemove(Guid.Parse(args["id"]));
                        break;

                    case "viewAdd":
                        ShowAdd(Guid.Parse(args["id"]));
                        break;

                    case "revertAdd":
                        RevertAdd(Guid.Parse(args["id"]));
                        break;

                    case "confirmAdd":
                        ConfirmAdd(Guid.Parse(args["id"]));
                        break;

                    case "confirmEnable":
                        ConfirmAdd(Guid.Parse(args["id"]));
                        break;

                    case "confirmDisable":
                        ConfirmAdd(Guid.Parse(args["id"]));
                        break;

                    case "enable":
                        Enable(Guid.Parse(args["id"]));
                        break;

                    case "disable":
                        Disable(Guid.Parse(args["id"]));
                        break;

                    default:
                        Logger.Trace("Unknown action {Action}", args["action"]);
                        break;
                    }
                });
            };
            base.OnStartup(e);
        }
Example #23
0
        public async Task Process(string arguments)
        {
            var toastArguments = ToastArguments.Parse(arguments);

            if (!toastArguments.TryGetValue(ToastNotificationConstants.ToastArgumentKey_Action, out string actionType))
            {
                return;
            }

            switch (actionType)
            {
            case ToastNotificationConstants.ToastArgumentValue_Action_DeleteCache:
            {
                if (!toastArguments.TryGetValue(ToastNotificationConstants.ToastArgumentKey_Id, out string id))
                {
                    throw new Models.Infrastructure.HohoemaExpception("no id");
                }

                await _videoCacheManager.CancelCacheRequestAsync(id);
            }
            break;

            case ToastNotificationConstants.ToastArgumentValue_Action_PlayVideo:
            {
                if (!toastArguments.TryGetValue(ToastNotificationConstants.ToastArgumentKey_Id, out string id))
                {
                    throw new Models.Infrastructure.HohoemaExpception("no id");
                }

                await PlayVideoFromExternal(id);
            }
            break;

            case ToastNotificationConstants.ToastArgumentValue_Action_PlayPlaylist:
            {
                if (!toastArguments.TryGetValue(ToastNotificationConstants.ToastArgumentKey_PlaylistId, out string playlistId))
                {
                    throw new Models.Infrastructure.HohoemaExpception("no id");
                }

                if (!toastArguments.TryGetValue(ToastNotificationConstants.ToastArgumentKey_PlaylistOrigin, out string playlistOrigin) ||
                    !Enum.TryParse <PlaylistItemsSourceOrigin>(playlistOrigin, out var origin)
                    )
                {
                    throw new Models.Infrastructure.HohoemaExpception("no id");
                }

                await PlayPlaylistFromExternal(origin, playlistId);
            }
            break;

            case ToastNotificationConstants.ToastArgumentValue_Action_OpenPage:
            {
                if (!toastArguments.TryGetValue(ToastNotificationConstants.ToastArgumentKey_PageType, out string pageTypeStr))
                {
                    throw new Models.Infrastructure.HohoemaExpception("no pageType");
                }

                if (!Enum.TryParse <HohoemaPageType>(pageTypeStr, out var pageType))
                {
                    throw new Models.Infrastructure.HohoemaExpception("no supported pageType: " + pageTypeStr);
                }

                if (toastArguments.TryGetValue(ToastNotificationConstants.ToastArgumentKey_PageParameters, out string parameters))
                {
                    _pageManager.OpenPage(pageType, parameters);
                }
                else
                {
                    _pageManager.OpenPage(pageType);
                }
            }
            break;
            }
        }
Example #24
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;
                    }
                }
            });
        }
Example #25
0
        private void Init(bool isFirst)
        {
            if (isFirst)
            {
                Timer.Enabled = true;

#if DEBUG
                Label_CurrentRequestCountText.Visible = true;
                Label_CurrentRequestCount.Visible     = true;
                Width += 200;
#endif

                #region Setting

                if (!ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).HasFile)
                {
                    Settings.Default.Upgrade();//低版本配置文件复制到高版本配置文件
                }

                #endregion

                DateTimePicker.Value   = DateTime.Today;
                DateTimePicker.MaxDate = DateTime.Today;
                DataGridViewIssues.AutoGenerateColumns = false;
                DataGridViewIssues.MultiSelect         = false;

                ToastManager.Clear();

                issueExcludeIdList = Settings.Default.issueExclude;
                ContextMenuStripForNotifyIcon.ItemClicked += new ToolStripItemClickedEventHandler(ToolStripItemForNotifyIcon_Click);
                if (Settings.Default.IsLogout)
                {
                    Logout();
                }
                else
                {
                    Login();
                }
                ToastNotificationManagerCompat.OnActivated += toastArgs =>
                {
                    ToastArguments args = ToastArguments.Parse(toastArgs.Argument);

                    switch (Enum.Parse(typeof(ToastActionType), args.Get("action")))
                    {
                    case ToastActionType.RemindLater:
                        issueManager.SendToast(args.Get("contentId"), isShow: false);
                        break;

                    case ToastActionType.Click:
                        Invoke((EventHandler) delegate
                        {
                            System.Diagnostics.Process.Start(Settings.Default.RedMineHost + "issues/" + args.Get("contentId"));
                        });
                        break;

                    default:
                        break;
                    }
                };
            }
        }
Example #26
0
        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;
            }
        }