Example #1
0
        static void Main(string[] args)
        {
            bool   hubUpload = false;
            string username  = null;
            string password  = null;

            if (args.Length < 1 || string.IsNullOrWhiteSpace(args[0]))
            {
                Console.Error.WriteLine("Arguments required: Scanner.exe <Path to Assembly to Scan> [<Output File>]");
                return;
            }

            if (args.Length < 2)
            {
                //No output argument. Do we have a preconfigured hub instance?
                if (Settings.Instance.Url != null)
                {
                    username = Settings.Instance.Username;
                    while (string.IsNullOrEmpty(username))
                    {
                        username = Prompt.Read($"Please enter a username for the hub instance at {Settings.Instance.Url}");
                    }
                    password = Settings.Instance.Password;
                    while (string.IsNullOrEmpty(password))
                    {
                        password = Prompt.ReadPassword($"Please enter the password for user {Settings.Instance.Username} at the Hub instance at {Settings.Instance.Url}");
                    }
                    hubUpload = true;
                }
                else
                {
                    Console.Error.WriteLine("No URL specified in configuration file. Exiting.");
                    return;
                }
            }


            string target = Path.GetFullPath(args[0]);

            Console.WriteLine("Scanning " + target + "...");

            ScannerJsonBuilder builder = scanAssembly(target);

            if (hubUpload)
            {
                HubUpload.UploadScan(Settings.Instance.Url, username, password, builder);
            }
            else
            {
                using (var fileWriter = new StreamWriter(args[1], false))
                {
                    builder.Write(fileWriter);
                }
            }
        }
        static void Main(string[] args)
        {
            bool   hubUpload          = false;
            string username           = null;
            string password           = null;
            bool   ignoreSsl          = false;
            string targetAssemblyPath = null;
            string outputFile         = null;


            ParserResult <Options> parseResult = CommandLine.Parser.Default.ParseArguments <Options>(args).WithNotParsed(result =>
            {
                Console.Error.WriteLine("Invalid usage");
                Environment.Exit(1);
            }).WithParsed(options =>
            {
                ignoreSsl          = options.IgnoreSslErrors;
                outputFile         = options.OutputFile.FirstOrDefault();
                targetAssemblyPath = Path.GetFullPath(options.AssemblyToScan);
            });

            if (string.IsNullOrWhiteSpace(outputFile))
            {
                //No output argument. Do we have a preconfigured hub instance?
                if (Settings.Instance.Url != null)
                {
                    username = Settings.Instance.Username;
                    while (string.IsNullOrEmpty(username))
                    {
                        username = Prompt.Read($"Please enter a username for the hub instance at {Settings.Instance.Url}");
                    }
                    password = Settings.Instance.Password;
                    while (string.IsNullOrEmpty(password))
                    {
                        password = Prompt.ReadPassword($"Please enter the password for user {Settings.Instance.Username} at the Hub instance at {Settings.Instance.Url}");
                    }
                    hubUpload = true;
                }
                else
                {
                    Console.Error.WriteLine("No URL specified in configuration file and no output file specified. Exiting.");
                    Environment.Exit(1);
                }
            }

            if (ignoreSsl)
            {
                Console.WriteLine("SSL errors will be ignored.");
                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
            }

            Console.WriteLine("Scanning " + targetAssemblyPath + "...");


            ScannerJsonBuilder builder = scanAssembly(targetAssemblyPath);

            if (hubUpload)
            {
                HubUpload.UploadScan(Settings.Instance.Url, username, password, builder);
            }
            else
            {
                using (var fileWriter = new StreamWriter(outputFile, false))
                {
                    builder.Write(fileWriter);
                }
            }
        }