コード例 #1
0
        public override void WriteResults(Result result, CLICommandOptions commandOptions, bool autoClose = true)
        {
            ExportTagsResult exportTagsResult = (ExportTagsResult)result;

            //For console output, update write once for same results to console or file
            WriteOnce.TextWriter = TextWriter;

            if (exportTagsResult.TagsList.Count > 0)
            {
                WriteOnce.Result("Results");

                foreach (string tag in exportTagsResult.TagsList)
                {
                    WriteOnce.General(tag);
                }
            }
            else
            {
                WriteOnce.General("No tags found");
            }

            if (autoClose)
            {
                FlushAndClose();
            }
        }
コード例 #2
0
        public override void WriteResults(Result result, CLICommandOptions commandOptions, bool autoClose = true)
        {
            VerifyRulesResult verifyRulesResult = (VerifyRulesResult)result;

            //For console output, update write once for same results to console or file
            WriteOnce.TextWriter = TextWriter;

            if (string.IsNullOrEmpty(commandOptions.OutputFilePath))
            {
                WriteOnce.Result("Results");
            }

            if (verifyRulesResult.ResultCode != VerifyRulesResult.ExitCode.Verified)
            {
                WriteOnce.Any(MsgHelp.GetString(MsgHelp.ID.TAGTEST_RESULTS_FAIL), true, ConsoleColor.Red, WriteOnce.ConsoleVerbosity.Low);
            }
            else
            {
                WriteOnce.Any(MsgHelp.GetString(MsgHelp.ID.TAGTEST_RESULTS_SUCCESS), true, ConsoleColor.Green, WriteOnce.ConsoleVerbosity.Low);
            }

            if (verifyRulesResult.RuleStatusList.Count > 0)
            {
                WriteOnce.Result("Rule status");
                foreach (RuleStatus ruleStatus in verifyRulesResult.RuleStatusList)
                {
                    WriteOnce.General(String.Format("Ruleid: {0}, Rulename: {1}, Status: {2}", ruleStatus.RulesId, ruleStatus.RulesName, ruleStatus.Verified));
                }
            }

            if (autoClose)
            {
                FlushAndClose();
            }
        }
コード例 #3
0
        private void WriteDependencies(MetaData metaData)
        {
            WriteOnce.General(MakeHeading("Dependencies"));

            foreach (string s in metaData.UniqueDependencies ?? new List <string>())
            {
                WriteOnce.General(s);
            }
        }
コード例 #4
0
        public void WriteAppMeta(MetaData metaData)
        {
            //write predefined characteristics
            WriteOnce.General(string.Format(MakeHeading("Project Info")));
            WriteOnce.General(string.Format("Name: {0}", metaData.ApplicationName + " " + metaData.SourceVersion));
            WriteOnce.General(string.Format("Description: {0}", metaData.Description));
            WriteOnce.General(string.Format("Source path: {0}", metaData.SourcePath));
            WriteOnce.General(string.Format("Authors: {0}", metaData.Authors));
            WriteOnce.General(string.Format("Last Updated: {0}", metaData.LastUpdated));
            WriteOnce.General(string.Format("Languages: {0}", StringList(metaData.Languages)));
            WriteOnce.General(string.Format(MakeHeading("Scan Settings")));
            WriteOnce.General(string.Format("Date scanned: {0}", metaData.DateScanned));
            WriteOnce.General(string.Format(MakeHeading("Source Info")));
            WriteOnce.General(string.Format("Application type: {0}", StringList(metaData.AppTypes)));
            WriteOnce.General(string.Format("Package types: {0}", StringList(metaData.PackageTypes)));
            WriteOnce.General(string.Format("File extensions: {0}", StringList(metaData.FileExtensions)));
            WriteOnce.General(string.Format(MakeHeading("Detetected Targets")));
            WriteOnce.General(string.Format("Output types: {0}", StringList(metaData.Outputs)));
            WriteOnce.General(string.Format("OS Targets: {0}", StringList(metaData.OSTargets)));
            WriteOnce.General(string.Format("CPU Targets: {0}", StringList(metaData.CPUTargets)));
            WriteOnce.General(string.Format("Cloud targets: {0}", StringList(metaData.CloudTargets)));
            WriteOnce.General(string.Format(MakeHeading("Stats")));
            WriteOnce.General(string.Format("Files analyzed: {0}", metaData.FilesAnalyzed));
            WriteOnce.General(string.Format("Files skipped: {0}", metaData.FilesSkipped));
            WriteOnce.General(string.Format("Total files: {0}", metaData.TotalFiles));
            WriteOnce.General(string.Format("Total matches: {0} in {1} file(s)", metaData.TotalMatchesCount, metaData.FilesAffected));
            WriteOnce.General(string.Format("Unique matches: {0}", metaData.UniqueMatchesCount));

            WriteOnce.General(MakeHeading("UniqueTags"));
            List <string> orderedTags = metaData.UniqueTags.ToList <string>();

            orderedTags.Sort();

            foreach (string tag in orderedTags)
            {
                WriteOnce.General(tag);
            }

            WriteOnce.General(MakeHeading("Select Counters"));
            foreach (MetricTagCounter tagCounter in metaData.TagCounters)
            {
                WriteOnce.General(string.Format("Tagname: {0}, Count: {1}", tagCounter.Tag, tagCounter.Count));
            }
        }
