コード例 #1
0
            public void AddAlias(string alias)
            {
                if (!CMDLineParser.isASwitch(alias))
                {
                    throw new CMDLineParserException("Invalid Option:'" + alias + "'::" + IS_NOT_A_SWITCH_MSG);
                }

                if (_Names == null)
                {
                    _Names = new System.Collections.ArrayList();
                }
                _Names.Add(alias);
            }
コード例 #2
0
        public Command(string[] _args)
        {
            uo = new UrlOperations(this);
            args = _args;
            //create parser
            parser = new CMDLineParser();

            if(_args.Length != 0){
                urlOpt = parser.AddStringParameter("-url", "adress of the website", true);
                if("get".Equals(_args[0]) || "test".Equals(_args[0])){
                    if("get".Equals(_args[0])){
                        getOpt=true;
                        saveOpt = parser.AddStringParameter("-save", "save the content of the website", false);
                    }
                    if("test".Equals(_args[0])){
                        testOpt=true;
                        timesOpt = parser.AddIntParameter("-times", "number of time to load the website", true);
                        avgOpt = parser.AddBoolSwitch("-avg", "average time to load the website");
                    }
                    try{
                        //parse the command line
                        parser.Parse(args);
                    } catch (CMDLineParser.CMDLineParserException ex){
                        getHelp();
                        Console.WriteLine("Error: " + ex.Message);
                        return;
                    }
                    //replace argument list with remaining arguments
                    args = parser.RemainingArgs();
                } else {
                    getHelp();
                  	Console.WriteLine("Error: Missing Required option: 'get' or 'set'");
                  	return;
                }
            }
        }
コード例 #3
0
ファイル: WorkInstruction.cs プロジェクト: c0ns0le/Xteq5
        public WorkInstruction(string[] CommandlineArguments)
        {
            //Set default values
            this.Execute = false;
            this.GenerateReport = false;
            this.DestinationFilepath = "";
            this.DestinationFormat = OutputFormatEnum.Unknown;

            CMDLineParser parser = new CMDLineParser();
            parser.throwInvalidOptionsException = true;

            //Add -Help option
            CMDLineParser.Option HelpOption = parser.AddBoolSwitch("-Help", "Displays help");
            HelpOption.AddAlias("/?");

            //Add -Run option
            CMDLineParser.Option RunOption = parser.AddBoolSwitch("-Run", "Required. Execute all files in compilation path");

            //Add -Path parameter
            CompilationPathOption PathParameter = new CompilationPathOption("-Path", "Compilation path to load scripts from", false);
            parser.AddOption(PathParameter);

            //Add -Format parameter
            ReportFormatOption FormatParameter = new ReportFormatOption("-Format", "Format of the report that should be generated (HTML, XML, JSON)", false);
            parser.AddOption(FormatParameter);

            //Add -Filename parameter
            FilenameOption FilenameParameter = new FilenameOption("-Filename", "Filename of the generated report", false);
            parser.AddOption(FilenameParameter);

            //Add -Text parameter
            CMDLineParser.Option TextParameter = parser.AddStringParameter("-Text", "Additional text to be included in generated report", false);
            //FilenameParameter.AddAlias("/Text");

            bool commandLineParsed = false;

            try
            {
                parser.Parse(CommandlineArguments);
                commandLineParsed = true;
            }
            catch (CMDLineParser.CMDLineParserException ex)
            {
                //That didn't worked...
                Console.WriteLine(ex.Message);
                Console.WriteLine("Use /? for help");
                Console.WriteLine();
            }

            if (commandLineParsed)
            {
                if (HelpOption.isMatched)
                {
                    Console.WriteLine(parser.HelpMessage());
                }
                else
                {
                    if (RunOption.isMatched == false)
                    {
                        //No -Run command, nothing to do.
                        Console.WriteLine("Missing -RUN option");
                        Console.WriteLine(parser.HelpMessage());
                    }
                    else
                    {
                        this.Execute = true;

                        //Check for PATH parameter is set and use default path if not
                        this.CompilationPath = OptionIsMatchedAndNotEmpty(PathParameter) ? PathParameter.Value.ToString() : Xteq5UIConstant.DefaultCompilationFolder;

                        //Check for FILENAME parameter if we should generate a report. Only if this is set, check the additonal parameters for the report
                        if (OptionIsMatchedAndNotEmpty(FilenameParameter))
                        {
                            this.GenerateReport = true;
                            this.DestinationFilepath = FilenameParameter.Value.ToString();

                            //Check for the FORMAT parameter and use HTML if not set
                            string reportFormatString = OptionIsMatchedAndNotEmpty(FormatParameter) ? FormatParameter.Value.ToString() : "HTML";

                            //This direct cast without any error checking is OK because FORMATPARAMETER already tried to parse it and will only be set if the value is OK
                            this.DestinationFormat = OutputFormatConverter.ParseReportFormat(reportFormatString);

                            this.UserText = OptionIsMatchedAndNotEmpty(TextParameter) ? TextParameter.Value.ToString() : "";

                        }

                        //All done!

                    }
                }
            }
        }
