Ejemplo n.º 1
0
        public void AddQuest(FPClient client, FPData data, IDictionary <string, object> payload, CallbackDelegate callback, int timeout)
        {
            if (data == null)
            {
                if (callback != null)
                {
                    callback(new CallbackData(new Exception("data is null!")));
                }
                return;
            }

            this.AddService(() => {
                if (client != null)
                {
                    byte[] bytes = new byte[0];

                    try {
                        using (MemoryStream outputStream = new MemoryStream()) {
                            MsgPack.Serialize(payload, outputStream);
                            outputStream.Seek(0, SeekOrigin.Begin);
                            bytes = outputStream.ToArray();
                        }
                    } catch (Exception ex) {
                        ErrorRecorderHolder.recordError(ex);

                        if (callback != null)
                        {
                            callback(new CallbackData(ex));
                        }

                        return;
                    }

                    data.SetPayload(bytes);
                    client.SendQuest(data, callback, timeout);
                }
            });
        }
Ejemplo n.º 2
0
    public IEnumerator Processor_PushmsgService_PushmsgService()
    {
        int count = 0;

        this._processor.AddPushService("pushmsg", (dict) => {
            count++;
        });
        byte[] bytes  = { 0x80 };
        FPData data_1 = new FPData();

        data_1.SetMethod("pushmsg");
        data_1.SetPayload(this._bytes);
        this._processor.Service(data_1, (payload, exception) => {});
        FPData data_2 = new FPData();

        data_2.SetMethod("pushmsg");
        data_2.SetPayload(this._bytes);
        this._processor.Service(data_2, (payload, exception) => {});
        this._processor.Destroy();
        yield return(new WaitForSeconds(1.0f));

        Assert.AreEqual(1, count);
    }
Ejemplo n.º 3
0
        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);
                }
            }
        }
Ejemplo n.º 4
0
        private void LoadConfig()
        {
            if (this._debug)
            {
                Debug.Log("[RUM] load config...");
            }

            long salt = this.GenSalt();

            IDictionary <string, object> payload = new Dictionary <string, object>();

            payload.Add("pid", this._pid);
            payload.Add("sign", this.GenSign(salt));
            payload.Add("salt", salt);
            payload.Add("uid", this._uid);
            payload.Add("rid", this._rumEvent.GetRumId());

            payload.Add("lang", RUMPlatform.Instance.GetLang());
            payload.Add("manu", RUMPlatform.Instance.GetManu());
            payload.Add("model", RUMPlatform.Instance.GetModel());
            payload.Add("os", RUMPlatform.Instance.GetOS());
            payload.Add("osv", RUMPlatform.Instance.GetOSV());
            payload.Add("nw", RUMPlatform.Instance.GetNetwork());
            payload.Add("carrier", RUMPlatform.Instance.GetCarrier());
            payload.Add("from", RUMPlatform.Instance.GetFrom());
            payload.Add("appv", this._appv);

            MemoryStream outputStream = new MemoryStream();

            MsgPack.Serialize(payload, outputStream);
            outputStream.Position = 0;

            byte[] bytes = outputStream.ToArray();

            FPData data = new FPData();

            data.SetFlag(0x1);
            data.SetMtype(0x1);
            data.SetMethod("getconfig");
            data.SetPayload(bytes);

            RUMClient self = this;

            this.SendQuest(data, (cbd) => {
                Exception ex = cbd.GetException();

                if (ex != null)
                {
                    self._configVersion = 0;
                    self.GetEvent().FireEvent(new EventData("error", ex));
                    return;
                }

                IDictionary <string, object> dict = (IDictionary <string, object>)cbd.GetPayload();

                if (self._debug)
                {
                    Debug.Log("[RUM] load config: " + Json.SerializeToString(dict));
                }

                self._rumEvent.UpdateConfig((IDictionary <string, object>)dict["events"]);
            }, RUMConfig.SENT_TIMEOUT);
        }
