/// <summary> /// Begins the processing. /// </summary> protected override void BeginProcessing() { try { // Get the directory where the service is installed RegistryKey subKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\CloudInit"); String imagePath = subKey.GetValue("ImagePath") as String; String directory = imagePath.Replace("CloudInit.exe", String.Empty); // Load all the assemblies and scan the types CIAssemblyLoader.Configure(directory); // Make a list of all the providers Hashtable providers = new Hashtable(); foreach (var type in CIAssemblyLoader.ScanFor <INotificationProvider>()) { INotificationProvider obj = Activator.CreateInstance(type) as INotificationProvider; providers.Add(obj.ProviderName, type); } WriteObject(providers); } catch (Exception ex) { WriteError(new ErrorRecord(ex, String.Empty, ErrorCategory.InvalidOperation, this)); } }
/// <summary> /// Begins the processing /// </summary> protected override void BeginProcessing() { try { // Get the directory where the service is installed RegistryKey subKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\CloudInit"); String imagePath = subKey.GetValue("ImagePath") as String; String directory = imagePath.Replace("CloudInit.exe", String.Empty); // Load all the assemblies and scan the types CIAssemblyLoader.Configure(directory); foreach (var type in CIAssemblyLoader.ScanFor <INotificationProvider>()) { INotificationProvider obj = Activator.CreateInstance(type) as INotificationProvider; if (obj.ProviderName == this.providerName) { RegistryKey settingKey = Registry.LocalMachine.OpenSubKey(obj.SettingsPath, true); List <String> settings = new List <String>(settingKey.GetValueNames()); // First make sure the setting exists, we don't want them typing in the name of the setting wrong if (settings.Exists((s) => { return(s.CompareTo(this.name) == 0); })) { settingKey.SetValue(this.name, this.value); WriteObject("OK-SettingUpdated"); } else { // Invalid name so throw an exception throw new ArgumentException("Invalid CloudInit setting", "Name"); } return; } } // Provider was not found WriteObject("Error-NoProviderFound"); } catch (Exception ex) { WriteError(new ErrorRecord(ex, String.Empty, ErrorCategory.InvalidOperation, this)); } }
/// <summary> /// Begins the processing. /// </summary> protected override void BeginProcessing() { try { // Get the directory where the service is installed RegistryKey subKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\CloudInit"); String imagePath = subKey.GetValue("ImagePath") as String; String directory = imagePath.Replace("CloudInit.exe", String.Empty); // Load all the assemblies and scan the types CIAssemblyLoader.Configure(directory); foreach (var type in CIAssemblyLoader.ScanFor <INotificationProvider>()) { INotificationProvider obj = Activator.CreateInstance(type) as INotificationProvider; if (obj.ProviderName == this.providerName) { RegistryKey settingKey = Registry.LocalMachine.OpenSubKey(obj.SettingsPath, true); Hashtable settings = new Hashtable(); // Write all the settings in the settings folder foreach (String name in settingKey.GetValueNames()) { settings.Add(name, settingKey.GetValue(name)); } WriteObject(settings); return; } } // Provider was not found WriteObject("Error-NoProviderFound"); } catch (Exception ex) { WriteError(new ErrorRecord(ex, String.Empty, ErrorCategory.InvalidOperation, this)); } }