protected void OnInvoke(object state) { object[] data = (object[])state; SubscribeEventArgs <Message> routemsg = (SubscribeEventArgs <Message>)data[0]; Message message = (Message)data[1]; Result result = (Result)data[2]; try { ControllerContext context = new ControllerContext(); Controller.Context = context; if (message.Body != null && (mToObjectMethod == null || mSelectTokenMethod == null)) { mToObjectMethod = message.Body.GetType().GetMethod(ToObjectMethodName, new Type[] { typeof(Type) }); mSelectTokenMethod = message.Body.GetType().GetMethod(SelectTokenMethodName, new Type[] { typeof(String) }); } object[] objs = new Object[Parameters.Count]; if (Parameters.Count == 1 && Parameters[0].ParameterType.IsClass) { objs[0] = mToObjectMethod.Invoke(message.Body, new object[] { Parameters[0].ParameterType }); } else { for (int i = 0; i < Parameters.Count; i++) { System.Reflection.ParameterInfo p = Parameters[i]; object pobject = mSelectTokenMethod.Invoke(message.Body, new object[] { p.Name }); if (pobject != null) { objs[i] = mToObjectMethod.Invoke(pobject, new object[] { p.ParameterType }); } else { objs[i] = GetTypeDefault(p.ParameterType); } } } result.Data = Method.Invoke(Controller, objs); result.Headers = context.ResultHeaders; } catch (Exception e_) { result.ErrorCode = 500; result.Error = e_.Message; result.ErrorStackTrace = e_.StackTrace; } finally { routemsg.Reply(result); } }
private void OnReceive(object sender, SubscribeEventArgs <Message> e) { Result result = new Result(); ActioHandler handler; if (mHandlers.TryGetValue(e.Data.Api, out handler)) { handler.Invoke(e, e.Data, result); } else { result.ErrorCode = 404; result.Error = string.Format("{0} api action not found!", e.Data.Api); e.Reply(result); } }