tgstation-server 6.19.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
ComponentInterfacingAuthorityBase.cs
Go to the documentation of this file.
1using System;
2using System.Threading.Tasks;
3
4using Microsoft.AspNetCore.Mvc;
5using Microsoft.Extensions.Logging;
6
7using Serilog.Context;
8
13
15{
20 {
25
34 IDatabaseContext databaseContext,
35 ILogger<ComponentInterfacingAuthorityBase> logger)
36 : base(databaseContext, logger)
37 {
38 this.instanceManager = instanceManager ?? throw new ArgumentNullException(nameof(instanceManager));
39 }
40
49 protected async ValueTask<AuthorityResponse<TResult>> WithComponentInstance<TResult>(Func<IInstanceCore, ValueTask<AuthorityResponse<TResult>>> action, long instanceId)
50 {
51 using var instanceReference = instanceManager.GetInstanceReference(instanceId);
52 using (LogContext.PushProperty(SerilogContextHelper.InstanceReferenceContextProperty, instanceReference?.Uid))
53 {
54 if (instanceReference == null)
55 return Conflict<TResult>(ErrorCode.InstanceOffline);
56 return await action(instanceReference);
57 }
58 }
59 }
60}
static AuthorityResponse< TResult > Conflict< TResult >(ErrorCode errorCode, string? additionalData=null)
Generates a HttpFailureResponse.Conflict type AuthorityResponse<TResult>.
AuthorityBase for IAuthoritys that need to access IInstanceCores.
async ValueTask< AuthorityResponse< TResult > > WithComponentInstance< TResult >(Func< IInstanceCore, ValueTask< AuthorityResponse< TResult > > > action, long instanceId)
Run a given action with the relevant IInstance.
readonly IInstanceManager instanceManager
The IInstanceManager for the ComponentInterfacingAuthorityBase.
ComponentInterfacingAuthorityBase(IInstanceManager instanceManager, IDatabaseContext databaseContext, ILogger< ComponentInterfacingAuthorityBase > logger)
Initializes a new instance of the ComponentInterfacingAuthorityBase class.
Helpers for manipulating the Serilog.Context.LogContext.
const string InstanceReferenceContextProperty
The Serilog.Context.LogContext property name for Components.IInstanceReference.Uids.
For interacting with the instance services.
IInstanceReference? GetInstanceReference(long instanceId)
Get the IInstanceReference associated with given instanceId .
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
Definition ErrorCode.cs:12