コード例 #5
0
        public void WriteMatch(MatchRecord match)
        {
            string output = _formatString.Replace("%F", match.FileName);

            output = output.Replace("%l", match.LanguageInfo.Name);
            output = output.Replace("%t", match.LanguageInfo.Type.ToString());
            output = output.Replace("%L", match.StartLocationLine.ToString());
            output = output.Replace("%C", match.StartLocationColumn.ToString());
            output = output.Replace("%l", match.EndLocationLine.ToString());
            output = output.Replace("%c", match.EndLocationColumn.ToString());
            output = output.Replace("%R", match.RuleId);
            output = output.Replace("%N", match.RuleName);
            output = output.Replace("%S", match.Severity.ToString());
            output = output.Replace("%X", match.Confidence.ToString());
            output = output.Replace("%D", match.RuleDescription);
            output = output.Replace("%m", match.Sample);
            output = output.Replace("%T", string.Join(',', match.Tags ?? System.Array.Empty <string>()));

            WriteOnce.General(output);
        }
コード例 #6
0
        public override void WriteResults(Result result, CLICommandOptions commandOptions, bool autoClose = true)
        {
            CLITagTestCmdOptions cLITagTestCmdOptions = (CLITagTestCmdOptions)commandOptions;
            TagTestResult        tagTestResult        = (TagTestResult)result;

            //For console output, update write once for same results to console or file
            WriteOnce.TextWriter = TextWriter;

            if (string.IsNullOrEmpty(commandOptions.OutputFilePath))
            {
                WriteOnce.Result("Results");
            }

            WriteOnce.General(MsgHelp.FormatString(MsgHelp.ID.TAGTEST_RESULTS_TEST_TYPE, cLITagTestCmdOptions.TestType), false, WriteOnce.ConsoleVerbosity.Low);

            if (tagTestResult.ResultCode == TagTestResult.ExitCode.TestFailed)
            {
                WriteOnce.Any(MsgHelp.GetString(MsgHelp.ID.TAGTEST_RESULTS_FAIL), true, ConsoleColor.Red, WriteOnce.ConsoleVerbosity.Low);
            }
            else
            {
                WriteOnce.Any(MsgHelp.GetString(MsgHelp.ID.TAGTEST_RESULTS_SUCCESS), true, ConsoleColor.Green, WriteOnce.ConsoleVerbosity.Low);
            }

            if (tagTestResult.TagsStatusList.Count > 0)
            {
                WriteOnce.Result("Test results:");

                foreach (TagStatus tag in tagTestResult.TagsStatusList)
                {
                    WriteOnce.General(string.Format("Tag: {0}, Detected: {1}", tag.Tag, tag.Detected));
                }
            }

            WriteOnce.NewLine();

            if (autoClose)
            {
                FlushAndClose();
            }
        }
