コード例 #1
0
        public override async Task Invoke(IOwinContext context)
        {
            var bodyStream = context.Request.Body;
            var sr = new StreamReader(bodyStream);
            var body = sr.ReadToEnd();

            string queryStringPaths = null;
            string queryStringMethod = null;
            dynamic jsonGraph = null;
            if (string.IsNullOrEmpty(body))
            {
                queryStringPaths = context.Request.Query["paths"];
                queryStringMethod = context.Request.Query["method"];
            }
            else
            {
                var parts = body.Split('&');
                var jsonGraphEnvelopeString = parts[0].Split('=')[1];
                dynamic jsonGraphEnvelope = JsonConvert.DeserializeObject(jsonGraphEnvelopeString);
                queryStringPaths = JsonConvert.SerializeObject(jsonGraphEnvelope.paths);
                queryStringMethod = parts[1].Split('=')[1];
                jsonGraph = jsonGraphEnvelope.jsonGraph;
            }

            var method = queryStringMethod == "get" ? FalcorMethod.Get : queryStringMethod == "set" ? FalcorMethod.Set : FalcorMethod.Call;
            var paths = FalcorRouterConfiguration.PathParser.ParseMany(queryStringPaths);
            var request = new FalcorRequest(method, paths,jsonGraph);
            var response = await RouterConfiguration.Router.RouteAsync(request);
            var jsonResponse = FalcorRouterConfiguration.ResponseSerializer.Serialize(response);
            context.Response.Headers.Set("content-type", "application/json");
            await context.Response.WriteAsync(jsonResponse);
        }
コード例 #2
0
        public async Task <FalcorResponse> RouteAsync(FalcorRequest request)
        {
            await Route(request).ToList().ToTask();

            var response = FalcorResponse.From(_results);

            return(response);
        }
コード例 #3
0
 public override async Task Invoke(IOwinContext context)
 {
     var queryStringPaths = context.Request.Query["paths"];
     var queryStringMethod = context.Request.Query["method"];
     var method = queryStringMethod == "get" ? FalcorMethod.Get : queryStringMethod == "set" ? FalcorMethod.Set : FalcorMethod.Call;
     var paths = FalcorRouterConfiguration.PathParser.ParseMany(queryStringPaths);
     var request = new FalcorRequest(method, paths);
     var response = await RouterConfiguration.Router.RouteAsync(request);
     var jsonResponse = FalcorRouterConfiguration.ResponseSerializer.Serialize(response);
     context.Response.Headers.Set("content-type", "application/json");
     await context.Response.WriteAsync(jsonResponse);
 }
コード例 #4
0
        public void SetSingleValue()
        {
            var router = new TestFalcorRouter();
            var jsonGraphEnvelopeString = "{\"jsonGraph\":{\"todos\":{\"1\":{\"done\":false}}},\"paths\":[[\"todos\",1,\"done\"]]}";
            dynamic jsonGraphEnvelope = JsonConvert.DeserializeObject(jsonGraphEnvelopeString);
            var paths = FalcorRouterConfiguration.PathParser.ParseMany(JsonConvert.SerializeObject(jsonGraphEnvelope.paths));

            var falcorRequest = new FalcorRequest(FalcorMethod.Set, paths, jsonGraphEnvelope.jsonGraph);
            var falcorResponse = router.RouteAsync(falcorRequest).Result;

            Assert.Equal(((Dictionary<string, object>) falcorResponse.JsonGraph["todos"])
                .Any(kv1 => kv1.Key.Equals("1") && ((Dictionary<string, object>) kv1.Value)
                .Any(kv2 => kv2.Key.Equals("done") && ((Atom)kv2.Value).Value.Equals(false))), true);
        }
コード例 #5
0
 private IObservable<PathValue> Route(FalcorRequest request) =>
     request.Paths.ToObservable()
         .SelectMany(unmatched => Resolve(RootRoute, new RequestContext(request, unmatched)));
コード例 #6
0
 public async Task<FalcorResponse> RouteAsync(FalcorRequest request)
 {
     await Route(request).ToList().ToTask();
     var response = FalcorResponse.From(_results);
     return response;
 }
コード例 #7
0
 public RequestContext(FalcorRequest request, FalcorPath unmatched, dynamic parameters = null)
 {
     Request = request;
     Unmatched = unmatched;
     Parameters = parameters;
 }
コード例 #8
0
ファイル: FalcorRouter.cs プロジェクト: Yshayy/falcor.net
 public Task<FalcorResponse> RouteAsync(FalcorRequest request) => RoutingEngine.RouteAsync(request);
コード例 #9
0
 public async Task<FalcorResponse> RouteAsync(FalcorRequest request)
 {
     IList<PathValue> result = await Route(request).ToList().ToTask();
     var response = _responseBuilder.CreateResponse();
     return response;
 }
コード例 #10
0
 private IObservable <PathValue> Route(FalcorRequest request) =>
 request.Paths.ToObservable()
 .SelectMany(unmatched => Resolve(RootRoute, new RequestContext(request, unmatched)));
コード例 #11
0
 public RequestContext(FalcorRequest request, FalcorPath unmatched, dynamic parameters = null)
 {
     Request    = request;
     Unmatched  = unmatched;
     Parameters = parameters;
 }