2
0
mirror of synced 2025-01-11 09:06:56 +00:00

Adds common header

This commit is contained in:
benbierens 2024-07-29 08:08:17 +02:00
parent 682c267b10
commit 9bebc23f6a
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
4 changed files with 36 additions and 0 deletions

View File

@ -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) =>

View File

@ -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
{

View File

@ -34,6 +34,15 @@ namespace OverwatchTranscript
LoadModel(inputFilename);
}
public OverwatchCommonHeader Header
{
get
{
CheckClosed();
return model.Header.Common;
}
}
public T GetHeader<T>(string key)
{
CheckClosed();

View File

@ -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.");