예제 #1
0
        internal override void DeseralizeFromStream()
        {
            DiagnoseHelper.CheckReference(ResponseStream, "Can not get response stream");

            ResponseStream.Seek(0, SeekOrigin.Begin);

            ContentTypeEntity ct = new ContentTypeEntity(OriginalResponse.ContentType);

            int contentLen = (int)OriginalResponse.ContentLength;

            //DiagnoseHelper.CheckStringIgnoreCase(ct.ContentType, HttpLayer.JSonContentType, "Login response content type is not correct");
            byte[] buffer = null;
            if (contentLen != -1)
            {
                buffer = new byte[contentLen];

                int leftLen = contentLen;

                while (leftLen != 0)
                {
                    int readLen = ResponseStream.Read(buffer, 0, leftLen);
                    leftLen -= readLen;

                    if (leftLen != 0)
                    {
                        LogHelper.OnlineLogger.Debug("ToDo:: can not read all data in once, need to sleep!" + HttpLayer.LogRequetId(ResponseId));
                    }
                }
            }
            else
            {
                List <byte> buffList   = new List <byte>();
                int         tempBufLen = 10 * 1024;
                byte[]      bufTemp    = new byte[tempBufLen];

                int readLen = 0;
                while ((readLen = ResponseStream.Read(bufTemp, 0, tempBufLen)) != 0)
                {
                    if (readLen == tempBufLen)
                    {
                        buffList.AddRange(bufTemp);
                    }
                    else
                    {
                        buffList.AddRange(bufTemp.Take(readLen));
                    }
                }

                buffer = buffList.ToArray();

                contentLen = buffList.Count;
            }

            string sResult = ct.Encoding.GetString(buffer, 0, contentLen);

            DiagnoseHelper.CheckString(sResult, "Login response content is empty");

            this.Object = JsonConvert.DeserializeObject <JObject>(sResult);
        }
        public string ReadResponseString()
        {
            // We do NOT put a using clause around this or dispose of the StreamReader
            // because that would dispose of the underlying stream, preventing this
            // method from being called again.
            StreamReader sr          = new StreamReader(ResponseStream, Encoding.GetEncoding(ContentEncoding));
            long         oldPosition = ResponseStream.Position;
            string       result      = sr.ReadToEnd();

            ResponseStream.Seek(oldPosition, SeekOrigin.Begin);
            return(result);
        }
예제 #3
0
 public override long Seek(long offset, SeekOrigin origin)
 {
     return(ResponseStream.Seek(offset, origin));
 }