예제 #1
0
        private void ProcessRequest(OwinEnvironment ctx, JArray results, JToken request, Func <OutputStreamType, bool> authFunc)
        {
            RPCRequest req = null;

            try {
                req = RPCRequest.FromJson(request);
            }
            catch (RPCError err) {
                results.Add(new RPCResponse(null, err).ToJson());
                return;
            }
            try {
                var methods = authFunc != null?this.methods.Where(method => authFunc(method.Grant)): this.methods;

                var m = methods.FirstOrDefault(method => method.Name == req.Method);
                if (m != null)
                {
                    var res = m.Invoke(ctx, req.Parameters);
                    if (req.Id != null)
                    {
                        results.Add(new RPCResponse(req.Id, res).ToJson());
                    }
                }
                else
                {
                    throw new RPCError(RPCErrorCode.MethodNotFound);
                }
            }
            catch (RPCError err) {
                results.Add(new RPCResponse(req.Id, err).ToJson());
            }
        }
예제 #2
0
        private void ProcessRequest(JArray results, JToken request)
        {
            RPCRequest req = null;

            try {
                req = RPCRequest.FromJson(request);
            }
            catch (RPCError err) {
                results.Add(new RPCResponse(null, err).ToJson());
                return;
            }
            try {
                var m = methods.FirstOrDefault(method => method.Name == req.Method);
                if (m != null)
                {
                    var res = m.Invoke(host, req.Parameters);
                    if (req.Id != null)
                    {
                        results.Add(new RPCResponse(req.Id, res).ToJson());
                    }
                }
                else
                {
                    throw new RPCError(RPCErrorCode.MethodNotFound);
                }
            }
            catch (RPCError err) {
                results.Add(new RPCResponse(req.Id, err).ToJson());
            }
        }