Пример #1
0
 public virtual void ResponseError(BaseGameResponse response, ActionGetter actionGetter, int errorCode, string errorInfo)
 {
     MessageHead head = new MessageHead(actionGetter.GetMsgId(), actionGetter.GetActionId(), errorCode, errorInfo);
     MessageStructure sb = new MessageStructure();
     sb.WriteBuffer(head);
     response.BinaryWrite(sb.PopBuffer());
 }
Пример #2
0
 /// <summary>
 /// 读取消息头,如果有Gzip压缩时自动解压字节流
 /// </summary>
 /// <returns></returns>
 /// <exception cref="OverflowException"></exception>
 public MessageHead ReadHeadGzip()
 {
     try
     {
         MessageHead head = new MessageHead();
         head.HasGzip      = true;
         head.PacketLength = Length;
         if (CheckGzipBuffer())
         {
             byte[] gzipData = PopBuffer();
             head.GzipLength = gzipData.Length;
             //gzip格式500+gzip( 1000+ XXXXXX)
             byte[] deZipData = GzipUtils.DeCompress(gzipData, 0, gzipData.Length);
             WriteByte(deZipData);
             Reset();
         }
         head.TotalLength = ReadInt();
         head.ErrorCode   = ReadInt();
         head.MsgId       = ReadInt();
         head.ErrorInfo   = ReadString();
         head.Action      = ReadInt();
         head.St          = ReadString();
         return(head);
     }
     catch (Exception ex)
     {
         string error = string.Format("read to {0}/{1}pos error,\r\nbytes:{2}", Offset, Length, ToHexString());
         throw new OverflowException(error, ex);
     }
 }
Пример #3
0
 protected override void SuccessCallback(MessageStructure writer, MessageHead head)
 {
     int type = writer.ReadInt();
     if (type == 1)
     {
         int recordCount = writer.ReadInt();
         JsonObject jsonContainer = new JsonObject();
         List<JsonObject> jsonList = new List<JsonObject>();
         for (int i = 0; i < recordCount; i++)
         {
             writer.RecordStart();
             var item = new JsonObject();
             item.Add("NoticeID", writer.ReadString());
             item.Add("Title",  writer.ReadString());
             item.Add("Content", writer.ReadString());
             item.Add("IsBroadcast", writer.ReadInt());
             item.Add("IsTop", writer.ReadInt());
             item.Add("Creater", writer.ReadString());
             item.Add("CreateDate", writer.ReadString());
             item.Add("ExpiryDate", writer.ReadString());
             jsonList.Add(item);
             writer.RecordEnd();
         }
         jsonContainer.Add("total", recordCount);
         jsonContainer.Add("rows", jsonList.ToArray());
         WriteTableJson(jsonContainer);
     }
 }
Пример #4
0
        /// <summary>
        /// 将缓冲队列写入缓冲区,大于10k开始压缩
        /// </summary>
        /// <param name="head"></param>
        public void WriteBuffer(MessageHead head)
        {
            int stackSize = GetHeadByteSize(head);

            stackSize       += GetStackByteSize();//包括了头部长度大小
            head.TotalLength = stackSize;
            bool hasGzipHead = false;

            if (head.HasGzip && (!EnableGzip || (EnableGzip && stackSize <= EnableGzipMinByte)))
            {
                hasGzipHead     = true;
                head.GzipLength = stackSize;
                WriteByte(head.GzipLength);
            }
            //输出总字节长度,公式: stackSize = len(头) + len(内容) + 4(int)
            WriteByte(stackSize);
            WriteHeadBufer(head);
            WriteStackToBuffer();
            //判断是否有启用Gzip
            if (head.HasGzip && EnableGzip && !hasGzipHead && stackSize > EnableGzipMinByte)
            {
                byte[] orgData = PopBuffer();
                head.GzipLength = WriteGzipCompressBuffer(orgData);
            }
            head.PacketLength = Length;
            Reset();
        }
