Class WolfClientExtensions
Extension methods for IWolfClient.
Namespace: TehGM.Wolfringo
Assembly: Wolfringo.Core.dll
Syntax
public static class WolfClientExtensions
Methods
| Improve this Doc View SourceAddMessageListener<T>(IWolfClient, Action<T>)
Adds event listener, invoking when received message is of correct type.
Declaration
public static void AddMessageListener<T>(this IWolfClient client, Action<T> callback)
where T : IWolfMessage
Parameters
Type | Name | Description |
---|---|---|
IWolfClient | client | Client to listen to events of. |
Action<T> | callback | Callback to invoke on event. |
Type Parameters
Name | Description |
---|---|
T | Type of received message to invoke callback for. |
AddMessageListener<T>(IWolfClient, String, Action<T>)
Adds event listener, invoking when received message is of correct type and has matching command.
Declaration
public static void AddMessageListener<T>(this IWolfClient client, string command, Action<T> callback)
where T : IWolfMessage
Parameters
Type | Name | Description |
---|---|---|
IWolfClient | client | Client to listen to events of. |
String | command | Message command that has to match for callback to be invoked. |
Action<T> | callback | Callback to invoke on event. |
Type Parameters
Name | Description |
---|---|
T | Type of received message to invoke callback for. |
RemoveMessageListener<T>(IWolfClient, Action<T>)
Removes event listener.
Declaration
public static void RemoveMessageListener<T>(this IWolfClient client, Action<T> callback)
where T : IWolfMessage
Parameters
Type | Name | Description |
---|---|---|
IWolfClient | client | Client to remove events listener from. |
Action<T> | callback | Callback to remove. |
Type Parameters
Name | Description |
---|---|
T |
Remarks
Provided type T
must be the same as the type used when adding the listener.
SendAsync(IWolfClient, IWolfMessage, CancellationToken)
Sends message, and waits for response from the server.
Declaration
public static Task<WolfResponse> SendAsync(this IWolfClient client, IWolfMessage message, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IWolfClient | client | Client to send the message with. |
IWolfMessage | message | Message to send. |
CancellationToken | cancellationToken | Cancellation token that can be used for Task cancellation. |
Returns
Type | Description |
---|---|
Task<WolfResponse> | Sending response. |
Remarks
If client uses ResponseTypeResolver, the type of response provided with
ResponseTypeAttribute on message
will be used for deserialization.
Otherwise, response will be deserialized asWolfResponse.
Exceptions
Type | Condition |
---|---|
MessageSendingException | Server responded with error. |