Example #1
0
        public async Task Invoke(HttpContext context, IEndpointRouter router /*, IUserSession session, IEventService events*/)
        {
            try {
                IEndpointHandler endpoint = router.Find(context);
                if (endpoint != null)
                {
                    _logger.LogInformation("Invoking IdentityServer endpoint: {endpointType} for {url}", endpoint.GetType().FullName, context.Request.Path.ToString());

                    IEndpointResult result = await endpoint.ProcessAsync(context);

                    if (result != null)
                    {
                        _logger.LogTrace("Invoking result: {type}", result.GetType().FullName);
                        await result.ExecuteAsync(context);
                    }

                    return;
                }
            } catch (Exception ex) {
                //await events.RaiseAsync(new UnhandledExceptionEvent(ex));
                _logger.LogCritical(ex, "Unhandled exception: {exception}", ex.Message);
                throw;
            }

            await _next(context);
        }
        public RequestContext ReceiveRequest()
        {
            try
            {
                NetworkStream dataStream = _connection.GetStream();

                byte[] buffer     = new byte[2048];
                int    bufferRead = dataStream.Read(buffer, 0, buffer.Length);
                string input      = null;
                input = Encoding.ASCII.GetString(buffer, 0, bufferRead); // get string from byte array

                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Received Data: \n" + input + "\n");
                Console.ForegroundColor = ConsoleColor.White;

                RequestContext myRequest = IEndpointHandler.ParseRequest(input);
                return(myRequest);
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem: " + ex.Message);
            }

            return(null);
        }
Example #3
0
        public HttpServer(IPAddress addr, int port, ref ConcurrentBag <Battle> allBattles)
        {
            try
            {
                _listener = new Listener(addr, port);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine("Problem with arguments" + ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem: " + ex.Message);
            }

            _endpointHandler = new EndpointHandler(ref allBattles);
        }
Example #4
0
        public Response HandleRequest(Request request)
        {
            IEndpointHandler endpointHandler = EndpointHandlerManager.Get(request.Endpoint);

            if (endpointHandler.IsNull())
            {
                return(ResponseManager.BadRequest($"Endpoint {request.Endpoint} does not exist"));
            }

            try
            {
                Response resp = endpointHandler.HandleRequest(request);
                return(resp);
            }
            catch (Exception ex)
            {
                ex.Log();
            }

            return(ResponseManager.InternalServerError());
        }
Example #5
0
 // only for mocking purpose
 public HttpServer(IPAddress addr, int port, string messagePath, IEndpointHandler endpointHandler)
 {
     _listener        = new Listener(addr, port);
     _endpointHandler = endpointHandler;
 }