Dispose() public method

Writes the log footer and closes the underlying JsonWriter.
public Dispose ( ) : void
return void
 public void ResultLogJsonWriter_MultipleDisposeAllowed()
 {
     using (var str = new StringWriter())
         using (var json = new JsonTextWriter(str))
             using (var uut = new ResultLogJsonWriter(json))
             {
                 // Assert no exception thrown
                 uut.Dispose();
                 uut.Dispose();
                 uut.Dispose();
             }
 }
Exemplo n.º 2
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() &&
                    !_dataToRemove.HasFlag(OptionallyEmittedData.NondeterministicProperties))
                {
                    _run.Invocations[0].EndTimeUtc = DateTime.UtcNow;
                }

                _issueLogJsonWriter.CompleteRun();
                _issueLogJsonWriter.Dispose();
            }

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

            GC.SuppressFinalize(this);
        }
Exemplo n.º 3
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;
                }

                _issueLogJsonWriter.CompleteRun();
                _issueLogJsonWriter.Dispose();
            }

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

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

            GC.SuppressFinalize(this);
        }
Exemplo n.º 4
0
        public 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 != null && _run.ConfigurationNotifications != null)
                {
                    _issueLogJsonWriter.WriteConfigurationNotifications(_run.ConfigurationNotifications);
                }

                if (_run != null && _run.ToolNotifications != null)
                {
                    _issueLogJsonWriter.WriteToolNotifications(_run.ToolNotifications);
                }

                if (_run != null &&
                    _run.Invocation != null &&
                    _run.Invocation.StartTime != new DateTime())
                {
                    _run.Invocation.EndTime = DateTime.UtcNow;
                }

                // Note: we write out the backing rules
                // to prevent the property accessor from populating
                // this data with an empty collection.
                if (_rules != null)
                {
                    _issueLogJsonWriter.WriteRules(_rules);
                }

                if (_run != null && _run.Files != null)
                {
                    _issueLogJsonWriter.WriteFiles(_run.Files);
                }

                if (_run != null && _run.Invocation != null)
                {
                    _issueLogJsonWriter.WriteInvocation(invocation: _run.Invocation);
                }

                _issueLogJsonWriter.Dispose();
            }

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

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

            GC.SuppressFinalize(this);
        }
 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);
             }
 }
Exemplo n.º 7
0
 public void ResultLogJsonWriter_CannotWriteIssuesToDisposedWriter()
 {
     using (var str = new StringWriter())
         using (var json = new JsonTextWriter(str))
             using (var uut = new ResultLogJsonWriter(json))
             {
                 uut.WriteToolAndRunInfo(s_defaultToolInfo, s_defaultRunInfo);
                 uut.Dispose();
                 uut.WriteResult(s_defaultIssue);
             }
 }
 public void ResultLogJsonWriter_CannotWriteResultsToDisposedWriter()
 {
     using (var str = new StringWriter())
         using (var json = new JsonTextWriter(str))
             using (var uut = new ResultLogJsonWriter(json))
             {
                 var run = new Run()
                 {
                     Tool = DefaultTool
                 };
                 uut.Initialize(run);
                 uut.Dispose();
                 Assert.Throws <InvalidOperationException>(() => uut.WriteResult(DefaultResult));
             }
 }
Exemplo n.º 9
0
        public static void ProcessLogFile(string filePath, ToolFormat toolFormat = ToolFormat.None)
        {
            SarifLog log;

            JsonSerializerSettings settings = new JsonSerializerSettings()
            {
                ContractResolver = SarifContractResolver.Instance,
            };

            string logText;

            if (toolFormat == ToolFormat.None)
            {
                logText = File.ReadAllText(filePath);
            }
            else if (toolFormat == ToolFormat.PREfast)
            {
                logText = ToolFormatConverter.ConvertPREfastToStandardFormat(filePath);
            }
            else
            {
                // We have conversion to do
                var converter = new ToolFormatConverter();
                var sb = new StringBuilder();

                using (var input = new MemoryStream(File.ReadAllBytes(filePath)))
                {
                    var outputTextWriter = new StringWriter(sb);
                    var outputJson = new JsonTextWriter(outputTextWriter);
                    var output = new ResultLogJsonWriter(outputJson);

                    input.Seek(0, SeekOrigin.Begin);
                    converter.ConvertToStandardFormat(toolFormat, input, output);

                    // This is serving as a flush mechanism
                    output.Dispose();

                    logText = sb.ToString();
                }
            }

            log = JsonConvert.DeserializeObject<SarifLog>(logText, settings);
            ProcessSarifLog(log, filePath);
        }
Exemplo n.º 10
0
 public void ResultLogJsonWriter_MultipleDisposeAllowed()
 {
     using (var str = new StringWriter())
     using (var json = new JsonTextWriter(str))
     using (var uut = new ResultLogJsonWriter(json))
     {
         // Assert no exception thrown
         uut.Dispose();
         uut.Dispose();
         uut.Dispose();
     }
 }
Exemplo n.º 11
0
 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);
     }
 }