Esempio n. 1
0
        //implementation of parseValue
        public override object parseValue(string Parameter)
        {
            OutputFormatEnum format = OutputFormatConverter.ParseReportFormat(Parameter);

            if (format == OutputFormatEnum.Unknown)
            {
                throw new System.ArgumentException(string.Format("Report format [{0}] is not valid", Parameter));
            }
            else
            {
                return(format);
            }
        }
Esempio n. 2
0
        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!
                    }
                }
            }
        }