private void UpdateCommandLineSwitch(object sender)
        {
            LabeledTextBox    textBox = sender as LabeledTextBox;
            CommandLineSwitch arg     = textBox.Tag as CommandLineSwitch;

            arg.Enabled = textBox.Checked;
            arg.Value   = arg.Enabled ? textBox.Text : string.Empty;
        }
        private void ChkBox_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox          chkBox = sender as CheckBox;
            CommandLineSwitch sw     = chkBox?.Tag as CommandLineSwitch;

            if (sw == null)
            {
                return;
            }
            sw.Enabled = chkBox.Checked;
            UpdateCommandLine();
        }
Beispiel #3
0
        /// <summary>
        /// Set Switch Flag and update switch value if valid.
        /// </summary>
        /// <param name="switchName">Switch Name</param>
        /// <param name="value">Value for switch (Optional)</param>
        /// <exception cref="ArgumentException">Invalid switch</exception>
        public void SetSwitch(string switchName, string value = "")
        {
            if (!Switches.ContainsKey(switchName))
            {
                throw new ArgumentException("Invalid Switch.", switchName);
            }

            CommandLineSwitch sw = Switches[switchName];

            sw.Enabled = true;
            if (!string.IsNullOrEmpty(sw.VariableName))
            {
                sw.Value = value;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Parse command line from arguments array
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        public bool ParseCommandLine(string[] arguments)
        {
            int x;

            if (arguments.Count() == 0)
            {
                return(false);
            }

            //Consume mandatory arguments
            for (x = 0; x < Arguments.Count(); x++)
            {
                if (arguments[x].StartsWith("/"))
                {
                    //We don't expect optional argument here until mandatory arguments are filled up.
                    throw new Exception("Missing argument " + Arguments[x].Name + "\n");
                }
                Arguments[x].Value = arguments[x];
            }

            //Consume Optional Argumnets
            for (; x < arguments.Count(); x++)
            {
                if (arguments[x].StartsWith("/"))
                {
                    //Split semicolumn
                    if (arguments[x].Contains(":"))
                    {
                        string[]          var = arguments[x].Split(':');
                        CommandLineSwitch sw  = Switches[var[0].ToUpper()];
                        sw.Enabled = true;
                        sw.Value   = var[1];
                    }
                    else
                    {
                        if (Switches.ContainsKey(arguments[x].ToUpper()))
                        {
                            Switches[arguments[x].ToUpper()].Enabled = true;
                        }
                    }
                }
                else
                {
                    continue;
                }
            }
            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Retrieve value associated with defined switch.
        /// </summary>
        /// <param name="name">Switch name, non case sensitive</param>
        /// <param name="defaultValue"> (OPTIONAL) Default value if switch is not defined, empty string by default.</param>
        /// <returns>value</returns>
        public string GetSwitchValue(string name, string defaultValue = "")
        {
            string swName = name.ToUpper();

            if (Switches.ContainsKey(swName))
            {
                CommandLineSwitch sw = Switches[swName];
                if (!string.IsNullOrEmpty(sw.VariableName))
                {
                    if (!string.IsNullOrEmpty(sw.Value))
                    {
                        return(sw.Value);
                    }
                }
            }
            return(defaultValue);
        }