public static int Run(RewriteOptions rewriteOptions)
        {
            try
            {
                rewriteOptions = ValidateOptions(rewriteOptions);

                SarifLog actualLog = MultitoolFileHelpers.ReadSarifFile(rewriteOptions.InputFilePath);

                LoggingOptions loggingOptions = rewriteOptions.ConvertToLoggingOptions();

                SarifLog reformattedLog = new ReformattingVisitor(loggingOptions).VisitSarifLog(actualLog);

                string fileName = GetOutputFileName(rewriteOptions);

                var formatting = rewriteOptions.PrettyPrint
                    ? Newtonsoft.Json.Formatting.Indented
                    : Newtonsoft.Json.Formatting.None;

                MultitoolFileHelpers.WriteSarifFile(reformattedLog, fileName, formatting);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(1);
            }

            return(0);
        }
Beispiel #2
0
        public static int Run(RewriteOptions rewriteOptions)
        {
            try
            {
                rewriteOptions = ValidateOptions(rewriteOptions);
                string fileName = GetOutputFileName(rewriteOptions);

                Newtonsoft.Json.Formatting formatting = rewriteOptions.PrettyPrint
                    ? Newtonsoft.Json.Formatting.Indented
                    : Newtonsoft.Json.Formatting.None;

                JsonSerializerSettings settings = new JsonSerializerSettings()
                {
                    ContractResolver = SarifContractResolver.Instance,
                    Formatting       = Newtonsoft.Json.Formatting.Indented
                };

                string   sarifText = File.ReadAllText(rewriteOptions.InputFilePath);
                SarifLog actualLog = JsonConvert.DeserializeObject <SarifLog>(sarifText, settings);

                LoggingOptions loggingOptions = rewriteOptions.ConvertToLoggingOptions();

                SarifLog reformattedLog = new ReformattingVisitor(loggingOptions).VisitSarifLog(actualLog);

                File.WriteAllText(fileName, JsonConvert.SerializeObject(reformattedLog, settings));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(1);
            }

            return(0);
        }