예제 #1
0
        public DynvokeMethod PrepTarget(string classname, string methodname, ParamProvider provider)
        {
            DynvokeMethod method = Get(classname, methodname);

            if (method == null)
            {
                return(null);
            }

            foreach (KeyValuePair <string, Type> entry in method.Parameters)
            {
                object value = null;

                if (provider.TryGetParam(entry.Key, entry.Value, out value))
                {
                    if (ParamReplacersExternal.ContainsKey(entry.Key) && ParamReplacersExternal[entry.Key].ExternalType == entry.Value)
                    {
                        ParamReplacmentContainer replCont = ParamReplacersExternal[entry.Key];

                        object newvalue = replCont.Replacer(value);

                        Log.Debug("  Replacement: [" + replCont.InternalParamName + "] = (" + replCont.InternalType + ") [" + newvalue + "]");

                        method.SetParameter(replCont.InternalParamName, newvalue);
                    }
                    else
                    {
                        Log.Debug("  Parameter:   [" + entry.Key + "] = (" + entry.Value + ") [" + value + "]");

                        method.SetParameter(entry.Key, value);
                    }
                }
            }

            foreach (KeyValuePair <string, Type> entry in method.InjectedParameters)
            {
                object value = null;

                if (ParamInjectors.ContainsKey(entry.Key) && ParamInjectors[entry.Key].Type == entry.Value)
                {
                    ParamInjectionContainer injCont = ParamInjectors[entry.Key];

                    value = injCont.Injector();

                    Log.Debug("  Injected:    [" + entry.Key + "] = (" + entry.Value + ") [" + value + "]");

                    method.SetParameter(entry.Key, value);
                }
            }

            return(method);
        }
예제 #2
0
        private DynvokeMethod Get(string classname, string methodname)
        {
            string key = GetKey(classname, methodname);

            if (!Targets.ContainsKey(key))
            {
                return(null);
            }

            DynvokeMethod method = new DynvokeMethod(Targets[key]);

            return(method);
        }
예제 #3
0
        public HttpDynvokeResponse HandleRequest(HttpDynvokeRequest request)
        {
            DateTime requestStart = DateTime.Now;

            try
            {
                string json = request.RequestBody;

                JsonParamProvider jsonParams = new JsonParamProvider(json);

                DynvokeMethod method = this.Dynvoke.PrepTarget(request.Controller, request.Action, jsonParams);

                if (method == null)
                {
                    return(NOT_FOUND);
                }

                if (!method.ReadyToCall)
                {
                    return(MISSING_ARGUMENTS);
                }

                object returnObj = method.Call();
                string outputStr = "";

                if (method.ReturnType != typeof(void))
                {
                    outputStr = JsonConvert.SerializeObject(returnObj);
                    Log.Debug("Called method, returned: [" + outputStr + "]");
                }
                else
                {
                    Log.Debug("Called method, void return");
                }

                return(new HttpDynvokeResponse(200, outputStr, "application/json"));
            }
            catch (Exception e)
            {
                Log.Error("Exception thrown while handling request!\n" + e.ToString());
                return(SERVER_ERROR);
            }
            finally
            {
                Log.Debug("Total response time in [" + DateTime.Now.Subtract(requestStart).TotalMilliseconds + "] ms");
            }
        }