private static FeatureCommandsCollection CreateCommandsImpl(IEnumerable <IISFeature> features, CommandOptions commandOptions) { var commands = new FeatureCommandsCollection(); try { bool internetInformationServerIsPresent = RegistryOperations.CheckMachineKey(@"SOFTWARE\Microsoft\InetStp"); if (!internetInformationServerIsPresent) { // IIS not installed > :-( Begin installation commands.Add(FeatureCommand.Create("IIS-DefaultDocument", "All")); } commands.InternetInformationServerIsPresent = internetInformationServerIsPresent; // IIS installed // > Enable All Features > Install foreach (IISFeature feature in features) { commands.Add(FeatureCommand.Create(feature, options: commandOptions)); } return(commands); } catch { return(commands); } }
// Configures IIS features from custom features public static void ExecuteFromCustomFeatures() { Console.WriteLine(string.Empty); Console.WriteLine($@"> Configures IIS features from custom features"); FeatureCommandsCollection commands = Configurator.CreateCommands(Configurator.GetAllFeatures(), CommandOptions.SilentModeDeactivated); commands.NotifyFeatureCommandCollectionExecuting += NotifyFeatureCommandCollectionExecuting; commands.NotifyFeatureCommandCollectionExecuted += NotifyFeatureCommandCollectionExecuted; commands.NotifyFeatureCommandsCollectionStart += NotifyFeatureCommandsCollectionStart; commands.NotifyFeatureCommandsCollectionFinish += NotifyFeatureCommandsCollectionFinish; commands.Process(); }
// Configures IIS features from XML configuration file public static void ExecuteFromXmlFile() { Console.WriteLine(); Console.WriteLine($@"> Configures IIS features from XML configuration file"); IISModel model = IISModel.LoadFromFile("~\\resources\\IIS-Features.xml"); FeatureCommandsCollection commands = Configurator.CreateCommands(model, CommandOptions.SilentModeDeactivated); commands.NotifyFeatureCommandCollectionExecuting += NotifyFeatureCommandCollectionExecuting; commands.NotifyFeatureCommandCollectionExecuted += NotifyFeatureCommandCollectionExecuted; commands.NotifyFeatureCommandsCollectionStart += NotifyFeatureCommandsCollectionStart; commands.NotifyFeatureCommandsCollectionFinish += NotifyFeatureCommandsCollectionFinish; commands.Process(); }
/// <summary> /// Initializes a new instance of the <see cref="NotifyFeatureCommandsCollectionStartEventArgs"/> class. /// </summary> /// <param name="commands">Reference to commands collection</param> public NotifyFeatureCommandsCollectionStartEventArgs(FeatureCommandsCollection commands) { InternetInformationServerIsPresent = commands?.InternetInformationServerIsPresent ?? false; }