Class GameSaveService
Default IGameSaveService implementation. Orchestrates every registered ISaveSection into a SaveDocument on save, and hands each section its stored payload back on load. Delegates persistence to an injected IGameSaveStore, one slot at a time. Broadcasts save/load/delete signals through an optional event dispatcher.
Inherited Members
Namespace: Serenity.GameSave.Application.Services
Assembly: Serenity.GameSave.Application.dll
Syntax
public class GameSaveService : IGameSaveService, IService, IFoundationSettings
Constructors
GameSaveService(IGameSaveStore, IGameSaveSettings, IEventDispatcherService, ILogService)
Initializes a new instance of the GameSaveService class.
Declaration
public GameSaveService(IGameSaveStore store, IGameSaveSettings settings, IEventDispatcherService eventDispatcherService, ILogService logService)
Parameters
| Type | Name | Description |
|---|---|---|
| IGameSaveStore | store | Backend store used to persist and load individual save slots. |
| IGameSaveSettings | settings | Business-facing configuration, at minimum the configured slot count. |
| IEventDispatcherService | eventDispatcherService | Dispatcher used to broadcast GameSavedSignal, GameLoadedSignal
and SaveSlotDeletedSignal. May be |
| ILogService | logService | Logging service. May be |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
Properties
ActiveSlot
The slot currently active for save/load, or null when none is selected.
Declaration
public virtual SaveSlotId? ActiveSlot { get; }
Property Value
| Type | Description |
|---|---|
| SaveSlotId? |
Guid
Declaration
public string Guid { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Id
Declaration
public string Id { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
LogService
Declaration
public ILogService LogService { get; set; }
Property Value
| Type | Description |
|---|---|
| ILogService |
Methods
CopyAsync(SaveSlotId, SaveSlotId, CancellationToken)
Copies the save at fromSlotId into toSlotId.
Declaration
public virtual Task CopyAsync(SaveSlotId fromSlotId, SaveSlotId toSlotId, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| SaveSlotId | fromSlotId | The source slot. A no-op (with a warning) when this slot is empty. |
| SaveSlotId | toSlotId | The destination slot. Any existing save there is overwritten. |
| CancellationToken | cancellationToken | Token used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task |
Remarks
Loads fromSlotId as-is and re-saves it under toSlotId
with a fresh, strictly-increasing tick for that destination slot. Any save already present
at toSlotId is unconditionally overwritten.
DeleteAsync(SaveSlotId, CancellationToken)
Deletes the save at slotId, clearing ActiveSlot when it was the deleted slot.
Declaration
public virtual Task DeleteAsync(SaveSlotId slotId, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| SaveSlotId | slotId | The slot to delete. |
| CancellationToken | cancellationToken | Token used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task |
IsSlotIndexValid(SaveSlotId)
Checks whether slotId is within the configured slot range.
Declaration
public virtual bool IsSlotIndexValid(SaveSlotId slotId)
Parameters
| Type | Name | Description |
|---|---|---|
| SaveSlotId | slotId |
Returns
| Type | Description |
|---|---|
| bool |
QuerySlotsAsync(CancellationToken)
Queries every configured slot's summary, filling in an empty SaveSlotSummary for any slot with no save, so the returned list always has exactly one entry per configured slot.
Declaration
public virtual Task<IReadOnlyList<SaveSlotSummary>> QuerySlotsAsync(CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | Token used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<IReadOnlyList<SaveSlotSummary>> |
RegisterSection(ISaveSection)
Registers a section so it is folded into every save and restored from every load.
Declaration
public virtual void RegisterSection(ISaveSection section)
Parameters
| Type | Name | Description |
|---|---|---|
| ISaveSection | section | The section to register. |
SaveActiveAsync(string, CancellationToken)
Saves to ActiveSlot. A no-op when no slot is active.
Declaration
public virtual Task SaveActiveAsync(string label, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | label | The save's display label. |
| CancellationToken | cancellationToken | Token used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task |
SaveAsync(SaveSlotId, string, CancellationToken)
Saves every registered section's current state to slotId under label.
Declaration
public virtual Task SaveAsync(SaveSlotId slotId, string label, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| SaveSlotId | slotId | The slot to save to. |
| string | label | The save's display label. |
| CancellationToken | cancellationToken | Token used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task |
TryLoadAsync(SaveSlotId, CancellationToken)
Loads slotId and hands each stored payload back to its matching
registered section, then makes slotId the active slot.
Declaration
public virtual Task<bool> TryLoadAsync(SaveSlotId slotId, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| SaveSlotId | slotId | The slot to load. |
| CancellationToken | cancellationToken | Token used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<bool> |
|
TrySetActiveSlot(SaveSlotId)
Selects slotId as the active slot.
Declaration
public virtual bool TrySetActiveSlot(SaveSlotId slotId)
Parameters
| Type | Name | Description |
|---|---|---|
| SaveSlotId | slotId | The slot to activate. |
Returns
| Type | Description |
|---|---|
| bool |
|