Class InterceptorExtensions
- Namespace
- Xabbo
- Assembly
- Xabbo.Common.dll
Provides extensions for IInterceptor.
public static class InterceptorExtensions
- Inheritance
-
InterceptorExtensions
Methods
Intercept(IInterceptor, ReadOnlySpan<Header>, InterceptCallback, ClientType)
Registers an intercept for the specified headers with the provided InterceptCallback.
public static IDisposable Intercept(this IInterceptor interceptor, ReadOnlySpan<Header> headers, InterceptCallback callback, ClientType clients = ClientType.All)
Parameters
interceptor
IInterceptorThe interceptor to register the intercept for.
headers
ReadOnlySpan<Header>The message headers to intercept.
callback
InterceptCallbackThe function to call when a packet is intercepted.
clients
ClientTypeSpecifies which clients to intercept on.
Returns
Intercept(IInterceptor, ReadOnlySpan<Identifier>, InterceptCallback, ClientType, bool)
Registers an intercept for the specified identifiers with the provided InterceptCallback.
public static IDisposable Intercept(this IInterceptor interceptor, ReadOnlySpan<Identifier> identifiers, InterceptCallback callback, ClientType clients = ClientType.All, bool targeted = false)
Parameters
interceptor
IInterceptorThe interceptor to register the intercept for.
identifiers
ReadOnlySpan<Identifier>The message identifiers to intercept.
callback
InterceptCallbackThe function to call when a packet is intercepted.
clients
ClientTypeSpecifies which clients to intercept on.
targeted
boolWhether to use client-targeted identifiers. For example, if the client type of the message identifier is Flash, then it will only intercept that identifier on the Flash client.
Returns
Intercept<TMsg>(IInterceptor, InterceptMessageCallback<TMsg>)
Registers an intercept for the specified message with the provided InterceptMessageCallback<TMsg>.
public static IDisposable Intercept<TMsg>(this IInterceptor interceptor, InterceptMessageCallback<TMsg> callback) where TMsg : IMessage<TMsg>
Parameters
interceptor
IInterceptorcallback
InterceptMessageCallback<TMsg>
Returns
Type Parameters
TMsg
Intercept<TMsg>(IInterceptor, MessageCallback<TMsg>)
Registers an intercept for the specified message with the provided MessageCallback<TMsg>.
public static IDisposable Intercept<TMsg>(this IInterceptor interceptor, MessageCallback<TMsg> callback) where TMsg : IMessage<TMsg>
Parameters
interceptor
IInterceptorcallback
MessageCallback<TMsg>
Returns
Type Parameters
TMsg
Intercept<TMsg>(IInterceptor, ModifyMessageCallback<TMsg>)
Registers an intercept for the specified message with the provided ModifyMessageCallback<TMsg>.
public static IDisposable Intercept<TMsg>(this IInterceptor interceptor, ModifyMessageCallback<TMsg> callback) where TMsg : IMessage<TMsg>
Parameters
interceptor
IInterceptorcallback
ModifyMessageCallback<TMsg>
Returns
Type Parameters
TMsg
ReceiveAsync(IInterceptor, ReadOnlySpan<Header>, int?, bool, Func<IPacket, bool>?, CancellationToken)
Asynchronously captures the first intercepted packet matching any of the specified headers.
public static Task<IPacket> ReceiveAsync(this IInterceptor interceptor, ReadOnlySpan<Header> headers, int? timeout = null, bool block = false, Func<IPacket, bool>? shouldCapture = null, CancellationToken cancellationToken = default)
Parameters
interceptor
IInterceptorThe interceptor.
headers
ReadOnlySpan<Header>Specifies which headers to listen for.
timeout
int?The maximum time in milliseconds to wait for a packet to be captured.
-1
specifies no timeout.block
boolWhether the captured packet should be blocked from its destination.
shouldCapture
Func<IPacket, bool>A callback that inspects intercepted packets and return whether the packet should be captured or not.
cancellationToken
CancellationTokenThe token used to cancel this operation.
Returns
ReceiveAsync(IInterceptor, ReadOnlySpan<Identifier>, int?, bool, Func<IPacket, bool>?, CancellationToken)
Asynchronously captures the first intercepted packet matching any of the specified headers.
public static Task<IPacket> ReceiveAsync(this IInterceptor interceptor, ReadOnlySpan<Identifier> identifiers, int? timeout = null, bool block = false, Func<IPacket, bool>? shouldCapture = null, CancellationToken cancellationToken = default)
Parameters
interceptor
IInterceptorThe interceptor.
identifiers
ReadOnlySpan<Identifier>Specifies which messages to listen for.
timeout
int?The maximum time in milliseconds to wait for a packet to be captured.
-1
specifies no timeout.block
boolWhether the captured packet should be blocked from its destination.
shouldCapture
Func<IPacket, bool>A callback that inspects intercepted packets and return whether the packet should be captured or not.
cancellationToken
CancellationTokenThe token used to cancel this operation.
Returns
ReceiveAsync<TMsg>(IInterceptor, int?, bool, Func<TMsg, bool>?, CancellationToken)
Asynchronously captures the first intercepted matching message.
public static Task<TMsg> ReceiveAsync<TMsg>(this IInterceptor interceptor, int? timeout = null, bool block = false, Func<TMsg, bool>? shouldCapture = null, CancellationToken cancellationToken = default) where TMsg : IMessage<TMsg>
Parameters
interceptor
IInterceptorThe interceptor.
timeout
int?The maximum time in milliseconds to wait for a message to be captured.
-1
specifies no timeout.block
boolWhether the captured message should be blocked from its destination.
shouldCapture
Func<TMsg, bool>A callback that inspects an intercepted message and return whether the message should be captured or not.
cancellationToken
CancellationTokenThe token used to cancel this operation.
Returns
- Task<TMsg>
A task that completes once a message has been captured, or the operation times out.
Type Parameters
TMsg
The type of message to capture.
RequestAsync<TReq, TRes, TData>(IInterceptor, IRequestMessage<TReq, TRes, TData>, int?, bool, CancellationToken)
Sends a request message and asynchronously captures its response.
public static Task<TData> RequestAsync<TReq, TRes, TData>(this IInterceptor interceptor, IRequestMessage<TReq, TRes, TData> request, int? timeout = null, bool block = true, CancellationToken cancellationToken = default) where TReq : IRequestMessage<TReq, TRes, TData> where TRes : IMessage<TRes>
Parameters
interceptor
IInterceptorThe interceptor.
request
IRequestMessage<TReq, TRes, TData>The request message to send.
timeout
int?The maximum time in milliseconds to wait for a message to be captured.
-1
specifies no timeout.block
boolWhether the captured message should be blocked from its destination.
cancellationToken
CancellationTokenThe token used to cancel this operation.
Returns
- Task<TData>
Type Parameters
TReq
The type of the request message.
TRes
The type of the response message.
TData
The type of the response data.