public DebugController( IWebSocketRepository webSocketRepository, DebugRepository debugRepository, OnlineUserRepository onlineUserRepository) { _webSocketRepository = webSocketRepository; _debugRepository = debugRepository; _onlineUserRepository = onlineUserRepository; }
public FilesController( DebugRepository debugRepository, IFileService fileService, IUserService userService, OpenRequestsRepository openRequestsRepository, IWebSocketHandler webSocketHandler, IServiceProvider serviceProvider) { _debugRepository = debugRepository; _fileService = fileService; _userService = userService; _openRequestsRepository = openRequestsRepository; _webSocketHandler = webSocketHandler; _serviceProvider = serviceProvider; }
public async Task AddPersonAsync(string first, string last) { var repo = new DebugRepository(); var person = new DebugPersonModel { FirstName = first, LastName = last }; try { await repo.InsertAsync(person); await ReplyAsync($"Person [{person.FirstName}], [{person.LastName}] added to DB successfully!"); } catch (Exception e) { Log.Error(e.Message); await ReplyAsync($"Could not save person: {e.Message}"); } }
public async Task InvokeAsync( HttpContext context, DebugRepository debugRepository, ILogger <ExceptionHandlerMiddleware> logger) { try { await _next(context); } catch (Exception exception) { logger.LogError(exception.ToString()); debugRepository.Errors.Add((exception.ToString(), DateTime.Now)); if (!context.Response.HasStarted) { if (exception is HandledException handledException) { context.Response.Clear(); context.Response.StatusCode = (int)handledException.StatusCode(); context.Response.ContentType = "application/json"; var error = new ErrorClass { StatusCode = context.Response.StatusCode, ErrorMessage = handledException.ErrorMessage() }; await context.Response.Body.WriteStringAsStreamAsync(JsonConvert.SerializeObject(error)); } else { context.Response.Clear(); context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; context.Response.ContentType = "application/json"; var error = new ErrorClass { StatusCode = context.Response.StatusCode, ErrorMessage = "Internal server error." }; await context.Response.Body.WriteStringAsStreamAsync(JsonConvert.SerializeObject(error)); } } else { if (exception is HandledException handledException) { var error = new ErrorClass { StatusCode = (int)handledException.StatusCode(), ErrorMessage = handledException.ErrorMessage() }; if (handledException.IsWebSocketException() && handledException.WebSocket() != null) { await handledException.WebSocket() .CloseAsync( WebSocketCloseStatus.InternalServerError, statusDescription: $"Status code: {error.StatusCode}\n {error.ErrorMessage}", cancellationToken: CancellationToken.None); } else { throw; } } else { throw; } } } }