Пример #5
0
 protected override bool DecodePacket(MessageStructure reader, MessageHead head)
 {
     responsePack = ProtoBufUtils.Deserialize<Response1010Pack>(netReader.Buffer);
     string responseDataInfo = "";
     responseDataInfo = "request :" + Game.Utils.JsonHelper.prettyJson<Request1010Pack>(req) + "\n";
     responseDataInfo += "response:" + Game.Utils.JsonHelper.prettyJson<Response1010Pack>(responsePack) + "\n";
     DecodePacketInfo = responseDataInfo;
     int childStepId = getChild(1010);
     System.Console.WriteLine("childStepID:" + childStepId);
     if (childStepId > 0)
     {
         System.Collections.Generic.Dictionary<string, string> dic = new System.Collections.Generic.Dictionary<string, string>();
         /*
           req.UserID = GetParamsData("UserID", req.UserID);
         req.identify = GetParamsData("identify", req.identify);
         req.version = GetParamsData("version", req.version);
         req.the3rdUserID = GetParamsData("the3rdUserID", req.the3rdUserID);
         req.happyPoint = GetParamsData("happyPoint", req.happyPoint);
         req.Rate = GetParamsData("Rate", req.Rate);
         req.index = GetParamsData("index", req.index);
         req.strThe3rdUserID = GetParamsData("strThe3rdUserID", req.strThe3rdUserID);
         req.typeUser = GetParamsData("typeUser", req.typeUser);
          */
         dic.Add("UserID", req.UserID.ToString());
         dic.Add("index", responsePack.index.ToString());
         dic.Add("the3rdUserID", req.the3rdUserID.ToString());
         dic.Add("strThe3rdUserID", req.strThe3rdUserID);
        SetChildStep(childStepId.ToString(), _setting,dic);
     }
     return true;
 }
Пример #6
0
        public override void OnReceiveTimeout(string clientAddress, byte[] receiveData)
        {
            try
            {
                BufferReader reader = new BufferReader(receiveData);
                string paramString = reader.ReadPacketString();
                paramString = HttpUtility.UrlDecode(paramString, Encoding.UTF8);
                int index = paramString.IndexOf("?d=");
                if (index != -1)
                {
                    index += 3;
                    paramString = paramString.Substring(index, paramString.Length - index);
                }
                PacketMessage receivePacket = ParsePacketMessage(clientAddress, paramString, ConnectType.Tcp);
                var recHead = receivePacket.Head;

                int errorCode = LanguageHelper.GetLang().ErrorCode;
                string errorMsg = LanguageHelper.GetLang().RequestTimeout;
                MessageHead head = new MessageHead(recHead.MsgId, recHead.ActionId, "st", errorCode, errorMsg);
                head.HasGzip = true;
                MessageStructure ds = new MessageStructure();
                ds.WriteBuffer(head);
                byte[] data = ds.ReadBuffer();
                OnSendCompleted(clientAddress, data);
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Send to client {0} timeout error:{1}", clientAddress, ex);
            }
        }
Пример #7
0
        public static MessageStructure Create(string serverUrl, string requestParams, out MessageHead header, bool isSocket)
        {
            header = null;
            MessageStructure msgReader = null;
            if (isSocket)
            {
                msgReader = DoRequest(serverUrl, requestParams);
            }
            else
            {
                Encoding encode = Encoding.GetEncoding("utf-8");
                string postData = "d=" + GetSign(requestParams);
                byte[] bufferData = encode.GetBytes(postData);

                HttpWebRequest serverRequest = (HttpWebRequest)WebRequest.Create(serverUrl);
                serverRequest.Method = "POST";
                serverRequest.ContentType = "application/x-www-form-urlencoded";
                serverRequest.ContentLength = bufferData.Length;
                Stream requestStream = serverRequest.GetRequestStream();
                requestStream.Write(bufferData, 0, bufferData.Length);
                requestStream.Close();
                //������
                WebResponse serverResponse = serverRequest.GetResponse();
                Stream responseStream = serverResponse.GetResponseStream();
                msgReader = MessageStructure.Create(responseStream, Encoding.UTF8);
            }
            if (msgReader != null)
            {
                header = msgReader.ReadHeadGzip();
            }
            return msgReader;
        }
