2021-02-15 07:46:19 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Net.Http;
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
using Google.Protobuf.WellKnownTypes;
|
|
|
|
using INetMock.Client.Audit.Details;
|
|
|
|
|
|
|
|
namespace INetMock.Client.Audit
|
|
|
|
{
|
|
|
|
public abstract record EventDetails;
|
|
|
|
public record EmptyDetails : EventDetails;
|
|
|
|
|
|
|
|
public record GenericDetails : EventDetails
|
|
|
|
{
|
|
|
|
private readonly Any? _detailsAny;
|
|
|
|
public GenericDetails()
|
|
|
|
{
|
|
|
|
_detailsAny = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GenericDetails(Any? any)
|
|
|
|
{
|
|
|
|
_detailsAny = any;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static implicit operator HttpDetails(GenericDetails gd)
|
|
|
|
{
|
|
|
|
if (gd._detailsAny == null || gd._detailsAny.Value == null) return new();
|
2021-02-16 08:36:04 +00:00
|
|
|
if(!gd._detailsAny.TypeUrl.EndsWith(HTTPDetailsEntity.Descriptor.FullName)) throw new InvalidOperationException();
|
2021-02-15 07:46:19 +00:00
|
|
|
return new HttpDetails(gd._detailsAny);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static implicit operator DnsDetails(GenericDetails gd)
|
|
|
|
{
|
|
|
|
if (gd._detailsAny == null || gd._detailsAny.Value == null) return new();
|
2021-02-16 08:36:04 +00:00
|
|
|
if(!gd._detailsAny.TypeUrl.EndsWith(HTTPDetailsEntity.Descriptor.FullName)) throw new InvalidOperationException();
|
2021-02-15 07:46:19 +00:00
|
|
|
return new DnsDetails(gd._detailsAny);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public record HttpDetails : EventDetails
|
|
|
|
{
|
|
|
|
public HttpDetails()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public HttpDetails(Any? any)
|
|
|
|
{
|
|
|
|
if (any == null || any.Value == null) return;
|
|
|
|
|
|
|
|
var detailsEntity = HTTPDetailsEntity.Parser.ParseFrom(any.Value);
|
|
|
|
|
|
|
|
Method = new HttpMethod(detailsEntity.Method.ToString());
|
|
|
|
Host = detailsEntity.Host;
|
|
|
|
Uri = detailsEntity.Uri;
|
|
|
|
Proto = detailsEntity.Proto;
|
|
|
|
Headers = new INetMockHttpHeaders(detailsEntity.Headers);
|
|
|
|
}
|
|
|
|
|
|
|
|
public HttpMethod Method { get; init; }
|
|
|
|
public string Host { get; init; }
|
|
|
|
public string Uri { get; init; }
|
|
|
|
public string Proto { get; init; }
|
|
|
|
public HttpHeaders Headers { get; init; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public record DnsDetails : EventDetails
|
|
|
|
{
|
|
|
|
public DnsDetails()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public DNSOpCode OpCode { get; init; }
|
|
|
|
|
|
|
|
public IReadOnlyList<DNSQuestionEntity> Questions { get; init; }
|
|
|
|
|
|
|
|
public DnsDetails(Any? any)
|
|
|
|
{
|
|
|
|
if(any == null || any.Value == null) return;
|
|
|
|
|
|
|
|
var entity = DNSDetailsEntity.Parser.ParseFrom(any.Value);
|
|
|
|
OpCode = entity.Opcode;
|
|
|
|
Questions = entity.Questions;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|