Ejemplo n.º 1
0
 /// <summary>
 /// 填充绑定词典
 /// </summary>
 public override void CustomPropertyBindAction()
 {
     BindBuilder.Instance()
     .Add((NetworkSwitchResponse resp) => resp.ESP_DataTotalLength,    //应用服务器返回数据总长度(7)
          (s, p, obj) =>
     {
         NetworkSwitchResponse cResponse = (NetworkSwitchResponse)obj;
         PropertyBindState state         = new PropertyBindState();
         if (cResponse.ESP_SuccessFlag == EaseSuccessFlag.Success || cResponse.ESP_SuccessFlag == EaseSuccessFlag.SuccessUserAgent)
         {
             state.StreamBind = true;
             cResponse.ESP_DataTotalLength = s.ReadNetworkStreamAsEntity <int>(4);
             state.PropertyValue           = cResponse.ESP_DataTotalLength;
         }
         return(state);
     })
     .Add((NetworkSwitchResponse resp) => resp.ESP_DataIndex,     //本次需返回数据起始位置(首字节从0开始)(9)
          (s, p, obj) =>
     {
         NetworkSwitchResponse cResponse = (NetworkSwitchResponse)obj;
         PropertyBindState state         = new PropertyBindState();
         if (cResponse.ESP_SuccessFlag == EaseSuccessFlag.Success || cResponse.ESP_SuccessFlag == EaseSuccessFlag.SuccessUserAgent)
         {
             state.StreamBind        = true;
             cResponse.ESP_DataIndex = s.ReadNetworkStreamAsEntity <int>(4);
             state.PropertyValue     = cResponse.ESP_DataIndex;
         }
         return(state);
     })
     .Add((NetworkSwitchResponse resp) => resp.ESP_DateEndIndex,     //本次需返回数据终止位置(0 – 不断点续传)(11)
          (s, p, obj) =>
     {
         NetworkSwitchResponse cResponse = (NetworkSwitchResponse)obj;
         PropertyBindState state         = new PropertyBindState();
         if (cResponse.ESP_SuccessFlag == EaseSuccessFlag.Success || cResponse.ESP_SuccessFlag == EaseSuccessFlag.SuccessUserAgent)
         {
             state.StreamBind           = true;
             cResponse.ESP_DateEndIndex = s.ReadNetworkStreamAsEntity <int>(4);
             state.PropertyValue        = cResponse.ESP_DateEndIndex;
         }
         return(state);
     })
     .Add((NetworkSwitchResponse resp) => resp.ESP_TransferData,       /*ESP_TransferData*/
          (s, p, obj) =>
     {
         NetworkSwitchResponse cResponse = (NetworkSwitchResponse)obj;
         int targetLen = cResponse.ESP_LeaveLength;
         if (cResponse.ESP_SuccessFlag == EaseSuccessFlag.Success || cResponse.ESP_SuccessFlag == EaseSuccessFlag.SuccessUserAgent)
         {
             targetLen = cResponse.ESP_LeaveLength - 4 * 3;
         }
         //System.Diagnostics.Trace.WriteLine(string.Format("Target:{0}", targetLen), "DEBUG");
         cResponse.ESP_TransferData = s.ReadNetworkStreamBytes(targetLen, true);
         return(new PropertyBindState {
             StreamBind = true, PropertyValue = cResponse.ESP_TransferData
         });
     })
     .End <NetworkSwitchResponse>();
 }
Ejemplo n.º 2
0
        public void DoTest()
        {
            int i = 0;

start:

            NetworkSwitchResponse response = new NetworkSwitchResponse();

            response.ESP_SuccessFlag = (i == 0) ? EaseSuccessFlag.SuccessExpress : EaseSuccessFlag.Success;
            response.ESP_CustomCode  = 0;

            response.ESP_TransferData = Encoding.UTF8.GetBytes("123456");

            if (response.ESP_SuccessFlag == EaseSuccessFlag.Success)
            {
                #region 设置完整参数
                response.ESP_DataTotalLength = 100;
                response.ESP_DataIndex       = 0;
                response.ESP_DateEndIndex    = 0;
                #endregion
            }

            if (response.ESP_SuccessFlag == EaseSuccessFlag.SuccessExpress)
            {
                response.ESP_LeaveLength = response.ESP_TransferData.Length;
            }
            else
            {
                response.ESP_LeaveLength = response.ESP_TransferData.Length + 4 * 3; //后续长度
            }
            //Console.WriteLine("后续长度:{0}", response.ESP_LeaveLength);

            byte[] networkBytes = response.GetNetworkBytes();

            //Console.WriteLine("Total:{0}\r\n{1}", networkBytes.ESP_Length, networkBytes.GetHexViewString());

            NetworkSwitchResponse response2 = new NetworkSwitchResponse();
            MemoryStream          ms        = new MemoryStream(networkBytes);
            ms.Position = 0;
            response2.BindFromNetworkStream(ms, 0, false);

            //Console.WriteLine("########################################");
            //Console.WriteLine(response2.GetNetworkBytes().GetHexViewString());
            //Console.WriteLine("########################################");

            ms.Dispose();

            Assert.That(SpecUtil.AreEqual(response2.GetNetworkBytes(), networkBytes));

            i++;

            if (i < 2)
            {
                //Console.WriteLine("\r\n下一次测试:\r\n");
                goto start;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取无效的网关数数据回复
        /// </summary>
        /// <param name="request">网关请求对象</param>
        /// <param name="bizRespBytes">业务返回字节数</param>
        public static NetworkSwitchResponse GetInvalidSwitchResponse(NetworkSwitchRequest request, byte[] bizRespBytes)
        {
            NetworkSwitchResponse resp = new NetworkSwitchResponse();

            resp.ESP_SuccessFlag = EaseSuccessFlag.Error;

            resp.ESP_CustomCode  = request.ESP_CustomeCode;
            resp.ESP_LeaveLength = bizRespBytes.Length;

            if (request.ESP_SuccessFlag != EaseSuccessFlag.SuccessExpress)
            {
                resp.ESP_DataTotalLength = bizRespBytes.Length;
                resp.ESP_DataIndex       = 0;
                resp.ESP_DateEndIndex    = 0;
                resp.ESP_LeaveLength    += 4 * 3;
            }

            resp.ESP_TransferData = bizRespBytes;
            return(resp);
        }