add check context events
This commit is contained in:
8
Pilz.Net/Api/ApiContextEventArgs.cs
Normal file
8
Pilz.Net/Api/ApiContextEventArgs.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using System.Net;
|
||||
|
||||
namespace Pilz.Net.Api;
|
||||
|
||||
public class ApiContextEventArgs(HttpListenerContext context) : EventArgs
|
||||
{
|
||||
public HttpListenerContext Context { get; } = context;
|
||||
}
|
||||
@@ -13,6 +13,8 @@ public class ApiServer(string apiUrl) : IApiServer
|
||||
protected readonly HttpListener httpListener = new();
|
||||
|
||||
public event OnCheckAuthenticationEventHandler? OnCheckAuthentication;
|
||||
public event OnCheckContextEventHandler? OnCheckContext;
|
||||
public event OnCheckContextEventHandler? OnCheckContextCompleted;
|
||||
|
||||
protected record PrivateApiResult(ApiResult Original, string? ResultJson);
|
||||
|
||||
@@ -104,6 +106,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
||||
Receive();
|
||||
|
||||
// Check context
|
||||
OnCheckContext?.Invoke(this, new(context));
|
||||
try
|
||||
{
|
||||
CheckContext(context);
|
||||
@@ -114,6 +117,10 @@ public class ApiServer(string apiUrl) : IApiServer
|
||||
if (DebugMode)
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
OnCheckContextCompleted?.Invoke(this, new(context));
|
||||
}
|
||||
|
||||
// Listen for new request
|
||||
if (!AllowMultipleRequests)
|
||||
|
||||
@@ -5,8 +5,11 @@ namespace Pilz.Net.Api;
|
||||
public interface IApiServer
|
||||
{
|
||||
public delegate void OnCheckAuthenticationEventHandler(object sender, ApiAuthCheckEventArgs e);
|
||||
public delegate void OnCheckContextEventHandler(object sender, ApiContextEventArgs e);
|
||||
|
||||
event OnCheckAuthenticationEventHandler? OnCheckAuthentication;
|
||||
event OnCheckContextEventHandler OnCheckContext;
|
||||
event OnCheckContextEventHandler OnCheckContextCompleted;
|
||||
|
||||
string ApiUrl { get; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user