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();
|
protected readonly HttpListener httpListener = new();
|
||||||
|
|
||||||
public event OnCheckAuthenticationEventHandler? OnCheckAuthentication;
|
public event OnCheckAuthenticationEventHandler? OnCheckAuthentication;
|
||||||
|
public event OnCheckContextEventHandler? OnCheckContext;
|
||||||
|
public event OnCheckContextEventHandler? OnCheckContextCompleted;
|
||||||
|
|
||||||
protected record PrivateApiResult(ApiResult Original, string? ResultJson);
|
protected record PrivateApiResult(ApiResult Original, string? ResultJson);
|
||||||
|
|
||||||
@@ -104,6 +106,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
|||||||
Receive();
|
Receive();
|
||||||
|
|
||||||
// Check context
|
// Check context
|
||||||
|
OnCheckContext?.Invoke(this, new(context));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CheckContext(context);
|
CheckContext(context);
|
||||||
@@ -114,6 +117,10 @@ public class ApiServer(string apiUrl) : IApiServer
|
|||||||
if (DebugMode)
|
if (DebugMode)
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
OnCheckContextCompleted?.Invoke(this, new(context));
|
||||||
|
}
|
||||||
|
|
||||||
// Listen for new request
|
// Listen for new request
|
||||||
if (!AllowMultipleRequests)
|
if (!AllowMultipleRequests)
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ namespace Pilz.Net.Api;
|
|||||||
public interface IApiServer
|
public interface IApiServer
|
||||||
{
|
{
|
||||||
public delegate void OnCheckAuthenticationEventHandler(object sender, ApiAuthCheckEventArgs e);
|
public delegate void OnCheckAuthenticationEventHandler(object sender, ApiAuthCheckEventArgs e);
|
||||||
|
public delegate void OnCheckContextEventHandler(object sender, ApiContextEventArgs e);
|
||||||
|
|
||||||
event OnCheckAuthenticationEventHandler? OnCheckAuthentication;
|
event OnCheckAuthenticationEventHandler? OnCheckAuthentication;
|
||||||
|
event OnCheckContextEventHandler OnCheckContext;
|
||||||
|
event OnCheckContextEventHandler OnCheckContextCompleted;
|
||||||
|
|
||||||
string ApiUrl { get; }
|
string ApiUrl { get; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user