示例#1
0
 private void RunServerCore()
 {
     _listener.BeginGetContext(async ar =>
     {
         try
         {
             var httpContext = _listener.EndGetContext(ar);
             RunServerCore();
             try
             {
                 var context = new ServiceContext {
                     HttpContext = httpContext, Server = this
                 };
                 await _handler.HandleAsync(context);
             }
             catch (HandlerClientException ex)
             {
                 Utility.ReplyClientErrorResponse(httpContext, $"Error occurs while handling context, {ex.Message}");
             }
             catch (HandlerServerException ex)
             {
                 Utility.ReplyServerErrorResponse(httpContext, $"Error occurs while handling context, {ex.Message}");
             }
             catch (Exception ex)
             {
                 Utility.ReplyServerErrorResponse(httpContext, $"Error occurs, {ex.ToString()}");
             }
         }
         catch (HttpListenerException)
         {
         }
     }, null);
 }
示例#2
0
            public async Task <HttpResponse> HandleAsync(HttpRequest request)
            {
                var response = await _handler1.HandleAsync(request);

                if (response != null)
                {
                    return(response);
                }
                response = await _handler2.HandleAsync(request);

                if (response != null)
                {
                    return(response);
                }
                response = await _handler3.HandleAsync(request);

                if (response != null)
                {
                    return(response);
                }
                response = await _handler4.HandleAsync(request);

                if (response != null)
                {
                    return(response);
                }

                return(await _handler5.HandleAsync(request));
            }