示例#1
0
        /// <summary>
        /// Put the computer into Standby in a MediaPortal friendly way.
        /// </summary>
        public static void Standby()
        {
            bool mpBasicHome;

            using (Settings xmlreader = new Settings(MPConfigFile))
                mpBasicHome = xmlreader.GetValueAsBool("general", "startbasichome", false);

            GUIGraphicsContext.ResetLastActivity();
            // Stop all media before suspending
            g_Player.Stop();

            GUIMessage msg;

            if (mpBasicHome)
            {
                msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0,
                                     (int)GUIWindow.Window.WINDOW_SECOND_HOME, 0, null);
            }
            else
            {
                msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)GUIWindow.Window.WINDOW_HOME, 0,
                                     null);
            }

            GUIWindowManager.SendThreadMessage(msg);

            WindowsController.ExitWindows(RestartOptions.Suspend, false);
        }
示例#2
0
        /// <summary>
        /// Invoked based on condition or 10-second timer.  Displays
        /// tooltip, then performs specified action if not cancelled.
        /// </summary>
        private void TakeAction()
        {
            string action = selectedAction.ToString();

            // If timer ticks with Disabled checked, it is immediate action
            if (waitingOnCondition == null)
            {
                timeBasedTimer.Stop();
                appNotifyIcon.Visible = false;
                appNotifyIcon.Visible = true;

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    MessageBox.Show("In debug mode: Action not taken");
                }
                else
                {
                    WindowsController.ExitWindows(selectedAction, false);
                }
            }
            // Otherwise, provide ten second warning
            else
            {
                waitingOnCondition.StopMonitoring();
                conditionComboBox.SelectedIndex = 0;

                appNotifyIcon.BalloonTipText = "The system will " + action + " in ten seconds.  Click to cancel.";
                appNotifyIcon.ShowBalloonTip(10);

                timeBasedTimer.Interval = 10000;
                timeBasedTimer.Start();
            }
        }
示例#3
0
        /// <summary>
        /// Shutdown/hibernate/reboot the htpc or exit mediaportal
        /// </summary>
        /// <param name="shutdownType">logoff|suspend|hibernate|reboot|shutdown|exit</param>
        public void SetPowerMode(String powerMode)
        {
            switch (powerMode.ToLower())
            {
            case "logoff":
                WindowsController.ExitWindows(RestartOptions.LogOff, true);
                break;

            case "suspend":
                WindowsController.ExitWindows(RestartOptions.Suspend, true);
                break;

            case "hibernate":
                WindowsController.ExitWindows(RestartOptions.Hibernate, true);
                break;

            case "reboot":
                WindowsController.ExitWindows(RestartOptions.Reboot, true);
                break;

            case "shutdown":
                WindowsController.ExitWindows(RestartOptions.ShutDown, true);
                break;

            case "exit":
                MediaPortal.GUI.Library.Action action = new MediaPortal.GUI.Library.Action(MediaPortal.GUI.Library.Action.ActionType.ACTION_EXIT, 0, 0);
                GUIGraphicsContext.OnAction(action);
                break;
            }
        }
示例#4
0
        /// <summary>
        /// Execute this command.
        /// </summary>
        /// <param name="variables">The variable list of the calling code.</param>
        public override void Execute(VariableList variables)
        {
            bool mpBasicHome = false;

            using (Settings xmlreader = new Settings(MPCommon.MPConfigFile))
                mpBasicHome = xmlreader.GetValueAsBool("general", "startbasichome", false);

            GUIGraphicsContext.ResetLastActivity();
            // Stop all media before hibernating
            g_Player.Stop();

            GUIMessage msg;

            if (mpBasicHome)
            {
                msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0,
                                     (int)GUIWindow.Window.WINDOW_SECOND_HOME, 0, null);
            }
            else
            {
                msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)GUIWindow.Window.WINDOW_HOME, 0,
                                     null);
            }

            GUIWindowManager.SendThreadMessage(msg);

            WindowsController.ExitWindows(RestartOptions.Hibernate, false);
        }
