Interface IGameLibrary
Represents an extendable Game library. An instance of IGameLibrary is one of the core services that are always available when Snowflake starts, and handles all information related to games, including files and configuration.
Implements the repository pattern for IGame.
Namespace: Snowflake.Model.Game
Assembly: Snowflake.Framework.Primitives.dll
Syntax
public interface IGameLibrary
Methods
AddExtension<TExtensionProvider, TExtension>(TExtensionProvider)
Registers an extension to the game library.
Extensions are responsible for their own data, and are created using a factory of type TExtensionProvider.
Extensions are local to a given IGameRecord that exists in this library, and are responsible for managing their
own data. It is also idiomatic to create an extension method WithExtension to allow fluent access to the extension.
See GameFileExtensionExtensions for an example of how such extension methods are implemented.
Declaration
void AddExtension<TExtensionProvider, TExtension>(TExtensionProvider extension)
where TExtensionProvider : IGameExtensionProvider<TExtension> where TExtension : class, IGameExtension
Parameters
| Type | Name | Description |
|---|---|---|
| TExtensionProvider | extension | An instance of the extension factory. |
Type Parameters
| Name | Description |
|---|---|
| TExtensionProvider | The type of the extension provider. |
| TExtension | The extension instance that is produced for a game. |
CreateGame(PlatformId)
Creates a game in the game library.
Declaration
IGame CreateGame(PlatformId platformId)
Parameters
| Type | Name | Description |
|---|---|---|
| PlatformId | platformId |
Returns
| Type | Description |
|---|---|
| IGame |
CreateGameAsync(PlatformId)
Asynchronously creates a game in the game library.
Declaration
Task<IGame> CreateGameAsync(PlatformId platformId)
Parameters
| Type | Name | Description |
|---|---|---|
| PlatformId | platformId |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<IGame> |
GetAllGames()
Retrieves all games in the library. See GetGames(Expression<Func<IGameRecord, Boolean>>) instead, instead of enumerating all possible games.
Declaration
IQueryable<IGame> GetAllGames()
Returns
| Type | Description |
|---|---|
| System.Linq.IQueryable<IGame> | All games in the library. |
GetAllGamesAsync()
Asynchronously retrieves all games in the library. See GetGames(Expression<Func<IGameRecord, Boolean>>) instead, instead of enumerating all possible games.
Declaration
IAsyncEnumerable<IGame> GetAllGamesAsync()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IAsyncEnumerable<IGame> | All games in the library. |
GetExtension<T>()
Gets a registered extension provider of the given type.
If no extension of type T is
registered, returns null.
Declaration
T GetExtension<T>()
where T : class, IGameExtensionProvider
Returns
| Type | Description |
|---|---|
| T | The regsitered instance of the requested extension provider. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the extension provider. |
GetGame(Guid)
Gets a game that was created in the library by its unique GUID.
Declaration
IGame GetGame(Guid guid)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Guid | guid | The unique GUID of the game. |
Returns
| Type | Description |
|---|---|
| IGame | The game with the provided GUID, or null if it does not exist |
GetGameAsync(Guid)
Asynchronously gets a game that was created in the library by its unique GUID.
Declaration
Task<IGame> GetGameAsync(Guid guid)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Guid | guid | The unique GUID of the game. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<IGame> | The game with the provided GUID, or null if it does not exist |
GetGames(Expression<Func<IGameRecord, Boolean>>)
Retrieves all games in the library that fulfill the provided predicate. The default implementation executes this predicate in client code. Use QueryGames(Expression<Func<IGameRecordQuery, Boolean>>) instead if possible for more performant queries.
Declaration
IEnumerable<IGame> GetGames(Expression<Func<IGameRecord, bool>> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Linq.Expressions.Expression<System.Func<IGameRecord, System.Boolean>> | predicate | The predicate to filter on. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<IGame> | All games in the library that fulfill the provided predicate. |
QueryGames(Expression<Func<IGameRecordQuery, Boolean>>)
Retrieves all games in the library that fulfill the provided predicate. The default implementation executes the predicate on the database than in client code, thus is much faster than using GetAllGames() or GetGames(Expression<Func<IGameRecord, Boolean>>).
Declaration
IQueryable<IGame> QueryGames(Expression<Func<IGameRecordQuery, bool>> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Linq.Expressions.Expression<System.Func<IGameRecordQuery, System.Boolean>> | predicate | The predicate to filter on. |
Returns
| Type | Description |
|---|---|
| System.Linq.IQueryable<IGame> | All games in the library that fulfill the provided predicate. |
QueryGamesAsync(Expression<Func<IGameRecordQuery, Boolean>>)
Retrieves all games in the library that fulfill the provided predicate asynchronously. The default implementation executes this predicate on the database rather than in client code, thus is much faster than using GetAllGamesAsync() or GetGames(Expression<Func<IGameRecord, Boolean>>).
Declaration
IAsyncEnumerable<IGame> QueryGamesAsync(Expression<Func<IGameRecordQuery, bool>> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Linq.Expressions.Expression<System.Func<IGameRecordQuery, System.Boolean>> | predicate | The predicate to filter on. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IAsyncEnumerable<IGame> | All games in the library that fulfill the provided predicate. |
UpdateGameRecord(IGameRecord)
Updates a IGameRecord that exists in the database by providing the changed IGameRecord.
Declaration
void UpdateGameRecord(IGameRecord game)
Parameters
| Type | Name | Description |
|---|---|---|
| IGameRecord | game | The updated IGameRecord |
UpdateGameRecordAsync(IGameRecord)
Asynchronously updates a IGameRecord that exists in the database by providing the changed IGameRecord.
Declaration
Task UpdateGameRecordAsync(IGameRecord game)
Parameters
| Type | Name | Description |
|---|---|---|
| IGameRecord | game | The updated IGameRecord |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task |