public void DoRequest() { byte[] linkBytes = EaseString.DefaultEncoding.GetBytes("http://118.123.205.218:888/blbook/index.aspx"); PageV21Request instance = new PageV21Request { ESP_Link = new EaseString { ESP_Length = (ushort)linkBytes.Length, ESP_Data = linkBytes }, ESP_Header = RequestHeader.RequestHeader4Test }; //ServiceConfig Config = ServiceConfig.GetByServiceID(1); byte[] testBytes = instance.GetNetworkBytes(); //Console.WriteLine("Total:{0}\r\n{1}", testBytes.ESP_Length, testBytes.GetHexViewString()); PageV21Request instanceCmp = new PageV21Request(); 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)); }
/// <summary> /// 根据网关传递信息获取转发的请求封装[TODO] /// </summary> /// <returns></returns> public RequestBase GetSubRequest() { if (ESP_TransferData == null || ESP_TransferData.Length < 2) { return(null); } System.IO.MemoryStream ms = ESP_TransferData.AsMemoryStream(); RequestBase subReq = null; RequestHeader header = SpecUtil.DataBind <RequestHeader>(ms, 0); switch (header.ESP_Protocol) { case RequestType.PageV21: subReq = new PageV21Request(Context); break; case RequestType.Mixed: subReq = new MixedRequest(Context); break; case RequestType.Page: subReq = new PageRequest(Context); break; case RequestType.Resource: subReq = new ResourceRequest(Context); break; case RequestType.Application: subReq = new ApplicationRequest(Context); break; case RequestType.UpdateCenter: subReq = new GatewayUpdateRequest(Context); break; case RequestType.SynServerAddress: subReq = new SynServerAddressRequest(Context); break; default: subReq = new ApplicationRequest(Context); break; } if (subReq != null) { subReq.ESP_Header = header; SpecUtil.BindFromNetworkStream(subReq, ms, ms.Position, false, 1); subReq.ContentRange[0] = 0; subReq.ContentRange[1] = ESP_TransferData.LongLength - 1; } ms.Dispose(); return(subReq); }