示例#1
0
        public void DoTest()
        {
            GatewayUpdateResponse instance = new GatewayUpdateResponse();

            instance.ESP_Header = ResponseHeader.ResponseHeader4Test;
            instance.ESP_Code   = StatusCode.Success;
            byte[] msgBytes = EaseString.DefaultEncoding.GetBytes("OK");
            instance.ESP_Message = new EaseString {
                ESP_Data = msgBytes, ESP_Length = (ushort)msgBytes.Length
            };
            instance.ESP_Method = CommandType.None;
            byte[] cmdBytes = EaseString.DefaultEncoding.GetBytes("GET / HTTP/1.1");
            instance.ESP_Command = new EaseString {
                ESP_Data = cmdBytes, ESP_Length = (ushort)cmdBytes.Length
            };

            byte[] linkDat = EaseString.DefaultEncoding.GetBytes("http://www.easegateway.com:7001/ease/servlet/ease");
            instance.ESP_HttpAddress = new EaseString {
                ESP_Data = linkDat, ESP_Length = (ushort)linkDat.Length
            };

            byte[] socketDat = EaseString.DefaultEncoding.GetBytes("10.199.112.14:9010");
            instance.ESP_SocketAddress = new EaseString {
                ESP_Data = socketDat, ESP_Length = (ushort)socketDat.Length
            };


            byte[] testBytes = instance.GetNetworkBytes();
            //Console.WriteLine("Total:{0}\r\n{1}", testBytes.ESP_Length, testBytes.GetHexViewString());

            GatewayUpdateResponse instanceCmp = new GatewayUpdateResponse();

            System.IO.MemoryStream ms = new System.IO.MemoryStream(testBytes);
            ms.Position = 0;
            instanceCmp.BindFromNetworkStream(ms, 0, false);

            byte[] bytes2cmp = instanceCmp.GetNetworkBytes();
            //Console.WriteLine("Cmp Total:{0}\r\n{1}", bytes2cmp.ESP_Length, bytes2cmp.GetHexViewString());

            Assert.That(SpecUtil.AreEqual(testBytes, bytes2cmp));
        }
示例#2
0
        /// <summary>
        /// 获取返回包装对象子类(6种Response对象中的一种)
        /// </summary>
        /// <returns></returns>
        public ESPDataBase GetSubResponse(RequestBase request)
        {
            RequestType requestType = request.ESP_Header.ESP_Protocol;
            ESPDataBase resp        = null;

            System.IO.MemoryStream ms = ESP_TransferData.AsMemoryStream();
            switch (requestType)
            {
            case RequestType.PageV21:
                resp = new PageV21Response(Context);
                break;

            case RequestType.Mixed:
                resp = new MixedResponse(Context);
                break;

            case RequestType.Page:
                resp = new PageResponse(Context);
                break;

            case RequestType.Resource:
                ResourceRequest resReq = request as ResourceRequest;
                if (!resReq.IsPackageReqeust())
                {
                    resp = new ResourcePartialResponse(Context);
                }
                else
                {
                    resp = new ResourceResponse(Context);
                }
                break;

            case RequestType.Application:
                ApplicationRequest appReq = request as ApplicationRequest;
                if (!appReq.IsPackageReqeust())
                {
                    resp = new ApplicationResponse(Context);
                }
                else
                {
                    resp = new ApplicationPartialResponse(Context);
                }
                break;

            case RequestType.UpdateCenter:
                resp = new GatewayUpdateResponse(Context);
                break;

            case RequestType.SynServerAddress:
                resp = new SynServerAddressResponse(Context);
                break;

            default:
                break;
            }

            SpecUtil.BindFromNetworkStream(resp, ms, ms.Position, false, 0);
            resp.ContentRange[0] = 0;
            resp.ContentRange[1] = ESP_TransferData.LongLength - 1;
            ms.Close();
            ms.Dispose();

            return(resp);
        }