コード例 #1
0
ファイル: IOTextReader.cs プロジェクト: tvoyle/nxkit
        /// <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));
        }
コード例 #2
0
ファイル: IOTextReader.cs プロジェクト: tvoyle/nxkit
        /// <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));
            }
        }
コード例 #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));
        }
コード例 #4
0
ファイル: IOXmlReader.cs プロジェクト: nxkit/nxkit
        /// <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);
        }
コード例 #5
0
ファイル: IOTextReader.cs プロジェクト: nxkit/nxkit
        /// <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);
        }
コード例 #6
0
ファイル: IOTextReader.cs プロジェクト: nxkit/nxkit
        /// <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);
        }