Extend docs and add missing constructors

This commit is contained in:
Peter 2022-01-27 20:37:25 +01:00
parent c564229fb2
commit 9191cbaa9f
Signed by: prskr
GPG key ID: C1DB5D2E8DB512F9
2 changed files with 43 additions and 6 deletions

View file

@ -1,7 +1,10 @@
# client-dotnet # INetMock .NET client library
## NuGet source ## 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 ```shell
dotnet nuget add source \ dotnet nuget add source \
https://gitlab.com/api/v4/projects/24385200/packages/nuget/index.json \ https://gitlab.com/api/v4/projects/24385200/packages/nuget/index.json \
@ -10,3 +13,20 @@ dotnet nuget add source \
-p 3FLWym5gfajuJNhBKvWV \ -p 3FLWym5gfajuJNhBKvWV \
--store-password-in-clear-text --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);
}
```

View file

@ -3,9 +3,9 @@ using System.Net;
namespace INetMock.Client.Audit; namespace INetMock.Client.Audit;
public abstract record EventBase public abstract record EventBase()
{ {
protected EventBase(EventEntity entity) protected EventBase(EventEntity entity) : this()
{ {
if (entity == null) if (entity == null)
{ {
@ -24,18 +24,30 @@ public abstract record EventBase
} }
public long Id { get; init; } public long Id { get; init; }
public DateTimeOffset Timestamp { get; init; }
public TransportProtocol Transport { get; init; } public DateTimeOffset Timestamp { get; init; } = DateTimeOffset.UnixEpoch;
public AppProtocol Application { get; init; }
public TransportProtocol Transport { get; init; } = TransportProtocol.Unspecified;
public AppProtocol Application { get; init; } = AppProtocol.Unspecified;
public IPAddress SourceIp { get; init; } = IPAddress.Any; public IPAddress SourceIp { get; init; } = IPAddress.Any;
public IPAddress DestinationIp { get; init; } = IPAddress.Any; public IPAddress DestinationIp { get; init; } = IPAddress.Any;
public ushort SourcePort { get; init; } public ushort SourcePort { get; init; }
public ushort DestinationPort { get; init; } public ushort DestinationPort { get; init; }
public TLSDetailsEntity TlsDetails { get; init; } = new(); public TLSDetailsEntity TlsDetails { get; init; } = new();
} }
public record Event : EventBase public record Event : EventBase
{ {
public Event()
{
}
public Event(EventEntity entity) : base(entity) public Event(EventEntity entity) : base(entity)
{ {
Details = entity.ProtocolDetailsCase switch Details = entity.ProtocolDetailsCase switch
@ -54,6 +66,11 @@ public record Event : EventBase
public record Event<T> : EventBase where T : EventDetails, new() public record Event<T> : EventBase where T : EventDetails, new()
{ {
public Event()
{
}
public Event(EventEntity entity) : base(entity) public Event(EventEntity entity) : base(entity)
{ {
Details = entity.ProtocolDetailsCase switch Details = entity.ProtocolDetailsCase switch