Пример #1
0
        private void SaveScanSettings()
        {
            SettingsDAO settingsDao = new SettingsDAO();

            settingsDao.SetSetting("AutoScanIntervalValue", tbScanInterval.Text, false);
            settingsDao.SetSetting("AutoScanNetwork", Convert.ToString(cbEnableScan.Checked), false);
            settingsDao.SetSetting("AutoScanDeployAgent", Convert.ToString(cbDeployAgent.Checked), false);
            settingsDao.SetSetting("AutoScanIntervalUnits", Convert.ToString(cbScanInterval.SelectedItem.ToString()), false);

            AuditWizardServiceController _serviceController = new Layton.AuditWizard.Common.AuditWizardServiceController();

            LaytonServiceController.ServiceStatus serviceStatus = _serviceController.CheckStatus();

            if (serviceStatus == LaytonServiceController.ServiceStatus.Running)
            {
                _serviceController.RestartService();
            }
            else
            {
                if (serviceStatus != LaytonServiceController.ServiceStatus.NotInstalled)
                {
                    _serviceController.Start();
                }
            }

            DesktopAlert.ShowDesktopAlert("Settings have been updated.");
        }
        /// <summary>
        /// Start the service - note that if it is currently not installed we will need to install
        /// it first and then start it.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bnStart_Click(object sender, EventArgs e)
        {
            // Get the current status of the Service
            LaytonServiceController.ServiceStatus serviceStatus = _serviceController.CheckStatus();

            // Update the configuration both locally and in the service controller
            if (SaveConfiguration())
            {
                _serviceController.ResetCredentials();

                using (new WaitCursor())
                {
                    // Now install the service (Under the specified username / password) unless it is already
                    // installed
                    try
                    {
                        if (serviceStatus == LaytonServiceController.ServiceStatus.NotInstalled)
                        {
                            _serviceController.Install();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(String.Format("Failed to install the AuditWizard Service, the error was {0}", ex.Message), "Service Control Error");
                        return;
                    }

                    // OK now start the service
                    try
                    {
                        _serviceController.Start();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(String.Format("Failed to start the AuditWizard Service, the error was {0}", ex.Message), "Service Control Error");
                        return;
                    }

                    // Now wait a few seconds and recover the latest status
                    Thread.Sleep(2000);

                    // ...and update the display
                    SetDisplayStates();
                }
            }
        }