Skip to content

Commit

Permalink
Move C# code into separate file for better development experience.
Browse files Browse the repository at this point in the history
  • Loading branch information
splatteredbits committed Feb 18, 2023
1 parent d81637c commit 9ebe381
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 70 deletions.
73 changes: 3 additions & 70 deletions W3CLogs/W3CLogs.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -51,77 +51,10 @@ $script:milliseconds = [Collections.Generic.Hashset[String]]::New()
$script:httpMethods = [Collections.Generic.Hashset[String]]::New()
[void]$script:httpMethods.Add('sc-method')

Add-Type -ReferencedAssemblies 'System.Net.Http' -TypeDefinition @'
using System;
using System.Net;
using System.Net.Http;
$srcPath = Join-Path -Path $script:moduleRoot -ChildPath 'src' -Resolve

namespace W3CLogs
{
public sealed class LogEntry
{
public DateTime Date { get; set; }
public TimeSpan Time { get; set; }
public DateTime DateTime { get; set; }
public IPAddress ClientIP { get; set; }
public string UserName { get; set; }
public string SiteName { get; set; }
public string ComputerName { get; set; }
public IPAddress ServerIP { get; set; }
public ushort Port { get; set; }
public HttpMethod Method { get; set; }
public Uri Url { get; set; }
public string Stem { get; set; }
public string Query { get; set; }
public HttpStatusCode Status { get; set; }
public int Substatus { get; set; }
public int Win32SStatus { get; set; }
public ulong BytesSent { get; set; }
public ulong BytesReceived { get; set; }
public TimeSpan TimeTaken { get; set; }
public string Version { get; set; }
public string Host { get; set; }
public string UserAgent { get; set; }
public string Cookie { get; set; }
public Uri Referer { get; set; }
public override bool Equals(object obj)
{
var entry = obj as LogEntry;
if (null == entry)
return false;
return this.Date == entry.Date &&
this.Time == entry.Time &&
this.ClientIP == entry.ClientIP &&
this.UserName == entry.UserName &&
this.SiteName == entry.SiteName &&
this.ComputerName == entry.ComputerName &&
this.ServerIP == entry.ServerIP &&
this.Port == entry.Port &&
this.Method == entry.Method &&
this.Stem == entry.Stem &&
this.Query == entry.Query &&
this.Status == entry.Status &&
this.Substatus == entry.Substatus &&
this.Win32SStatus == entry.Win32SStatus &&
this.BytesSent == entry.BytesSent &&
this.BytesReceived == entry.BytesReceived &&
this.TimeTaken == entry.TimeTaken &&
this.Version == entry.Version &&
this.Host == entry.Host &&
this.UserAgent == entry.UserAgent &&
this.Cookie == entry.Cookie &&
this.Referer == entry.Referer;
}
public override int GetHashCode()
{
throw new NotImplementedException();
}
}
}
'@
Add-Type -Path (Get-ChildItem -Path $srcPath -Filter '*.cs').FullName `
-ReferencedAssemblies 'System.Net.Http','System.Net','System.Net.Primitives'

# Store each of your module's functions in its own file in the Functions
# directory. On the build server, your module's functions will be appended to
Expand Down
69 changes: 69 additions & 0 deletions W3CLogs/src/LogEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Net;
using System.Net.Http;

namespace W3CLogs
{
public sealed class LogEntry
{
public DateTime Date { get; set; }
public TimeSpan Time { get; set; }
public DateTime DateTime { get; set; }
public IPAddress ClientIP { get; set; }
public string UserName { get; set; }
public string SiteName { get; set; }
public string ComputerName { get; set; }
public IPAddress ServerIP { get; set; }
public ushort Port { get; set; }
public HttpMethod Method { get; set; }
public Uri Url { get; set; }
public string Stem { get; set; }
public string Query { get; set; }
public HttpStatusCode Status { get; set; }
public int Substatus { get; set; }
public int Win32SStatus { get; set; }
public ulong BytesSent { get; set; }
public ulong BytesReceived { get; set; }
public TimeSpan TimeTaken { get; set; }
public string Version { get; set; }
public string Host { get; set; }
public string UserAgent { get; set; }
public string Cookie { get; set; }
public Uri Referer { get; set; }

public override bool Equals(object obj)
{
var entry = obj as LogEntry;
if (null == entry)
return false;

return this.Date == entry.Date &&
this.Time == entry.Time &&
this.ClientIP == entry.ClientIP &&
this.UserName == entry.UserName &&
this.SiteName == entry.SiteName &&
this.ComputerName == entry.ComputerName &&
this.ServerIP == entry.ServerIP &&
this.Port == entry.Port &&
this.Method == entry.Method &&
this.Stem == entry.Stem &&
this.Query == entry.Query &&
this.Status == entry.Status &&
this.Substatus == entry.Substatus &&
this.Win32SStatus == entry.Win32SStatus &&
this.BytesSent == entry.BytesSent &&
this.BytesReceived == entry.BytesReceived &&
this.TimeTaken == entry.TimeTaken &&
this.Version == entry.Version &&
this.Host == entry.Host &&
this.UserAgent == entry.UserAgent &&
this.Cookie == entry.Cookie &&
this.Referer == entry.Referer;
}

public override int GetHashCode()
{
throw new NotImplementedException();
}
}
}

0 comments on commit 9ebe381

Please sign in to comment.