Пример #8
0
 private void WriteHeadBufer(MessageHead head)
 {
     WriteByte(head.ErrorCode);
     WriteByte(head.MsgId);
     WriteByte(head.ErrorInfo);
     WriteByte(head.Action);
     WriteByte(head.St);
 }
Пример #9
0
 public bool getResult()
 {
     if (Reader.Offset == 0)
     {
         _head = instance.Reader.ReadHeadGzip();
     }
     return !_head.Faild;
 }
Пример #10
0
 public static byte[] CtorErrMsg(int error, string msg, NameValueCollection requestParam)
 {
     int msgId = Convert.ToInt32(requestParam["msgid"]);
     int actionid = Convert.ToInt32(requestParam["actionid"]);
     var ms = new MessageStructure();
     var head = new MessageHead(msgId, actionid, "st", error, msg);
     ms.WriteBuffer(head);
     return ms.PosGzipBuffer();
 }
Пример #11
0
 protected override bool DecodePacket(MessageStructure reader, MessageHead head)
 {
     responsePack = ProtoBufUtils.Deserialize<Response1003Pack>(netReader.Buffer);
     string responseDataInfo = "";
     responseDataInfo = "request :" + Game.Utils.JsonHelper.prettyJson<Request1003Pack>(req) + "\n";
     responseDataInfo += "response:" + Game.Utils.JsonHelper.prettyJson<Response1003Pack>(responsePack) + "\n";
     DecodePacketInfo = responseDataInfo;
     return true;
 }
Пример #12
0
        private int GetHeadByteSize(MessageHead head)
        {
            int length = 0;

            length += GetByteSize(head.ErrorCode);
            length += GetByteSize(head.MsgId);
            length += GetByteSize(head.ErrorInfo);
            length += GetByteSize(head.Action);
            length += GetByteSize(head.St);
            return(length);
        }
Пример #13
0
 protected override bool DecodePacket(MessageStructure reader, MessageHead head)
 {
     _session.Context.SessionId = reader.ReadString();
     _session.Context.UserId = reader.ReadString().ToInt();
     int UserType = reader.ReadInt();
     string LoginTime = reader.ReadString();
     int GuideID = reader.ReadInt();
     if (GuideID == 1005)
     {
         SetChildStep("1005");
     }
     return true;
 }
Пример #14
0
        /// <summary>
        /// 读取消息头
        /// </summary>
        /// <returns></returns>
        public MessageHead ReadHead()
        {
            MessageHead head = new MessageHead();

            head.PacketLength = Length;
            head.TotalLength  = ReadInt();
            head.ErrorCode    = ReadInt();
            head.MsgId        = ReadInt();
            head.ErrorInfo    = ReadString();
            head.Action       = ReadInt();
            head.St           = ReadString();
            return(head);
        }
Пример #15
0
 protected override bool DecodePacket(MessageStructure reader, MessageHead head)
 {
     responsePack = ProtoBufUtils.Deserialize<ResponsePack>(netReader.Buffer);
      string responseDataInfo = "";
      responseDataInfo  = "request :" + Game.Utils.JsonHelper.prettyJson<Request1000Pack>(req) + "\n";
      responseDataInfo += "response:" + Game.Utils.JsonHelper.prettyJson<ResponsePack>(responsePack) + "\n";
      DecodePacketInfo = responseDataInfo;
      int childStepId = getChild(1000);
      if(childStepId>0)
      {
         System.Collections.Generic.Dictionary<string,string> dic = new System.Collections.Generic.Dictionary<string,string>();
         dic.Add("UserID",responsePack.UserID.ToString()) ;
         SetChildStep(childStepId.ToString(),_setting,dic);
      }
      return true;
 }
Пример #16
0
        protected override bool DecodePacket(MessageStructure reader, MessageHead head)
        {
            try
            {
                responsePack = ProtoBufUtils.Deserialize<Action3000Response>(netReader.Buffer);
                string responseDataInfo = "";
                responseDataInfo = "request :" + Game.Utils.JsonHelper.prettyJson<Action3000Request>(req) + "\n";
                responseDataInfo += "response:" + Game.Utils.JsonHelper.prettyJson<Action3000Response>(responsePack) + "\n";
                DecodePacketInfo = responseDataInfo;
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e.Message);
            }

            return true;
        }
