Example #1
0
        public void Import(RPC.MethodResult result)
        {
            mMethodResult = result;
            if (MethodResult.Status == ResultStatus.Error)
            {
                Status = InvokeStatus.Completed;
            }
            else
            {
                Status = InvokeStatus.Return;
                if (result.Parameters != null)
                {
                    foreach (string p in result.Parameters)
                    {
                        if (!string.IsNullOrEmpty(p))
                        {
                            ParameterNames.Add(p);
                        }
                    }
                }

                if (result.IsVoid && ParameterNames.Count == 0)
                {
                    Status = InvokeStatus.Completed;
                }
                else if (result.IsVoid && ParameterNames.Count > 0)
                {
                    Status = InvokeStatus.Parameter;
                }
                else
                {
                    Status = InvokeStatus.Return;
                }
            }
        }
Example #2
0
        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__);
            }

        }
Example #3
0
        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);
                }
            }


        }
Example #4
0
        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__);
            }
        }
Example #5
0
        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);
                }
            }
        }