Exemplo n.º 1
0
        private void CheckFPCallback(CallbackData cbd)
        {
            bool   isAnswerException = false;
            FPData data = cbd.GetData();
            IDictionary <string, object> payload = null;

            if (data != null)
            {
                if (data.GetFlag() == 0)
                {
                    payload = Json.Deserialize <IDictionary <string, object> >(data.JsonPayload());
                }

                if (data.GetFlag() == 1)
                {
                    MemoryStream inputStream = new MemoryStream(data.MsgpackPayload());
                    payload = MsgPack.Deserialize <IDictionary <string, object> >(inputStream);
                }

                if (this._baseClient.GetPackage().IsAnswer(data))
                {
                    isAnswerException = data.GetSS() != 0;
                }
            }

            cbd.CheckException(isAnswerException, payload);
        }
        public void Service(FPData data, AnswerDelegate answer)
        {
            if (data == null)
            {
                return;
            }

            bool callCb = true;

            if (RTMConfig.KICKOUT == data.GetMethod())
            {
                callCb = false;
            }

            if (RTMConfig.SERVER_PUSH.kickOutRoom == data.GetMethod())
            {
                callCb = false;
            }

            IDictionary <string, object> payload = null;

            if (data.GetFlag() == 0 && data.JsonPayload() != null)
            {
                try {
                    if (callCb && answer != null)
                    {
                        answer(JSON_PAYLOAD, false);
                    }

                    payload = Json.Deserialize <IDictionary <string, object> >(data.JsonPayload());
                } catch (Exception ex) {
                    ErrorRecorderHolder.recordError(ex);
                }
            }

            if (data.GetFlag() == 1 && data.MsgpackPayload() != null)
            {
                try {
                    if (callCb && answer != null)
                    {
                        answer(MSGPACK_PAYLOAD, false);
                    }

                    using (MemoryStream inputStream = new MemoryStream(data.MsgpackPayload())) {
                        payload = MsgPackFix.Deserialize <IDictionary <string, object> >(inputStream, RTMRegistration.RTMEncoding);
                    }
                } catch (Exception ex) {
                    ErrorRecorderHolder.recordError(ex);
                }
            }

            if (payload != null)
            {
                try {
                    MethodInfo method = this._type.GetMethod(data.GetMethod());

                    if (method != null)
                    {
                        object[] paras = new object[] { payload };
                        method.Invoke(this, paras);
                    }
                } catch (Exception ex) {
                    ErrorRecorderHolder.recordError(ex);
                }
            }
        }
        public void Service(FPData data, AnswerDelegate answer)
        {
            bool callCb = true;

            if (RTMConfig.SERVER_PUSH.kickOut == data.GetMethod())
            {
                callCb = false;
            }

            if (RTMConfig.SERVER_PUSH.kickOutRoom == data.GetMethod())
            {
                callCb = false;
            }

            IDictionary <string, object> payload = null;

            if (data.GetFlag() == 0)
            {
                if (callCb)
                {
                    answer(Json.SerializeToString(new Dictionary <string, object>()), false);
                }

                try {
                    payload = Json.Deserialize <IDictionary <string, object> >(data.JsonPayload());
                }catch (Exception ex) {
                    this._event.FireEvent(new EventData("error", ex));
                }
            }

            if (data.GetFlag() == 1)
            {
                if (callCb)
                {
                    using (MemoryStream msgpackStream = new MemoryStream()) {
                        MsgPack.Serialize(new Dictionary <string, object>(), msgpackStream);
                        msgpackStream.Seek(0, SeekOrigin.Begin);

                        answer(msgpackStream.ToArray(), false);
                    }
                }

                try {
                    using (MemoryStream inputStream = new MemoryStream(data.MsgpackPayload())) {
                        payload = MsgPack.Deserialize <IDictionary <string, object> >(inputStream);
                    }
                } catch (Exception ex) {
                    this._event.FireEvent(new EventData("error", ex));
                }
            }

            if (payload != null)
            {
                MethodInfo method = this._type.GetMethod(data.GetMethod());

                if (method != null)
                {
                    object[] paras = new object[] { payload };
                    method.Invoke(this, paras);
                }
            }
        }