Exemplo n.º 1
0
        public Dictionary <string, object> GetApiJson()
        {
            Dictionary <string, object> root = new Dictionary <string, object>();

            root["name"]        = this.GetName();
            root["description"] = this.GetDescrpition();
            Dictionary <string, object> args = new Dictionary <string, object>();

            foreach (string key in this._args.Keys)
            {
                IArg i_arg = this._args[key];
                Dictionary <string, object> arg = new Dictionary <string, object>();
                arg["name"]        = key;
                arg["type"]        = i_arg.GetDataType();
                arg["description"] = i_arg.GetDescription();
                arg["default"]     = i_arg.GetDefault();
                arg["level"]       = i_arg.GetLevel().ToString();
                arg["example"]     = i_arg.GetExample();
                arg["examples"]    = i_arg.GetExamples();
                args[key]          = arg;
            }
            root["args"] = args;
            Dictionary <string, object> children = new Dictionary <string, object>();

            foreach (string key in this._children.Keys)
            {
                IApiUnit <TContext> iau = this._children[key];
                children[key] = iau.GetApiJson();
            }
            root["return_description"] = this.GetReturnDescription();
            root["return_example"]     = this.GetReturnExample();
            root["return_examples"]    = this.GetReturnExamples();
            root["children"]           = children;
            return(root);
        }
Exemplo n.º 2
0
        public object Request(TContext ctx)
        {
            string[]            actions = ctx.Url.Split('/');
            IApiUnit <TContext> iau     = this.root;

            if (actions.Length == 0)
            {
                return(null);
            }
            if (actions[0] != this.root.GetName())
            {
                return(null);
            }
            for (int i = 1; i < actions.Length; i++)
            {
                string action = actions[i];
                if (iau.GetChildren().ContainsKey(action))
                {
                    iau = iau.GetChildren()[action];
                }
                else
                {
                    return(null);
                }
            }
            ctx.TestArgs(iau.GetArgs());
            this._before(ctx);
            iau.RunBefore(ctx);
            object result = iau.Run(ctx);

            result = iau.RunAfter(ctx, result);
            result = this._after(ctx, result);
            return(result);
        }
Exemplo n.º 3
0
 private void _Register(string name, IApiUnit <TContext> au)
 {
     if (this._children.ContainsKey(name))
     {
         throw new ApiException((int)APISTATUS.ERROR, string.Format("[{0}]分支下已经注册了[{1}]接口。", this._name, name));
     }
     this._children.Add(name, au);
 }
Exemplo n.º 4
0
 public void Register(IApiUnit <TContext> i_api_unit)
 {
     this.root = i_api_unit;
 }