Ejemplo n.º 5
0
        private void SendPing(long timestamp)
        {
            if (this._lastPingTime == 0)
            {
                return;
            }

            if (timestamp - this._lastPingTime < RUMConfig.PING_INTERVAL)
            {
                return;
            }

            this._lastPingTime += RUMConfig.PING_INTERVAL;

            if (this._debug)
            {
                Debug.Log("[RUM] ping...");
            }

            long lastEid   = this._pingEid;
            int  lastCount = this._writeCount;

            this._writeCount = 0;
            this._pingEid    = MidGenerator.Gen();

            long salt = this.GenSalt();

            IDictionary <string, object> payload = new Dictionary <string, object>();

            payload.Add("pid", this._pid);
            payload.Add("sign", this.GenSign(salt));
            payload.Add("salt", salt);
            payload.Add("uid", this._uid);
            payload.Add("rid", this._rumEvent.GetRumId());
            payload.Add("sid", this._session);
            payload.Add("cv", this._configVersion);
            payload.Add("pt", this._pingLatency);
            payload.Add("ss", this._rumEvent.GetStorageSize());
            payload.Add("wc", lastCount);
            payload.Add("feid", lastEid);
            payload.Add("teid", this._pingEid);

            MemoryStream outputStream = new MemoryStream();

            MsgPack.Serialize(payload, outputStream);
            outputStream.Position = 0;

            byte[] bytes = outputStream.ToArray();

            FPData data = new FPData();

            data.SetFlag(0x1);
            data.SetMtype(0x1);
            data.SetMethod("ping");
            data.SetPayload(bytes);

            long      pingTime = timestamp;
            RUMClient self     = this;

            this.SendQuest(data, (cbd) => {
                self._pingLatency = Convert.ToInt32(ThreadPool.Instance.GetMilliTimestamp() - pingTime);

                Exception ex = cbd.GetException();

                if (ex != null)
                {
                    self.GetEvent().FireEvent(new EventData("error", ex));
                    return;
                }

                IDictionary <string, object> dict = (IDictionary <string, object>)cbd.GetPayload();

                if (self._debug)
                {
                    Debug.Log("[RUM] ping: " + Json.SerializeToString(dict));
                }

                self._rumEvent.SetTimestamp(Convert.ToInt64(dict["ts"]));
                self._rumEvent.SetSizeLimit(Convert.ToInt32(dict["bw"]));

                int cv = Convert.ToInt32(dict["cv"]);

                if (self._configVersion != cv || (cv == 0 && !self._rumEvent.HasConfig()))
                {
                    self._configVersion = cv;
                    this.LoadConfig();
                }
            }, RUMConfig.PING_INTERVAL);
        }
Ejemplo n.º 6
0
        public static List <T> GetList <T>(string prefix) where T : new()
        {
            List <T> list           = new List <T>();
            Type     typeFromHandle = typeof(T);
            int      num            = 0;
            bool     flag           = true;

            while (flag)
            {
                T              val        = new T();
                bool           flag2      = false;
                PropertyInfo[] properties = typeFromHandle.GetProperties();
                foreach (PropertyInfo propertyInfo in properties)
                {
                    string text = prefix + propertyInfo.Name + "[" + num.ToString() + "]";
                    if (propertyInfo.PropertyType == typeof(FPData))
                    {
                        FPData fPData = GetFPData(text, propertyInfo.GetValue(val, null) as FPData);
                        if (fPData.Count > 0)
                        {
                            propertyInfo.SetValue(val, fPData, null);
                            flag2 = true;
                        }
                    }
                    else if (propertyInfo.PropertyType == typeof(List <FPData>))
                    {
                        List <FPData> fPList = GetFPList(text);
                        if (fPList.Count > 0)
                        {
                            propertyInfo.SetValue(val, fPList, null);
                            flag2 = true;
                        }
                    }
                    else if (HttpContext.Current.Request.QueryString[text] != null || HttpContext.Current.Request.Form[text] != null)
                    {
                        flag2 = true;
                        if (propertyInfo.PropertyType == typeof(string))
                        {
                            propertyInfo.SetValue(val, GetString(text), null);
                        }
                        else if (propertyInfo.PropertyType == typeof(int))
                        {
                            propertyInfo.SetValue(val, GetInt(text), null);
                        }
                        else if (propertyInfo.PropertyType == typeof(short))
                        {
                            propertyInfo.SetValue(val, short.Parse(GetInt(text).ToString()), null);
                        }
                        else if (propertyInfo.PropertyType == typeof(DateTime))
                        {
                            propertyInfo.SetValue(val, GetDateTime(text), null);
                        }
                        else if (propertyInfo.PropertyType == typeof(decimal))
                        {
                            propertyInfo.SetValue(val, GetDecimal(text), null);
                        }
                        else if (propertyInfo.PropertyType == typeof(float))
                        {
                            propertyInfo.SetValue(val, GetFloat(text), null);
                        }
                        else if (propertyInfo.PropertyType == typeof(double))
                        {
                            propertyInfo.SetValue(val, GetDouble(text), null);
                        }
                        else if (propertyInfo.PropertyType == typeof(DateTime?))
                        {
                            propertyInfo.SetValue(val, GetDateTime2(text), null);
                        }
                    }
                }
                if (!flag2)
                {
                    flag = false;
                    break;
                }
                list.Add(val);
                num++;
            }
            return(list);
        }
