Example #1
0
        public void DoTest()
        {
            ResourcePartialResponse instance = new ResourcePartialResponse();

            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_PackageIndex      = 1;
            instance.ESP_LeavePackageCount = 0;

            //instance.ESP_PackageData = Encoding.ASCII.GetBytes("12345678");
            //instance.ESP_PackageLength = instance.ESP_PackageData.Length;


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

            ResourcePartialResponse instanceCmp = new ResourcePartialResponse();

            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));
        }
Example #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);
        }