public void ExportDebug(string path)
        {
            var bon = BonUtil.ToBon(this.asset, new BonUtil.Config {
                debug = true
            });

            System.IO.File.WriteAllText(path, bon.ToJsonString(true));
        }
        public void ExportBon(string path)
        {
            var bon = BonUtil.ToBon(this, new BonUtil.Config {
                omitempty = true, typeInfo = false
            });

            System.IO.File.WriteAllBytes(path, bon.ToBonBytes());
        }
        public void ExportJson(string path)
        {
            var bon = BonUtil.ToBon(this, new BonUtil.Config {
                omitempty = true, typeInfo = false
            });

            System.IO.File.WriteAllText(path, bon.ToJsonString(true));
        }
Пример #4
0
        int SyncPrivateMsgs(BonDocument chd)
        {
            lastId = chd["lastId"].AsLong;
            List <IMMsg> newMsgs = new List <IMMsg>();

            BonUtil.ToObj(chd["msgs"], newMsgs);
            for (int i = newMsgs.Count; --i >= 0;)
            {
                newMsgs[i].im     = im;
                newMsgs[i].recTgt = IMChatTarget.用户;
            }
            im.AddNewMsgs(newMsgs);
            return(newMsgs.Count);
        }
Пример #5
0
        int SyncChannelMsgs(BonDocument chd, IMChannel ch)
        {
            IMChatSession session = im.GetSession(ch);

            session.lastId = chd["lastId"].AsLong;
            newMsgs.Clear();
            BonUtil.ToObj(chd["msgs"], newMsgs);
            for (int i = newMsgs.Count; --i >= 0;)
            {
                newMsgs[i].im     = im;
                newMsgs[i].recTgt = IMChatTarget.频道;
            }
            im.AddNewMsgs(newMsgs);
            return(newMsgs.Count);
        }
Пример #6
0
 public void FromBon(BonValue jv, HashSet <string> fields)
 {
     BonUtil.ToObj(jv, this.GetType(), this, fields);//, this as IBonMonitor);
 }
Пример #7
0
 public BonDocument ToBon(HashSet <string> fields)
 {
     return(BonUtil.ToBon(this, fields).AsBonDocument);
 }
Пример #8
0
    IEnumerator _Send()
    {
        IMHttpContext ctx     = sendQueue.Dequeue();
        BonDocument   request = new BonDocument();

        ctx.request   = request;
        request["ul"] = ctx.ul.GetType().Name;
        BonDocument p = BonUtil.ToBon(ctx.ul, null, null) as BonDocument;

        request["p"]   = p;
        ctx.sno        = (++snoSeed);
        request["sno"] = ctx.sno;
        IMMe me = IM.Instance.me;

        if (me != null)
        {
            p["uid"] = me.id;
            if (me.auth != null)
            {
                request["auth"] = me.auth;
            }
        }
        byte[] postdata = ctx.request.ToBonBytes();
        postdata = EncryptDecrypt.Encrypt(postdata);

        while (ctx.retry >= 0)
        {
#if HTTP_DEBUG_LOG
            Debug.Log("发送数据{" + postdata.Length + "}: " + ctx.request.ToJsonString());
            Debug.Log("到: " + ctx.url);
#endif
            ctx.sendTime = TimeUtil.UnixTimestampNow();
            float  lastProgress = 0;
            double timeout      = TimeUtil.UnixTimestampNow() + 10;
            bool   isTimeout    = false;
            using (WWW www = new WWW(ctx.url, postdata, header)) {
                while (!www.isDone)
                {
                    double now = TimeUtil.UnixTimestampNow();
                    if (now >= timeout)
                    {
                        isTimeout = true;
                        break;
                    }
                    if (lastProgress != www.progress)
                    {
                        lastProgress = www.progress;
                        timeout      = now + 20;
                    }
                    yield return(null);
                }
                if (destroyed)
                {
                    busy = false;
                    yield break;
                }
                if (isTimeout)
                {
                    ctx.error = "UI.网络错误";
                    ctx.code  = -1;
                    Debug.LogError("访问超时");
                }
                else if (www.error != null)
                {
                    ctx.error = "UI.网络错误";
                    ctx.code  = -1;
                    Debug.LogError("Err:" + www.error);
                }
                else
                {
                    byte[] data = www.bytes;
                    try {
                        if (data[0] == 31)
                        {
                            try {
                                data = GZip.Decompress(data);
                            } catch (Exception) { }
                        }
                        ctx.response = BonDocument.FromBonBytes(data);
#if HTTP_DEBUG_LOG
                        Debug.Log("收到数据: " + ctx.response);
#endif
                        ctx.code  = ctx.response.GetInt("code");
                        ctx.error = null;
                        ctx.retry = 0;
                    } catch (Exception e) {
                        ctx.error = "数据解析错误";
                        Debug.LogError("下行数据解析错误 " + e.ToString());
                    }
                }
            }
            ctx.retry--;
        }
        busy = false;
        if (ctx.callback != null)
        {
            ctx.callback(ctx);
        }
        if (OnResult != null)
        {
            OnResult(ctx);
        }
    }