private void MuteButton_Click(object sender, RoutedEventArgs e)
 {
     if (muted)
     {
         audio.Unmute();
     }
     else
     {
         audio.Mute();
     }
 }
示例#2
0
文件: Mqtt.cs 项目: vageesh79/Win10As
        private void MessageReceived(string subtopic, string message)
        {
            switch (subtopic)
            {
            case "app/running":
                Publish("app/running/" + message, Process.IsRunning(message, ""));
                break;

            case "app/close":
                Publish("app/running/" + message, Process.Close(message));
                break;

            case "monitor/set":
                if (message == "1" || message == "on")
                {
                    Monitor.TurnOn();
                    Publish("monitor", "1");
                }
                else if (message == "0" || message == "off")
                {
                    Monitor.TurnOff();
                    Publish("monitor", "0");
                }
                break;

            case "mute/set":
                if (message == "1" || message == "on")
                {
                    _audio.Mute(true);
                }
                else if (message == "0" || message == "off")
                {
                    _audio.Mute(false);
                }
                Publish("mute", message);
                break;

            case "volume/set":
                _audio.Volume(Convert.ToInt32(message));
                break;

            case "hibernate":
                Application.SetSuspendState(PowerState.Hibernate, true, true);
                break;

            case "suspend":
                Application.SetSuspendState(PowerState.Suspend, true, true);
                break;

            case "reboot":
                System.Diagnostics.Process.Start("shutdown.exe", $"-r -t {GetDelay(message)}");
                break;

            case "shutdown":
                System.Diagnostics.Process.Start("shutdown.exe", $"-s -t {GetDelay(message)}");
                break;

            case "tts":
                SpeechSynthesizer synthesizer = new SpeechSynthesizer();
                synthesizer.Volume = 100;     // 0...100
                synthesizer.SpeakAsync(message);
                break;

            case "toast":
                string[] words = message.Split(',');
                if (words.Length >= 3)
                {
                    string imageUrl = words[words.Length - 1];
                    _toastMessage.ShowImage(words, imageUrl);
                }
                else
                {
                    _toastMessage.ShowText(words);
                }
                break;

            default:
                MqttTrigger currentMqttTrigger = new MqttTrigger();
                if (currentMqttTrigger.CmdText.Length > 2)
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo(currentMqttTrigger.CmdText);
                    startInfo.WindowStyle = ProcessWindowStyle.Maximized;
                    if (currentMqttTrigger.CmdParameters.Length > 2)
                    {
                        startInfo.Arguments = currentMqttTrigger.CmdParameters;
                    }
                    System.Diagnostics.Process.Start(startInfo);
                }

                break;
            }
        }
