/// <summary> /// Over-ride the base class Install function so that we can do more of the tasks in one go /// </summary> /// <returns></returns> public override void Install() { LogFile ourLog = LogFile.Instance; ourLog.Write("AuditAgentServiceController::Install", true); // First lets see iwhat the current status of the servie is LaytonServiceController.ServiceStatus serviceStatus = CheckStatus(); // If we cannot connect then throw this as an exception if (serviceStatus == ServiceStatus.UnableToConnect) { ThrowWin32Error(_lastWin32Error); } // If the service shows any sign of being installed then remove it first if (serviceStatus != ServiceStatus.NotInstalled) { Remove(); } // Construct the list of files that the agent will need to be copied to the remote computer string sourcePath = Path.Combine(Application.StartupPath, AuditAgentStrings.AuditAgentFilesPath); List <string> listFiles = new List <string>(); listFiles.Add(Path.Combine(sourcePath, AuditWizardAgentExe)); listFiles.Add(Path.Combine(sourcePath, AuditWizardAgentIni)); // Copy the files to the remote Asset // The caller should catch any exceptions thrown as we do not want to continue after a failure CopyFilesToRemote(listFiles); // Now install the service base.Install(); }
/// <summary> /// Display the appropriate service status indicator /// </summary> protected void ShowAuditWizardServiceStatus() { LaytonServiceController.ServiceStatus serviceStatus = _AuditWizardServiceController.CheckStatus(); switch (serviceStatus) { case LaytonServiceController.ServiceStatus.Running: pbAuditWizardServiceStatus.Image = Properties.Resources.active; break; case LaytonServiceController.ServiceStatus.Stopped: pbAuditWizardServiceStatus.Image = Properties.Resources.stopped; break; case LaytonServiceController.ServiceStatus.NotInstalled: pbAuditWizardServiceStatus.Image = Properties.Resources.notinstalled; break; default: pbAuditWizardServiceStatus.Image = Properties.Resources.unavailable; break; } // Get the setting for the 'Ping' check box Configuration config = ConfigurationManager.OpenExeConfiguration(Path.Combine(Application.StartupPath, "AuditWizardv8.exe")); try { cbUsePing.Checked = Convert.ToBoolean(config.AppSettings.Settings["PingConnections"].Value); } catch (Exception) { cbUsePing.Checked = true; } }
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(); } } }
/// <summary> /// Called to return and update the current status of the specified (named) asset /// </summary> /// <param name="assetName"></param> /// <param name="assetStatus"></param> /// <param name="message"></param> protected int UpdateCurrentAgentStatus(string assetName, int assetID, out Asset.AGENTSTATUS assetStatus, out string message) { // Get the Agent Service Controller passing it the name of the computer AuditAgentServiceController agentServiceController = new AuditAgentServiceController(assetName); // Use it to get the current status of the asset LaytonServiceController.ServiceStatus serviceStatus = agentServiceController.CheckStatus(); assetStatus = Asset.AGENTSTATUS.notdeployed; switch (serviceStatus) { case LaytonServiceController.ServiceStatus.Running: assetStatus = Asset.AGENTSTATUS.Running; break; case LaytonServiceController.ServiceStatus.Stopped: assetStatus = Asset.AGENTSTATUS.deployed; break; case LaytonServiceController.ServiceStatus.NotInstalled: assetStatus = Asset.AGENTSTATUS.notdeployed; break; case LaytonServiceController.ServiceStatus.UnableToConnect: message = "Error: Could not connect to remote computer, please check that it is turned on"; return(-1); default: message = "Error: An Invalid or Unknown Status was returned"; return(-1); } // Update the status of the computer in the database if we were successful message = Asset.TranslateDeploymentStatus(assetStatus); AssetDAO lwDataAccess = new AssetDAO(); lwDataAccess.AssetUpdateAssetStatus(assetID, assetStatus); return(0); }
/// <summary> /// Set the state of the various buttons and other fields on this form based on the /// current state of the service /// </summary> /// <param name="serviceStatus"></param> private void SetDisplayStates() { // Get the current status of the service LaytonServiceController.ServiceStatus serviceStatus = _serviceController.CheckStatus(); // Select the appropriate status image to show switch (serviceStatus) { case LaytonServiceController.ServiceStatus.Running: pbServiceStatus.Image = Properties.Resources.active; break; case LaytonServiceController.ServiceStatus.Stopped: pbServiceStatus.Image = Properties.Resources.stopped; break; case LaytonServiceController.ServiceStatus.NotInstalled: pbServiceStatus.Image = Properties.Resources.notinstalled; break; default: pbServiceStatus.Image = Properties.Resources.unavailable; break; } // The start button is valid so long as the service is currently in a 'stopped' or // 'not installed' state bnStart.Enabled = ((serviceStatus == LaytonServiceController.ServiceStatus.NotInstalled) || (serviceStatus == LaytonServiceController.ServiceStatus.Stopped)); // Stop is enabled if the service is currently in a 'Running' State bnStop.Enabled = (serviceStatus == LaytonServiceController.ServiceStatus.Running); // Remove is enabled if the service is stopped bnRemove.Enabled = (serviceStatus == LaytonServiceController.ServiceStatus.Stopped); // We cannot change the logon credentials UNLESS the service is stopped panelLogonCredentials.Enabled = (serviceStatus == LaytonServiceController.ServiceStatus.NotInstalled); }