コード例 #1
0
        public void ExportDebug(string path)
        {
            var bon = BonUtil.ToBon(this.asset, new BonUtil.Config {
                debug = true
            });

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

            System.IO.File.WriteAllBytes(path, bon.ToBonBytes());
        }
コード例 #3
0
        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
 public BonDocument ToBon(HashSet <string> fields)
 {
     return(BonUtil.ToBon(this, fields).AsBonDocument);
 }
コード例 #5
0
ファイル: IMHttpClient.cs プロジェクト: atpx0001/XGames
    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);
        }
    }