public static void ConvertSarifLog(JsonSerializer serializer, string sarifFilePath, CsvWriter writer, IEnumerable <Action <WriteContext> > selectedWriters) { SarifLog log = null; // Read the SarifLog with the deferred reader using (JsonPositionedTextReader jtr = new JsonPositionedTextReader(sarifFilePath)) { log = serializer.Deserialize <SarifLog>(jtr); } WriteContext context = new WriteContext(); context.Writer = writer; // Write a row in the output file for each result location if (log.Runs != null) { context.RunIndex = 0; foreach (var run in log.Runs) { context.Run = run; context.ResultIndex = 0; if (run.Results != null) { foreach (var result in run.Results) { context.Result = result; if (result.Locations == null || result.Locations.Count == 0) { context.PLoc = null; Write(context, selectedWriters); } else { foreach (PhysicalLocation location in result.PhysicalLocations()) { context.PLoc = location; Write(context, selectedWriters); } } context.ResultIndex++; } } context.RunIndex++; } } }
public static void Write(WriteContext context, IEnumerable <Action <WriteContext> > columnWriters) { foreach (Action <WriteContext> columnWriter in columnWriters) { columnWriter(context); } context.Writer.NextRow(); if (context.Writer.RowCountWritten % 1000 == 0) { Console.Write("."); } }
private static void WriteProperties(WriteContext c) { StringBuilder result = new StringBuilder(); foreach (string propertyName in c?.Result?.PropertyNames ?? Enumerable.Empty <string>()) { if (result.Length > 0) { result.Append("; "); } result.Append(propertyName); result.Append(": "); result.Append(c.Result.GetSerializedPropertyValue(propertyName) ?? "<null>"); } c.Writer.Write(result.ToString()); }