示例#5
0
 private void RestartSys_Click(object sender, HtmlElementEventArgs e)
 {
     if (MessageBox.Show("确定要重启机器?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
     {
         WindowsController.ExitWindows(RestartOptions.Reboot, true);
         Sleep(5000);
     }
 }
示例#6
0
        private void timerTick_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            TimeSpan remaining = endTime - DateTime.Now;

            if (remaining.TotalSeconds < 0)
            {
                timerTick.Enabled = false;
                RestartOptions option = (RestartOptions)comboBoxRestartType.SelectedValue;
                WindowsController.ExitWindows(option, checkBoxForce.Checked);
            }

            maskedTextBoxTime.Text = remaining.ToString();
        }
示例#7
0
        //Apply selected settings and reboot
        private void buttonReboot_Click(object sender, EventArgs e)
        {
            if (this.testConfig())
            {
                PwrMzrSettings pm = this.collectDataFromControls();

                try
                {
                    if (MessageBox.Show("The changes will be applied to the registry.", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        this.pwrmzrManager.changePowermizerSettings(pm);
                    }
                    else
                    {
                        return;
                    }
                }
                catch
                {
                    //All errors logged
                    MessageBox.Show("Could't change powermizer settings. Check debug console for more details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                try
                {
                    if (MessageBox.Show("Do you want to reboot NOW?. Click NO if you want to reboot manually.", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        WindowsController.ExitWindows(RestartOptions.Reboot, false);
                    }
                    else
                    {
                        return;
                    }
                }
                catch
                {
                    log("Error while rebooting!. Try rebooting manually.");
                    return;
                }
            }
        }
示例#8
0
    public static void Main()
    {
        Console.WriteLine("Restart Program\r\n--------------\r\n\r\n Select the restart mode:\r\n   l - LogOff\r\n   p - PowerOff\r\n   r - Reboot\r\n   s - Shutdown\r\n   u - Suspend\r\n   h - Hibernate\r\n   c - Exit the program\r\n\r\n Make your choice: ");
        string input = Console.ReadLine();

        switch (input.ToLower())
        {
        case "l":
            WindowsController.ExitWindows(RestartOptions.LogOff, false);
            break;

        case "p":
            WindowsController.ExitWindows(RestartOptions.PowerOff, false);
            break;

        case "r":
            WindowsController.ExitWindows(RestartOptions.Reboot, false);
            break;

        case "s":
            WindowsController.ExitWindows(RestartOptions.ShutDown, false);
            break;

        case "u":
            WindowsController.ExitWindows(RestartOptions.Suspend, false);
            break;

        case "h":
            WindowsController.ExitWindows(RestartOptions.Hibernate, false);
            break;

        case "c":
            return;

            break;

        default:
            Console.WriteLine("Invalid input...");
            break;
        }
    }
示例#9
0
 public void OnTimeTick(int count)
 {
     if (step == 3)
     {
         if (readyTime == 0)
         {
             Initialized = true;
             StartActivity("主界面");
         }
         else
         {
             GetElementById("procNum").InnerText = (readyTime--).ToString();
         }
     }
     if (step == 1)
     {
         if (initTime++ == restartTime)
         {
             WindowsController.ExitWindows(RestartOptions.Reboot, true);
             System.Threading.Thread.Sleep(5000);
         }
     }
 }
示例#10
0
        /// <summary>
        /// Evaluates the button number, gets its mapping and executes the action
        /// </summary>
        /// <param name="btnCode">Button code (ref: XML file)</param>
        /// <param name="processID">Process-ID for close/kill commands</param>
        private bool DoMapAction(string btnCode, int processID)
        {
            if (!_isLoaded) // No mapping loaded
            {
                Log.Info("Map: No button mapping loaded");
                return(false);
            }
            Mapping map = null;

            map = GetMapping(btnCode);
            if (map == null)
            {
                return(false);
            }

            Log.Debug("{0} / {1} / {2} / {3}", map.Condition, map.ConProperty, map.Command, map.CmdProperty);

            Action action;

            if (map.Sound != string.Empty) // && !g_Player.Playing)
            {
                Util.Utils.PlaySound(map.Sound, false, true);
            }
            if (map.Focus && !GUIGraphicsContext.HasFocus)
            {
                GUIGraphicsContext.ResetLastActivity();
                GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GETFOCUS, 0, 0, 0, 0, 0, null);
                GUIWindowManager.SendThreadMessage(msg);
                return(true);
            }
            switch (map.Command)
            {
            case "ACTION": // execute Action x
                Key key = new Key(map.CmdKeyChar, map.CmdKeyCode);

                Log.Debug("Executing: key {0} / {1} / Action: {2} / {3}", map.CmdKeyChar, map.CmdKeyCode, map.CmdProperty,
                          ((Action.ActionType)Convert.ToInt32(map.CmdProperty)).ToString());

                action = new Action(key, (Action.ActionType)Convert.ToInt32(map.CmdProperty), 0, 0);
                GUIGraphicsContext.OnAction(action);
                break;

            case "KEY": // send Key x
                SendKeys.SendWait(map.CmdProperty);
                break;

            case "WINDOW": // activate Window x
                GUIGraphicsContext.ResetLastActivity();
                GUIMessage msg;
                if ((Convert.ToInt32(map.CmdProperty) == (int)GUIWindow.Window.WINDOW_HOME) ||
                    (Convert.ToInt32(map.CmdProperty) == (int)GUIWindow.Window.WINDOW_SECOND_HOME))
                {
                    if (_basicHome)
                    {
                        msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0,
                                             (int)GUIWindow.Window.WINDOW_SECOND_HOME, 0, null);
                    }
                    else
                    {
                        msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0,
                                             (int)GUIWindow.Window.WINDOW_HOME, 0, null);
                    }
                }
                else
                {
                    msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, Convert.ToInt32(map.CmdProperty),
                                         0, null);
                }

                GUIWindowManager.SendThreadMessage(msg);
                break;

            case "TOGGLE": // toggle Layer 1/2
                if (_currentLayer == 1)
                {
                    _currentLayer = 2;
                }
                else
                {
                    _currentLayer = 1;
                }
                break;

            case "POWER": // power down commands

                if ((map.CmdProperty == "STANDBY") || (map.CmdProperty == "HIBERNATE"))
                {
                    GUIGraphicsContext.ResetLastActivity();

                    //Stop all media before suspending or hibernating
                    if (g_Player.Playing)
                    {
                        GUIWindowManager.SendThreadCallbackAndWait(StopPlayback, 0, 0, null);
                    }

                    // this is all handled in mediaportal.cs - OnSuspend

                    /*
                     * if (_basicHome)
                     * msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)GUIWindow.Window.WINDOW_SECOND_HOME, 0, null);
                     * else
                     * msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)GUIWindow.Window.WINDOW_HOME, 0, null);
                     *
                     * GUIWindowManager.SendThreadMessage(msg);
                     */
                }

                switch (map.CmdProperty)
                {
                case "EXIT":
                    action = new Action(Action.ActionType.ACTION_EXIT, 0, 0);
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "REBOOT":
                    action = new Action(Action.ActionType.ACTION_REBOOT, 0, 0);
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "SHUTDOWN":
                    action = new Action(Action.ActionType.ACTION_SHUTDOWN, 0, 0);
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "STANDBY":
                    // we need a slow standby (force=false), in order to have the onsuspend method being called on mediportal.cs
                    // this is needed in order to have "ShowLastActiveModule" working correctly.
                    // also using force=true results in a silent non critical D3DERR_DEVICELOST exception when resuming from powerstate.
                    MPControlPlugin.OnSuspend();
                    WindowsController.ExitWindows(RestartOptions.Suspend, false);
                    break;

                case "HIBERNATE":
                    // we need a slow hibernation (force=false), in order to have the onsuspend method being called on mediportal.cs
                    // this is needed in order to have "ShowLastActiveModule" working correctly.
                    // also using force=true results in a silent non critical D3DERR_DEVICELOST exception when resuming from powerstate.
                    MPControlPlugin.OnSuspend();
                    WindowsController.ExitWindows(RestartOptions.Hibernate, false);
                    break;
                }
                break;

            case "PROCESS":
            {
                GUIGraphicsContext.ResetLastActivity();
                if (processID > 0)
                {
                    Process proc = Process.GetProcessById(processID);
                    if (null != proc)
                    {
                        switch (map.CmdProperty)
                        {
                        case "CLOSE":
                            proc.CloseMainWindow();
                            break;

                        case "KILL":
                            proc.Kill();
                            break;
                        }
                    }
                }
            }
            break;

            case "BLAST":
                MPControlPlugin.ProcessCommand(map.CmdProperty, true);
                break;

            default:
                return(false);
            }
            return(true);
        }
示例#11
0
 /// <summary>
 /// //Restart System
 /// </summary>
 public static void Restart()
 {
     WindowsController.ExitWindows(RestartOptions.Reboot, true);
 }
示例#12
0
文件: Client.cs 项目: Jonah0x90/WiFi
 private void Timer_Count_Tick(object sender, EventArgs e)
 {
     WindowsController.ExitWindows(RestartOptions.PowerOff, true);
 }
示例#13
0
        /// <summary>
        /// Event handler for Immediate menu option --
        /// triggers power management event without condition.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void immediateMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;

            WindowsController.ExitWindows((RestartOptions)(item.Tag), true);
        }
