Adds common header
This commit is contained in:
parent
682c267b10
commit
9bebc23f6a
@ -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<TestHeader>(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<MyEvent>();
|
||||
reader.AddHandler<MyEvent>((utc, e) =>
|
||||
|
@ -10,9 +10,18 @@
|
||||
[Serializable]
|
||||
public class OverwatchHeader
|
||||
{
|
||||
public OverwatchCommonHeader Common { get; set; } = new();
|
||||
public OverwatchHeaderEntry[] Entries { get; set; } = Array.Empty<OverwatchHeaderEntry>();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class OverwatchCommonHeader
|
||||
{
|
||||
public long NumberOfEvents { get; set; }
|
||||
public DateTime EarliestUct { get; set; }
|
||||
public DateTime LatestUtc { get; set; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class OverwatchHeaderEntry
|
||||
{
|
||||
|
@ -34,6 +34,15 @@ namespace OverwatchTranscript
|
||||
LoadModel(inputFilename);
|
||||
}
|
||||
|
||||
public OverwatchCommonHeader Header
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckClosed();
|
||||
return model.Header.Common;
|
||||
}
|
||||
}
|
||||
|
||||
public T GetHeader<T>(string key)
|
||||
{
|
||||
CheckClosed();
|
||||
|
@ -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.");
|
||||
|
Loading…
x
Reference in New Issue
Block a user