示例#3
0
        private void MessageReceived(string subtopic, string message)
        {
            try
            {
                switch (subtopic)
                {
                case "app/running":

                    var isRunning = JsonConvert.DeserializeObject <Win10MqttLibrary.Models.IsRunning>(message);

                    switch (isRunning.Action)
                    {
                    case "1":
                        Publish($"app/running/{isRunning.ApplicationName}", Process.IsRunning(message, ""));
                        break;

                    case "0":
                        //close the app
                        Process.Close(isRunning.ApplicationName);
                        Publish($"app/running/{isRunning.ApplicationName}", "0");
                        break;

                    default:
                        Publish($"app/running/{isRunning.ApplicationName}", Process.IsRunning(message, ""));
                        break;
                    }
                    break;

                case "app/close":
                    Publish($"app/running/{message}", Process.Close(message));
                    break;

                case "monitor/set":
                    if (message == "1" || message == "on")
                    {
                        Monitor.TurnOn();
                        Publish("monitor", "1");
                    }
                    else if (message == "0" || message == "off")
                    {
                        Monitor.TurnOff();
                        Publish("monitor", "0");
                    }
                    break;

                case "mute/set":
                    if (message == "1" || message == "on")
                    {
                        _audio.Mute(true);
                    }
                    else if (message == "0" || message == "off")
                    {
                        _audio.Mute(false);
                    }
                    Publish("mute", message);
                    break;

                case "volume/set":
                    _audio.Volume(Convert.ToInt32(message, CultureInfo.CurrentCulture));
                    break;

                case "hibernate":
                    Application.SetSuspendState(PowerState.Hibernate, true, true);
                    break;

                case "suspend":
                    Application.SetSuspendState(PowerState.Suspend, true, true);
                    break;

                case "reboot":
                    System.Diagnostics.Process.Start("shutdown.exe", $"-r -t {GetDelay(message)}");
                    break;

                case "shutdown":
                    System.Diagnostics.Process.Start("shutdown.exe", $"-s -t {GetDelay(message)}");
                    break;

                case "tts":
                    SpeechSynthesizer synthesizer = new SpeechSynthesizer
                    {
                        Volume = 100
                    };
                    synthesizer.SpeakAsync(message);
                    break;

                case "toast":
                    string[] words = message.Split(',');
                    if (words.Length >= 3)
                    {
                        string imageUrl = words[words.Length - 1];
                        _toastMessage.ShowImage(words, imageUrl);
                    }
                    else
                    {
                        _toastMessage.ShowText(words);
                    }
                    break;

                case "cmd":

                    ProcessWindowStyle processWindowStyle = new ProcessWindowStyle();

                    var commandParameters = JsonConvert.DeserializeObject <Win10MqttLibrary.Models.CommandParameters>(message);

                    switch (Convert.ToInt16(commandParameters.WindowStyle))
                    {
                    case 0:
                        processWindowStyle = ProcessWindowStyle.Normal;
                        break;

                    case 1:
                        processWindowStyle = ProcessWindowStyle.Hidden;
                        break;

                    case 2:
                        processWindowStyle = ProcessWindowStyle.Minimized;
                        break;

                    case 3:
                        processWindowStyle = ProcessWindowStyle.Maximized;
                        break;

                    default:
                        processWindowStyle = ProcessWindowStyle.Normal;
                        break;
                    }


                    ProcessStartInfo startInfo = new ProcessStartInfo(commandParameters.CommandString, commandParameters.ExecParameters)
                    {
                        WindowStyle = processWindowStyle
                    };

                    System.Diagnostics.Process.Start(startInfo);

                    break;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#4
0
文件: Mqtt.cs 项目: wiuwiu/Win10As
        private void MessageReceived(string subtopic, string message)
        {
            try
            {
                switch (subtopic)
                {
                case "app/running":
                    Publish($"app/running/{message}", Process.IsRunning(message, ""));
                    break;

                case "app/close":
                    Publish($"app/running/{message}", Process.Close(message));
                    break;

                case "monitor/set":
                    if (message == "1" || message == "on")
                    {
                        Monitor.TurnOn();
                        Publish("monitor", "1");
                    }
                    else if (message == "0" || message == "off")
                    {
                        Monitor.TurnOff();
                        Publish("monitor", "0");
                    }
                    break;

                case "mute/set":
                    if (message == "1" || message == "on")
                    {
                        _audio.Mute(true);
                    }
                    else if (message == "0" || message == "off")
                    {
                        _audio.Mute(false);
                    }
                    Publish("mute", message);
                    break;

                case "volume/set":
                    _audio.Volume(Convert.ToInt32(message, CultureInfo.CurrentCulture));
                    break;

                case "hibernate":
                    Application.SetSuspendState(PowerState.Hibernate, true, true);
                    break;

                case "suspend":
                    Application.SetSuspendState(PowerState.Suspend, true, true);
                    break;

                case "reboot":
                    System.Diagnostics.Process.Start("shutdown.exe", $"-r -t {GetDelay(message)}");
                    break;

                case "shutdown":
                    System.Diagnostics.Process.Start("shutdown.exe", $"-s -t {GetDelay(message)}");
                    break;

                case "tts":
                    SpeechSynthesizer synthesizer = new SpeechSynthesizer
                    {
                        Volume = 100
                    };
                    synthesizer.SpeakAsync(message);
                    break;

                case "toast":
                    string[] words = message.Split(',');
                    if (words.Length >= 3)
                    {
                        string imageUrl = words[words.Length - 1];
                        _toastMessage.ShowImage(words, imageUrl);
                    }
                    else
                    {
                        _toastMessage.ShowText(words);
                    }
                    break;

                case "cmd":
                    ProcessStartInfo startInfo = new ProcessStartInfo(message)
                    {
                        WindowStyle = ProcessWindowStyle.Maximized
                    };

                    System.Diagnostics.Process.Start(startInfo);

                    break;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }