Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="ioService"></param>
        /// <param name="uri"></param>
        /// <param name="accept"></param>
        /// <returns></returns>
        public static TextReader Create(IIOService ioService, Uri uri, MediaRangeList accept)
        {
            Contract.Requires <ArgumentNullException>(ioService != null);
            Contract.Requires <ArgumentNullException>(uri != null);

            return(Create(ioService, uri, accept, null));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="ioService"></param>
        /// <param name="uri"></param>
        /// <param name="accept"></param>
        public static TextReader Create(IIOService ioService, Uri uri, MediaRangeList accept, Encoding encoding)
        {
            Contract.Requires <ArgumentNullException>(ioService != null);
            Contract.Requires <ArgumentNullException>(uri != null);

            var request = new IORequest(uri, IOMethod.Get)
            {
                Accept = accept,
            };

            var response = ioService.Send(request);

            if (response.Status != IOStatus.Success)
            {
                throw new IOException();
            }

            if (!response.ContentType.Matches(accept))
            {
                throw new IOException();
            }

            if (encoding != null)
            {
                return(new IOTextReader(uri, response.Content, encoding));
            }
            else
            {
                return(new IOTextReader(uri, response.Content));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="ioService"></param>
        /// <param name="uri"></param>
        /// <param name="accept"></param>
        public static XmlReader Create(IIOService ioService, Uri uri, MediaRangeList accept)
        {
            Contract.Requires <ArgumentNullException>(ioService != null);
            Contract.Requires <ArgumentNullException>(uri != null);

            // default acceptable media types
            accept = !accept.IsEmpty ? accept : XML_MEDIA_RANGES;

            // format request
            var request = new IORequest(uri, IOMethod.Get)
            {
                Accept = accept,
            };

            // get response
            var response = ioService.Send(request);

            if (response.Status != IOStatus.Success)
            {
                throw new XmlException();
            }

            // acceptable response?
            if (!response.ContentType.Matches(accept))
            {
                throw new XmlException();
            }

            return(new IOXmlReader(uri, response.Content));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="ioService"></param>
        /// <param name="uri"></param>
        /// <param name="accept"></param>
        public static XmlReader Create(IIOService ioService, Uri uri, MediaRangeList accept)
        {
            Contract.Requires<ArgumentNullException>(ioService != null);
            Contract.Requires<ArgumentNullException>(uri != null);

            // default acceptable media types
            accept = !accept.IsEmpty ? accept : XML_MEDIA_RANGES;

            // format request
            var request = new IORequest(uri, IOMethod.Get)
            {
                Accept = accept,
            };

            // get response
            var response = ioService.Send(request);
            if (response.Status != IOStatus.Success)
                throw new XmlException();

            // acceptable response?
            if (!response.ContentType.Matches(accept))
                throw new XmlException();

            return new IOXmlReader(uri, response.Content);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="ioService"></param>
        /// <param name="uri"></param>
        /// <param name="accept"></param>
        public static TextReader Create(IIOService ioService, Uri uri, MediaRangeList accept, Encoding encoding)
        {
            Contract.Requires<ArgumentNullException>(ioService != null);
            Contract.Requires<ArgumentNullException>(uri != null);

            var request = new IORequest(uri, IOMethod.Get)
            {
                Accept = accept,
            };

            var response = ioService.Send(request);
            if (response.Status != IOStatus.Success)
                throw new IOException();

            if (!response.ContentType.Matches(accept))
                throw new IOException();

            if (encoding != null)
                return new IOTextReader(uri, response.Content, encoding);
            else
                return new IOTextReader(uri, response.Content);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="ioService"></param>
        /// <param name="uri"></param>
        /// <param name="accept"></param>
        /// <returns></returns>
        public static TextReader Create(IIOService ioService, Uri uri, MediaRangeList accept)
        {
            Contract.Requires<ArgumentNullException>(ioService != null);
            Contract.Requires<ArgumentNullException>(uri != null);

            return Create(ioService, uri, accept, null);
        }