From 9191cbaa9f1afd060ea46e3ec44ac1c09cecaea3 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Thu, 27 Jan 2022 20:37:25 +0100 Subject: [PATCH] Extend docs and add missing constructors --- README.md | 22 +++++++++++++++++++++- src/INetMock.Client/Audit/Event.cs | 27 ++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a4677e9..31eaa80 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ -# client-dotnet +# INetMock .NET client library ## NuGet source +Due to limitations in GitLab one is required to be authenticated to use packages in GitLab NuGet registry. +The following credentials are `read_only` and allowed to be used by anyone. + ```shell dotnet nuget add source \ https://gitlab.com/api/v4/projects/24385200/packages/nuget/index.json \ @@ -10,3 +13,20 @@ dotnet nuget add source \ -p 3FLWym5gfajuJNhBKvWV \ --store-password-in-clear-text ``` + +## Reading audit files + +```c# +using System.IO; +using System.Threading.Tasks; +using INetMock.Client.Audit; +using INetMock.Client.Audit.Serialization; + +await using var auditFileStream = File.OpenRead("test.ima"); +await using IEventReader reader = new GenericReader(new ProtoReader(auditFileStream)); + +await foreach (var ev in reader.ReadAllAsync()) +{ + Console.WriteLine(ev.Application); +} +``` diff --git a/src/INetMock.Client/Audit/Event.cs b/src/INetMock.Client/Audit/Event.cs index 3eeb1ff..eda96fa 100644 --- a/src/INetMock.Client/Audit/Event.cs +++ b/src/INetMock.Client/Audit/Event.cs @@ -3,9 +3,9 @@ using System.Net; namespace INetMock.Client.Audit; -public abstract record EventBase +public abstract record EventBase() { - protected EventBase(EventEntity entity) + protected EventBase(EventEntity entity) : this() { if (entity == null) { @@ -24,18 +24,30 @@ public abstract record EventBase } public long Id { get; init; } - public DateTimeOffset Timestamp { get; init; } - public TransportProtocol Transport { get; init; } - public AppProtocol Application { get; init; } + + public DateTimeOffset Timestamp { get; init; } = DateTimeOffset.UnixEpoch; + + public TransportProtocol Transport { get; init; } = TransportProtocol.Unspecified; + + public AppProtocol Application { get; init; } = AppProtocol.Unspecified; + public IPAddress SourceIp { get; init; } = IPAddress.Any; + public IPAddress DestinationIp { get; init; } = IPAddress.Any; + public ushort SourcePort { get; init; } + public ushort DestinationPort { get; init; } + public TLSDetailsEntity TlsDetails { get; init; } = new(); } public record Event : EventBase { + public Event() + { + } + public Event(EventEntity entity) : base(entity) { Details = entity.ProtocolDetailsCase switch @@ -54,6 +66,11 @@ public record Event : EventBase public record Event : EventBase where T : EventDetails, new() { + public Event() + { + + } + public Event(EventEntity entity) : base(entity) { Details = entity.ProtocolDetailsCase switch