示例#1
0
        public MetAdapter(Object moduleInstance, MethodInfo metInfo)
        {
            this.moduleInstance = moduleInstance;
            this.metInfo        = metInfo;

            //conservative form
            ParameterInfo[] pars = metInfo.GetParameters();
            if (pars.Length == 2 &&
                pars[0].ParameterType == typeof(HttpRequest) &&
                pars[1].ParameterType == typeof(HttpResponse))
            {
                _conservativeForm = true;
            }
            else
            {
                parAdapters = new ParameterAdapter[pars.Length];

                int i = 0;
                foreach (ParameterInfo p in pars)
                {
                    ParameterAdapter parAdapter = new ParameterAdapter(p.Name, p.ParameterType);
                    parAdapters[i] = parAdapter;
                    i++;
                }
                _conservativeForm = false;
            }
        }
示例#2
0
        object[] PrepareInputArgs(HttpRequest req)
        {
            int j = parAdapters.Length;

            object[] pars = new object[j];
            for (int i = 0; i < j; ++i)
            {
                ParameterAdapter a          = parAdapters[i];
                string           inputValue = req.GetReqParameterValue(a.ParName);


                pars[i] = a.GetActualValue(inputValue);
            }
            return(pars);
        }
示例#3
0
        public void Invoke(HttpRequest req, HttpResponse resp)
        {
            //check parameter before invoke
            if (parAdapters != null)
            {
                int      j     = parAdapters.Length;
                object[] check = new object[j];
                if (j != req.ReqParameters.Length) //parameters
                {
                    resp.End("Please input only " + j + " parameters");
                    return;
                }
                for (int i = 0; i < j; ++i)
                {
                    ParameterAdapter a          = parAdapters[i];
                    string           inputValue = req.GetReqParameterValue(a.ParName); //value
                    check[i] = a.GetActualValue(inputValue);                           //type
                    if (inputValue == "")                                              //wrong parameter
                    {
                        resp.End("Wrong parameter name or invalid input.");
                        return;
                    }
                    if (check[i] == null) //worng type
                    {
                        resp.End("Wrong input type.");
                        return;
                    }
                }
            }

            //object check = PrepareInputArgs(req);
            if (_conservativeForm)
            {
                this.metInfo.Invoke(
                    moduleInstance, new object[] { req, resp }
                    );
            }
            else
            {
                //....prepare input

                object result = metInfo.Invoke(moduleInstance, PrepareInputArgs(req));

                //prepare result
                resp.End(result.ToString());
            }
        }