public static Control CreateFromXml(XmlElement element) { string xmltype = element.Attributes["type"].InnerText; Control control = null; ControlType type = (ControlType)Enum.Parse(typeof(ControlType), xmltype); switch (type) { case ControlType.label: control = new ControlLabel(); break; case ControlType.checkbox: control = new ControlCheckBox(); break; case ControlType.edit: control = new ControlEdit(); break; case ControlType.browse: control = new ControlBrowse(); break; case ControlType.license: control = new ControlLicense(); break; case ControlType.hyperlink: control = new ControlHyperlink(); break; case ControlType.image: control = new ControlImage(); break; default: throw new Exception(string.Format("Invalid type: {0}", xmltype)); } control.FromXml(element); return(control); }
public void TestUserControlCheckboxInstallCheck() { Console.WriteLine("TestUserControlCheckboxInstallCheck"); // a configuration with a checkbox control which has an installed check that disables it ConfigFile configFile = new ConfigFile(); SetupConfiguration setupConfiguration = new SetupConfiguration(); configFile.Children.Add(setupConfiguration); // a checkbox that changes are return value ControlCheckBox checkbox = new ControlCheckBox(); checkbox.UncheckedValue = "3"; checkbox.CheckedValue = "4"; checkbox.Checked = true; checkbox.Id = "checkbox1"; setupConfiguration.Children.Add(checkbox); // an installed check that is always false InstalledCheckRegistry check = new InstalledCheckRegistry(); check.path = @"SOFTWARE\KeyDoesntExist"; check.comparison = installcheckregistry_comparison.exists; checkbox.Children.Add(check); // command that depends on the value of checkbox1 ComponentCmd cmd = new ComponentCmd(); cmd.command = "cmd.exe /C exit /b [checkbox1]5"; cmd.required_install = true; setupConfiguration.Children.Add(cmd); // save config file string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); Console.WriteLine("Writing '{0}'", configFilename); configFile.SaveAs(configFilename); // execute dotNetInstaller, this checkbox is disabled, so all runs ignore checkbox1 value Assert.AreEqual(5, dotNetInstallerExeUtils.Run(configFilename)); checkbox.Checked = false; configFile.SaveAs(configFilename); Assert.AreEqual(5, dotNetInstallerExeUtils.Run(configFilename)); checkbox.Checked = true; checkbox.CheckedValue = "0"; configFile.SaveAs(configFilename); Assert.AreEqual(5, dotNetInstallerExeUtils.Run(configFilename)); File.Delete(configFilename); }
public static Control CreateFromXml(XmlElement element) { string xmltype = element.Attributes["type"].InnerText; Control control = null; ControlType type = (ControlType)Enum.Parse(typeof(ControlType), xmltype); switch (type) { case ControlType.label: control = new ControlLabel(); break; case ControlType.checkbox: control = new ControlCheckBox(); break; case ControlType.edit: control = new ControlEdit(); break; case ControlType.browse: control = new ControlBrowse(); break; case ControlType.license: control = new ControlLicense(); break; case ControlType.hyperlink: control = new ControlHyperlink(); break; case ControlType.image: control = new ControlImage(); break; default: throw new Exception(string.Format("Invalid type: {0}", xmltype)); } control.FromXml(element); return control; }
public void TestUserControlCheckboxControlArgs() { Console.WriteLine("TestUserControlCheckboxControlArgs"); // a configuration with a checkbox control ConfigFile configFile = new ConfigFile(); SetupConfiguration setupConfiguration = new SetupConfiguration(); configFile.Children.Add(setupConfiguration); // a checkbox that changes are return value ControlCheckBox checkbox = new ControlCheckBox(); checkbox.UncheckedValue = "3"; checkbox.CheckedValue = "4"; checkbox.Checked = true; checkbox.Id = "checkbox1"; setupConfiguration.Children.Add(checkbox); ComponentCmd cmd = new ComponentCmd(); cmd.command = "cmd.exe /C exit /b [checkbox1]"; cmd.required_install = true; setupConfiguration.Children.Add(cmd); // save config file string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); Console.WriteLine("Writing '{0}'", configFilename); configFile.SaveAs(configFilename); // execute dotNetInstaller dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions(); options.configFile = configFilename; // unchecked value options.args = "/controlArgs checkbox1:3"; Assert.AreEqual(3, dotNetInstallerExeUtils.Run(options)); // checked value options.args = "/controlArgs checkbox1:4"; Assert.AreEqual(4, dotNetInstallerExeUtils.Run(options)); // invalid value options.args = "/controlArgs checkbox1:5"; Assert.AreEqual(-1, dotNetInstallerExeUtils.Run(options)); File.Delete(configFilename); }