示例#1
0
        /// <summary>
        /// Opens, closes, or minimizes the application depending on the
        /// submitted command parameter.
        /// </summary>
        public override void Execute(object parameter)
        {
            if (!ServiceRegistration.IsRegistered <IAppController>())
            {
                return;
            }

            Window mainWindow = Application.Current.MainWindow;

            if (mainWindow == null)
            {
                return;
            }

            IAppController controller = ServiceRegistration.Get <IAppController>();

            switch ((string)parameter)
            {
            case "DoubleClick": // DoubleClick of TrayIcon
                if (mainWindow.Visibility == Visibility.Visible)
                {
                    // The window is opened => it should be hidden
                    controller.HideMainWindow();
                }
                else
                {
                    // The window is hidden => it should be shown
                    controller.ShowMainWindow();
                }
                break;

            case "Open":
                controller.ShowMainWindow();
                break;

            case "Quit":
                controller.CloseMainApplication();
                break;

            case "Hide":
                controller.HideMainWindow();
                break;

            case "Minimize":
                controller.HideMainWindow();
                break;

            case "StartService":
                // avoid any delay due to starting of the MP2 Server Service
                ServiceRegistration.Get <IThreadPool>().Add(() => controller.StartServerService());
                break;

            case "StopService":
                // avoid any delay due to stopping of the MP2 Server Service
                ServiceRegistration.Get <IThreadPool>().Add(() => controller.StopServerService());
                break;

            case "EnableAutoStart":
                controller.IsAutoStartEnabled = true;
                break;

            case "DisableAutoStart":
                controller.IsAutoStartEnabled = false;
                break;

            default:
                var msg = String.Format("ApplicationCommand fired with missing or invalid parameter: {0}", parameter);
                throw new InvalidOperationException(msg);
            }
        }