コード例 #4
0
ファイル: WorkInstruction.cs プロジェクト: c0ns0le/Xteq5
        /// <summary>
        /// Return TRUE if an option is both matched and is not null or empty
        /// </summary>
        /// <param name="Option">Option to check</param>
        /// <returns>TRUE if an option is both matched and is not null or empty</returns>
        private bool OptionIsMatchedAndNotEmpty(CMDLineParser.Option Option)
        {
            bool returnvalue = false;

            if (Option.isMatched)
            {
                if (Option.Value != null)
                {
                    if (string.IsNullOrWhiteSpace(Option.Value.ToString()) == false)
                    {
                        returnvalue = true;
                    }
                }
            }

            return returnvalue;
        }
コード例 #5
0
        /// <summary>
        /// Run Test Cases for CMDLineParser
        /// </summary>
        public static void RunTests()
        {
            Console.WriteLine("\nStarting CMDLineParser tests:\n");
            //create parser
            CMDLineParser parser = new CMDLineParser();
            parser.throwInvalidOptionsException = false;

            //add Options
            #region addOptions
            CMDLineParser.Option DebugOption = parser.AddBoolSwitch("-Debug", "Print Command Line Parser Debug information");
            DebugOption.AddAlias("/Debug");
            CMDLineParser.Option OptionOpenfolder = parser.AddBoolSwitch("/openfolder", "Open files in folder if path is a folder");
            OptionOpenfolder.AddAlias("-openfolder");
            CMDLineParser.Option UserNameOpt = parser.AddStringParameter("-User="******"User Name", true);
            UserNameOpt.AddAlias("-U");
            CMDLineParser.NumberOption DoubleOpt = parser.AddDoubleParameter("-DoubleNum", "A Double", false);
            NumberFormatInfo numberformat = (new CultureInfo("de-DE", false)).NumberFormat;
            CMDLineParser.NumberOption FormatedNumOpt = parser.AddDoubleParameter("-NegNum", "A negativ Number", false, numberformat);
            CMDLineParser.Option IntNumOpt = parser.AddIntParameter("-IntNum", "A Integer Number", false);

            //Test creation of an invalid option - Throws exception
            string test = "Test creation of an invalid option";
            string testcomment = " - " + test + " - :";
            try
            {
                CMDLineParser.Option InvalidOpt = parser.AddStringParameter("-Option Nr1", "Invalid Option", false);
                Console.WriteLine("\nTestFailed: " + testcomment);
            }
            catch (CMDLineParser.CMDLineParserException ex)
            {

                Console.WriteLine("\nTestOK: " + testcomment + "Caught Error: " + ex.Message);
            }
            #endregion

            //do tests and write results to the console window
            #region Tests
            //test missing required opt -U
            String[] testmissingreqopt = { "/Debug" }; //missing required opt -U
            TestException("missing required opt -U", parser, testmissingreqopt, typeof(CMDLineParser.MissingRequiredOptionException));

            //test neg. integer
            String[] test1 = { "-UChris", "-NegNum", "-13,56", "-IntNum", "-123", "/Debug" };
            TestOption("test neg. integer", parser, test1, IntNumOpt);

            //test Double Option
            double val = -10113.56;
            String[] testDoubleOptPoint = { "-UChris", "-DoubleNum", "-10113.56" }; //test formated double
            String[] testDoubleOptComma = { "-UChris", "-DoubleNum", "-10113,56" }; //test formated double
            TestOptionValue("testDoubleOpt-dec.point", parser, testDoubleOptPoint, DoubleOpt, val);
            TestOptionValue("testDoubleOpt-dec.comma", parser, testDoubleOptComma, DoubleOpt, val);

            //test formated (globalized) double
            String[] test2 = { "-UChris", "-NegNum", "-10.113,56", "-IntNum", "123", "/Debug" }; //test formated double
            TestOption("test formated double", parser, test2, FormatedNumOpt);

            //test wrong int format
            String[] test3 = { "-UChris", "-IntNum", "123.00", "/Debug" }; //test wrong int format
            TestException("test wrong int format", parser, test3, typeof(CMDLineParser.ParameterConversionException));

            //test InvalidOptionsException
            String[] test4 = { "-UChris", "-Inv", "-IntNum", "-123", "/Debug", "/Inv2" }; //invalid options found
            parser.throwInvalidOptionsException = true;
            TestException("invalid options found", parser, test4, typeof(CMDLineParser.InvalidOptionsException));
            //parser.Debug();

            //test custom (subclassed) option
            String[] testDate = { "-Date", "2001-11-22" }; //test custom (subclassed) option

            // New parser instance
            CMDLineParser parser2 = new CMDLineParser();

            parser2.throwInvalidOptionsException = true;
            PastDateOption DateOpt = new PastDateOption("-Date", "A test Date", false);
            parser2.AddOption(DateOpt);
            TestOption("test custom (subclassed) option", parser2, testDate, DateOpt);
            //parser2.Debug();

            //Test missing parseValue method
            MissingMethodOption missMethOpt = new MissingMethodOption("-missing", "test opt", false);
            parser2.AddOption(missMethOpt);
            string[] testmiss = { "-missing", "123" };
            TestException("Test missing parseValue method", parser2, testmiss, typeof(CMDLineParser.ParameterConversionException));

            //test 'help'
            parser2.AddHelpOption();
            parser2.isConsoleApplication = true;
            parser2.throwInvalidOptionsException = false;
            String[] testh = { "-?" };
            TestOption("test help", parser2, testh, null);

            //test generic DefaultOption ( using Convert.ChangeType..)
            //one of the two methods will fail depend on your system settings
            double dval = -10113.56;
            String[] testDefOpt1 = { "/Debug", "-NegNum", "-10113.56"}; //test formated double
            String[] testDefOpt2 = { "/Debug", "-NegNum", "-10113,56"}; //test formated double

            DefaultOption defnumop = new DefaultOption("-NegNum", "Test default Option", typeof(double), false);
            parser2.AddOption(defnumop);
            TestOptionValue("defnumop - dec.point", parser2, testDefOpt1, defnumop, dval);
            TestOptionValue("defnumop - dec.comma", parser2, testDefOpt2, defnumop, dval);

            #endregion

            parser2.Debug();

            //showCulturinfos();
        }
