示例#1
0
        private void _hwsClient_DataReceived(object sender, DataReceivedEventArgs e)
        {
            var strMsg = Encoding.UTF8.GetString(GZip.Decompress(e.Data));

            if (strMsg.Contains("state.update") || strMsg.Contains("state.updateall") || strMsg.Contains("pong"))
            {
                return;
            }

            if (strMsg.Contains("status") && strMsg.Contains("success"))
            {
                var updateModel = JSONHelper.ConvertToObject <HotbitUpdateModel>(strMsg);
                if (updateModel.id == SUB_REQ_ID)
                {
                    OnConnectionOpened?.Invoke(this, this.SubItemName);
                }
                else if (updateModel.id == SUB_AUTH_ID)
                {
                    var authModel = this.SubModel as AuthSubscribeModel;
                    authModel.reqList.ForEach(p => _hwsClient.Send(p.ToJson()));
                }
                return;
            }

            //_logger.Info($"recieve@{strMsg}@{Title}");

            if (this.SubscribeType == "ASSET" && strMsg.Contains("result"))
            {
                strMsg = strMsg.Replace("error", "method").Replace("null", "\"asset.update\"").Replace("result", "params");
                strMsg = strMsg.Replace("\"params\":", "\"params\":[").Replace("}}", "}}]");
                strMsg = strMsg.Replace("}, ", "}},{");
            }

            OnRecieveMessage?.Invoke(this, strMsg);
        }