// Copyright Epic Games, Inc. All Rights Reserved. using HordeServer.Utilities; using Microsoft.Extensions.Diagnostics.HealthChecks; using MongoDB.Driver; namespace HordeServer.Server { /// /// Interface for the Horde MongoDB instance /// public interface IMongoService : IHealthCheck { /// /// The database instance /// IMongoDatabase Database { get; } /// /// Access the database in a read-only mode (don't create indices or modify content) /// public bool ReadOnlyMode { get; } /// /// Get the MongoDB client /// /// A MongoDB client instance MongoClient GetClient(); /// /// Get a MongoDB collection from database /// /// Name of collection /// A MongoDB document /// IMongoCollection GetCollection(string name); /// /// Get a MongoDB collection from database with a single index /// /// Name of collection /// Method to configure keys for the collection /// Whether a unique index is required /// A MongoDB document /// IMongoCollection GetCollection(string name, Func, IndexKeysDefinition> keysFunc, bool unique = false); /// /// Get a MongoDB collection from database /// /// Name of collection /// Indexes for the collection /// A MongoDB document /// IMongoCollection GetCollection(string name, IEnumerable> indexes); /// /// Gets a singleton document by id /// /// The document Task GetSingletonAsync(CancellationToken cancellationToken) where T : SingletonBase, new(); /// /// Gets a singleton document by id /// /// Method to use to construct a new object /// Cancellation token for the operation /// The document Task GetSingletonAsync(Func constructor, CancellationToken cancellationToken) where T : SingletonBase, new(); /// /// Updates a singleton /// /// /// /// Cancellation token for the operation /// Task UpdateSingletonAsync(Action updater, CancellationToken cancellationToken) where T : SingletonBase, new(); /// /// Updates a singleton /// /// /// /// Cancellation token for the operation /// Task UpdateSingletonAsync(Func updater, CancellationToken cancellationToken) where T : SingletonBase, new(); /// /// Attempts to update a singleton object /// /// The singleton object /// Cancellation token for the operation /// True if the singleton document was updated Task TryUpdateSingletonAsync(T singletonObject, CancellationToken cancellationToken) where T : SingletonBase; } }