public bool Process(HttpListenerContext context) { var segments = context.Request.Url.Segments; string action; if (segments.Length < 3) { action = "index"; } else { action = segments[2].TrimEnd('/').ToLower(); } MethodInfo mi; if (!_methods.TryGetValue(action, out mi)) { return(false); } HttpController ctrl = (HttpController)Activator.CreateInstance(_type); ctrl.Init(_server, context); try { mi.Invoke(ctrl, new object[0]); } catch (TargetInvocationException tex) { ctrl.WriteException(tex.InnerException); } catch (Exception ex) { ctrl.WriteException(ex); } if (!ctrl.IsAsync) { ctrl._ProcessCompleted(); } return(true); }
internal void Init(HttpController controller) { _controller = controller; _server = controller.Server; }