public Result Execute(RemoteInvokeArgs info) { Result result = new Result(); result.Status = ResultStatus.Success; MethodHandler handler; if(mHandlers.TryGetValue(info.GetKey(),out handler)) { try { result.Data = handler.Execute(info.Parameters); if (handler.Parameters != null && handler.Parameters.Length > 0) { for (int i = 0; i < handler.Parameters.Length; i++) { if (handler.Parameters[i].IsRetval || handler.Parameters[i].IsOut) { result[handler.Parameters[i].Name] = info.Parameters[i]; } } } } catch(Exception e_) { result.Status = ResultStatus.Error; result.Error = string.Format("{0} method invoke error {1}!\r\nStackTrace:{2}", info.GetKey(), e_.Message, e_.StackTrace); } } else{ result.Status = ResultStatus.Error; result.Error = string.Format("{0} method handler not found!", info.GetKey()); } return result; }
public Result Execute(RemoteInvokeArgs info) { MethodReturnArgs returnArgs = info.CommunicationObject.Client.Pop(); IClient client = info.CommunicationObject.Client; List<Message> sendDatas = new List<Message>(); RPC.MethodCall call = new RPC.MethodCall(); Result result = new Result(); result.Status = ResultStatus.Success; try { info.CommunicationObject.Client.RegisterRemote(call.ID, returnArgs); call.Service = info.Interface; call.Method = info.Method; call.Parameters = info.ParameterTypes; sendDatas.Add(new Message(call, typeof(RPC.MethodCall))); if (info.Parameters != null) for (int i = 0; i < info.Parameters.Length; i++) { Type ptype = info.ParameterInfos[i].ParameterType; sendDatas.Add(new Message(info.Parameters[i], ptype.Name.IndexOf('&') ==-1 ? ptype : ptype.GetElementType())); } Beetle.Express.IData sdata = ((Packet)client.Connection.Package).GetMessageData(sendDatas); LastRemotingData = sdata; if (!client.Send(sdata)) { throw client.Connection.LastError; } returnArgs.Status = InvokeStatus.Receiving; if (!returnArgs.Wait()) throw new Exception("invoke timeout!"); if (returnArgs.MethodResult.Status == ResultStatus.Error) throw new Exception(returnArgs.MethodResult.Error); if (!returnArgs.MethodResult.IsVoid) result.Data = returnArgs.Result; if (returnArgs.ParameterNames.Count > 0) { for (int i = 0; i < returnArgs.ParameterNames.Count; i++) { result.Parameters[returnArgs.ParameterNames[i]] = returnArgs.Parameters[i]; } } return result; } catch (Exception e_) { throw new ProxyException(string.Format("remote access {0}.{1} error {2}", info.Interface, info.Method, e_.Message)); } finally { info.CommunicationObject.Client.UnRegisterRemote(call.ID); info.CommunicationObject.Client.Push(returnArgs); } }
public Result Execute(ICommunicationObject client, string service, System.Reflection.MethodBase method, params object[] data) { RemoteInvokeArgs info = new RemoteInvokeArgs(); info.Interface = service; info.Method = method.Name; info.Parameters = data; info.CommunicationObject = client; info.ParameterInfos = method.GetParameters(); foreach (System.Reflection.ParameterInfo pi in method.GetParameters()) { info.ParameterTypes.Add(pi.ParameterType.Name); } return(Handler.Execute(info)); }
public Result Execute(RemoteInvokeArgs info) { Result result = new Result(); result.Status = ResultStatus.Success; MethodHandler handler; if (mHandlers.TryGetValue(info.GetKey(), out handler)) { try { result.Data = handler.Execute(info.Parameters); if (handler.Parameters != null && handler.Parameters.Length > 0) { for (int i = 0; i < handler.Parameters.Length; i++) { if (handler.Parameters[i].IsRetval || handler.Parameters[i].IsOut) { result[handler.Parameters[i].Name] = info.Parameters[i]; } } } } catch (Exception e_) { result.Status = ResultStatus.Error; result.Error = string.Format("{0} method invoke error {1}!\r\nStackTrace:{2}", info.GetKey(), e_.Message, e_.StackTrace); } } else { result.Status = ResultStatus.Error; result.Error = string.Format("{0} method handler not found!", info.GetKey()); } return(result); }
public Result Execute(RemoteInvokeArgs info) { MethodReturnArgs returnArgs = info.CommunicationObject.Client.Pop(); IClient client = info.CommunicationObject.Client; List <Message> sendDatas = new List <Message>(); RPC.MethodCall call = new RPC.MethodCall(); Result result = new Result(); result.Status = ResultStatus.Success; try { info.CommunicationObject.Client.RegisterRemote(call.ID, returnArgs); call.Service = info.Interface; call.Method = info.Method; call.Parameters = info.ParameterTypes; sendDatas.Add(new Message(call, typeof(RPC.MethodCall))); if (info.Parameters != null) { for (int i = 0; i < info.Parameters.Length; i++) { Type ptype = info.ParameterInfos[i].ParameterType; sendDatas.Add(new Message(info.Parameters[i], ptype.Name.IndexOf('&') == -1 ? ptype : ptype.GetElementType())); } } Beetle.Express.IData sdata = ((Packet)client.Connection.Package).GetMessageData(sendDatas); LastRemotingData = sdata; if (!client.Send(sdata)) { throw client.Connection.LastError; } returnArgs.Status = InvokeStatus.Receiving; if (!returnArgs.Wait()) { throw new Exception("invoke timeout!"); } if (returnArgs.MethodResult.Status == ResultStatus.Error) { throw new Exception(returnArgs.MethodResult.Error); } if (!returnArgs.MethodResult.IsVoid) { result.Data = returnArgs.Result; } if (returnArgs.ParameterNames.Count > 0) { for (int i = 0; i < returnArgs.ParameterNames.Count; i++) { result.Parameters[returnArgs.ParameterNames[i]] = returnArgs.Parameters[i]; } } return(result); } catch (Exception e_) { throw new ProxyException(string.Format("remote access {0}.{1} error {2}", info.Interface, info.Method, e_.Message)); } finally { info.CommunicationObject.Client.UnRegisterRemote(call.ID); info.CommunicationObject.Client.Push(returnArgs); } }
public void ProcessMessage(object message, ISession context) { Events.EventMessageProcessArgs mpa = new Events.EventMessageProcessArgs(); mpa.Application = this.mApplication; mpa.Cancel = false; mpa.Session = context; mpa.Message = message; OnMessageExecting(mpa); if (mpa.Cancel) return; IMethodHandler handler = null; RemoteInvokeArgs invokeArgs = (RemoteInvokeArgs)context[SOA_INVOKE_TAG]; if (message is RPC.MethodCall) { invokeArgs = new RemoteInvokeArgs((RPC.MethodCall)message); context[SOA_INVOKE_TAG] = invokeArgs; } else { if (invokeArgs == null) { if (mControllerHandlers.TryGetValue(message.GetType(), out handler)) { object data = new object[] { handler, context, message }; if (handler.UseThreadPool) { System.Threading.ThreadPool.QueueUserWorkItem(OnControllerProcess, data); } else { OnControllerProcess(data); } } else { "{0} messgae action notfound".Log4Error(message.GetType()); } return; } else { invokeArgs.AddParameter(message); } } if (invokeArgs.HasCompleted) { context[SOA_INVOKE_TAG] = null; string key = invokeArgs.GetKey(); if (mSoaHandlers.TryGetValue(key, out handler)) { object data = new object[] { handler, context, invokeArgs.Parameters, invokeArgs }; if (handler.UseThreadPool) { System.Threading.ThreadPool.QueueUserWorkItem(OnSOAProcess, data); } else { OnSOAProcess(data); } } else { RPC.MethodResult result = new RPC.MethodResult(); result.Status = ResultStatus.Error; result.Error = string.Format("{0} method not found!", key); mApplication.Server.Send(result, context.Channel); "{0} method notfound".Log4Error(key); } } }
private void OnSOAProcess(object data) { object[] array = (object[])data; IMethodHandler handler = (IMethodHandler)array[0]; ISession context = (ISession)array[1]; object[] message = (object[])array[2]; RemoteInvokeArgs riargs = (RemoteInvokeArgs)array[3]; RPC.MethodResult result = new RPC.MethodResult(); result.ID = riargs.CallID; Implement.Session.Current = context; result.Status = ResultStatus.Success; MethodContext mc; object rdata = null; IList <Message> returnValues = new List <Message>(); returnValues.Add(new Message(result, typeof(RPC.MethodResult))); IList <string> refParameters = null; try { mc = new MethodContext(mApplication, context, message, handler); mc.Execute(); rdata = mc.Result; result.IsVoid = handler.Info.ReturnType == typeof(void); if (!result.IsVoid) { returnValues.Add(new Message(rdata, handler.Info.ReturnType)); } if (handler.Parameters.Length > 0) { result.Parameters = new string[handler.Parameters.Length]; for (int i = 0; i < handler.Parameters.Length; i++) { System.Reflection.ParameterInfo pi = handler.Parameters[i]; if (pi.IsOut || pi.IsRetval) { if (refParameters == null) { refParameters = new List <string>(); } Type ptype = pi.ParameterType; returnValues.Add(new Message(message[i], ptype.Name.IndexOf('&') == -1 ? ptype : ptype.GetElementType())); refParameters.Add(pi.Name); } } if (refParameters != null) { result.Parameters = refParameters.ToArray(); } } } catch (Exception e_) { result.Status = ResultStatus.Error; result.Error = e_.Message; "{0} invoke error ".Log4Error(e_, handler.ToString()); context.Channel.InvokeError(e_); } finally { Implement.Session.Current = null; } try { Beetle.Express.IData sdata = ((IPacketAnalyzer)context.Channel.Package).GetMessageData(returnValues); context.Application.Server.Send(sdata, context.Channel); } catch (Exception e__) { "{0} get return data error ".Log4Error(e__, handler.ToString()); context.Channel.InvokeError(e__); } }
public void ProcessMessage(object message, ISession context) { Events.EventMessageProcessArgs mpa = new Events.EventMessageProcessArgs(); mpa.Application = this.mApplication; mpa.Cancel = false; mpa.Session = context; mpa.Message = message; OnMessageExecting(mpa); if (mpa.Cancel) { return; } IMethodHandler handler = null; RemoteInvokeArgs invokeArgs = (RemoteInvokeArgs)context[SOA_INVOKE_TAG]; if (message is RPC.MethodCall) { invokeArgs = new RemoteInvokeArgs((RPC.MethodCall)message); context[SOA_INVOKE_TAG] = invokeArgs; } else { if (invokeArgs == null) { if (mControllerHandlers.TryGetValue(message.GetType(), out handler)) { object data = new object[] { handler, context, message }; if (handler.UseThreadPool) { System.Threading.ThreadPool.QueueUserWorkItem(OnControllerProcess, data); } else { OnControllerProcess(data); } } else { "{0} messgae action notfound".Log4Error(message.GetType()); } return; } else { invokeArgs.AddParameter(message); } } if (invokeArgs.HasCompleted) { context[SOA_INVOKE_TAG] = null; string key = invokeArgs.GetKey(); if (mSoaHandlers.TryGetValue(key, out handler)) { object data = new object[] { handler, context, invokeArgs.Parameters, invokeArgs }; if (handler.UseThreadPool) { System.Threading.ThreadPool.QueueUserWorkItem(OnSOAProcess, data); } else { OnSOAProcess(data); } } else { RPC.MethodResult result = new RPC.MethodResult(); result.Status = ResultStatus.Error; result.Error = string.Format("{0} method not found!", key); mApplication.Server.Send(result, context.Channel); "{0} method notfound".Log4Error(key); } } }