Пример #17
0
        public void RequestTimeout(HttpConnection connection)
        {
            var param = connection.Param;
            int msgId = param.Get("MsgId").ToInt();
            int actionId = param.Get("ActionId").ToInt();
            int errorCode = LanguageHelper.GetLang().ErrorCode;
            string errorMsg = LanguageHelper.GetLang().RequestTimeout;
            var head = new MessageHead(msgId, actionId, "st", errorCode, errorMsg);
            head.HasGzip = true;
            var ms = new MessageStructure();
            ms.WriteBuffer(head);
            byte[] data = ms.ReadBuffer();

            string remoteAddress = connection.Context.Request.RemoteEndPoint.Address.ToString();
            string successMsg = string.Format("{0}>>发送超时到{1} {2}字节!",
                                              DateTime.Now.ToString("HH:mm:ss:ms"), remoteAddress, data.Length);
            Console.WriteLine(successMsg);
            OnResponseCompleted(connection, data);
        }
Пример #18
0
        /// <summary>
        /// 读取消息头,如果有Gzip压缩时自动解压字节流
        /// </summary>
        /// <returns></returns>
        public MessageHead ReadHeadGzip()
        {
            MessageHead head = new MessageHead();

            head.HasGzip      = true;
            head.PacketLength = Length;
            //head.GzipLength = ReadInt();
            if (CheckGzipBuffer())
            {
                byte[] gzipData = ReadBuffer();
                //格式500+gzip( 1000+ XXXXXX)
                byte[] deZipData = GzipUtils.DeCompress(gzipData, 0, gzipData.Length);
                WriteByte(deZipData);
            }
            head.TotalLength = ReadInt();
            head.ErrorCode   = ReadInt();
            head.MsgId       = ReadInt();
            head.ErrorInfo   = ReadString();
            head.Action      = ReadInt();
            head.St          = ReadString();
            return(head);
        }
Пример #19
0
 protected override bool DecodePacket(MessageStructure reader, MessageHead head)
 {
     responsePack = ProtoBufUtils.Deserialize<ResponsePack>(netReader.Buffer);
     string responseDataInfo = "";
     responseDataInfo = "request :" + Game.Utils.JsonHelper.prettyJson<Request2000Pack>(req) + "\n";
     responseDataInfo += "response:" + Game.Utils.JsonHelper.prettyJson<ResponsePack>(responsePack) + "\n";
     DecodePacketInfo = responseDataInfo;
     int childStepId = getChild(2000);
     System.Console.WriteLine("childStepID:"+childStepId);
     if (childStepId > 0)
     {
         System.Collections.Generic.Dictionary<string, string> dic = new System.Collections.Generic.Dictionary<string, string>();
         /*
            req.token = GetParamsData("token",req.token);
                   req.typeUser = GetParamsData("typeUser",req.typeUser);
                   req.version = GetParamsData("version", req.version);
                   req.UserID = GetParamsData("UserID", req.UserID);
          */
         SetChildStep(childStepId.ToString(),_setting,dic);
     }
     return true;
 }