Ejemplo n.º 7
0
 public static T GetModel <T>(T model, string prefix)
 {
     PropertyInfo[] properties = model.GetType().GetProperties();
     foreach (PropertyInfo propertyInfo in properties)
     {
         if (propertyInfo == null || !propertyInfo.CanWrite)
         {
             continue;
         }
         string text = prefix + propertyInfo.Name;
         if (text.ToLower() == prefix + "pageurl")
         {
             propertyInfo.SetValue(model, GetRawUrl(), null);
         }
         else if (propertyInfo.PropertyType == typeof(FPData))
         {
             FPData   fPData           = propertyInfo.GetValue(model, null) as FPData;
             object[] customAttributes = propertyInfo.GetCustomAttributes(true);
             foreach (object obj in customAttributes)
             {
                 if (!(obj is CheckBox))
                 {
                     continue;
                 }
                 CheckBox checkBox = obj as CheckBox;
                 if (!checkBox.IsCheckBox)
                 {
                     continue;
                 }
                 if (checkBox.CheckName != "")
                 {
                     string[] array = FPArray.SplitString(checkBox.CheckName);
                     foreach (string key in array)
                     {
                         fPData[key] = "";
                     }
                 }
                 else
                 {
                     string[] array = fPData.Keys;
                     foreach (string key2 in array)
                     {
                         fPData[key2] = "";
                     }
                 }
             }
             fPData = GetFPData(text, fPData);
             propertyInfo.SetValue(model, fPData, null);
         }
         else if (propertyInfo.PropertyType == typeof(List <FPData>))
         {
             List <FPData> fPList = GetFPList(text);
             propertyInfo.SetValue(model, fPList, null);
         }
         else if (HttpContext.Current.Request.QueryString[text] == null && HttpContext.Current.Request.Form[text] == null)
         {
             object[] customAttributes = propertyInfo.GetCustomAttributes(true);
             foreach (object obj2 in customAttributes)
             {
                 if (obj2 is CheckBox && (obj2 as CheckBox).IsCheckBox)
                 {
                     if (propertyInfo.PropertyType == typeof(int))
                     {
                         propertyInfo.SetValue(model, 0, null);
                     }
                     else
                     {
                         propertyInfo.SetValue(model, "", null);
                     }
                 }
             }
         }
         else if (propertyInfo.PropertyType == typeof(string))
         {
             propertyInfo.SetValue(model, GetString(text), null);
         }
         else if (propertyInfo.PropertyType == typeof(int))
         {
             propertyInfo.SetValue(model, GetInt(text), null);
         }
         else if (propertyInfo.PropertyType == typeof(DateTime))
         {
             propertyInfo.SetValue(model, GetDateTime(text), null);
         }
         else if (propertyInfo.PropertyType == typeof(decimal))
         {
             propertyInfo.SetValue(model, GetDecimal(text), null);
         }
         else if (propertyInfo.PropertyType == typeof(float))
         {
             propertyInfo.SetValue(model, GetFloat(text), null);
         }
         else if (propertyInfo.PropertyType == typeof(double))
         {
             propertyInfo.SetValue(model, GetDouble(text), null);
         }
         else if (propertyInfo.PropertyType == typeof(DateTime?))
         {
             propertyInfo.SetValue(model, GetDateTime2(text), null);
         }
     }
     return(model);
 }
Ejemplo n.º 8
0
        public static T GetModel <T>(string prefix) where T : new()
        {
            T val = new T();

            PropertyInfo[] properties = typeof(T).GetProperties();
            foreach (PropertyInfo propertyInfo in properties)
            {
                if (propertyInfo == null || !propertyInfo.CanWrite)
                {
                    continue;
                }
                string text = prefix + propertyInfo.Name;
                if (text.ToLower() == prefix + "pageurl")
                {
                    propertyInfo.SetValue(val, GetRawUrl(), null);
                }
                else if (propertyInfo.PropertyType == typeof(FPData))
                {
                    FPData fPData = GetFPData(text, propertyInfo.GetValue(val, null) as FPData);
                    propertyInfo.SetValue(val, fPData, null);
                }
                else if (propertyInfo.PropertyType == typeof(List <FPData>))
                {
                    List <FPData> fPList = GetFPList(text);
                    propertyInfo.SetValue(val, fPList, null);
                }
                else if (HttpContext.Current.Request.QueryString[text] != null || HttpContext.Current.Request.Form[text] != null)
                {
                    if (propertyInfo.PropertyType == typeof(string))
                    {
                        propertyInfo.SetValue(val, GetString(text), null);
                    }
                    else if (propertyInfo.PropertyType == typeof(int))
                    {
                        propertyInfo.SetValue(val, GetInt(text), null);
                    }
                    else if (propertyInfo.PropertyType == typeof(short))
                    {
                        propertyInfo.SetValue(val, short.Parse(GetInt(text).ToString()), null);
                    }
                    else if (propertyInfo.PropertyType == typeof(DateTime))
                    {
                        propertyInfo.SetValue(val, GetDateTime(text), null);
                    }
                    else if (propertyInfo.PropertyType == typeof(decimal))
                    {
                        propertyInfo.SetValue(val, GetDecimal(text), null);
                    }
                    else if (propertyInfo.PropertyType == typeof(float))
                    {
                        propertyInfo.SetValue(val, GetFloat(text), null);
                    }
                    else if (propertyInfo.PropertyType == typeof(double))
                    {
                        propertyInfo.SetValue(val, GetDouble(text), null);
                    }
                    else if (propertyInfo.PropertyType == typeof(DateTime?))
                    {
                        propertyInfo.SetValue(val, GetDateTime2(text), null);
                    }
                }
            }
            return(val);
        }
Ejemplo n.º 9
0
        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);
                }
            }
        }