Пример #1
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     if (disposing)
     {
         _stream?.Dispose();
         _stream = null;
         var reader = _readerFactory?.Invoke() as IDisposable;
         reader?.Dispose();
         _readerFactory = null;
     }
 }
Пример #2
0
        internal static Stream Seekable(this Stream data)
        {
            if (data.CanSeek)
            {
                data.Position = 0;
                return(data);
            }

            var trib = new MemoryTributary();

            data.CopyTo(trib);
            trib.Position = 0;
            return(trib);
        }
Пример #3
0
        private Stream EnsureStream()
        {
            if (_stream != null)
            {
                return(_stream);
            }

            _stream = new MemoryTributary();
            using (var writer = XmlWriter.Create(_stream, new XmlWriterSettings()
            {
                OmitXmlDeclaration = true
            }))
            {
                var reader = _readerFactory();
                writer.WriteNode(reader, false);
            }
            return(_stream);
        }
Пример #4
0
        private HttpResponseMsg CreateResponseMessage(HttpWebResponse webResponse, HttpRequestMessage request)
        {
            var httpResponseMessage = new HttpResponseMsg(webResponse.StatusCode);

            httpResponseMessage.ReasonPhrase   = webResponse.StatusDescription;
            httpResponseMessage.Version        = webResponse.ProtocolVersion;
            httpResponseMessage.RequestMessage = request;

            var content = new MemoryTributary();

            using (var stream = webResponse.GetResponseStream())
            {
                stream.CopyTo(content);
            }
            content.Position = 0;

            httpResponseMessage.Content = new ResponseContent(content);
            request.RequestUri          = webResponse.ResponseUri;
            WebHeaderCollection headers  = webResponse.Headers;
            HttpContentHeaders  headers2 = httpResponseMessage.Content.Headers;
            HttpResponseHeaders headers3 = httpResponseMessage.Headers;

            if (webResponse.ContentLength >= 0L)
            {
                headers2.ContentLength = new long?(webResponse.ContentLength);
            }

            for (int i = 0; i < headers.Count; i++)
            {
                string key = headers.GetKey(i);
                if (string.Compare(key, "Content-Length", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    string[] values = headers.GetValues(i);
                    if (!headers3.TryAddWithoutValidation(key, values))
                    {
                        bool flag = headers2.TryAddWithoutValidation(key, values);
                    }
                }
            }
            webResponse.Close();
            return(httpResponseMessage);
        }
Пример #5
0
 public ResponseContent(MemoryTributary content) : base(content)
 {
     _content = content;
 }