Exemplo 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>();
 }
Exemplo n.º 2
0
        ///// <summary>
        ///// 作为自身基类的相关属性绑定
        ///// </summary>
        ///// <typeparam name="TEntity">The type of the entity.</typeparam>
        //protected BindBuilder SubClassPropertyBindAction<TEntity>()
        //    where TEntity : PackageResponse
        //{
        //    return BindBuilder.Instance()
        //            .Add((TEntity resp) => resp.ESP_PackageData,
        //                (s, obj) =>
        //                {
        //                    TEntity cResp = (TEntity)obj;
        //                    cResp.ESP_PackageData = s.ReadNetworkStreamBytes(cResp.ESP_PackageLength);
        //                    return cResp.ESP_PackageData;
        //                });
        //}

        /// <summary>
        /// 填充绑定词典
        /// </summary>
        public override void CustomPropertyBindAction()
        {
            BindBuilder.Instance()
            .Add((PackageResponse h) => h.ESP_PackageBytes,      //分包数据
                 (s, p, obj) =>
            {
                PackageResponse instance = (PackageResponse)obj;
                PropertyBindState state  = new PropertyBindState();
                if (instance.ESP_PackageLength > 0)
                {
                    state.StreamBind          = true;
                    instance.ESP_PackageBytes = s.ReadNetworkStreamBytes(instance.ESP_PackageLength);
                    state.PropertyValue       = instance.ESP_PackageBytes;
                }
                return(state);
            })
            .End <PackageResponse>();
        }
Exemplo n.º 3
0
 /// <summary>
 /// 填充绑定词典
 /// </summary>
 public override void CustomPropertyBindAction()
 {
     //ParamsCount : 18, 20, 21
     BindBuilder.Instance()
     .Add((RequestHeader h) => h.ESP_ScreenWidth,      //屏幕宽度
          (s, p, obj) =>
     {
         RequestHeader instance  = (RequestHeader)obj;
         PropertyBindState state = new PropertyBindState();
         if (instance.ESP_ParamsCount > 18)
         {
             state.StreamBind         = true;
             instance.ESP_ScreenWidth = s.ReadNetworkStreamAsEntity <short>(2);
             state.PropertyValue      = instance.ESP_ScreenWidth;
         }
         return(state);
     })
     .Add((RequestHeader h) => h.ESP_ScreenHeight,       //屏幕高度
          (s, p, obj) =>
     {
         RequestHeader instance  = (RequestHeader)obj;
         PropertyBindState state = new PropertyBindState();
         if (instance.ESP_ParamsCount > 18)
         {
             state.StreamBind          = true;
             instance.ESP_ScreenHeight = s.ReadNetworkStreamAsEntity <short>(2);
             state.PropertyValue       = instance.ESP_ScreenHeight;
         }
         return(state);
     })
     .Add((RequestHeader h) => h.ESP_DID,       //设备ID
          (s, p, obj) =>
     {
         RequestHeader instance  = (RequestHeader)obj;
         PropertyBindState state = new PropertyBindState();
         if (instance.ESP_SuccessFlag == EaseSuccessFlag.Success ||
             instance.ESP_SuccessFlag == EaseSuccessFlag.SuccessUserAgent)
         {
             state.StreamBind    = true;
             instance.ESP_DID    = s.ReadNetworkStreamAsEntity <int>(4);
             state.PropertyValue = instance.ESP_DID;
         }
         return(state);
     })
     .Add((RequestHeader h) => h.ESP_UserAgent,       //设备UserAgent(2010-9-2, Ridge)
          (s, p, obj) =>
     {
         RequestHeader instance  = (RequestHeader)obj;
         PropertyBindState state = new PropertyBindState();
         if (instance.ESP_SuccessFlag == EaseSuccessFlag.SuccessUserAgent)
         {
             state.StreamBind       = true;
             instance.ESP_UserAgent = s.ReadNetworkStreamAsEntity <EaseString>();
             state.PropertyValue    = instance.ESP_UserAgent;
         }
         return(state);
     }).Add((RequestHeader h) => h.ESP_DailType,       //拨号方式
            (s, p, obj) =>
     {
         RequestHeader instance  = (RequestHeader)obj;
         PropertyBindState state = new PropertyBindState();
         if (instance.ESP_ParamsCount > 20)
         {
             state.StreamBind      = true;
             instance.ESP_DailType = s.ReadNetworkStreamAsEntity <ClientDialType>(1);
             state.PropertyValue   = instance.ESP_DailType;
         }
         return(state);
     })
     .Add((RequestHeader h) => h.ESP_Protocol,       //请求功能号
          (s, p, obj) =>
     {
         RequestHeader instance  = (RequestHeader)obj;
         PropertyBindState state = new PropertyBindState();
         instance.ESP_Protocol   = s.ReadNetworkStreamAsEntity <RequestType>(1);
         state.PropertyValue     = instance.ESP_Protocol;
         state.StreamBind        = true;
         return(state);
     })
     .End <RequestHeader>();
 }
