コード例 #1
0
    public IEnumerator Processor_PushmsgService_Delay_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) => {});
        yield return(new WaitForSeconds(6.0f));

        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(2, count);
    }
コード例 #2
0
    public IEnumerator Processor_AddPushService_Service()
    {
        int count = 0;

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

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

        Assert.AreEqual(1, count);
    }
コード例 #3
0
        private void SendEvents(List <object> items)
        {
            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("events", items);

            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("adds");
            data.SetPayload(bytes);

            RUMClient self = this;

            this.SendQuest(data, (cbd) => {
                self._rumEvent.RemoveFromCache(items);

                Exception ex = cbd.GetException();

                if (ex != null)
                {
                    self.GetEvent().FireEvent(new EventData("error", ex));
                    self._rumEvent.WriteEvents(items);
                    return;
                }
            }, RUMConfig.SENT_TIMEOUT);
        }
コード例 #4
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);
                }
            });
        }
コード例 #5
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);
        }
コード例 #6
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);
        }