Пример #1
0
        public static void Main(string[] args)
        {
            bool inputDirValid      = false;
            bool outputDirValid     = false;
            bool exclusionDirsValid = false;
            bool buildCheck         = false;
            bool optionGUI          = false;
            // Command line interface can be enabled as a command line option
            bool consoleEnabled = false;

            if (args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    // Find the input directory paramter, which should follow the "-i" parameter
                    if (args[i].Equals("-i", StringComparison.OrdinalIgnoreCase) && (i < args.Length - 1))
                    {
                        inputDirValid = Directory.Exists(args[i + 1]);
                        if (inputDirValid)
                        {
                            inputDir = args[i + 1];
                        }
                    }

                    // Find the output directory parameter, which should follow the "-o" parameter
                    if (args[i].Equals("-o", StringComparison.OrdinalIgnoreCase) && (i < args.Length - 1))
                    {
                        outputDirValid = Directory.Exists(args[i + 1]);
                        if (outputDirValid)
                        {
                            outputDir = args[i + 1];
                        }
                    }

                    // The "GUI" option enables GUI mode of operation as opposed to command-line mode.
                    if (args[i].Equals("-GUI", StringComparison.OrdinalIgnoreCase))
                    {
                        optionGUI = true;
                    }

                    // The "CSV" option forces reports to be generated in the comma-separated values (CSV) format in addition to plain text reports.
                    if (args[i].Equals("-CSV", StringComparison.OrdinalIgnoreCase))
                    {
                        MainForm.outputCSV = true;
                    }

                    // The "BUILDCHECK" option forces reports to be generated in the comma-separated values (CSV) format in addition to plain text reports.
                    if (args[i].Equals("-BUILDCHECK", StringComparison.OrdinalIgnoreCase))
                    {
                        MainForm.buildCheck = true;
                        buildCheck          = true;
                    }

                    if (args[i].Equals("-e", StringComparison.OrdinalIgnoreCase) && (i < args.Length - 1))
                    {
                        string[] dirs = args[i + 1].Split(';');
                        exclusionDirsValid = true;
                        foreach (string d in dirs)
                        {
                            exclusionDirsValid &= Directory.Exists(d);
                        }
                        if (exclusionDirsValid)
                        {
                            exclusionDirs = dirs;
                        }
                    }
                }

                // parse out incompatible options
                if ((buildCheck && (optionGUI || MainForm.outputCSV || outputDirValid)) ||
                    (!buildCheck && (!outputDirValid && !optionGUI)))
                {
                    Usage();
                    exitCode = 1;
                }

                if (!optionGUI && !inputDirValid)
                {
                    Usage();
                    exitCode = 1;
                }
            }
            else
            {
                //Default to enable console if Usage is wrong.
                consoleEnabled = enableConsole();
                Usage();
                exitCode = 1;
            }



            if (exitCode == 0)
            {
                if (!optionGUI)
                {
                    consoleEnabled = enableConsole();
                }

                if (optionGUI)
                {
                    // GUI enabled
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new MainForm());
                }
                else
                {
                    // The minimum required parameters were correctly specified.  Run the reports in CLI mode
                    exitCode = ReportGenerator.GenerateReport(inputDir, outputDir, exclusionDirs, null);
                    Console.WriteLine();
                    if (outputDirValid)
                    {
                        Console.WriteLine("Reports have been generated in " + outputDir);
                    }
                }
            }


            if (consoleEnabled)
            {
                FreeConsole();
            }

            System.Environment.Exit(exitCode);
        }
Пример #2
0
        public static void Main(string[] args)
        {
            bool inputDirValid  = false;
            bool outputDirValid = false;
            bool optionGUI      = false;

            for (int i = 0; i < args.Length; i++)
            {
                // Find the input directory paramter, which should follow the "-i" parameter
                if (args[i].Equals("-i", StringComparison.OrdinalIgnoreCase) && (i < args.Length - 1))
                {
                    inputDirValid = Directory.Exists(args[i + 1]);
                    if (inputDirValid)
                    {
                        inputDir = args[i + 1];
                    }
                }

                // Find the output directory paramter, which should follow the "-o" parameter
                if (args[i].Equals("-o", StringComparison.OrdinalIgnoreCase) && (i < args.Length - 1))
                {
                    outputDirValid = Directory.Exists(args[i + 1]);
                    if (outputDirValid)
                    {
                        outputDir = args[i + 1];
                    }
                }

                // The "GUI" option enables GUI mode of operation as opposed to command-line mode.
                if (args[i].Equals("-GUI", StringComparison.OrdinalIgnoreCase))
                {
                    optionGUI = true;
                }

                // The "CSV" option forces reports to be generated in the comma-separated values (CSV) format in addition to plain text reports.
                if (args[i].Equals("-CSV", StringComparison.OrdinalIgnoreCase))
                {
                    MainForm.outputCSV = true;
                }
            }


            // Command line interface can be enabled as a command line option
            bool consoleEnabled = false;

            if (!optionGUI)
            {
                // Locate the console (cmd process) from which the program was started if it was invoked from command line.
                IntPtr ptr = GetForegroundWindow();
                int    cmdProcessID;
                GetWindowThreadProcessId(ptr, out cmdProcessID);
                Process process = Process.GetProcessById(cmdProcessID);
                if (process.ProcessName == "cmd")
                {
                    // The uppermost window is a cmd process.  The console is already running.
                    AttachConsole(process.Id);
                    consoleEnabled = true;
                }
            }


            if (optionGUI)
            {
                // GUI enabled
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());
            }
            else
            {
                // Run reports if CLI mode is selected and both directories specified are valid.
                if (inputDirValid && outputDirValid)
                {
                    // The minimum required parameters were correctly specified.  Run the reports.
                    ReportGenerator.GenerateReport(inputDir, outputDir, null);
                    Console.WriteLine();
                    Console.WriteLine("Reports have been generated in " + outputDir);
                }
                else
                {
                    Console.WriteLine("Command line parameters are invalid.");
                    Console.WriteLine("Valid parameters:");
                    Console.WriteLine("-i <path> to specify the input/root directory path to search for requirements documents and source code in.");
                    Console.WriteLine("-o <path> to specify the output directory path to write reports into.");
                    Console.WriteLine("-gui to use the GUI interface.");
                    Console.WriteLine("-csv to generate reports in CSV format in addition to default plain text reports.");
                    Console.WriteLine("Note that both input and output directores must be specified and must be valid in order to run the program in CLI mode.");
                    exitCode = 1;
                }
            }

            if (consoleEnabled)
            {
                FreeConsole();
            }

            System.Environment.Exit(exitCode);
        }
