/// <summary> /// Method defining the actual work for a task. /// </summary> /// <param name="environment">The script execution environment.</param> protected override void DoExecute(IScriptExecutionEnvironment environment) { string input = environment.ReceiveInput(prompt); if (configurationSettingName != null) { environment.SetConfigSetting(configurationSettingName, input); } }
protected override void DoExecute(IScriptExecutionEnvironment environment) { try { using (ServiceController serviceController = new ServiceController(serviceName)) { // this should throw an exception if the service does not exist System.Runtime.InteropServices.SafeHandle serviceHandle = serviceController.ServiceHandle; environment.SetConfigSetting(configurationSetting, "true"); environment.LogMessage("Windows service '{0}' exists.", serviceName); } } catch (InvalidOperationException) { environment.SetConfigSetting(configurationSetting, "false"); environment.LogMessage( "Windows service '{0}' does not exist.", serviceName); } }
/// <summary> /// Internal task execution code. /// </summary> /// <param name="environment">The script execution environment.</param> protected override void DoExecute(IScriptExecutionEnvironment environment) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlFileName); XmlNode node = xmlDoc.SelectSingleNode("Configuration"); if (node != null) { environment.SetConfigSetting(configurationSettingName, node.InnerText); } }
protected override void DoExecute(IScriptExecutionEnvironment environment) { using (RegistryKey key = rootKey.OpenSubKey(registryKeyPath, false)) { if (key == null) { throw new RunnerFailedException( String.Format( System.Globalization.CultureInfo.InvariantCulture, "Registry key '{0}' does not exist.", registryKeyPath)); } environment.SetConfigSetting( configurationSettingName, Convert.ToString(key.GetValue(registryValueName), System.Globalization.CultureInfo.InvariantCulture)); } }
/// <summary> /// Internal task execution code. /// </summary> /// <param name="environment">The script execution environment.</param> protected override void DoExecute(IScriptExecutionEnvironment environment) { XmlDocument xmlDoc = new XmlDocument(); if (configurationString != null) { xmlDoc.LoadXml(configurationString); } else if (configurationFileName != null) { xmlDoc.Load(configurationFileName); } else { throw new RunnerFailedException("Either the configuration string or the configuration fileName has to be set."); } XmlNode configurationRootNode = xmlDoc.SelectSingleNode("Configuration"); XmlNodeList nodes = xmlDoc.SelectNodes("Configuration//*"); foreach (XmlNode node in nodes) { if (node.InnerText == node.InnerXml) { StringBuilder settingName = new StringBuilder(); string terminator = null; for (XmlNode parentNode = node; parentNode != null && parentNode != configurationRootNode; parentNode = parentNode.ParentNode) { settingName.Insert(0, terminator); settingName.Insert(0, parentNode.Name); terminator = "/"; } environment.LogMessage( "Configuration setting '{0}' has value '{1}'", settingName, node.InnerText); environment.SetConfigSetting(settingName.ToString(), node.InnerText); } } }