示例#1
0
        public static CommandResultsWriter GetExportWriter(CLIExportTagsCmdOptions options)
        {
            CommandResultsWriter writer = null;

            switch (options.OutputFileFormat.ToLower())
            {
            case "_dummy":
                writer = new ExportDummyWriter();
                break;

            case "json":
                writer = new JsonWriter();
                break;

            case "text":
                writer = new ExportTextWriter();
                break;

            default:
                WriteOnce.Error(MsgHelp.FormatString(MsgHelp.ID.CMD_INVALID_ARG_VALUE, "-f"));
                throw new OpException((MsgHelp.FormatString(MsgHelp.ID.CMD_INVALID_ARG_VALUE, "-f")));
            }

            //assign the stream as a file or console
            writer.OutputFileName = options.OutputFilePath;
            writer.TextWriter     = GetTextWriter(writer.OutputFileName);

            return(writer);
        }
示例#2
0
        public static void Write(Result result, CLICommandOptions options)
        {
            CommandResultsWriter writer = WriterFactory.GetWriter(options);
            string commandCompletedMsg  = "Unknown";

            //perform type checking and assign final msg string
            if (result is TagTestResult)
            {
                commandCompletedMsg = "Tag Test";
            }
            else if (result is TagDiffResult)
            {
                commandCompletedMsg = "Tag Diff";
            }
            else if (result is ExportTagsResult)
            {
                commandCompletedMsg = "Export Tags";
            }
            else if (result is VerifyRulesResult)
            {
                commandCompletedMsg = "Verify Rules";
            }
            else if (result is PackRulesResult)
            {
                commandCompletedMsg = "Pack Rules";
            }
            else if (result is AnalyzeResult analyzeResult && options is CLIAnalyzeCmdOptions cLIAnalyzeCmdOptions) //special handling for html format
            {
                commandCompletedMsg = "Analyze";

                //additional prechecks required for analyze html format
                if (cLIAnalyzeCmdOptions.OutputFileFormat == "html")
                {
                    int MAX_HTML_REPORT_FILE_SIZE = 1024 * 1000 * 3;  //warn about potential slow rendering

                    //prechecks
                    if (analyzeResult.ResultCode != AnalyzeResult.ExitCode.Success)
                    {
                        Finalize(writer, commandCompletedMsg);
                        return;
                    }

                    writer.WriteResults(analyzeResult, cLIAnalyzeCmdOptions);

                    //post checks
                    if (File.Exists(options.OutputFilePath) && new FileInfo(options.OutputFilePath).Length > MAX_HTML_REPORT_FILE_SIZE)
                    {
                        WriteOnce.Info(MsgHelp.GetString(MsgHelp.ID.ANALYZE_REPORTSIZE_WARN));
                    }

                    if (!cLIAnalyzeCmdOptions.SuppressBrowserOpen)
                    {
                        Utils.OpenBrowser(cLIAnalyzeCmdOptions.OutputFilePath);
                    }

                    Finalize(writer, "Analyze");
                    return;
                }
            }
示例#3
0
        /// <summary>
        /// Responsible for returning the correct cmd and format writer for output of cmd results.  An an output
        /// file will be opened as a stream if provided otherwise the console.out stream is used
        /// A downcast is expected as the input param containing the common output format and filepath for simplifying
        /// the allocation to a single method and serves as a type selector but is also recast for command specific
        /// options in the writer as needed
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public static CommandResultsWriter GetWriter(CLICommandOptions options)
        {
            CommandResultsWriter writer = null;

            //allocate the right writer by cmd (options) type
            if (options is CLIAnalyzeCmdOptions cLIAnalyzeCmdOptions)
            {
                writer = GetAnalyzeWriter(cLIAnalyzeCmdOptions);
            }
            else if (options is CLITagTestCmdOptions cLITagTestCmdOptions)
            {
                writer = GetTagTestWriter(cLITagTestCmdOptions);
            }
            else if (options is CLITagDiffCmdOptions cLITagDiffCmdOptions)
            {
                writer = GetTagDiffWriter(cLITagDiffCmdOptions);
            }
            else if (options is CLIExportTagsCmdOptions cLIExportTagsCmdOptions)
            {
                writer = GetExportWriter(cLIExportTagsCmdOptions);
            }
            else if (options is CLIVerifyRulesCmdOptions cLIVerifyRulesCmdOptions)
            {
                writer = GetVerifyRulesWriter(cLIVerifyRulesCmdOptions);
            }
            else if (options is CLIPackRulesCmdOptions cLIPackRulesCmdOptions)
            {
                writer = GetPackRulesWriter(cLIPackRulesCmdOptions);
            }
            else
            {
                throw new Exception("Unrecognized object type in writer request");
            }

            return(writer);
        }