private void settingsCommand(object sender, EventArgs e)
        {
            using (ServiceController pmsService = new ServiceController(serviceName))
            {
            SettingsWindow settings = new SettingsWindow();
            if (settings.ShowDialog() == true && pmsService.Status == ServiceControllerStatus.Running)
            {
                if (MessageBox.Show("Settings changed, do you want to restart the service?", "Settings changed!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                        try
                        {
                            pmsService.Stop();
                            pmsService.WaitForStatus(ServiceControllerStatus.Stopped, timeOut);
                            pmsService.Start();
                            pmsService.WaitForStatus(ServiceControllerStatus.Running, timeOut);
                        }
                        catch (System.ComponentModel.Win32Exception ex)
                        {
                            MessageBox.Show("Unable to restart service" + Environment.NewLine + ex.Message);
                        }

                }
            }
            }
        }
        /// <summary>
        /// Show the settings dialogue
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SettingsCommand(object sender, EventArgs e)
        {
            if (_plexService != null)
            {
                Settings settings = null;
                try
                {
                    settings = Settings.Deserialize(_plexService.GetSettings());
                }
                catch
                {
                    Disconnect();
                }

                if (settings != null)
                {
                    //Save the current server port setting for reference
                    int oldPort = settings.ServerPort;
                    SettingsWindowViewModel settingsViewModel = new SettingsWindowViewModel(settings);
                    settingsViewModel.AuxAppStartRequest += (s, args) =>
                    {
                        var requester = s as AuxiliaryApplicationViewModel;
                        if (requester != null)
                        {
                            _plexService.StartAuxApp(requester.Name);
                            requester.Running = _plexService.IsAuxAppRunning(requester.Name);
                        }
                    };
                    settingsViewModel.AuxAppStopRequest += (s, args) =>
                    {
                        var requester = s as AuxiliaryApplicationViewModel;
                        if(requester != null)
                        {
                            _plexService.StopAuxApp(requester.Name);
                            requester.Running = _plexService.IsAuxAppRunning(requester.Name);
                        }
                    };
                    settingsViewModel.AuxAppCheckRunRequest += (s, args) =>
                    {
                        var requester = s as AuxiliaryApplicationViewModel;
                        if (requester != null)
                        {
                            requester.Running = _plexService.IsAuxAppRunning(requester.Name);
                        }
                    };
                    SettingsWindow settingsWindow = new SettingsWindow(settingsViewModel);
                    if (settingsWindow.ShowDialog() == true)
                    {
                        PlexState status = PlexState.Pending;
                        try
                        {
                            _plexService.SetSettings(settingsViewModel.WorkingSettings.Serialize());
                            status = _plexService.GetStatus();
                        }
                        catch(Exception ex)
                        {
                            Disconnect();
                            MessageBox.Show("Unable to save settings" + Environment.NewLine + ex.Message);
                        }
                        //The only setting that would require a restart of the service is the listening port.
                        //If that gets changed notify the user to restart the service from the service snap in
                        if (settingsViewModel.WorkingSettings.ServerPort != oldPort)
                        {
                            MessageBox.Show("Server port changed! You will need to restart the service from the services snap in for the change to be applied", "Settings changed!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Show the settings dialogue
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SettingsCommand(object sender, EventArgs e)
        {
            if (_plexService != null)
            {
                Settings settings = null;
                try
                {
                    settings = Settings.Deserialize(_plexService.GetSettings());
                }
                catch
                {
                    Disconnect();
                }

                if (settings != null)
                {
                    //Save the current server port setting for reference
                    int oldPort = settings.ServerPort;
                    SettingsWindowViewModel settingsViewModel = new SettingsWindowViewModel(settings);
                    settingsViewModel.AuxAppStartRequest += (s, args) =>
                    {
                        var requester = s as AuxiliaryApplicationViewModel;
                        if (requester != null)
                        {
                            _plexService.StartAuxApp(requester.Name);
                            requester.Running = _plexService.IsAuxAppRunning(requester.Name);
                        }
                    };
                    settingsViewModel.AuxAppStopRequest += (s, args) =>
                    {
                        var requester = s as AuxiliaryApplicationViewModel;
                        if (requester != null)
                        {
                            _plexService.StopAuxApp(requester.Name);
                            requester.Running = _plexService.IsAuxAppRunning(requester.Name);
                        }
                    };
                    settingsViewModel.AuxAppCheckRunRequest += (s, args) =>
                    {
                        var requester = s as AuxiliaryApplicationViewModel;
                        if (requester != null)
                        {
                            requester.Running = _plexService.IsAuxAppRunning(requester.Name);
                        }
                    };
                    _settingsWindow = new SettingsWindow(settingsViewModel);
                    if (_settingsWindow.ShowDialog() == true)
                    {
                        PlexState status = PlexState.Pending;
                        try
                        {
                            _plexService.SetSettings(settingsViewModel.WorkingSettings.Serialize());
                            status = _plexService.GetStatus();
                        }
                        catch (Exception ex)
                        {
                            Disconnect();
                            System.Windows.MessageBox.Show("Unable to save settings" + Environment.NewLine + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        }
                        //The only setting that would require a restart of the service is the listening port.
                        //If that gets changed notify the user to restart the service from the service snap in
                        if (settingsViewModel.WorkingSettings.ServerPort != oldPort)
                        {
                            System.Windows.MessageBox.Show("Server port changed! You will need to restart the service from the services snap in for the change to be applied", "Settings changed!", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                    }
                    _settingsWindow = null;
                }
            }
        }