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); }
public IEnumerable ExecuteQuery(QueryExpression query) { QueryExecutor executor = new QueryExecutor(query); return(executor.Build().Execute()); }
public string ToSQL(QueryExpression query) { QueryExecutor executor = new QueryExecutor(query); return(executor.Build().ToSQL()); }