cs-codex-dist-tests/ProjectPlugins/CodexPlugin/OverwatchSupport/ModelExtensions.cs

141 lines
3.8 KiB
C#
Raw Normal View History

2024-07-29 09:02:24 +00:00
using OverwatchTranscript;
namespace CodexPlugin.OverwatchSupport
2024-07-25 13:12:25 +00:00
{
[Serializable]
public class OverwatchCodexHeader
{
2024-08-13 12:21:15 +00:00
public CodexNodeIdentity[] Nodes { get; set; } = Array.Empty<CodexNodeIdentity>();
2024-07-25 13:12:25 +00:00
}
[Serializable]
public class OverwatchCodexEvent
{
2024-08-13 12:21:15 +00:00
public int NodeIdentity { get; set; } = -1;
2024-07-25 14:00:51 +00:00
public ScenarioFinishedEvent? ScenarioFinished { get; set; }
public NodeStartingEvent? NodeStarting { get; set; }
2024-07-25 13:12:25 +00:00
public NodeStartedEvent? NodeStarted { get; set; }
public NodeStoppingEvent? NodeStopping { get; set; }
public BootstrapConfigEvent? BootstrapConfig { get; set; }
public FileUploadingEvent? FileUploading { get; set; }
2024-07-25 13:12:25 +00:00
public FileUploadedEvent? FileUploaded { get; set; }
public FileDownloadingEvent? FileDownloading { get; set; }
2024-07-25 13:12:25 +00:00
public FileDownloadedEvent? FileDownloaded { get; set; }
public BlockReceivedEvent? BlockReceived { get; set; }
public PeerDialSuccessfulEvent? DialSuccessful { get; set; }
public PeerDroppedEvent? PeerDropped { get; set; }
2024-07-29 09:02:24 +00:00
public void Write(DateTime utc, ITranscriptWriter writer)
{
2024-08-13 12:21:15 +00:00
if (NodeIdentity == -1 && ScenarioFinished == null)
{
throw new Exception("NodeIdentity not set, and event is not ScenarioFinished.");
}
2024-07-29 09:02:24 +00:00
if (AllNull()) throw new Exception("No event data was set");
writer.Add(utc, this);
}
private bool AllNull()
{
var props = GetType()
.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)
.Where(p => p.PropertyType != typeof(string)).ToArray();
return props.All(p => p.GetValue(this) == null);
}
2024-07-25 13:12:25 +00:00
}
[Serializable]
public class CodexNodeIdentity
{
2024-08-13 12:21:15 +00:00
public string Name { get; set; } = string.Empty;
public string PeerId { get; set; } = string.Empty;
public string NodeId { get; set; } = string.Empty;
}
2024-07-25 13:12:25 +00:00
#region Scenario Generated Events
2024-07-25 14:00:51 +00:00
[Serializable]
public class ScenarioFinishedEvent
{
public bool Success { get; set; }
public string Result { get; set; } = string.Empty;
}
2024-07-25 13:12:25 +00:00
[Serializable]
public class NodeStartingEvent
2024-07-25 13:12:25 +00:00
{
public string Image { get; set; } = string.Empty;
}
[Serializable]
public class NodeStartedEvent
{
2024-07-25 13:12:25 +00:00
}
[Serializable]
public class NodeStoppingEvent
2024-07-25 13:12:25 +00:00
{
}
[Serializable]
public class BootstrapConfigEvent
{
public string BootstrapPeerId { get; set; } = string.Empty;
}
[Serializable]
public class FileUploadingEvent
{
public string UniqueId { get; set;} = string.Empty;
public long ByteSize { get; set; }
}
[Serializable]
public class FileDownloadingEvent
{
public string Cid { get; set; } = string.Empty;
}
2024-07-25 13:12:25 +00:00
[Serializable]
public class FileUploadedEvent
{
public string UniqueId { get; set; } = string.Empty;
public long ByteSize { get; set; }
2024-07-25 13:12:25 +00:00
public string Cid { get; set; } = string.Empty;
}
[Serializable]
public class FileDownloadedEvent
{
public string Cid { get; set; } = string.Empty;
public long ByteSize { get; set; }
2024-07-25 13:12:25 +00:00
}
#endregion
#region Codex Generated Events
[Serializable]
public class BlockReceivedEvent
{
public string BlockAddress { get; set; } = string.Empty;
public string SenderPeerId { get; set; } = string.Empty;
2024-07-25 13:12:25 +00:00
}
2024-08-01 06:29:12 +00:00
[Serializable]
public class PeerDialSuccessfulEvent
2024-08-01 06:29:12 +00:00
{
public string TargetPeerId { get; set; } = string.Empty;
}
[Serializable]
public class PeerDroppedEvent
{
public string DroppedPeerId { get; set; } = string.Empty;
}
2024-07-25 13:12:25 +00:00
#endregion
}