public void ExecuteRequest(IDictionary<string, object> env, ResultDelegate result, Action<Exception> fault) { var environment = new Environment(env); var response = new Response(result); if (Verbose) Console.WriteLine("Received {0} - {1}", environment.Method, environment.Path); var routeData = determineRouteData(environment); if (routeData == null) { // TODO -- try to do it by mapping the files write404(response); } else { var request = new OwinRequestBody(environment); var bodyDelegate = environment["owin.RequestBody"] as BodyDelegate; if (bodyDelegate == null) { executeRoute(routeData, response, request); } else { var bodyBuilder = request.GetRequestBodyBuilder(); bodyDelegate(bodyBuilder, fault, () => executeRoute(routeData, response, request)); } } if (Verbose) Console.WriteLine(" ({0})", response.Status); }
public OwinCurrentHttpRequest(OwinRequestBody body) { _body = body; // TODO -- Owin and protocol? _baseUrl = new Lazy <string>(() => "http://" + _body.HostWithPort + "/" + _body.PathBase.TrimEnd('/')); }
private static void executeRoute(RouteData routeData, Response response, OwinRequestBody request) { var arguments = new OwinServiceArguments(routeData, request, response); var invoker = routeData.RouteHandler.As <FubuRouteHandler>().Invoker; var exceptionHandlingObserver = new ExceptionHandlingObserver(); arguments.Set(typeof(IExceptionHandlingObserver), exceptionHandlingObserver); var task = Task.Factory.StartNew(() => invoker.Invoke(arguments, routeData.Values)); task.ContinueWith(x => { try { x.FinishProcessingTask(exceptionHandlingObserver); } catch (Exception ex) { write500(response, ex); } finally { response.Finish(); } }); }
private static void executeRoute(RouteData routeData, Response response, OwinRequestBody request) { var arguments = new OwinServiceArguments(routeData, request, response); var invoker = routeData.RouteHandler.As<FubuRouteHandler>().Invoker; var exceptionHandlingObserver = new ExceptionHandlingObserver(); arguments.Set(typeof(IExceptionHandlingObserver), exceptionHandlingObserver); var task = Task.Factory.StartNew(() => invoker.Invoke(arguments, routeData.Values)); task.ContinueWith(x => { try { x.FinishProcessingTask(exceptionHandlingObserver); } catch (Exception ex) { write500(response, ex); } finally { response.Finish(); } }); }
private static object findRequestValue(string key, OwinRequestBody body) { var values = valuesForRequest(body); string found; values.TryGetValue(key, out found); return found; }
public OwinCurrentHttpRequest(OwinRequestBody body) { _body = body; // TODO -- Owin and protocol? _baseUrl = new Lazy<string>(() => "http://" + _body.HostWithPort + "/" + _body.PathBase.TrimEnd('/')); }
public OwinServiceArguments(RouteData routeData, OwinRequestBody body, Response response) { With <AggregateDictionary>(new OwinAggregateDictionary(routeData, body)); With <ICurrentHttpRequest>(new OwinCurrentHttpRequest(body)); With <IStreamingData>(new OwinStreamingData(body)); With <IHttpWriter>(new OwinHttpWriter(response)); }
public OwinServiceArguments(RouteData routeData, OwinRequestBody body, Response response) { With<IRequestData>(new OwinRequestData(routeData, body)); With<ICurrentHttpRequest>(new OwinCurrentHttpRequest(body)); With<IStreamingData>(new OwinStreamingData(body)); With<IHttpWriter>(new OwinHttpWriter(response)); }
private static object findRequestValue(string key, OwinRequestBody body) { var values = valuesForRequest(body); string found; values.TryGetValue(key, out found); return(found); }
public OwinRequestData(RouteData routeData, OwinRequestBody body) { AddValues(new RouteDataValues(routeData)); AddValues("OwinQuerystring", new DictionaryKeyValues(body.Querystring())); AddValues("OwinFormPost", new DictionaryKeyValues(body.FormData ?? new Dictionary<string, string>())); AddValues(RequestDataSource.Header.ToString(), new DictionaryKeyValues(body.Headers())); }
public OwinRequestData(RouteData routeData, OwinRequestBody body) { AddValues(new RouteDataValues(routeData)); AddValues(Querystring, new DictionaryKeyValues(body.Querystring())); AddValues(FormPost, new DictionaryKeyValues(body.FormData ?? new Dictionary <string, string>())); AddValues(RequestDataSource.Header.ToString(), new DictionaryKeyValues(body.Headers())); }
public OwinAggregateDictionary(RouteData routeData, OwinRequestBody body) { Func<string, object> locator = key => { object found; routeData.Values.TryGetValue(key, out found); return found; }; AddLocator(RequestDataSource.Route.ToString(), locator, () => routeData.Values.Keys); AddLocator(RequestDataSource.Request.ToString(), key => findRequestValue(key, body), () => valuesForRequest(body).Keys); addDictionaryLocator("Query string", body.Querystring()); addDictionaryLocator("Form Post", body.FormData ?? new Dictionary<string, string>()); addDictionaryLocator(RequestDataSource.Header.ToString(), body.Headers()); }
public OwinAggregateDictionary(RouteData routeData, OwinRequestBody body) { Func <string, object> locator = key => { object found; routeData.Values.TryGetValue(key, out found); return(found); }; AddLocator(RequestDataSource.Route.ToString(), locator, () => routeData.Values.Keys); AddLocator(RequestDataSource.Request.ToString(), key => findRequestValue(key, body), () => valuesForRequest(body).Keys); addDictionaryLocator("Query string", body.Querystring()); addDictionaryLocator("Form Post", body.FormData ?? new Dictionary <string, string>()); addDictionaryLocator(RequestDataSource.Header.ToString(), body.Headers()); }
public OwinAggregateDictionary(RouteData routeData, OwinRequestBody body) { // TODO -- this is duplication w/ AspNetAggregateDictionary. DRY it baby! Func<string, object> locator = key => { object found; routeData.Values.TryGetValue(key, out found); return found; }; AddLocator(RequestDataSource.Route.ToString(), locator, () => routeData.Values.Keys); addDictionaryLocator("Query string", body.Querystring()); addDictionaryLocator("Form Post", body.FormData ?? new Dictionary<string, string>()); addDictionaryLocator(RequestDataSource.Header.ToString(), body.Headers()); }
public OwinAggregateDictionary(RouteData routeData, OwinRequestBody body) { // TODO -- this is duplication w/ AspNetAggregateDictionary. DRY it baby! Func <string, object> locator = key => { object found; routeData.Values.TryGetValue(key, out found); return(found); }; AddLocator(RequestDataSource.Route.ToString(), locator, () => routeData.Values.Keys); addDictionaryLocator("Query string", body.Querystring()); addDictionaryLocator("Form Post", body.FormData ?? new Dictionary <string, string>()); addDictionaryLocator(RequestDataSource.Header.ToString(), body.Headers()); }
private static void executeRoute(RouteData routeData, Response response, OwinRequestBody request) { var arguments = new OwinServiceArguments(routeData, request, response); var invoker = routeData.RouteHandler.As<FubuRouteHandler>().Invoker; try { invoker.Invoke(arguments, routeData.Values); } catch (Exception ex) { write500(response, ex); } finally { response.Finish(); } }
private static void executeRoute(RouteData routeData, Response response, OwinRequestBody request) { var arguments = new OwinServiceArguments(routeData, request, response); var invoker = routeData.RouteHandler.As <FubuRouteHandler>().Invoker; try { invoker.Invoke(arguments, routeData.Values); } catch (Exception ex) { write500(response, ex); } finally { response.Finish(); } }
private static IDictionary<string, string> valuesForRequest(OwinRequestBody body) { var dictionary = new Dictionary<string, string>(); var queryString = body.Querystring(); foreach(var key in queryString.Keys) { dictionary.Add(key, queryString[key]); } IDictionary<string, string> formData = body.FormData ?? new Dictionary<string, string>(); foreach (var key in formData.Keys.Where(x => x != null)) { if(!dictionary.ContainsKey(key)) { dictionary.Add(key, formData[key]); } } return dictionary; }
public void ExecuteRequest(IDictionary <string, object> env, ResultDelegate result, Action <Exception> fault) { var environment = new Environment(env); var response = new Response(result); if (Verbose) { Console.WriteLine("Received {0} - {1}", environment.Method, environment.Path); } var routeData = determineRouteData(environment); if (routeData == null) { // TODO -- try to do it by mapping the files write404(response); } else { var request = new OwinRequestBody(environment); var bodyDelegate = environment["owin.RequestBody"] as BodyDelegate; if (bodyDelegate == null) { executeRoute(routeData, response, request); } else { var bodyBuilder = request.GetRequestBodyBuilder(); bodyDelegate(bodyBuilder, fault, () => executeRoute(routeData, response, request)); } } if (Verbose) { Console.WriteLine(" ({0})", response.Status); } }
private static IDictionary <string, string> valuesForRequest(OwinRequestBody body) { var dictionary = new Dictionary <string, string>(); var queryString = body.Querystring(); foreach (var key in queryString.Keys) { dictionary.Add(key, queryString[key]); } IDictionary <string, string> formData = body.FormData ?? new Dictionary <string, string>(); foreach (var key in formData.Keys.Where(x => x != null)) { if (!dictionary.ContainsKey(key)) { dictionary.Add(key, formData[key]); } } return(dictionary); }
public OwinStreamingData(OwinRequestBody request) { _stream = request.Stream ?? new MemoryStream(); }