Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public OwinCurrentHttpRequest(OwinRequestBody body)
        {
            _body = body;

            // TODO -- Owin and protocol?
            _baseUrl = new Lazy <string>(() => "http://" + _body.HostWithPort + "/" + _body.PathBase.TrimEnd('/'));
        }
Ejemplo n.º 3
0
        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();
                }
            });
        }
Ejemplo n.º 4
0
        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();
                }
            });
        }
Ejemplo n.º 5
0
 private static object findRequestValue(string key, OwinRequestBody body)
 {
     var values = valuesForRequest(body);
     string found;
     values.TryGetValue(key, out found);
     return found;
 }
Ejemplo n.º 6
0
        public OwinCurrentHttpRequest(OwinRequestBody body)
        {
            _body = body;

            // TODO -- Owin and protocol?
            _baseUrl = new Lazy<string>(() => "http://" + _body.HostWithPort + "/" + _body.PathBase.TrimEnd('/'));
        }
Ejemplo n.º 7
0
        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));
        }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
0
        private static object findRequestValue(string key, OwinRequestBody body)
        {
            var    values = valuesForRequest(body);
            string found;

            values.TryGetValue(key, out found);
            return(found);
        }
Ejemplo n.º 10
0
        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()));
        }
Ejemplo n.º 11
0
        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()));
        }
Ejemplo n.º 12
0
        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());
        }
Ejemplo n.º 13
0
        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());
        }
Ejemplo n.º 14
0
        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());
        }
Ejemplo n.º 15
0
        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());
        }
Ejemplo n.º 16
0
        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();
            }
        }
Ejemplo n.º 17
0
        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();
            }
        }
Ejemplo n.º 18
0
        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;
        }
Ejemplo n.º 19
0
        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);
            }
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
 public OwinStreamingData(OwinRequestBody request)
 {
     _stream = request.Stream ?? new MemoryStream();
 }
Ejemplo n.º 22
0
 public OwinStreamingData(OwinRequestBody request)
 {
     _stream = request.Stream ?? new MemoryStream();
 }