private void ProcessRequest(HttpListenerContext context) { string url = context.Request.RawUrl; RestRoute route = resources.Keys.Where(rt => rt.Matches(context.Request.HttpMethod, url)) .FirstOrDefault(); try { if (route != null) { RestLogger.LogInfo("RestServer::ProcessRequest: " + route + " found"); resources[route](new ResourceData(context, route)); } else if (fileResponder.FileExists(url)) { RestLogger.LogInfo("RestServer::ProcessRequest: file {0} found", url); fileResponder.SendFileResponse(context); } else { RestLogger.LogWarning("RestServer::ProcessRequest: url {0} not found", url); responseWriter.SendNotFound(context.Response); } } catch (Exception ex) { LogException("ProcessRequest", ex); responseWriter.SendInternalServerError(context.Response, ex.ToString()); } }
public void AddResource(RestRoute route, Action <ResourceData> action) { if (action == null) { throw new ArgumentNullException("action"); } resources.Add(route, action); }
public ResourceData(HttpListenerContext context, RestRoute route) { this.HttpListenerContext = context; this.MatchedRoute = route; }