Class GenericClientManager<TKey, TClient>
A generic client manager.
Implements
Inherited Members
Namespace: Microsoft.XboxStudios.ClientManager
Assembly: ClientManager.dll
Syntax
public class GenericClientManager<TKey, TClient> : ClientScopeBase<TKey>, ICanConnect<TKey>, IEnumerable<TKey>, IEnumerable, IClientManager<TKey, TClient>, IClientManager<TKey>, ICanDisconnect<TKey>, IHoldsBaggage<TKey>, IDisposable where TKey : notnull where TClient : class
Type Parameters
Name | Description |
---|---|
TKey | The key object that contains the |
TClient | The client type. |
Remarks
Initializes a new instance of the GenericClientManager<TKey, TClient> class.
Constructors
View SourceGenericClientManager(IClientManagerAdapter<TKey, TClient>, IEnumerable<IBaggageFactory<TClient>>?)
A generic client manager.
Declaration
public GenericClientManager(IClientManagerAdapter<TKey, TClient> adapter, IEnumerable<IBaggageFactory<TClient>>? baggageFactories = null)
Parameters
Type | Name | Description |
---|---|---|
IClientManagerAdapter<TKey, TClient> | adapter | The client manager adapter to manage connections. |
IEnumerable<IBaggageFactory<TClient>> | baggageFactories | An enumeration of factories to create baggages and attach them to clients. |
Remarks
Initializes a new instance of the GenericClientManager<TKey, TClient> class.
Methods
View SourceClientAndBaggageFor(TKey)
Gets a client and its baggage, or creates it if possible.
Declaration
protected (ISharedRef<TClient, Reserved<TClient>> Connection, ConcurrentDictionary<Type, object>? Baggage)? ClientAndBaggageFor(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The client key. |
Returns
Type | Description |
---|---|
(ISharedRef<TClient, Reserved<TClient>> Connection, ConcurrentDictionary<Type, object> Baggage)? | The client and baggage if it existed or could be created. |
ClientFor(TKey)
Gets a client, or creates it if possible.
Declaration
protected TClient? ClientFor(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The client key. |
Returns
Type | Description |
---|---|
TClient | The client if it existed or could be created. |
ConnectAsync(TKey, CancellationOptions?)
Connects a client to a game instance.
Declaration
public override ValueTask<bool> ConnectAsync(TKey key, CancellationOptions? co = null)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The TKey to use to fetch a client and attempt a connection. |
CancellationOptions? | co | The Microsoft.XboxStudios.Bifrost.CancellationOptions. |
Returns
Type | Description |
---|---|
ValueTask<bool> | A value indicating whether connection was successful or not. |
Overrides
Remarks
This method reuses the same client to connect if it got disconnected externally.
ConnectionChanged((TKey Key, TClient Client))
Sends an event that connection has changed.
Declaration
protected void ConnectionChanged((TKey Key, TClient Client) eventArgs)
Parameters
Type | Name | Description |
---|---|---|
(TKey Key, TClient Client) | eventArgs | The event args. |
CreateScope()
Creates a connection scope to manage reservations.
Declaration
public IConnectionScope<TKey, TClient> CreateScope()
Returns
Type | Description |
---|---|
IConnectionScope<TKey, TClient> | A connection scope. |
Disconnect(IEnumerable<TKey>)
Disconnect clients from a game instance synchronously.
Declaration
public void Disconnect(IEnumerable<TKey> keys)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TKey> | keys | The keys to use to fetch clients and attempt disconnections synchronously. |
Disconnect(TKey)
Disconnects a client from a game instance synchronously.
Declaration
public void Disconnect(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The TKey to use to fetch a client and attempt a disconnection. |
DisconnectAsync(IEnumerable<TKey>)
Disconnect clients from a game instance asynchronously.
Declaration
public ValueTask DisconnectAsync(IEnumerable<TKey> keys)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TKey> | keys | The keys to use to fetch clients and attempt disconnections asynchronously. |
Returns
Type | Description |
---|---|
ValueTask | A Task that represents the asynchronous operation. |
DisconnectAsync(TKey)
Disconnects a client from a game instance asynchronously.
Declaration
public ValueTask DisconnectAsync(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The TKey to use to fetch a client and attempt a disconnection. |
Returns
Type | Description |
---|---|
ValueTask | A Task that represents the asynchronous operation. |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public virtual void Dispose()
ExistingClientFor(TKey)
Gets an existing client.
Declaration
protected TClient? ExistingClientFor(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The client key. |
Returns
Type | Description |
---|---|
TClient | The client if it existed. |
GetBaggageFactory<T>()
Gets a registered baggage factory.
Declaration
protected IBaggageFactory<TClient> GetBaggageFactory<T>()
Returns
Type | Description |
---|---|
IBaggageFactory<TClient> | The factory. |
Type Parameters
Name | Description |
---|---|
T | The baggage type. |
Exceptions
Type | Condition |
---|---|
MissingBaggageFactoryException | If no such factory was registered. |
GetBaggage<TBaggage>(TKey)
Gets the baggage associated with a key.
Declaration
public override TBaggage GetBaggage<TBaggage>(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The TKey to use to fetch a baggage. |
Returns
Type | Description |
---|---|
TBaggage | The baggage or null if no connection exists. |
Type Parameters
Name | Description |
---|---|
TBaggage | The type of the baggage. |
Overrides
Exceptions
Type | Condition |
---|---|
BaggageNullException | Thrown if the registered baggage factory returned null. |
MissingBaggageFactoryException | Thrown if the baggage factory of the requested baggage is not registered. |
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public override IEnumerator<TKey> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<TKey> | An enumerator that can be used to iterate through the collection. |
Overrides
View SourceNeedsToConnect(TClient)
Checks whether a client needs to connect or not.
Declaration
public bool NeedsToConnect(TClient client)
Parameters
Type | Name | Description |
---|---|---|
TClient | client | The client to check for. |
Returns
Type | Description |
---|---|
bool | True if client needs to connect. False otherwise. |
Reserve(TKey)
Reserves the client for a specific TKey. Callers are responsible to dispose of the reserved client.
Declaration
public Reserved<TClient>? Reserve(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to use. |
Returns
Type | Description |
---|---|
Reserved<TClient> | The client assosciated with the requested key. |
ReserveAndConnectAsync(TKey, CancellationOptions?)
Reserves the client for a specific TKey and establishes connection if necessary. Callers are responsible to dispose of the reserved client.
Declaration
public ValueTask<Reserved<TClient>?> ReserveAndConnectAsync(TKey key, CancellationOptions? co = null)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to use. |
CancellationOptions? | co | The Microsoft.XboxStudios.Bifrost.CancellationOptions. |
Returns
Type | Description |
---|---|
ValueTask<Reserved<TClient>> | The client assosciated with the requested key. Null if connection failed. |
TryGetClientAndBaggage(TKey, out (ISharedRef<TClient, Reserved<TClient>> Connection, ConcurrentDictionary<Type, object>? Baggage))
Gets an existing client and its baggage.
Declaration
protected bool TryGetClientAndBaggage(TKey key, out (ISharedRef<TClient, Reserved<TClient>> Connection, ConcurrentDictionary<Type, object>? Baggage) clientAndBaggage)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The client key. |
(ISharedRef<TClient, Reserved<TClient>> Connection, ConcurrentDictionary<Type, object> Baggage) | clientAndBaggage | Stores the client and baggage, if it exists. |
Returns
Type | Description |
---|---|
bool | True if the client existed. |
Events
View SourceOnConnected
Event triggered when client has connected.
Declaration
public event EventHandler<TClient>? OnConnected
Event Type
Type | Description |
---|---|
EventHandler<TClient> |
OnConnecting
Event triggered when client is connecting.
Declaration
public event EventHandler<TClient>? OnConnecting
Event Type
Type | Description |
---|---|
EventHandler<TClient> |
OnConnectionChanged
Event triggered when connection changes on a client.
Declaration
public event EventHandler<(TKey Key, TClient Client)>? OnConnectionChanged
Event Type
Type | Description |
---|---|
EventHandler<(TKey Key, TClient Client)> |
OnDisconnected
Event triggered when client has disconnected.
Declaration
public event EventHandler<TClient>? OnDisconnected
Event Type
Type | Description |
---|---|
EventHandler<TClient> |
OnDisconnecting
Event triggered when client is disconnecting.
Declaration
public event EventHandler<TClient>? OnDisconnecting
Event Type
Type | Description |
---|---|
EventHandler<TClient> |