Start() public method

public Start ( ) : void
return void
コード例 #1
0
        public void OnExecute()
        {
            if (EnableLogging)
            {
                XamarinSecurityScannerLogger.LogEvent = (m) => File.AppendAllText(LogFile, m);
            }

            if (IgnoreFile != null)
            {
                SetIgnoreObject();
            }

            Reporter = ReporterFactory.Create(Output);
            IScanner scanner = ScannerFactory.Create();

            Reporter.Start();
            Task task = scanner.Start(Path);

            task.Wait();

            Reporter.Finish();
            EnvironmentWrapper.Exit(Reporter.VulnerabilityCount < Threshold ? 0 : 1);
        }
コード例 #2
0
        private static Reporter Run(CommandLineOptions commandLineOptions, CancellationTokenSource source,
                                    IAsyncRequester requester, int total, string reportFolder)
        {
            var until = DateTimeOffset.MaxValue;

            if (!commandLineOptions.IsDryRun && commandLineOptions.NumberOfSeconds > 0)
            {
                commandLineOptions.NumberOfRequests = int.MaxValue / 10;
                until = DateTimeOffset.Now.AddSeconds(commandLineOptions.NumberOfSeconds + commandLineOptions.WarmupSeconds);
            }

            var warmUpTotal      = 0;
            var customThreadPool = new CustomThreadPool(new WorkItemFactory(
                                                            requester,
                                                            commandLineOptions.NumberOfRequests,
                                                            commandLineOptions.DelayInMillisecond,
                                                            commandLineOptions.WarmupSeconds),
                                                        source,
                                                        commandLineOptions.Concurrency,
                                                        commandLineOptions.WarmupSeconds);

            var reporter = new Reporter(Environment.CommandLine, commandLineOptions.ReportSliceSeconds, () => customThreadPool.WorkerCount);

            if (commandLineOptions.WarmupSeconds == 0)
            {
                reporter.Start();
            }

            customThreadPool.WarmupFinished += (sender, args) =>
            {
                _stopwatch.Restart();
                reporter.Start();
            };

            customThreadPool.WorkItemFinished += (sender, args) =>
            {
                if (args.Result.NoWork)
                {
                    return;
                }

                if (args.Result.IsWarmUp)
                {
                    var t = Interlocked.Increment(ref warmUpTotal);
                    if (!commandLineOptions.Verbose)
                    {
                        ConsoleWrite(ConsoleColor.Green, "\rWarmup [Users {1}]: {0}", warmUpTotal, customThreadPool.WorkerCount);
                    }

                    return;
                }

                reporter.AddResponse((HttpStatusCode)args.Result.Status, (long)args.Result.Ticks);
                ConsiderUpdatingReport(reporter, reportFolder, !commandLineOptions.DontBrowse);

                var n       = Interlocked.Increment(ref total);
                var logData = new LogData()
                {
                    Millis     = (int)args.Result.Ticks / TimeSpan.TicksPerMillisecond,
                    Index      = args.Result.Index,
                    EventDate  = DateTimeOffset.Now,
                    StatusCode = args.Result.Status,
                    Parameters = args.Result.Parameters
                };

                _logDataQueue.Enqueue(logData);

                if (DateTimeOffset.Now > until)
                {
                    source.Cancel();
                }

                if (!commandLineOptions.Verbose)
                {
                    ConsoleWrite(ConsoleColor.DarkYellow, "\r{0}	(RPS: {1})			", total, Math.Round(total * 1000f / _stopwatch.ElapsedMilliseconds, 1));
                }
            };

            customThreadPool.Start(commandLineOptions.NumberOfRequests);

            // set until - only after started
            if (!commandLineOptions.IsDryRun && commandLineOptions.NumberOfSeconds > 0)
            {
                until = DateTimeOffset.Now.AddSeconds(commandLineOptions.NumberOfSeconds + commandLineOptions.WarmupSeconds);
            }

            while (!source.IsCancellationRequested)
            {
                Thread.Sleep(200);
            }

            return(reporter);
        }