コード例 #1
0
        private void OnAuditCompleted(object sender, AuditCompletedEventArgs e)
        {
            VSPackage.AssertOnMainThread();

            if (e.Exception != null)
            {
                WriteLine(Resources.AuditingPackageError, e.Exception.Message);
                ExceptionHelper.WriteToActivityLog(e.Exception);
            }
            else if (e.Results.Count() == 0)
            {
                WriteLine(Resources.NoPackagesToAudit);
            }
            else
            {
                var vulnerableCount = e.Results.Count(x => x.Status == AuditStatus.HasVulnerabilities);

                if (vulnerableCount > 0)
                {
                    WriteLine(Resources.VulnerabilitiesFound, vulnerableCount);
                }
                else
                {
                    WriteLine(Resources.NoVulnarebilitiesFound);
                }

                //update audit results dictionary
                foreach (var auditResult in e.Results)
                {
                    _auditResults[auditResult.PackageId] = auditResult;
                }

                //refresh tasks
                RefreshTasks();

                if (vulnerableCount > 0)
                {
                    _taskProvider.BringToFront();
                }
            }
        }
コード例 #2
0
        private void OnAuditCompleted(object sender, AuditCompletedEventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (e.Exception != null)
            {
                WriteLine(Resources.AuditingPackageError, e.Exception.Message);
                WriteLine("");
                WriteLine(Resources.AuditingPackageError, e.Exception.StackTrace);
                ExceptionHelper.WriteToActivityLog(e.Exception);
            }
            else if (e.Results.Count() == 0)
            {
                WriteLine(Resources.NoPackagesToAudit);
            }
            else
            {
                WriteLine("Packages audited:");
                foreach (var result in e.Results)
                {
                    WriteLine("  * " + result.PackageId.Id + "@" + result.PackageId.VersionString);
                }

                var vulnerableCount = e.Results.Count(x => x.Status == AuditStatus.HasVulnerabilities);

                if (vulnerableCount > 0)
                {
                    WriteLine(Resources.VulnerabilitiesFound, vulnerableCount);
                    foreach (AuditResult r in e.Results.Where(x => x.Status == AuditStatus.HasVulnerabilities))
                    {
                        if (r.MatchedVulnerabilities == 1)
                        {
                            WriteLine("Package: {0} is vulnerable. 1 vulnerability found.", r.PackageId);
                        }
                        else
                        {
                            WriteLine("Package: {0} is vulnerable. {1} vulnerabilities found.", r.PackageId, r.MatchedVulnerabilities);
                        }
                        foreach (var v in r.Vulnerabilities)
                        {
                            WriteLine("    {0} {1} {2} CWE: {3} CvssS: {4} CvssV: {5}", v.Id, v.Title, v.Description, v.Cwe, v.CvssScore, v.CvssVector);
                        }
                    }
                }
                else
                {
                    foreach (AuditResult r in e.Results)
                    {
                        WriteLine("No vulnerabilities found for package {0}.", r.PackageId);
                    }
                }

                //update audit results dictionary
                foreach (var auditResult in e.Results)
                {
                    _auditResults[auditResult.PackageId] = auditResult;
                }

                //refresh tasks
                RefreshTasks();

                if (vulnerableCount > 0)
                {
                    _taskProvider.BringToFront();
                }
            }
        }