/// <summary> /// Initializes the SARIF log by emitting properties and other constructs /// sufficient to being populating a run with results. /// </summary> /// <param name="id">A string that uniquely identifies a run.</param> /// <param name="automationId">A global identifier for a run that permits correlation with a larger automation process.</param> public void Initialize(string id, string automationId) { this.EnsureStateNotAlreadySet(Conditions.Disposed | Conditions.Initialized); SarifVersion sarifVersion = SarifVersion.OneZeroZero; _jsonWriter.WriteStartObject(); // Begin: sarifLog _jsonWriter.WritePropertyName("$schema"); _jsonWriter.WriteValue(sarifVersion.ConvertToSchemaUri().OriginalString); _jsonWriter.WritePropertyName("version"); _jsonWriter.WriteValue(sarifVersion.ConvertToText()); _jsonWriter.WritePropertyName("runs"); _jsonWriter.WriteStartArray(); // Begin: runs _jsonWriter.WriteStartObject(); // Begin: run if (!string.IsNullOrEmpty(id)) { _jsonWriter.WritePropertyName("id"); _serializer.Serialize(_jsonWriter, id, typeof(string)); } if (!string.IsNullOrEmpty(automationId)) { _jsonWriter.WritePropertyName("automationId"); _serializer.Serialize(_jsonWriter, automationId, typeof(string)); } _writeConditions |= Conditions.Initialized; }
/// <summary> /// Initializes the SARIF log by emitting properties and other constructs /// sufficient to being populating a run with results. /// </summary> /// <param name="id">A string that uniquely identifies a run.</param> /// <param name="automationId">A global identifier for a run that permits correlation with a larger automation process.</param> public void Initialize(Run run) { if (run == null) { throw new ArgumentNullException(nameof(run)); } _run = run; this.EnsureStateNotAlreadySet(Conditions.Disposed | Conditions.RunInitialized); SarifVersion sarifVersion = SarifVersion.Current; _jsonWriter.WriteStartObject(); // Begin: sarifLog _jsonWriter.WritePropertyName("$schema"); _jsonWriter.WriteValue(sarifVersion.ConvertToSchemaUri().OriginalString); _jsonWriter.WritePropertyName("version"); _jsonWriter.WriteValue(sarifVersion.ConvertToText()); _jsonWriter.WritePropertyName("runs"); _jsonWriter.WriteStartArray(); // Begin: runs _jsonWriter.WriteStartObject(); // Begin: run _writeConditions |= Conditions.RunInitialized; }
public static Uri ConvertToSchemaUri(this SarifVersion sarifVersion) { return(new Uri( SarifSchemaUriBase + sarifVersion.ConvertToText() + (sarifVersion == SarifVersion.Current ? VersionConstants.PackageVersionSuffix : ""), UriKind.Absolute)); }
public static Uri ConvertToSchemaUri(this SarifVersion sarifVersion) { return(new Uri( SarifSchemaUriBase + (sarifVersion == SarifVersion.Current ? VersionConstants.SchemaVersionAsPublishedToSchemaStoreOrg : sarifVersion.ConvertToText()) + ".json", UriKind.Absolute)); }
/// <summary> /// Initializes the SARIF log by emitting properties and other constructs /// sufficient to being populating a run with results. /// </summary> /// <param name="id">A string that uniquely identifies a run.</param> /// <param name="automationId">A global identifier for a run that permits correlation with a larger automation process.</param> public void Initialize(Run run) { if (run == null) { throw new ArgumentNullException(nameof(run)); } this.EnsureStateNotAlreadySet(Conditions.Disposed | Conditions.RunInitialized); SarifVersion sarifVersion = SarifVersion.Current; _jsonWriter.WriteStartObject(); // Begin: sarifLog _jsonWriter.WritePropertyName("$schema"); _jsonWriter.WriteValue(sarifVersion.ConvertToSchemaUri().OriginalString); _jsonWriter.WritePropertyName("version"); _jsonWriter.WriteValue(sarifVersion.ConvertToText()); _jsonWriter.WritePropertyName("runs"); _jsonWriter.WriteStartArray(); // Begin: runs _jsonWriter.WriteStartObject(); // Begin: run if (run.Id != null) { _jsonWriter.WritePropertyName("id"); _serializer.Serialize(_jsonWriter, run.Id); } if (!string.IsNullOrEmpty(run.BaselineInstanceGuid)) { _jsonWriter.WritePropertyName("baselineInstanceGuid"); _serializer.Serialize(_jsonWriter, run.BaselineInstanceGuid); } if (run.AggregateIds != null) { _jsonWriter.WritePropertyName("aggregateIds"); _serializer.Serialize(_jsonWriter, run.AggregateIds); } if (run.Conversion != null) { _jsonWriter.WritePropertyName("conversion"); _serializer.Serialize(_jsonWriter, run.Conversion); } if (run.VersionControlProvenance != null) { _jsonWriter.WritePropertyName("versionControlProvenance"); _serializer.Serialize(_jsonWriter, run.VersionControlProvenance); } if (run.OriginalUriBaseIds != null) { _jsonWriter.WritePropertyName("originalUriBaseIds"); _serializer.Serialize(_jsonWriter, run.OriginalUriBaseIds); } if (run.DefaultFileEncoding != null) { _jsonWriter.WritePropertyName("defaultFileEncoding"); _serializer.Serialize(_jsonWriter, run.DefaultFileEncoding); } if (run.MarkdownMessageMimeType != null && run.MarkdownMessageMimeType != "text/markdown;variant=GFM") { _jsonWriter.WritePropertyName("markdownMessageMimeType"); _serializer.Serialize(_jsonWriter, run.MarkdownMessageMimeType); } if (run.RedactionToken != null) { _jsonWriter.WritePropertyName("redactionToken"); _serializer.Serialize(_jsonWriter, run.RedactionToken); } // For this Windows-relevant SDK, if the column kind isn't explicitly set, // we will set it to Utf16CodeUnits. Our jschema-generated OM is tweaked to // always persist this property. _jsonWriter.WritePropertyName("columnKind"); _jsonWriter.WriteValue(run.ColumnKind == ColumnKind.UnicodeCodePoints ? "unicodeCodePoints" : "utf16CodeUnits"); _writeConditions |= Conditions.RunInitialized; _run = run; }
public static Uri ConvertToSchemaUri(this SarifVersion sarifVersion) { return(new Uri("http://json.schemastore.org/sarif-" + sarifVersion.ConvertToText(), UriKind.Absolute)); }
public static Uri ConvertToSchemaUri(this SarifVersion sarifVersion) { return(new Uri(SarifSchemaUriBase + sarifVersion.ConvertToText(), UriKind.Absolute)); }
/// <summary> /// Initializes the SARIF log by emitting properties and other constructs /// sufficient to being populating a run with results. /// </summary> /// <param name="id">A string that uniquely identifies a run.</param> /// <param name="automationId">A global identifier for a run that permits correlation with a larger automation process.</param> public void Initialize(Run run) { if (run == null) { throw new ArgumentNullException(nameof(run)); } if (run.Tool == null) { throw new ArgumentNullException(nameof(run.Tool)); } this.EnsureStateNotAlreadySet(Conditions.Disposed | Conditions.RunInitialized); SarifVersion sarifVersion = SarifVersion.TwoZeroZero; _jsonWriter.WriteStartObject(); // Begin: sarifLog _jsonWriter.WritePropertyName("$schema"); _jsonWriter.WriteValue(sarifVersion.ConvertToSchemaUri().OriginalString); _jsonWriter.WritePropertyName("version"); _jsonWriter.WriteValue(sarifVersion.ConvertToText()); _jsonWriter.WritePropertyName("runs"); _jsonWriter.WriteStartArray(); // Begin: runs _jsonWriter.WriteStartObject(); // Begin: run if (!string.IsNullOrEmpty(run.InstanceGuid)) { _jsonWriter.WritePropertyName("instanceGuid"); _serializer.Serialize(_jsonWriter, run.InstanceGuid); } if (!string.IsNullOrEmpty(run.BaselineInstanceGuid)) { _jsonWriter.WritePropertyName("baselineInstanceGuid"); _serializer.Serialize(_jsonWriter, run.BaselineInstanceGuid); } if (!string.IsNullOrEmpty(run.AutomationLogicalId)) { _jsonWriter.WritePropertyName("automationLogicalId"); _serializer.Serialize(_jsonWriter, run.AutomationLogicalId); } if (!string.IsNullOrEmpty(run.LogicalId)) { _jsonWriter.WritePropertyName("logicalId"); _serializer.Serialize(_jsonWriter, run.LogicalId); } if (!string.IsNullOrEmpty(run.Architecture)) { _jsonWriter.WritePropertyName("architecture"); _serializer.Serialize(_jsonWriter, run.Architecture); } if (run.Description != null) { _jsonWriter.WritePropertyName("description"); _serializer.Serialize(_jsonWriter, run.Description); } if (run.Tool != null) { _jsonWriter.WritePropertyName("tool"); _serializer.Serialize(_jsonWriter, run.Tool); } if (run.Conversion != null) { _jsonWriter.WritePropertyName("conversion"); _serializer.Serialize(_jsonWriter, run.Conversion); } if (run.VersionControlProvenance != null) { _jsonWriter.WritePropertyName("versionControlProvenance"); _serializer.Serialize(_jsonWriter, run.VersionControlProvenance); } if (run.OriginalUriBaseIds != null) { _jsonWriter.WritePropertyName("originalUriBaseIds"); _serializer.Serialize(_jsonWriter, run.OriginalUriBaseIds); } if (run.DefaultFileEncoding != null) { _jsonWriter.WritePropertyName("defaultFileEncoding"); _serializer.Serialize(_jsonWriter, run.DefaultFileEncoding); } if (run.RichMessageMimeType != null) { _jsonWriter.WritePropertyName("richMessageMimeType"); _serializer.Serialize(_jsonWriter, run.RichMessageMimeType); } if (run.RedactionToken != null) { _jsonWriter.WritePropertyName("redactionToken"); _serializer.Serialize(_jsonWriter, run.RedactionToken); } _writeConditions |= Conditions.RunInitialized; }