示例#14
0
 /// <summary>
 /// //Hibernate system
 /// </summary>
 public static void hibernate()
 {
     WindowsController.ExitWindows(RestartOptions.Hibernate, true);
 }
示例#15
0
 /// <summary>
 /// //Suspend System
 /// </summary>
 public static void Suspend()
 {
     WindowsController.ExitWindows(RestartOptions.Suspend, true);
 }
示例#16
0
 /// <summary>
 /// //Shut System down
 /// </summary>
 public static void Shutdown()
 {
     WindowsController.ExitWindows(RestartOptions.ShutDown, true);
 }
示例#17
0
        private void SystemTimer_Tick(object sender, EventArgs e)
        {
            DateTime now = DateTime.Now;

            if (this.ucCheckBox_CloseTime.Checked && ((int)(now.TimeOfDay.TotalSeconds)).Equals((int)this.CloseTime.TimeOfDay.TotalSeconds))
            {
                MessageBox.Show("系统将于60s后自动关机,请及时关闭保存文件!", "番茄钟", MessageBoxButtons.OK, MessageBoxIcon.Information);
                CancelShutDown = new CancellationTokenSource();
                new Thread(() => {
                    int count = 0;
                    this.Invoke(new Action(() =>
                    {
                        this.timer.Enabled = true;
                        this.btn_Play_Click(null, null);
                        this.player.Stop();
                    }));
                    while (count < 60)
                    {
                        count++;
                        if (CancelShutDown.IsCancellationRequested == true)
                        {
                            return;
                        }
                        this.WorkingState.Text = String.Format("{0}S后关闭系统", 60 - count);
                        Thread.Sleep(1000);
                    }

                    if (MessageBox.Show("系统即将关机,请确认文件是否全部保存确定立即关机,取消进入休眠模式!", "番茄钟", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        WindowsController.ExitWindows(RestartOptions.PowerOff, false);
                    }
                    else
                    {
                        WindowsController.ExitWindows(RestartOptions.Hibernate, false);
                    }
                }).Start();
            }
            string flag = "";

            if (now.Hour > 0 && now.Hour <= 5)
            {
                flag = "凌晨";
            }
            else if (now.Hour > 5 && now.Hour <= 7)
            {
                flag = "早晨";
            }
            else if (now.Hour > 7 && now.Hour <= 11)
            {
                flag = "上午";
            }
            else if (now.Hour > 11 && now.Hour <= 13)
            {
                flag = "中午";
            }
            else if (now.Hour > 13 && now.Hour <= 17)
            {
                flag = "下午";
            }
            else if (now.Hour > 17 && now.Hour <= 19)
            {
                flag = "傍晚";
            }
            else if (now.Hour > 19 && now.Hour <= 23)
            {
                flag = "晚上";
            }
            else if (now.Hour > 23 && now.Hour <= 0)
            {
                flag = "子夜";
            }
            this.label1.Text = now.Year.ToString() + "/" + now.Month.ToString() + "/" + now.Day.ToString() + " " + flag + now.Hour.ToString("D2") + ":" + now.Minute.ToString("D2") + ":" + now.Second.ToString("D2");
            if ((now.Minute == 0 || now.Minute == 30) && now.Second == 20)
            {
                new Thread(() => {
                    string minutes = "";
                    if (now.Minute == 30)
                    {
                        minutes = "半";
                    }
                    TTSUtils.SayChinese("现在是:" + flag + (now.Hour % 12).ToString() + "点" + minutes);
                }).Start();
            }
        }
示例#18
0
 /// <summary>
 /// //Log system off
 /// </summary>
 public static void Log_off()
 {
     WindowsController.ExitWindows(RestartOptions.LogOff, true);
 }