Wolfringo Wolfringo
Wolfringo Wolfringo
Wolfringo (c) 2020 TehGM
DocFX, DiscordFX theme.
Search Results for

    Class HostedWolfClient

    A wrapper for WolfClient designed to use with .NET Core Host.

    Inheritance
    System.Object
    HostedWolfClient
    Implements
    Microsoft.Extensions.Hosting.IHostedService
    IWolfClient
    IWolfClientCacheAccessor
    System.IDisposable
    Namespace: TehGM.Wolfringo.Hosting
    Assembly: Wolfringo.Hosting.dll
    Syntax
    public class HostedWolfClient : IHostedService, IWolfClient, IWolfClientCacheAccessor, IDisposable
    Remarks

    This wrapper uses WolfClient internally, and delegates all method calls and events.

    This class supports configuration changes by using Microsoft.Extensions.Options.IOptionsMonitor<TOptions>. Whenever settings are changed, existing client is disconnected and disposed, and a new one is constructed.
    All listeners and event registrations will be re-assigned to the new client. All caches will be empty when client is rebuilt.

    This class automatically handles reconnection, unless AutoReconnectAttempts is set to 0. If the client is disconnected manually by calling DisconnectAsync(CancellationToken), automatic reconnection will not happen.

    The connection will automatically start when Host starts the service. This means that in Hosted scenarios (ASP.NET Core/Generic Host), starting the connection manually is not necessary.

    The client will login automatically whenever a connection is established, provided LoginUsername and LoginPassword are populated and AutoLogin is set to true. Otherwise, manual login will be required.

    Constructors

    | Improve this Doc View Source

    HostedWolfClient(IOptionsMonitor<HostedWolfClientOptions>, ILogger<HostedWolfClient>, IServiceProvider, IApplicationLifetime)

    Creates a new hosted client.

    Declaration
    public HostedWolfClient(IOptionsMonitor<HostedWolfClientOptions> options, ILogger<HostedWolfClient> log, IServiceProvider services, IApplicationLifetime hostLifetime)
    Parameters
    Type Name Description
    Microsoft.Extensions.Options.IOptionsMonitor<HostedWolfClientOptions> options

    Client configuration.

    Microsoft.Extensions.Logging.ILogger<HostedWolfClient> log

    Logger to log all log events.

    System.IServiceProvider services

    Service provider that will be passed to underlying WolfClient.

    Microsoft.AspNetCore.Hosting.IApplicationLifetime hostLifetime

    Host lifetime used to terminate application.

    Properties

    | Improve this Doc View Source

    CurrentUserID

    Currently logged in user. Null if not connected.

    Declaration
    public uint? CurrentUserID { get; }
    Property Value
    Type Description
    System.Nullable<System.UInt32>
    | Improve this Doc View Source

    IsConnected

    Is underlying client created and connected?

    Declaration
    public bool IsConnected { get; }
    Property Value
    Type Description
    System.Boolean

    Methods

    | Improve this Doc View Source

    AddMessageListener(IMessageCallback)

    Adds event listener.

    Declaration
    public void AddMessageListener(IMessageCallback listener)
    Parameters
    Type Name Description
    IMessageCallback listener

    Callback to invoke on event.

    | Improve this Doc View Source

    ConnectAsync(CancellationToken)

    Connects to the server.

    Declaration
    public async Task ConnectAsync(CancellationToken cancellationToken = default(CancellationToken))
    Parameters
    Type Name Description
    System.Threading.CancellationToken cancellationToken

    Token to abort entire connection.

    Returns
    Type Description
    System.Threading.Tasks.Task
    | Improve this Doc View Source

    DisconnectAsync(CancellationToken)

    Disconnects from the server.

    Declaration
    public async Task DisconnectAsync(CancellationToken cancellationToken = default(CancellationToken))
    Parameters
    Type Name Description
    System.Threading.CancellationToken cancellationToken
    Returns
    Type Description
    System.Threading.Tasks.Task
    | Improve this Doc View Source

    Dispose()

    Disposes this client, underlying client and all related resources.

    Declaration
    public void Dispose()
    | Improve this Doc View Source

    RemoveMessageListener(IMessageCallback)

    Removes event listener.

    Declaration
    public void RemoveMessageListener(IMessageCallback listener)
    Parameters
    Type Name Description
    IMessageCallback listener

    Callback to remove.

    | Improve this Doc View Source

    SendAsync<TResponse>(IWolfMessage, CancellationToken)

    Sends message, and waits for response from the server.

    Declaration
    public async Task<TResponse> SendAsync<TResponse>(IWolfMessage message, CancellationToken cancellationToken = default(CancellationToken))
        where TResponse : IWolfResponse
    Parameters
    Type Name Description
    IWolfMessage message

    Message to send.

    System.Threading.CancellationToken cancellationToken

    Cancellation token that can be used for Task cancellation.

    Returns
    Type Description
    System.Threading.Tasks.Task<TResponse>

    Sending response.

    Type Parameters
    Name Description
    TResponse

    Response type to use for casting of response.

    Remarks

    If client uses ResponseTypeResolver, the type of response provided with ResponseTypeAttribute on message will be used for deserialization, and TResponse will be used only for casting. If ResponseTypeAttribute is not set on message, TResponse will be used for deserialization as normal.

    Exceptions
    Type Condition
    MessageSendingException

    Server responded with error.

    Events

    | Improve this Doc View Source

    Connected

    Rasied when the client connects to the server.

    Declaration
    public event EventHandler Connected
    Event Type
    Type Description
    System.EventHandler
    | Improve this Doc View Source

    Disconnected

    Raised when the client disconnects from the server.

    Declaration
    public event EventHandler Disconnected
    Event Type
    Type Description
    System.EventHandler
    | Improve this Doc View Source

    ErrorRaised

    Raised when an error has occured.

    Declaration
    public event EventHandler<UnhandledExceptionEventArgs> ErrorRaised
    Event Type
    Type Description
    System.EventHandler<System.UnhandledExceptionEventArgs>
    | Improve this Doc View Source

    MessageReceived

    Raised when the client receives an event from the server.

    Declaration
    public event EventHandler<WolfMessageEventArgs> MessageReceived
    Event Type
    Type Description
    System.EventHandler<WolfMessageEventArgs>
    | Improve this Doc View Source

    MessageSent

    Raised when the client sends a message to the server.

    Declaration
    public event EventHandler<WolfMessageSentEventArgs> MessageSent
    Event Type
    Type Description
    System.EventHandler<WolfMessageSentEventArgs>

    Explicit Interface Implementations

    | Improve this Doc View Source

    IHostedService.StartAsync(CancellationToken)

    Declaration
    async Task IHostedService.StartAsync(CancellationToken cancellationToken)
    Parameters
    Type Name Description
    System.Threading.CancellationToken cancellationToken
    Returns
    Type Description
    System.Threading.Tasks.Task
    | Improve this Doc View Source

    IHostedService.StopAsync(CancellationToken)

    Declaration
    Task IHostedService.StopAsync(CancellationToken cancellationToken)
    Parameters
    Type Name Description
    System.Threading.CancellationToken cancellationToken
    Returns
    Type Description
    System.Threading.Tasks.Task
    | Improve this Doc View Source

    IWolfClientCacheAccessor.GetCachedAchievement(WolfLanguage, UInt32)

    Get achievement from cache.

    Declaration
    WolfAchievement IWolfClientCacheAccessor.GetCachedAchievement(WolfLanguage language, uint id)
    Parameters
    Type Name Description
    WolfLanguage language

    Language of achievement's translations.

    System.UInt32 id

    ID of the achievement.

    Returns
    Type Description
    WolfAchievement

    Cached achievement if found in requested language; otherwise null.

    | Improve this Doc View Source

    IWolfClientCacheAccessor.GetCachedCharm(UInt32)

    Get charm from cache.

    Declaration
    WolfCharm IWolfClientCacheAccessor.GetCachedCharm(uint id)
    Parameters
    Type Name Description
    System.UInt32 id

    ID of the charm.

    Returns
    Type Description
    WolfCharm

    Cached charm if found; otherwise null.

    | Improve this Doc View Source

    IWolfClientCacheAccessor.GetCachedGroup(String)

    Declaration
    WolfGroup IWolfClientCacheAccessor.GetCachedGroup(string name)
    Parameters
    Type Name Description
    System.String name
    Returns
    Type Description
    WolfGroup
    | Improve this Doc View Source

    IWolfClientCacheAccessor.GetCachedGroup(UInt32)

    Get group from cache.

    Declaration
    WolfGroup IWolfClientCacheAccessor.GetCachedGroup(uint id)
    Parameters
    Type Name Description
    System.UInt32 id

    ID of the group.

    Returns
    Type Description
    WolfGroup

    Cached group if found; otherwise null.

    | Improve this Doc View Source

    IWolfClientCacheAccessor.GetCachedUser(UInt32)

    Get user from cache.

    Declaration
    WolfUser IWolfClientCacheAccessor.GetCachedUser(uint id)
    Parameters
    Type Name Description
    System.UInt32 id

    ID of the user.

    Returns
    Type Description
    WolfUser

    Cached user if found; otherwise null.

    Implements

    Microsoft.Extensions.Hosting.IHostedService
    IWolfClient
    IWolfClientCacheAccessor
    System.IDisposable

    See Also

    WolfClient
    IWolfClient