1 using Microsoft.AspNetCore.Mvc;
2 using Microsoft.Extensions.Hosting;
3 using Microsoft.Extensions.Logging;
10 using System.Threading.Tasks;
20 [Produces(MediaTypeNames.Application.Json)]
36 readonly ILogger<BridgeController>
logger;
46 this.bridgeDispatcher = bridgeDispatcher ??
throw new ArgumentNullException(nameof(bridgeDispatcher));
47 if (applicationLifetime == null)
48 throw new ArgumentNullException(nameof(applicationLifetime));
50 this.logger = logger ??
throw new ArgumentNullException(nameof(logger));
52 applicationLifetime.ApplicationStopped.Register(() => requestsProcessed = 0);
62 public async Task<IActionResult>
Process([FromQuery]
string data, CancellationToken cancellationToken)
65 if (!IPAddress.IsLoopback(Request.HttpContext.Connection.RemoteIpAddress))
68 using (LogContext.PushProperty(
"Bridge", Interlocked.Increment(ref requestsProcessed)))
77 logger.LogWarning(
"Error deserializing bridge request: {0}", data);
81 logger.LogTrace(
"Bridge Request: {0}", data);
83 var response = await bridgeDispatcher.ProcessBridgeRequest(request, cancellationToken).ConfigureAwait(
false);
88 logger.LogTrace(
"Bridge Response: {0}", responseJson);
89 return Content(responseJson, MediaTypeNames.Application.Json);
async Task< IActionResult > Process([FromQuery]string data, CancellationToken cancellationToken)
Processes a bridge request.
BridgeController(IBridgeDispatcher bridgeDispatcher, IHostApplicationLifetime applicationLifetime, ILogger< BridgeController > logger)
Initializes a new instance of the BridgeController .
Use server authentication
static long requestsProcessed
Static counter for the number of requests processed.
Constants used for communication with the DMAPI
readonly IBridgeDispatcher bridgeDispatcher
The IBridgeDispatcher for the BridgeController
static readonly JsonSerializerSettings SerializerSettings
JsonSerializerSettings for use when communicating with the DMAPI.
Parameters for a bridge request.
Controller for recieving DMAPI requests from DreamDaemon.
readonly ILogger< BridgeController > logger
The ILogger for the BridgeController
Handler for BridgeParameters.