Пример #3
0
 private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     ReportGenerator.GenerateReport(txtRootPath.Text, txtOutputPath.Text, this);
 }
Пример #4
0
        public static void Main(string[] args)
        {
            bool inputDirValid      = false;
            bool outputDirValid     = false;
            bool exclusionDirsValid = false;
            bool buildCheck         = false;
            bool optionGUI          = false;

            for (int i = 0; i < args.Length; i++)
            {
                // Find the input directory paramter, which should follow the "-i" parameter
                if (args[i].Equals("-i", StringComparison.OrdinalIgnoreCase) && (i < args.Length - 1))
                {
                    inputDirValid = Directory.Exists(args[i + 1]);
                    if (inputDirValid)
                    {
                        inputDir = args[i + 1];
                    }
                }

                // Find the output directory parameter, which should follow the "-o" parameter
                if (args[i].Equals("-o", StringComparison.OrdinalIgnoreCase) && (i < args.Length - 1))
                {
                    outputDirValid = Directory.Exists(args[i + 1]);
                    if (outputDirValid)
                    {
                        outputDir = args[i + 1];
                    }
                }

                // The "GUI" option enables GUI mode of operation as opposed to command-line mode.
                if (args[i].Equals("-GUI", StringComparison.OrdinalIgnoreCase))
                {
                    optionGUI = true;
                }

                // The "CSV" option forces reports to be generated in the comma-separated values (CSV) format in addition to plain text reports.
                if (args[i].Equals("-CSV", StringComparison.OrdinalIgnoreCase))
                {
                    MainForm.outputCSV = true;
                }

                // The "BUILDCHECK" option forces reports to be generated in the comma-separated values (CSV) format in addition to plain text reports.
                if (args[i].Equals("-BUILDCHECK", StringComparison.OrdinalIgnoreCase))
                {
                    MainForm.buildCheck = true;
                    buildCheck          = true;
                }

                if (args[i].Equals("-e", StringComparison.OrdinalIgnoreCase) && (i < args.Length - 1))
                {
                    string[] dirs = args[i + 1].Split(';');
                    exclusionDirsValid = true;
                    foreach (string d in dirs)
                    {
                        exclusionDirsValid &= Directory.Exists(d);
                    }
                    if (exclusionDirsValid)
                    {
                        exclusionDirs = dirs;
                    }
                }
            }

            // parse out incompatible options
            if ((buildCheck && (optionGUI || MainForm.outputCSV || outputDirValid)) ||
                (!buildCheck && (!outputDirValid && !optionGUI)))
            {
                Usage();
                exitCode = 1;
            }

            if (!optionGUI && !inputDirValid)
            {
                Usage();
                exitCode = 1;
            }

            if (exitCode == 0)
            {
                // Command line interface can be enabled as a command line option
                bool consoleEnabled = false;

                if (!optionGUI)
                {
                    // Locate the console (cmd process) from which the program was started if it was invoked from command line.
                    IntPtr ptr = GetForegroundWindow();
                    int    cmdProcessID;
                    GetWindowThreadProcessId(ptr, out cmdProcessID);
                    Process process = Process.GetProcessById(cmdProcessID);
                    if (process.ProcessName == "cmd")
                    {
                        // The uppermost window is a cmd process.  The console is already running.
                        AttachConsole(process.Id);
                        consoleEnabled = true;
                    }
                }

                if (optionGUI)
                {
                    // GUI enabled
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new MainForm());
                }
                else
                {
                    // The minimum required parameters were correctly specified.  Run the reports in CLI mode
                    exitCode = ReportGenerator.GenerateReport(inputDir, outputDir, exclusionDirs, null);
                    Console.WriteLine();
                    if (outputDirValid)
                    {
                        Console.WriteLine("Reports have been generated in " + outputDir);
                    }
                }

                if (consoleEnabled)
                {
                    FreeConsole();
                }
            }


            System.Environment.Exit(exitCode);
        }