コード例 #7
0
        public override void WriteResults(Result result, CLICommandOptions commandOptions, bool autoClose = true)
        {
            TagDiffResult        tagDiffResult        = (TagDiffResult)result;
            CLITagDiffCmdOptions cLITagDiffCmdOptions = (CLITagDiffCmdOptions)commandOptions;

            //For console output, update write once for same results to console or file
            WriteOnce.TextWriter = TextWriter;

            if (string.IsNullOrEmpty(commandOptions.OutputFilePath))
            {
                WriteOnce.Result("Results");
            }

            WriteOnce.General(MsgHelp.FormatString(MsgHelp.ID.TAGTEST_RESULTS_TEST_TYPE, cLITagDiffCmdOptions.TestType), false, WriteOnce.ConsoleVerbosity.Low);

            if (tagDiffResult.ResultCode == TagDiffResult.ExitCode.TestFailed)
            {
                WriteOnce.Any(MsgHelp.GetString(MsgHelp.ID.TAGTEST_RESULTS_FAIL), true, ConsoleColor.Red, WriteOnce.ConsoleVerbosity.Low);
            }
            else
            {
                WriteOnce.Any(MsgHelp.GetString(MsgHelp.ID.TAGTEST_RESULTS_SUCCESS), true, ConsoleColor.Green, WriteOnce.ConsoleVerbosity.Low);
            }

            //Results list
            if (tagDiffResult.TagDiffList.Count > 0)
            {
                WriteOnce.Result("Differences");
                foreach (TagDiff tagDiff in tagDiffResult.TagDiffList)
                {
                    WriteOnce.General(string.Format("Tag: {0}, Only found in file: {1}", tagDiff.Tag, tagDiff.Source));
                }
            }

            if (autoClose)
            {
                FlushAndClose();
            }
        }
コード例 #8
0
        public override void WriteResults(Result result, CLICommandOptions commandOptions, bool autoClose = true)
        {
            CLIAnalyzeCmdOptions cLIAnalyzeCmdOptions = (CLIAnalyzeCmdOptions)commandOptions;
            AnalyzeResult        analyzeResult        = (AnalyzeResult)result;

            //For console output, update write once for same results to console or file
            WriteOnce.TextWriter = TextWriter;

            WriteOnce.Result("Results");

            if (cLIAnalyzeCmdOptions.SimpleTagsOnly)
            {
                List <string> keys = new List <string>(analyzeResult.Metadata.UniqueTags);
                keys.Sort();

                foreach (string tag in keys)
                {
                    WriteOnce.General(tag);
                }
            }
            else
            {
                WriteAppMeta(analyzeResult.Metadata);
                WriteDependencies(analyzeResult.Metadata);
                WriteOnce.General(MakeHeading("Match Details"));

                foreach (MatchRecord match in analyzeResult.Metadata.Matches)
                {
                    WriteMatch(match);
                }
            }

            if (autoClose)
            {
                FlushAndClose();
            }
        }
コード例 #9
0
        public override void WriteResults(Result result, CLICommandOptions commandOptions, bool autoClose = true)
        {
            CLIAnalyzeCmdOptions cLIAnalyzeCmdOptions = (CLIAnalyzeCmdOptions)commandOptions;
            AnalyzeResult        analyzeResult        = (AnalyzeResult)result;

            //For console output, update write once for same results to console or file
            WriteOnce.TextWriter = TextWriter;

            WriteOnce.Result("Results");

            WriteAppMeta(analyzeResult.Metadata);
            WriteDependencies(analyzeResult.Metadata);
            WriteOnce.General(MakeHeading("Match Details"));

            foreach (MatchRecord match in analyzeResult.Metadata.Matches ?? new List <MatchRecord>())
            {
                WriteMatch(match);
            }

            if (autoClose)
            {
                FlushAndClose();
            }
        }