コード例 #6
0
 public static string printValue(CMDLineParser.Option opt)
 {
     if (opt == null) return "";
     return("'" + opt.Name + "'=" + opt.Value);
 }
コード例 #7
0
 public static bool TestOptionValue(string test, CMDLineParser parser, string[] testargs, CMDLineParser.Option opt, object val)
 {
     string testcomment = " - " + test + " - :";
     try
     {
         parser.Parse(testargs);
         if (opt.Value.Equals(val))
         {
             Console.WriteLine("\nTestOK: " + testcomment + printValue(opt));
             return true;
         }
         else
         {
             Console.WriteLine("\nTestFailed: " + testcomment + " Expected Value:" + val + "::Value found:" + opt.Value);
             return false;
         }
     }
     catch (CMDLineParser.CMDLineParserException pex)
     {
         Console.WriteLine("\nTestFailed: " + testcomment + pex.Message);
     }
     return false;
 }
コード例 #8
0
 public static bool TestOption(string test,CMDLineParser parser,string[] testargs,CMDLineParser.Option opt)
 {
     string testcomment= " - " + test + " - :";
     try
     {
         parser.Parse(testargs);
         Console.WriteLine("\nTestOK: " + testcomment + printValue(opt));
         return true;
     }
     catch (CMDLineParser.CMDLineParserException pex)
     {
         Console.WriteLine("\nTestFailed: " + testcomment + pex.Message);
     }
     return false;
 }