Пример #20
0
 /// <summary>
 /// Call remote method
 /// </summary>
 /// <param name="routePath"></param>
 /// <param name="actionGetter"></param>
 /// <param name="response"></param>
 protected virtual void OnCallRemote(string routePath, ActionGetter actionGetter, MessageStructure response)
 {
     try
     {
         string[] mapList = routePath.Split('.');
         string funcName = "";
         string routeName = routePath;
         if (mapList.Length > 1)
         {
             funcName = mapList[mapList.Length - 1];
             routeName = string.Join("/", mapList, 0, mapList.Length - 1);
         }
         string routeFile = "";
         int actionId = actionGetter.GetActionId();
         MessageHead head = new MessageHead(actionId);
         if (!ScriptEngines.SettupInfo.DisablePython)
         {
             routeFile = string.Format("Remote.{0}", routeName);
             dynamic scope = ScriptEngines.ExecutePython(routeFile);
             if (scope != null)
             {
                 var funcHandle = scope.GetVariable<RemoteHandle>(funcName);
                 if (funcHandle != null)
                 {
                     funcHandle(actionGetter, head, response);
                     response.WriteBuffer(head);
                     return;
                 }
             }
         }
         string typeName = string.Format(GameEnvironment.Setting.RemoteTypeName, routeName);
         routeFile = string.Format("Remote.{0}", routeName);
         var args = new object[] { actionGetter, response };
         var instance = (object)ScriptEngines.Execute(routeFile, typeName, args);
         if (instance is RemoteStruct)
         {
             var target = instance as RemoteStruct;
             target.DoRemote();
         }
     }
     catch (Exception ex)
     {
         TraceLog.WriteError("OnCallRemote error:{0}", ex);
     }
 }
Пример #21
0
 private void OnCallRemote(string route, HttpGet httpGet, MessageStructure response)
 {
     try
     {
         string[] mapList = route.Split('.');
         string funcName = "";
         string routeName = "";
         if (mapList.Length > 1)
         {
             funcName = mapList[mapList.Length - 1];
             routeName = string.Join("/", mapList, 0, mapList.Length - 1);
         }
         string routeFile = "";
         string typeName = string.Format("Game.Script.Remote.{0}", routeName);
         int actionId = httpGet.ActionId;
         MessageHead head = new MessageHead(actionId);
         if (!ScriptEngines.DisablePython)
         {
             routeFile = string.Format("{0}/Remote/{1}.py", ScriptEngines.PythonDirName, routeName);
             dynamic scope = ScriptEngines.Execute(routeFile, typeName);
             if (scope != null)
             {
                 var funcHandle = scope.GetVariable<RemoteHandle>(funcName);
                 if (funcHandle != null)
                 {
                     funcHandle(httpGet, head, response);
                     response.WriteBuffer(head);
                     return;
                 }
             }
         }
         routeFile = string.Format("{0}/Remote/{1}.cs", ScriptEngines.CSharpDirName, routeName);
         var instance = (object)ScriptEngines.Execute(routeFile, typeName);
         if (instance != null)
         {
             var result = ObjectAccessor.Create(instance, true)[funcName];
         }
     }
     catch (Exception ex)
     {
         TraceLog.WriteError("{0}", ex);
     }
 }
Пример #22
0
 /// <summary>
 /// 将缓冲队列写入缓冲区,大于10k开始压缩
 /// </summary>
 /// <param name="head"></param>
 public void WriteBuffer(MessageHead head)
 {
     int stackSize = GetHeadByteSize(head);
     stackSize += GetStackByteSize();//包括了头部长度大小
     head.TotalLength = stackSize;
     bool hasGzipHead = false;
     if (head.HasGzip && (!EnableGzip || (EnableGzip && stackSize <= EnableGzipMinByte)))
     {
         hasGzipHead = true;
         head.GzipLength = stackSize;
         WriteByte(head.GzipLength);
     }
     //输出总字节长度,公式: stackSize = len(头) + len(内容) + 4(int)
     WriteByte(stackSize);
     WriteHeadBufer(head);
     WriteStackToBuffer();
     //判断是否有启用Gzip
     if (head.HasGzip && EnableGzip && !hasGzipHead && stackSize > EnableGzipMinByte)
     {
         byte[] orgData = PopBuffer();
         head.GzipLength = WriteGzipCompressBuffer(orgData);
     }
     head.PacketLength = Length;
     Reset();
 }
