Пример #1
0
        private void OnRequestProcess(Request e)
        {
            Response response;

            try
            {
                EventNext.EventActionHandler handler = EventCenter.GetActionHandler(e.Url);
                BindRequestParameter(e, handler);
                if (handler != null)
                {
                    OnEventNext(e);
                }
                else
                {
                    if (EnableLog(LogType.Debug))
                    {
                        Log(LogType.Debug, $"[{e.ID}]{e.Sesion.RemoteEndPoint} request {e.Url} not found!");
                    }
                    response        = new Response();
                    response.Status = (short)ResponseCode.ACTION_NOT_FOUND;
                    response.Data   = new object[] { $"request {e.Url} not found!" };
                    OnResponse(e, response);
                }
            }
            catch (Exception e_)
            {
                response        = new Response();
                response.Status = (short)ResponseCode.INNER_ERROR;
                response.Data   = new object[] { e_.Message };
                OnResponse(e, response);
                if (EnableLog(LogType.Error))
                {
                    Log(LogType.Debug, $"[{e.ID}]{e.Sesion.RemoteEndPoint} request {e.Url} error {e_.Message}@{e_.StackTrace}!");
                }
            }
            finally
            {
                var array = e.DataBuffer;
                if (array != null)
                {
                    this.RPCOptions.PushBuffer(array.Array, array.Count);
                }
                e.DataBuffer = null;
            }
        }
Пример #2
0
        private void OnRequestProcess(RPCPacket e)
        {
            RPCPacket response = e;

            try
            {
                var evt = OnProcessing(e);
                if (evt != null && evt.Cancel)
                {
                    return;
                }
                if (this.Security)
                {
                    if (e.Session.Authentication < AuthenticationType.User && e.Url != Clients.XRPCClient.LOGIN_TAG)
                    {
                        e.ReplyError((short)StatusCode.INNER_ERROR, "No permission operation in secure mode!");
                        return;
                    }
                }
                EventNext.EventActionHandler handler = EventCenter.GetActionHandler(e.Url);
                if (handler != null)
                {
                    BindRequestParameter(e, handler);
                    OnEventNext(e);
                }
                else
                {
                    if (e.Url == "/__System/Ping")
                    {
                        response = new RPCPacket();
                        if (EnableLog(LogType.Debug))
                        {
                            Log(LogType.Debug, $"[{e.ID}]{e.Session.RemoteEndPoint} request {e.Url}");
                        }
                        response.Status = (short)StatusCode.SUCCESS;
                        OnResponse(e, response);
                    }
                    else if (e.Url == Clients.XRPCClient.LOGIN_TAG)
                    {
                        EventLoginArgs login = new EventLoginArgs(this, e.Session);
                        e.LoadParameters <string, string>();
                        login.UserName = (string)e.Data[0];
                        login.Password = (string)e.Data[1];
                        Login?.Invoke(this, login);
                        if (login.Success)
                        {
                            e.Session[NAME_PROPERTY_TAG] = login.UserName;
                            e.ReplySuccess();
                        }
                        else
                        {
                            string error = login.Message;
                            if (string.IsNullOrEmpty(error))
                            {
                                error = "Invalid username or password!";
                            }
                            e.ReplyError(error);
                        }
                    }
                    else
                    {
                        var awaitItem = AwaiterFactory.GetItem(response.ID);
                        if (awaitItem != null)
                        {
                            response.ResultType = awaitItem.ResultType;
                            try
                            {
                                if (response.ResultType != null)
                                {
                                    response.LoadParameters(response.ResultType);
                                }
                            }
                            catch (Exception e_)
                            {
                                response.Status = (short)StatusCode.INNER_ERROR;
                                response.Data   = new object[] { $"{e_.Message}@{e_.StackTrace}" };
                            }
                            AwaiterFactory.Completed(awaitItem, response);
                        }
                        else
                        {
                            if (response.Url.IndexOf(XRPCClient.DELEGATE_TAG, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                InvokeDelegate(response);
                                return;
                            }
                            if (response.Url.IndexOf(XRPCClient.SUBSCRIBE_TAG, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                OnSubscribe(response);
                                return;
                            }
                            if (NotFound == null)
                            {
                                if (EnableLog(LogType.Debug))
                                {
                                    Log(LogType.Debug, $"[{e.ID}]{e.Session.RemoteEndPoint} request {e.Url} not found!");
                                }
                                response        = new RPCPacket();
                                response.Status = (short)StatusCode.ACTION_NOT_FOUND;
                                response.Data   = new object[] { $"request {e.Url} not found!" };
                                OnResponse(e, response);
                            }
                            else
                            {
                                NotFound.Invoke(this, new Events.EventPacketArgs(this, e));
                            }
                        }
                    }
                }
            }
            catch (Exception e_)
            {
                if (EnableLog(LogType.Error))
                {
                    Log(LogType.Error, $"[{e.ID}]{e.Session.RemoteEndPoint} process {e.Url} error {e_.Message}@{e_.StackTrace}!");
                }
            }
        }
Пример #3
0
        private void OnRequestProcess(RPCPacket e)
        {
            RPCPacket response = e;

            try
            {
                EventNext.EventActionHandler handler = EventCenter.GetActionHandler(e.Url);
                if (handler != null)
                {
                    BindRequestParameter(e, handler);
                    OnEventNext(e);
                }
                else
                {
                    if (e.Url == "/__System/Ping")
                    {
                        response = new RPCPacket();
                        if (EnableLog(LogType.Debug))
                        {
                            Log(LogType.Debug, $"[{e.ID}]{e.Sesion.RemoteEndPoint} request {e.Url}");
                        }
                        response.Status = (short)StatusCode.SUCCESS;
                        OnResponse(e, response);
                    }
                    else
                    {
                        var awaitItem = AwaiterFactory.GetItem(response.ID);
                        if (awaitItem != null)
                        {
                            response.ResultType = awaitItem.ResultType;
                            try
                            {
                                if (response.ResultType != null)
                                {
                                    response.LoadParameters(response.ResultType);
                                }
                            }
                            catch (Exception e_)
                            {
                                response.Status = (short)StatusCode.INNER_ERROR;
                                response.Data   = new object[] { $"{e_.Message}@{e_.StackTrace}" };
                            }
                            AwaiterFactory.Completed(awaitItem, response);
                        }
                        else
                        {
                            if (Receive == null)
                            {
                                if (EnableLog(LogType.Debug))
                                {
                                    Log(LogType.Debug, $"[{e.ID}]{e.Sesion.RemoteEndPoint} request {e.Url} not found!");
                                }
                                response        = new RPCPacket();
                                response.Status = (short)StatusCode.ACTION_NOT_FOUND;
                                response.Data   = new object[] { $"request {e.Url} not found!" };
                                OnResponse(e, response);
                            }
                            else
                            {
                                Receive.Invoke(this, new Events.EventActionNotFoundArgs(this, e));
                            }
                        }
                    }
                }
            }
            catch (Exception e_)
            {
                if (EnableLog(LogType.Error))
                {
                    Log(LogType.Debug, $"[{e.ID}]{e.Sesion.RemoteEndPoint} request {e.Url} error {e_.Message}@{e_.StackTrace}!");
                }
            }
        }