コード例 #9
0
        public static bool TestException(string test , CMDLineParser parser, string[] testargs, System.Type exceptionType)
        {
            string testcomment = " - " + test + " - :";
            try
            {
                parser.Parse(testargs);
                Console.WriteLine("\nTestFailed: " + testcomment);
            }
            catch (Exception ex)
            {

                if (ex.GetType() == exceptionType)
                {
                    Console.WriteLine("\nTestOK: "+ testcomment + "Caught Error: " + ex.Message);
                    return true;
                }
                else
                    Console.WriteLine("\nTestFailed: " + testcomment + ex.Message);
            }
            return false;
        }
コード例 #10
0
ファイル: MainForm.cs プロジェクト: nerndt/iRobotKinect
 public MainForm(string[] args = null, CMDLineParser parser = null)
 {
     InitAll();
 }
コード例 #11
0
ファイル: MainForm.cs プロジェクト: nerndt/iRobotKinect
        public void SecondInstanceStarted(string[] args)
        {
            if (InvokeRequired)
            {
                BeginInvoke((MethodInvoker)delegate()
                {
                    SecondInstanceStarted(args);
                });
                return;
            }

            // This will force the MainForm to show up on top
            TopMost = true;
            TopMost = false;

            // add code here to safely handle arguments given to 2nd instance
            if (args != null && (args.Count() == 1 || (args.Count() == 2 && Path.GetFileName((string)args[0]) == "Pixel.exe")))
            {
                if (args.Count() == 1)
                {
                    CommandLineDrivenOpenPlate(args[0]);
                }
                else if (args.Count() == 2 && Path.GetFileName((string)args[0]) == "Pixel.exe") // Assume it is the qlp file to load
                {
                    CommandLineDrivenOpenPlate(args[1]);
                }
                // NGE07252013 ShowMessageBox("B ProgramArgs = null");
                ProgramArgs = null;
                ProgramParser = null;
            }
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: nerndt/iRobotKinect
        static void Main(string[] args)
        {
            UnhandledExceptionManager.AddHandler(); // This allows ability to catch all unhandled exceptions in the program!

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //create parser
            CMDLineParser parser = new CMDLineParser();
            parser.throwInvalidOptionsException = false;

            //add Options
            #region addOptions
            //add default help "-help",..
            parser.AddHelpOption();
            CMDLineParser.Option TouchInputFilenameOpt = parser.AddStringParameter("-l", "Left", false);
            CMDLineParser.Option TouchInputDirectoryOpt = parser.AddStringParameter("-r", "Right", false);
            CMDLineParser.Option TouchOutputFilenameOpt = parser.AddStringParameter("-f", "Forwards", false);
            CMDLineParser.Option TouchOutputReportFileOpt = parser.AddStringParameter("-b", "Backwards", false);
            #endregion

            if (args.Length > 0)
            {
                try
                {
                    parser.Parse(args);
                }
                catch (CMDLineParser.CMDLineParserException e)
                {
                    Console.WriteLine("Error: " + e.Message);
                    parser.HelpMessage();
                }

                //parser.Debug();

                #region Section dealing with Multiple Instances of iRobotKinect
                if (ApplicationMutex != null && MainForm.MainFormMutex == ApplicationMutex) // This is sent to us by another copy of the program! Assume it is the qlp file to load
                {
                    MainForm.CRMainForm.TopMost = true;
                    MessageBox.Show("Args passed to iRobotKinect by another instance are:" + args[0], "iRobotKinect Remote Message"); // NGE07252013
                    if (args != null)
                    {
                        if (args.Count() == 1)
                        {
                            MainForm.CRMainForm.CommandLineDrivenOpenPlate(args[0]);
                        }
                        else if (parser._matchedSwitches.Count == 0 && parser._unmatchedArgs.Count == 2 && System.IO.Path.GetFileName((string)args[0]) == "iRobotKinect.exe") // Assume it is the file to load               
                        {
                            MainForm.CRMainForm.CommandLineDrivenOpenPlate(args[1]);
                        }
                    }
                #endregion Section dealing with Multiple Instances of iRobotKinect

                    return;
                }

                Application.EnableVisualStyles(); // NGE07242014 // Changes default way buttons and controls are shown - commented out makes basic 3d button shading
                Application.SetCompatibleTextRenderingDefault(false);
                // NGE07252013 if (args != null)
                // NGE07252013     MessageBox.Show("A Application.Run(CRMainForm = new MainForm(args, parser))" + string.Join("\t", args));
                // NGE07252013 else
                // NGE07252013     MessageBox.Show("A Application.Run(CRMainForm = new MainForm(args, parser))");

                CRMainForm = new MainForm();
                Program.Menu_Cache.Add(CRMainForm.Handle);
                Application.Run(CRMainForm);
            }
            else
            {
                #region Section dealing with Multiple Instances of iRobotKinect
                if (MainForm.AllowForMultipleInstancesOfiRobotKinect == false)
                {
                    bool MutexOwner = false;

                    // This application wants initial ownership of the "iRobotKinect", if not, then iRobotKinect is already running
                    ApplicationMutex = new Mutex(true, DefaultMutexName, out MutexOwner);

                    int tryNumber = 0;
                    while (MutexOwner == false && tryNumber < 5)
                    {
                        Thread.Sleep(3000); // Sleep for 3 seconds to see if other instance has finished exiting
                        // Try 5 times, waiting 3 seconds between each try
                        ApplicationMutex = new Mutex(true, DefaultMutexName, out MutexOwner);
                        tryNumber++;
                    }

                    if (MutexOwner == false)
                    {
                        MessageBox.Show("iRobotKinect software is already running.", "Error - Unable To Run iRobotKinect", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    bool TooManyInstancesRunning = false;
                    string currentMutexName = "", newMutexName = "";
                    if (RuniRobotKinectDueToMutexCondition(true, out TooManyInstancesRunning, ref currentMutexName, ref newMutexName) == false)
                        return;

                    string mutexName = "";
                    bool bRet = IsiRobotKinectAlreadyRunning(ref mutexName);

                    bool MutexOwner = false;
                    if (newMutexName == "" || currentMutexName == mutexName) // The initial instance of iRobotKinect
                    {
                        if (newMutexName == "")
                            MainForm.InitialInstanceMutexName = currentMutexName;
                        ApplicationMutex = new Mutex(true, currentMutexName, out MutexOwner);
                    }
                    else
                        ApplicationMutex = null;
                }
                #endregion Section dealing with Multiple Instances of iRobotKinect

                Application.EnableVisualStyles(); // NGE07242014 // Changes default way buttons and controls are shown - commented out makes basic 3d button shading
                Application.SetCompatibleTextRenderingDefault(false);
                SetMessageFiltering();
              
                SplashCurrentlyShown = false; // NGE12262011 Set to True if showing Splash Screen
                // Show the splash ASAP
                // NGE11202013 SplashScreen.ShowSplash();

                try
                {
                    CRMainForm = new MainForm();
                    Program.Menu_Cache.Add(CRMainForm.Handle);
                    Application.Run(CRMainForm);
                }
                catch (System.IO.FileNotFoundException excep)
                {
                    MessageBox.Show("Missing file is : " + excep.FileName);
                }
                //catch (Exception ex)
                //{
                //    string errorString = ex.Message;
                //    if (MainForm.ShowApplication) MessageBox.Show(errorString);
                //}
            }
        }