public GameStatusController(RequestContext requestContext, IGameApiService gameApiService, IRequestLoggingService requestLoggingService, ILogger <GameStatusController> logger) { this.requestContext = requestContext ?? throw new ArgumentNullException("RequestContext"); this.gameApiService = gameApiService ?? throw new ArgumentNullException("IGameApiService"); this.requestLoggingService = requestLoggingService ?? throw new ArgumentNullException("IRequestLoggingService"); this.logger = logger ?? throw new ArgumentNullException("ILogger"); }
public JoinController(RequestContext requestContext, IGameApiService gameApiService, IRequestLoggingService requestLoggingService, ILogger <JoinController> logger) { this.requestContext = requestContext; this.gameApiService = gameApiService; this.requestLoggingService = requestLoggingService; this.logger = logger; }
public LoggingController(IRequestLoggingService logginService) => this.loggingService = logginService;
public async Task InvokeAsync(HttpContext context, RequestContext requestContext, ILogger <RequestRecordingMiddleware> logger, IRequestLoggingService requestLoggingService) { await _next(context); try { var requestMethod = (RequestMethod)Enum.Parse(typeof(RequestMethod), context.Request.Method); var statusCode = context.Response.StatusCode; var requestApi = context.Request.Path; logger.LogWarning($"Recording Request { requestContext.RequestId } | {requestMethod} | {requestApi} | {statusCode}"); await requestLoggingService.RecordRequest(requestMethod, statusCode, requestApi, context.User.Identity.Name); } catch (Exception) { logger.LogError($"Failed recording request {requestContext.RequestId} | {context.Request.Method} | {context.Request.Path}"); } }
public RequestLoggingFilter(IRequestLoggingService requestLoggingService) { this._requestLoggingService = requestLoggingService; }
public ApiExceptionFilter() { _requestLoggingService = (IRequestLoggingService)NinjectHelper.GetResolveService(typeof(IRequestLoggingService)); }
public async Task InvokeAsync(HttpContext httpContext, IGameApiService gameApiService, RequestContext requestContext, ILogger <ThrottlingMiddleware> logger, IRequestLoggingService requestLoggingService) { var endpoint = httpContext.GetEndpoint(); var jsonSerializerSettings = new JsonSerializerSettings { ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() } }; if (endpoint != null) { var metadata = endpoint.Metadata; foreach (var metadataObject in metadata) { if (metadataObject.GetType().Equals(typeof(ThrottleAttribute))) { var throttleAttribute = (ThrottleAttribute)metadataObject; var path = httpContext.Request.Path; var username = httpContext.User.Identity.Name; if (username == null || !path.HasValue || !await gameApiService.ValidRequest(path.ToString(), username, throttleAttribute.ticks)) { logger.LogWarning($"Request { requestContext.RequestId } rejected in api throttling"); string json = JsonConvert.SerializeObject(new GuessResponse { RequestId = requestContext.RequestId, Err = new Error { Message = "Rejected in Api Throttling", Description = $"Please send a valid request. Only 1 request allowed every { throttleAttribute.ticks / ticksPerSecond } seconds" } }, jsonSerializerSettings); httpContext.Response.StatusCode = 400; httpContext.Response.ContentType = "application/json; charset=utf-8"; await httpContext.Response.WriteAsync(json, Encoding.UTF8); return; } } } } await _next(httpContext); }