Exemplo n.º 4
0
 /// <summary>
 /// 填充绑定词典
 /// </summary>
 public override void CustomPropertyBindAction()
 {
     BindBuilder.Instance()
     .Add((NetworkSwitchRequest req) => req.ESP_SocketParamCount,     //SOCKET头参数个数(7)
          (s, p, obj) =>
     {
         NetworkSwitchRequest cRequest = (NetworkSwitchRequest)obj;
         PropertyBindState state       = new PropertyBindState();
         if (cRequest.ESP_SuccessFlag == EaseSuccessFlag.Success || cRequest.ESP_SuccessFlag == EaseSuccessFlag.SuccessUserAgent)
         {
             state.StreamBind = true;
             cRequest.ESP_SocketParamCount = s.ReadNetworkStreamAsEntity <short>(2);
             state.PropertyValue           = cRequest.ESP_SocketParamCount;
         }
         return(state);
     })
     .Add((NetworkSwitchRequest req) => req.ESP_EncodeType,        //客户端编码(9)
          (s, p, obj) =>
     {
         NetworkSwitchRequest cRequest = (NetworkSwitchRequest)obj;
         PropertyBindState state       = new PropertyBindState();
         if (cRequest.ESP_SuccessFlag == EaseSuccessFlag.Success || cRequest.ESP_SuccessFlag == EaseSuccessFlag.SuccessUserAgent)
         {
             state.StreamBind        = true;
             cRequest.ESP_EncodeType = s.ReadNetworkStreamAsEntity <EaseEncode>(1);
             state.PropertyValue     = cRequest.ESP_EncodeType;
         }
         return(state);
     })
     .Add((NetworkSwitchRequest req) => req.ESP_DataIndex,        //返回数据起始位置(11)
          (s, p, obj) =>
     {
         NetworkSwitchRequest cRequest = (NetworkSwitchRequest)obj;
         PropertyBindState state       = new PropertyBindState();
         if (cRequest.ESP_SuccessFlag == EaseSuccessFlag.Success || cRequest.ESP_SuccessFlag == EaseSuccessFlag.SuccessUserAgent)
         {
             state.StreamBind       = true;
             cRequest.ESP_DataIndex = s.ReadNetworkStreamAsEntity <int>(4);
             state.PropertyValue    = cRequest.ESP_DataIndex;
         }
         return(state);
     })
     .Add((NetworkSwitchRequest req) => req.ESP_DateEndIndex,        //数据终止位置(13)
          (s, p, obj) =>
     {
         NetworkSwitchRequest cRequest = (NetworkSwitchRequest)obj;
         PropertyBindState state       = new PropertyBindState();
         if (cRequest.ESP_SuccessFlag == EaseSuccessFlag.Success || cRequest.ESP_SuccessFlag == EaseSuccessFlag.SuccessUserAgent)
         {
             state.StreamBind          = true;
             cRequest.ESP_DateEndIndex = s.ReadNetworkStreamAsEntity <int>(4);
             state.PropertyValue       = cRequest.ESP_DateEndIndex;
         }
         return(state);
     })
     .Add((NetworkSwitchRequest req) => req.ESP_AppServerID,        //应用服务器的地址ID(15)
          (s, p, obj) =>
     {
         NetworkSwitchRequest cRequest = (NetworkSwitchRequest)obj;
         PropertyBindState state       = new PropertyBindState();
         if (cRequest.ESP_SuccessFlag == EaseSuccessFlag.Success || cRequest.ESP_SuccessFlag == EaseSuccessFlag.SuccessUserAgent)
         {
             state.StreamBind         = true;
             cRequest.ESP_AppServerID = s.ReadNetworkStreamAsEntity <short>(2);
             state.PropertyValue      = cRequest.ESP_AppServerID;
         }
         return(state);
     })
     .Add((NetworkSwitchRequest req) => req.ESP_Link,        //请求链接(17)
          (s, p, obj) =>
     {
         NetworkSwitchRequest cRequest = (NetworkSwitchRequest)obj;
         //45
         PropertyBindState state = new PropertyBindState();
         if (cRequest.ESP_SuccessFlag == EaseSuccessFlag.Success || cRequest.ESP_SuccessFlag == EaseSuccessFlag.SuccessUserAgent)
         {
             state.StreamBind    = true;
             cRequest.ESP_Link   = s.DataBind <EaseString>(p);
             state.PropertyValue = cRequest.ESP_Link;
         }
         return(state);
     })
     .Add((NetworkSwitchRequest req) => req.ESP_TransferLength,        //应用请求数据(19)
          (s, p, obj) =>
     {
         NetworkSwitchRequest cRequest = (NetworkSwitchRequest)obj;
         PropertyBindState state       = new PropertyBindState();
         if (cRequest.ESP_SuccessFlag == EaseSuccessFlag.Success || cRequest.ESP_SuccessFlag == EaseSuccessFlag.SuccessUserAgent)
         {
             state.StreamBind            = true;
             cRequest.ESP_TransferLength = s.ReadNetworkStreamAsEntity <int>(4);
             state.PropertyValue         = cRequest.ESP_TransferLength;
         }
         return(state);
     })
     .Add((NetworkSwitchRequest req) => req.ESP_TransferData,        /*ESP_TransferData*/
          (s, p, obj) =>
     {
         NetworkSwitchRequest cRequest = (NetworkSwitchRequest)obj;
         int readLen = (cRequest.ESP_SuccessFlag == EaseSuccessFlag.Success || cRequest.ESP_SuccessFlag == EaseSuccessFlag.SuccessUserAgent) ? cRequest.ESP_TransferLength : cRequest.ESP_LeaveLength;
         cRequest.ESP_TransferData = s.ReadNetworkStreamBytes(readLen, true);
         return(new PropertyBindState {
             PropertyValue = cRequest.ESP_TransferData, StreamBind = true
         });
     })
     .End <NetworkSwitchRequest>();
 }