Пример #23
0
 /// <summary>
 /// 读取消息头,如果有Gzip压缩时自动解压字节流
 /// </summary>
 /// <returns></returns>
 /// <exception cref="OverflowException"></exception>
 public MessageHead ReadHeadGzip()
 {
     try
     {
         MessageHead head = new MessageHead();
         head.HasGzip = true;
         head.PacketLength = Length;
         if (CheckGzipBuffer())
         {
             byte[] gzipData = PopBuffer();
             head.GzipLength = gzipData.Length;
             //gzip格式500+gzip( 1000+ XXXXXX)
             byte[] deZipData = GzipUtils.DeCompress(gzipData, 0, gzipData.Length);
             WriteByte(deZipData);
             Reset();
         }
         head.TotalLength = ReadInt();
         head.ErrorCode = ReadInt();
         head.MsgId = ReadInt();
         head.ErrorInfo = ReadString();
         head.Action = ReadInt();
         head.St = ReadString();
         return head;
     }
     catch (Exception ex)
     {
         string error = string.Format("read to {0}/{1}pos error,\r\nbytes:{2}", Offset, Length, ToHexString());
         throw new OverflowException(error, ex);
     }
 }
Пример #24
0
 /// <summary>
 /// 读取消息头
 /// </summary>
 /// <returns></returns>
 public MessageHead ReadHead()
 {
     MessageHead head = new MessageHead();
     head.PacketLength = Length;
     head.TotalLength = ReadInt();
     head.ErrorCode = ReadInt();
     head.MsgId = ReadInt();
     head.ErrorInfo = ReadString();
     head.Action = ReadInt();
     head.St = ReadString();
     return head;
 }
Пример #25
0
 private int GetHeadByteSize(MessageHead head)
 {
     int length = 0;
     length += GetByteSize(head.ErrorCode);
     length += GetByteSize(head.MsgId);
     length += GetByteSize(head.ErrorInfo);
     length += GetByteSize(head.Action);
     length += GetByteSize(head.St);
     return length;
 }
Пример #26
0
 private void WriteHeadBufer(MessageHead head)
 {
     WriteByte(head.ErrorCode);
     WriteByte(head.MsgId);
     WriteByte(head.ErrorInfo);
     WriteByte(head.Action);
     WriteByte(head.St);
 }
Пример #27
0
 private void DoWriteError(MessageStructure ms, MessageHead head)
 {
     head.ErrorCode = (int)MessageError.SystemError;
     head.ClientVersion = 1;
     string msg = string.Format("Request action:{0} wcfserver error:{1}-{2},MsgId:{3}",
                                head.Action, head.ErrorCode, head.ErrorInfo, head.MsgId);
     TraceLog.WriteError(msg);
     #if DEBUG
     Console.WriteLine(msg);
     #endif
     ms.WriteBuffer(head);
 }
Пример #28
0
 private static string PostGameServer(int contractId, int slnId, string serverUrl, string requestParams, bool isSocket, out string sid, out string uid)
 {
     sid = "";
     uid = "";
     StringBuilder respContent = new StringBuilder();
     MessageHead msg = new MessageHead();
     MessageStructure msgReader = NetHelper.Create(serverUrl, requestParams, out msg, isSocket);
     if (msgReader != null)
     {
         ProcessResult(contractId, slnId, respContent, msg, msgReader, out sid, out uid);
     }
     return respContent.ToString();
 }
Пример #29
0
 //protected override void DoListen()
 //{
 //    this.ServiceProxy.Listen(9001);
 //}
 protected override void OnCallRemote(string route, HttpGet httpGet, MessageHead head, MessageStructure structure)
 {
 }
Пример #30
0
        protected void btnTest_Click(object sender, EventArgs e)
        {
            int contractID = int.Parse(ddlContract.Text);
            MessageHead msg = new MessageHead();

            var paramList = DbDataLoader.GetParamInfo(SlnID, contractID);
            string requestParams = GetRequestParams(paramList, contractID, txtVersion.Text);
            string serverUrl = txtServerUrl.Text;
            string[] keyNames = txtKeyName.Text.Split(new char[] { ',' });
            var msgReader = NetHelper.Create(serverUrl, requestParams, out msg, false);
            if (msgReader != null)
            {
                try
                {
                    if (msg.ErrorCode != 0)
                    {
                        txtResponse.Text = msg.ErrorInfo;
                    }
                    else
                    {
                        txtResponse.Text = BuildLuaFile(paramList, msgReader, keyNames);
                    }
                }
                catch (Exception ex)
                {
                    txtResponse.Text = ex.ToString();
                }
            }
        }
