示例#1
0
 private void ProcessGET(IRaptorDB rdb, HttpListenerContext ctx, string path, RDBRoute route)
 {
     try
     {
         var result = DoQuery(rdb, ctx, path, route);
         var s      = fastJSON.JSON.ToJSON(result, new fastJSON.JSONParameters {
             UseExtensions = false, UseFastGuid = false, EnableAnonymousTypes = true
         });
         ctx.Response.ContentType = "application/json";
         WriteResponse(ctx, 200, s);
         return;
     }
     catch (Exception ex)
     {
         WriteResponse(ctx, 500, "" + ex);
     }
 }
示例#2
0
 public void AddRoute(RDBRoute route)
 {
     _log.Debug("adding route : " + route.URL);
     _routing.Add(route.URL.ToLower(), route);
 }
示例#3
0
        private Result <object> DoQuery(IRaptorDB rdb, HttpListenerContext ctx, string path, RDBRoute route)
        {
            string qry      = ctx.Request.Url.GetComponents(UriComponents.Query, UriFormat.Unescaped);
            string viewname = path;

            if (route != null)
            {
                //if (route.EntityType != null)
                //{
                //    if (qry != "")
                //    {
                //        // fetch the json document
                //        string[] s = qry.Split('=');
                //        object obj = null;
                //        if (_jsonstore.GetObject(Guid.Parse(s[1].Replace("\"", "")), out obj))
                //        {
                //            RDBJsonContainer d = (RDBJsonContainer)obj;
                //            WriteResponse(ctx, 200, d.json);
                //            return;
                //        }
                //    }

                //    WriteResponse(ctx, 404, "GUID not found :" + qry);
                //    return;
                //}
                if (route.Viewname == null && route.function != null)
                {
                    viewname = route.Viewname;
                    var             o    = route.function(_rdb, qry);
                    Result <object> resf = new Result <object>(true);
                    resf.Rows       = o;
                    resf.TotalCount = o.Count;
                    resf.Count      = o.Count;
                    resf.Title      = route.Viewname;
                    return(resf);
                }
            }

            // parse "start" and "count" from qry if exists
            int    start   = 0;
            int    count   = -1;
            string orderby = "";

            var m = _start_regex.Match(qry);

            if (m.Success)
            {
                start = int.Parse(m.Groups["start"].Value);
                qry   = qry.Replace(m.Value, "");
            }
            m = _count_regex.Match(qry);
            if (m.Success)
            {
                count = int.Parse(m.Groups["count"].Value);
                qry   = qry.Replace(m.Value, "");
            }
            m = _order_regex.Match(qry);
            if (m.Success)
            {
                orderby = m.Groups["orderby"].Value;
                qry     = qry.Replace(m.Value, "");
            }

            var res = rdb.Query(viewname, qry, start, count, orderby);

            res.Title = viewname;
            return(res);
        }