diff --git a/csharp/extractor/Semmle.Util/ToolStatusPage.cs b/csharp/extractor/Semmle.Util/ToolStatusPage/DiagnosticMessage.cs similarity index 77% rename from csharp/extractor/Semmle.Util/ToolStatusPage.cs rename to csharp/extractor/Semmle.Util/ToolStatusPage/DiagnosticMessage.cs index a93cdec5fdf6..e8b061b29f2b 100644 --- a/csharp/extractor/Semmle.Util/ToolStatusPage.cs +++ b/csharp/extractor/Semmle.Util/ToolStatusPage/DiagnosticMessage.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.IO; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Serialization; @@ -179,64 +178,4 @@ public DiagnosticMessage( this.PlaintextMessage = plaintextMessage; } } - - /// - /// Provides the ability to write diagnostic messages to some output. - /// - public interface IDiagnosticsWriter : IDisposable - { - /// - /// Adds as a new diagnostics entry. - /// - /// The diagnostics entry to add. - void AddEntry(DiagnosticMessage message); - } - - /// - /// A wrapper around an underlying which allows - /// objects to be serialized to it. - /// - public sealed class DiagnosticsStream : IDiagnosticsWriter, IDisposable - { - private readonly JsonSerializer serializer; - private readonly StreamWriter writer; - - /// - /// Initialises a new for a file at . - /// - /// The path to the file that should be created. - public DiagnosticsStream(string path) - { - this.writer = File.CreateText(path); - - var contractResolver = new DefaultContractResolver - { - NamingStrategy = new CamelCaseNamingStrategy() - }; - - serializer = new JsonSerializer - { - ContractResolver = contractResolver, - NullValueHandling = NullValueHandling.Ignore - }; - } - - /// - /// Adds as a new diagnostics entry. - /// - /// The diagnostics entry to add. - public void AddEntry(DiagnosticMessage message) - { - serializer.Serialize(writer, message); - writer.Flush(); - } - - /// - /// Releases all resources used by the object. - /// - public void Dispose() - { - writer.Dispose(); - } - } } diff --git a/csharp/extractor/Semmle.Util/ToolStatusPage/DiagnosticsStream.cs b/csharp/extractor/Semmle.Util/ToolStatusPage/DiagnosticsStream.cs new file mode 100644 index 000000000000..1ac2edc5602c --- /dev/null +++ b/csharp/extractor/Semmle.Util/ToolStatusPage/DiagnosticsStream.cs @@ -0,0 +1,55 @@ +using System; +using System.IO; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; + +namespace Semmle.Util +{ + /// + /// A wrapper around an underlying which allows + /// objects to be serialized to it. + /// + public sealed class DiagnosticsStream : IDiagnosticsWriter, IDisposable + { + private readonly JsonSerializer serializer; + private readonly StreamWriter writer; + + /// + /// Initialises a new for a file at . + /// + /// The path to the file that should be created. + public DiagnosticsStream(string path) + { + this.writer = File.CreateText(path); + + var contractResolver = new DefaultContractResolver + { + NamingStrategy = new CamelCaseNamingStrategy() + }; + + serializer = new JsonSerializer + { + ContractResolver = contractResolver, + NullValueHandling = NullValueHandling.Ignore + }; + } + + /// + /// Adds as a new diagnostics entry. + /// + /// The diagnostics entry to add. + public void AddEntry(DiagnosticMessage message) + { + serializer.Serialize(writer, message); + writer.Flush(); + } + + /// + /// Releases all resources used by the object. + /// + public void Dispose() + { + writer.Dispose(); + } + } +} diff --git a/csharp/extractor/Semmle.Util/ToolStatusPage/IDiagnosticsWriter.cs b/csharp/extractor/Semmle.Util/ToolStatusPage/IDiagnosticsWriter.cs new file mode 100644 index 000000000000..eda3dbb41d83 --- /dev/null +++ b/csharp/extractor/Semmle.Util/ToolStatusPage/IDiagnosticsWriter.cs @@ -0,0 +1,16 @@ +using System; + +namespace Semmle.Util +{ + /// + /// Provides the ability to write diagnostic messages to some output. + /// + public interface IDiagnosticsWriter : IDisposable + { + /// + /// Adds as a new diagnostics entry. + /// + /// The diagnostics entry to add. + void AddEntry(DiagnosticMessage message); + } +}