diff --git a/Tests/FrameworkTests/OverwatchTranscript/TranscriptTests.cs b/Tests/FrameworkTests/OverwatchTranscript/TranscriptTests.cs index 5e01752..2b058c6 100644 --- a/Tests/FrameworkTests/OverwatchTranscript/TranscriptTests.cs +++ b/Tests/FrameworkTests/OverwatchTranscript/TranscriptTests.cs @@ -50,6 +50,8 @@ namespace FrameworkTests.OverwatchTranscript EventData = EventData1 }); + if (File.Exists(TranscriptFilename)) File.Delete(TranscriptFilename); + writer.Write(TranscriptFilename); } @@ -59,6 +61,9 @@ namespace FrameworkTests.OverwatchTranscript var header = reader.GetHeader(HeaderKey); Assert.That(header.HeaderData, Is.EqualTo(HeaderData)); + Assert.That(reader.Header.NumberOfEvents, Is.EqualTo(3)); + Assert.That(reader.Header.EarliestUct, Is.EqualTo(t0)); + Assert.That(reader.Header.LatestUtc, Is.EqualTo(t2)); var events = new List(); reader.AddHandler((utc, e) => diff --git a/Tools/OverwatchTranscript/Model.cs b/Tools/OverwatchTranscript/Model.cs index 233b7f6..db3f8e2 100644 --- a/Tools/OverwatchTranscript/Model.cs +++ b/Tools/OverwatchTranscript/Model.cs @@ -10,9 +10,18 @@ [Serializable] public class OverwatchHeader { + public OverwatchCommonHeader Common { get; set; } = new(); public OverwatchHeaderEntry[] Entries { get; set; } = Array.Empty(); } + [Serializable] + public class OverwatchCommonHeader + { + public long NumberOfEvents { get; set; } + public DateTime EarliestUct { get; set; } + public DateTime LatestUtc { get; set; } + } + [Serializable] public class OverwatchHeaderEntry { diff --git a/Tools/OverwatchTranscript/TranscriptReader.cs b/Tools/OverwatchTranscript/TranscriptReader.cs index 85da353..1f0c617 100644 --- a/Tools/OverwatchTranscript/TranscriptReader.cs +++ b/Tools/OverwatchTranscript/TranscriptReader.cs @@ -34,6 +34,15 @@ namespace OverwatchTranscript LoadModel(inputFilename); } + public OverwatchCommonHeader Header + { + get + { + CheckClosed(); + return model.Header.Common; + } + } + public T GetHeader(string key) { CheckClosed(); diff --git a/Tools/OverwatchTranscript/TranscriptWriter.cs b/Tools/OverwatchTranscript/TranscriptWriter.cs index 02e76d4..74b5ac2 100644 --- a/Tools/OverwatchTranscript/TranscriptWriter.cs +++ b/Tools/OverwatchTranscript/TranscriptWriter.cs @@ -77,6 +77,8 @@ namespace OverwatchTranscript public void Write(string outputFilename) { + if (!buffer.Any()) throw new Exception("No entries added."); + CheckClosed(); closed = true; @@ -97,6 +99,7 @@ namespace OverwatchTranscript { Header = new OverwatchHeader { + Common = CreateCommonHeader(), Entries = header.Select(h => { return new OverwatchHeaderEntry @@ -123,6 +126,16 @@ namespace OverwatchTranscript } } + private OverwatchCommonHeader CreateCommonHeader() + { + return new OverwatchCommonHeader + { + NumberOfEvents = buffer.Sum(e => e.Value.Count), + EarliestUct = buffer.Min(e => e.Key), + LatestUtc = buffer.Max(e => e.Key) + }; + } + private void CheckClosed() { if (closed) throw new Exception("Transcript has already been written. Cannot modify or write again.");