Пример #31
0
        private static void ProcessResult(List<ParamInfoModel> paramList, int contractId, StringBuilder respContent, MessageHead msg, MessageStructure msgReader, out string sid, out string uid, out string st)
        {
            sid = "";
            uid = "";
            st = msg.St;
            ResponseHead(contractId, respContent, msg.ErrorCode, msg.ErrorInfo, msg.St);

            //AccountServer Error
            if (msg.ErrorCode < ErrorCode && msg.ErrorCode != 105 && msg.ErrorCode != 106)
            {
                //消息体
                respContent.AppendFormat("<h3>{0}-{1}</h3>", contractId, "返回结果");
                respContent.Append("<table style=\"width:99%; border-color:#f0f0f0\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">");
                respContent.Append("<tr><td style=\"width:15%;\"><strong>参数</strong></td><td style=\"width:10%;\"><strong>类型</strong></td>");
                respContent.Append("<td style=\"width:75%;\"><strong>参数值</strong></td></tr>");
                int loopDepth = 0;//循环深度
                List<ParamInfoModel> recordQueue = new List<ParamInfoModel>();
                #region 循环体
                foreach (var record in paramList)
                {
                    if (record.FieldType == FieldType.Void)
                    {
                        continue;
                    }
                    string fieldName = record.Field;
                    FieldType fieldType = record.FieldType;
                    string fieldValue = "";
                    try
                    {
                        if (loopDepth > 0 && fieldType == FieldType.End)
                        {
                            loopDepth--;
                            recordQueue.Add(record);
                        }
                        if (loopDepth == 0 && recordQueue.Count > 0)
                        {
                            //处理循环记录
                            ProcessLoopRocord(respContent, recordQueue, msgReader);
                            recordQueue.Clear();
                        }

                        if (loopDepth == 0)
                        {
                            if (NetHelper.GetFieldValue(msgReader, fieldType, ref fieldValue))
                            {
                                //自动登录
                                if (NetHelper.LoginActionId.IndexOf(contractId.ToString(), StringComparison.OrdinalIgnoreCase) != -1)
                                {
                                    if ("SessionID".Equals(fieldName, StringComparison.OrdinalIgnoreCase)) sid = fieldValue;
                                    if ("UserID".Equals(fieldName, StringComparison.OrdinalIgnoreCase)) uid = fieldValue;
                                }
                                respContent.Append("<tr>");
                                respContent.AppendFormat("<td>&nbsp;{0}</td>", fieldName);
                                respContent.AppendFormat("<td>&nbsp;{0}</td>", fieldType);
                                respContent.AppendFormat("<td>&nbsp;{0}</td>", fieldValue);
                                respContent.Append("</tr>");
                            }
                            if (fieldType == FieldType.Record)
                            {
                                loopDepth++;
                                recordQueue.Add(record);
                            }
                        }
                        else if (fieldType != FieldType.End)
                        {
                            if (fieldType == FieldType.Record)
                            {
                                loopDepth++;
                            }
                            recordQueue.Add(record);
                        }
                    }
                    catch (Exception ex)
                    {
                        respContent.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", fieldName, fieldType, ex.ToString());
                    }

                }
                #endregion

                respContent.Append("</table>");

            }
        }
Пример #32
0
 protected override void SuccessCallback(MessageStructure writer, MessageHead head)
 {
 }
Пример #33
0
 protected virtual void FailCallback(MessageHead head)
 {
     string msg = string.Format("出错:{0}-{1}", head.ErrorCode, head.ErrorInfo);
     _context.Response.Write(new JsonObject().Add("state", false).Add("message", msg).ToJson());
 }
Пример #34
0
 protected virtual void SuccessCallback(MessageStructure writer, MessageHead head)
 {
 }
Пример #35
0
        private static void ProcessResult(int contractId, int slnId, StringBuilder respContent, MessageHead msg, MessageStructure msgReader, out string sid, out string uid)
        {
            sid = "";
            uid = "";
            //头部消息
            respContent.AppendFormat("<h3>{0}-{1}</h3>", contractId, "基本消息");
            respContent.Append("<table style=\"width:90%; border-color:#999\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">");
            respContent.Append("<tr><td style=\"width:25%;\"><strong>状态值</strong></td>");
            respContent.Append("<td style=\"width:75%;\"><strong>描述</strong></td></tr>");
            respContent.AppendFormat("<tr><td>{0}</td>", msg.ErrorCode);
            respContent.AppendFormat("<td>{0}&nbsp;</td></tr>", msg.ErrorInfo);
            respContent.Append("</table>");

            if (msg.ErrorCode != ErrorCode)
            {
                var respRecords = GetResponseFields(contractId, slnId);

                //消息体
                respContent.AppendFormat("<h3>{0}-{1}</h3>", contractId, "返回结果");
                respContent.Append("<table style=\"width:90%; border-color:#999\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">");
                respContent.Append("<tr><td style=\"width:15%;\"><strong>参数</strong></td><td style=\"width:10%;\"><strong>类型</strong></td>");
                respContent.Append("<td style=\"width:75%;\"><strong>参数值</strong></td></tr>");
                int loopDepth = 0;//循环深度
                List<ParamInfoModel> recordQueue = new List<ParamInfoModel>();
                #region 循环体
                foreach (var record in respRecords)
                {
                    string fieldName = record.Field;
                    FieldType fieldType = record.FieldType;
                    string fieldValue = "";
                    try
                    {
                        if (loopDepth > 0 && fieldType == FieldType.End)
                        {
                            loopDepth--;
                            recordQueue.Add(record);
                        }
                        if (loopDepth == 0 && recordQueue.Count > 0)
                        {
                            //处理循环记录
                            ProcessLoopRocord(respContent, recordQueue, msgReader);
                            recordQueue.Clear();
                        }

                        if (loopDepth == 0)
                        {
                            if (NetHelper.GetFieldValue(msgReader, fieldType, ref fieldValue))
                            {
                                //自动登录
                                if ("1004".Equals(contractId))
                                {
                                    if ("SessionID".Equals(fieldName)) sid = fieldValue;
                                    if ("UserID".Equals(fieldName)) uid = fieldValue;
                                }
                                respContent.Append("<tr>");
                                respContent.AppendFormat("<td>&nbsp;{0}</td>", fieldName);
                                respContent.AppendFormat("<td>&nbsp;{0}</td>", fieldType);
                                respContent.AppendFormat("<td>&nbsp;{0}</td>", fieldValue);
                                respContent.Append("</tr>");
                            }
                            if (fieldType == FieldType.Record)
                            {
                                loopDepth++;
                                recordQueue.Add(record);
                            }
                        }
                        else if (fieldType != FieldType.End)
                        {
                            if (fieldType == FieldType.Record)
                            {
                                loopDepth++;
                            }
                            recordQueue.Add(record);
                        }
                    }
                    catch (Exception ex)
                    {
                        respContent.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", fieldName, fieldType, ex.ToString());
                    }

                }
                #endregion

                respContent.Append("</table>");

            }
        }
Пример #36
0
 /// <summary>
 /// 读取消息头,如果有Gzip压缩时自动解压字节流
 /// </summary>
 /// <returns></returns>
 public MessageHead ReadHeadGzip()
 {
     MessageHead head = new MessageHead();
     head.HasGzip = true;
     head.PacketLength = Length;
     //head.GzipLength = ReadInt();
     if (CheckGzipBuffer())
     {
         byte[] gzipData = ReadBuffer();
         //格式500+gzip( 1000+ XXXXXX)
         byte[] deZipData = GzipUtils.DeCompress(gzipData, 0, gzipData.Length);
         WriteByte(deZipData);
     }
     head.TotalLength = ReadInt();
     head.ErrorCode = ReadInt();
     head.MsgId = ReadInt();
     head.ErrorInfo = ReadString();
     head.Action = ReadInt();
     head.St = ReadString();
     return head;
 }