-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move TSP diagnostics related classes to separate files
- Loading branch information
Showing
3 changed files
with
71 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
csharp/extractor/Semmle.Util/ToolStatusPage/DiagnosticsStream.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.IO; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
|
||
namespace Semmle.Util | ||
{ | ||
/// <summary> | ||
/// A wrapper around an underlying <see cref="StreamWriter" /> which allows | ||
/// <see cref="DiagnosticMessage" /> objects to be serialized to it. | ||
/// </summary> | ||
public sealed class DiagnosticsStream : IDiagnosticsWriter, IDisposable | ||
{ | ||
private readonly JsonSerializer serializer; | ||
private readonly StreamWriter writer; | ||
|
||
/// <summary> | ||
/// Initialises a new <see cref="DiagnosticsStream" /> for a file at <paramref name="path" />. | ||
/// </summary> | ||
/// <param name="path">The path to the file that should be created.</param> | ||
public DiagnosticsStream(string path) | ||
{ | ||
this.writer = File.CreateText(path); | ||
|
||
var contractResolver = new DefaultContractResolver | ||
{ | ||
NamingStrategy = new CamelCaseNamingStrategy() | ||
}; | ||
|
||
serializer = new JsonSerializer | ||
{ | ||
ContractResolver = contractResolver, | ||
NullValueHandling = NullValueHandling.Ignore | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Adds <paramref name="message" /> as a new diagnostics entry. | ||
/// </summary> | ||
/// <param name="message">The diagnostics entry to add.</param> | ||
public void AddEntry(DiagnosticMessage message) | ||
{ | ||
serializer.Serialize(writer, message); | ||
writer.Flush(); | ||
} | ||
|
||
/// <summary> | ||
/// Releases all resources used by the <see cref="DiagnosticsStream" /> object. | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
writer.Dispose(); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
csharp/extractor/Semmle.Util/ToolStatusPage/IDiagnosticsWriter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
|
||
namespace Semmle.Util | ||
{ | ||
/// <summary> | ||
/// Provides the ability to write diagnostic messages to some output. | ||
/// </summary> | ||
public interface IDiagnosticsWriter : IDisposable | ||
{ | ||
/// <summary> | ||
/// Adds <paramref name="message" /> as a new diagnostics entry. | ||
/// </summary> | ||
/// <param name="message">The diagnostics entry to add.</param> | ||
void AddEntry(DiagnosticMessage message); | ||
} | ||
} |