Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 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 TestUserControlEditHtmlValues()
        {
            Console.WriteLine("TestUserControlEditHtmlValues");

            bool usingHtmlInstaller = dotNetInstallerExeUtils.Executable.EndsWith("htmlInstaller.exe");
            if (!usingHtmlInstaller) return;

            // a configuration with a checkbox control
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            setupConfiguration.auto_start = true;
            setupConfiguration.failed_exec_command_continue = "";
            setupConfiguration.auto_close_on_error = true;
            configFile.Children.Add(setupConfiguration);
            ControlEdit edit = new ControlEdit();
            edit.Text = "3";
            edit.Id = "edit1";
            setupConfiguration.Children.Add(edit);
            ComponentCmd cmd = new ComponentCmd();
            cmd.command = "cmd.exe /C exit /b [edit1]1";
            cmd.required_install = true;
            setupConfiguration.Children.Add(cmd);
            // save config file
            InstallerLinkerArguments args = new InstallerLinkerArguments();
            args.config = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", args.config);
            configFile.SaveAs(args.config);
            // create HTML directory
            string htmlPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            Directory.CreateDirectory(htmlPath);
            string htmlIndexFilename = Path.Combine(htmlPath, "index.html");
            File.WriteAllText(htmlIndexFilename,
                              @"<html><head><title></title></head><body>
                                <input type=""text"" id=""edit1"" value=""4"" />
                                <input id=""button_install"" type=""button"" value=""Install"" />
                                </body></html>");
            // link the install executable
            args.htmlFiles = new string[] { htmlPath };
            args.embed = true;
            args.apppath = Path.GetTempPath();
            args.embedFiles = new string[] { Path.GetFileName(args.config) };
            args.output = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".exe");
            args.template = dotNetInstallerExeUtils.Executable;
            Console.WriteLine("Linking '{0}'", args.output);
            InstallerLinkerExeUtils.CreateInstaller(args);
            Assert.IsTrue(File.Exists(args.output));
            // execute dotNetInstaller
            dotNetInstallerExeUtils.RunOptions runOptions = new dotNetInstallerExeUtils.RunOptions();
            runOptions.autostart = true;
            runOptions.quiet = false;
            Assert.AreEqual(41, dotNetInstallerExeUtils.Run(args.output, runOptions.CommandLineArgs));
            File.Delete(args.config);
            Directory.Delete(args.htmlFiles[0], true);
        }
        public void TestUserControlEditInstalledCheckHasValueDisabled()
        {
            Console.WriteLine("TestUserControlEditInstalledCheckHasValueDisabled");

            // a configuration with a checkbox control
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ControlEdit edit = new ControlEdit();
            edit.Text = "4";
            edit.Id = "edit1";
            edit.Check = ControlCheckType.enabled; // control will be disabled, but has a value when disabled
            edit.HasValueDisabled = true;
            setupConfiguration.Children.Add(edit);
            // an installed check that is always false
            InstalledCheckRegistry check = new InstalledCheckRegistry();
            check.path = @"SOFTWARE\KeyDoesntExist";
            check.comparison = installcheckregistry_comparison.exists;
            edit.Children.Add(check);
            ComponentCmd cmd = new ComponentCmd();
            cmd.command = "cmd.exe /C exit /b [edit1]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
            Assert.AreEqual(45, dotNetInstallerExeUtils.Run(configFilename));
            File.Delete(configFilename);
        }
        public void TestUserControlEditControlArgs()
        {
            Console.WriteLine("TestUserControlEditControlArgs");

            // a configuration with a checkbox control
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ControlEdit edit = new ControlEdit();
            edit.Text = "4";
            edit.Id = "edit1";
            setupConfiguration.Children.Add(edit);
            ComponentCmd cmd = new ComponentCmd();
            cmd.command = "cmd.exe /C exit /b [edit1]";
            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;
            // edit value
            options.args = "/controlArgs edit1:4";
            Assert.AreEqual(4, dotNetInstallerExeUtils.Run(options));
            File.Delete(configFilename);
        }