示例#1
0
        public async Task Invoke(HttpContext context)
        {
            if (context.Request.Method == "GET" || context.Request.Method == "POST")
            {
                //if (routes.Count == 0)
                //{
                routes = Metadata.GetRequests();
                //}

                Request request = null;
                string  json    = string.Empty;

                _logger.LogInformation("Request path: {0}", context.Request.Path);

                if (routes.TryGetValue(context.Request.Path, out request))
                {
                    json = request.ParseTree;
                    QueryExpression query = Serializer.FromJson(json);

                    JObject parameters = this.ReadParameters(context);
                    if (parameters != null && query.Parameters != null && query.Parameters.Count > 0)
                    {
                        this.SetParameters(parameters, query);
                    }

                    QueryExecutor executor = new QueryExecutor(query);
                    try
                    {
                        var result = executor.Build().ExecuteAsRowData();
                        json = JsonConvert.SerializeObject(result);
                    }
                    catch (Exception ex)
                    {
                        json = Program.GetErrorText(ex);
                    }
                }
                else
                {
                    _logger.LogInformation("Requested path not found.");
                    _logger.LogInformation("Available paths are:");
                    foreach (string route in routes.Keys)
                    {
                        _logger.LogInformation(route);
                    }
                }

                context.Response.ContentType = "application/json";
                await context.Response.WriteAsync(json);
            }
            else
            {
                await _next(context);
            }
        }
        public async Task Invoke(HttpContext context)
        {
            if (context.Request.Method == "GET" || context.Request.Method == "POST")
            {
                //if (routes.Count == 0)
                //{
                routes = Metadata.GetRequests();
                //}

                Request request = null;
                string  json    = string.Empty;

                if (routes.TryGetValue(context.Request.Path, out request))
                {
                    json = request.ParseTree;
                    QueryExpression query = Serializer.FromJson(json);

                    JObject parameters = this.ReadParameters(context);
                    if (parameters != null && query.Parameters != null && query.Parameters.Count > 0)
                    {
                        this.SetParameters(parameters, query);
                    }

                    QueryExecutor executor = new QueryExecutor(query);
                    try
                    {
                        var result = executor.Build().ExecuteAsRowData();
                        json = JsonConvert.SerializeObject(result);
                    }
                    catch (Exception ex)
                    {
                        json = Program.GetErrorText(ex);
                    }
                }
                //context.Response.StatusCode = 500;

                context.Response.StatusCode  = 200;
                context.Response.ContentType = "application/json";
                await context.Response.WriteAsync(json);
            }
            //context.Response.StatusCode = 200;
            await _next(context);
        }
示例#3
0
        public IEnumerable ExecuteQuery(QueryExpression query)
        {
            QueryExecutor executor = new QueryExecutor(query);

            return(executor.Build().Execute());
        }
示例#4
0
        public string ToSQL(QueryExpression query)
        {
            QueryExecutor executor = new QueryExecutor(query);

            return(executor.Build().ToSQL());
        }