WriteTool() public method

Writes a tool information entry to the log. This must be the first entry written into a log, and it may be written at most once.
A file IO error occured. Clients implementing /// should allow these exceptions to propagate. Thrown if the tool info block has already been /// written.
public WriteTool ( Tool tool ) : void
tool Tool
return void
 public void ResultLogJsonWriter_CannotWriteToolTwice()
 {
     using (var str = new StringWriter())
         using (var json = new JsonTextWriter(str))
             using (var uut = new ResultLogJsonWriter(json))
             {
                 var run = new Run()
                 {
                 };
                 uut.Initialize(run);
                 uut.WriteTool(DefaultTool);
                 Assert.Throws <InvalidOperationException>(() => uut.WriteTool(DefaultTool));
             }
 }
 public void ResultLogJsonWriter_CannotWriteToolToDisposedWriter()
 {
     using (var str = new StringWriter())
         using (var json = new JsonTextWriter(str))
             using (var uut = new ResultLogJsonWriter(json))
             {
                 uut.Dispose();
                 Assert.Throws <InvalidOperationException>(() => uut.WriteTool(DefaultTool));
             }
 }
 public void ResultLogJsonWriter_CannotWriteToolToDisposedWriter()
 {
     using (var str = new StringWriter())
         using (var json = new JsonTextWriter(str))
             using (var uut = new ResultLogJsonWriter(json))
             {
                 uut.Dispose();
                 uut.WriteTool(s_defaultTool);
             }
 }
 public void ResultLogJsonWriter_CannotWriteConfigurationNotificationsTwice()
 {
     using (var str = new StringWriter())
         using (var json = new JsonTextWriter(str))
             using (var uut = new ResultLogJsonWriter(json))
             {
                 uut.WriteTool(DefaultTool);
                 uut.WriteConfigurationNotifications(s_notifications);
                 Assert.Throws <InvalidOperationException>(() => uut.WriteConfigurationNotifications(s_notifications));
             }
 }
 public void ResultLogJsonWriter_CannotWriteConfigurationNotificationsTwice()
 {
     using (var str = new StringWriter())
         using (var json = new JsonTextWriter(str))
             using (var uut = new ResultLogJsonWriter(json))
             {
                 uut.WriteTool(DefaultTool);
                 uut.WriteConfigurationNotifications(s_notifications);
                 uut.WriteConfigurationNotifications(s_notifications);
             }
 }
 public void ResultLogJsonWriter_CannotWriteInvocationTwice()
 {
     using (var str = new StringWriter())
         using (var json = new JsonTextWriter(str))
             using (var uut = new ResultLogJsonWriter(json))
             {
                 uut.WriteTool(DefaultTool);
                 uut.WriteInvocation(s_invocation);
                 uut.WriteInvocation(s_invocation);
             }
 }
Exemplo n.º 7
0
        public virtual void Dispose()
        {
            // Disposing the json writer closes the stream but the textwriter
            // still needs to be disposed or closed to write the results
            if (_issueLogJsonWriter != null)
            {
                _issueLogJsonWriter.CloseResults();

                if (_run?.Invocations?.Count > 0 && _run.Invocations[0].StartTimeUtc != new DateTime())
                {
                    _run.Invocations[0].EndTimeUtc = DateTime.UtcNow;
                }

                if (_run?.Tool != null)
                {
                    _issueLogJsonWriter.WriteTool(_run.Tool);
                }

                if (_run?.Artifacts != null)
                {
                    _issueLogJsonWriter.WriteArtifacts(_run.Artifacts);
                }

                if (_run?.Invocations != null)
                {
                    _issueLogJsonWriter.WriteInvocations(invocations: _run.Invocations);
                }

                if (_run?.Properties != null)
                {
                    _issueLogJsonWriter.WriteRunProperties(_run.Properties);
                }

                _issueLogJsonWriter.Dispose();
            }

            if (_textWriter != null)
            {
                _textWriter.Dispose();
            }

            if (_jsonTextWriter == null)
            {
                _jsonTextWriter.Close();
            }

            GC.SuppressFinalize(this);
        }
Exemplo n.º 8
0
        public SarifLogger(
            TextWriter textWriter,
            LoggingOptions loggingOptions = LoggingOptions.PrettyPrint,
            Tool tool = null,
            Run run   = null,
            IEnumerable <string> analysisTargets = null,
            bool targetsAreTextFiles             = true,
            string prereleaseInfo = null,
            IEnumerable <string> invocationTokensToRedact  = null,
            IEnumerable <string> invocationPropertiesToLog = null) : this(textWriter, loggingOptions)
        {
            _run = run ?? CreateRun(
                analysisTargets,
                loggingOptions,
                invocationTokensToRedact,
                invocationPropertiesToLog);


            tool = tool ?? Tool.CreateFromAssemblyData();
            SetSarifLoggerVersion(tool);
            _issueLogJsonWriter.WriteTool(tool);
        }
 public void ResultLogJsonWriter_CannotWriteToolToDisposedWriter()
 {
     using (var str = new StringWriter())
     using (var json = new JsonTextWriter(str))
     using (var uut = new ResultLogJsonWriter(json))
     {
         uut.Dispose();
         uut.WriteTool(DefaultTool);
     }
 }
Exemplo n.º 10
0
 public void ResultLogJsonWriter_CannotWriteToolNotificationsTwice()
 {
     using (var str = new StringWriter())
     using (var json = new JsonTextWriter(str))
     using (var uut = new ResultLogJsonWriter(json))
     {
         uut.WriteTool(DefaultTool);
         uut.WriteToolNotifications(s_notifications);
         uut.WriteToolNotifications(s_notifications);
     }
 }