コード例 #1
0
        /// <summary>
        /// Gets the result.
        /// </summary>
        /// <param name="requestBaseUrl">The request base URL.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="response">The response from the server.</param>
        /// <returns></returns>
        private static DownloadResult <Image> GetImage(Uri requestBaseUrl, Stream stream,
                                                       HttpResponseMessage response)
        {
            Image image = null;
            HttpWebClientServiceException error = null;
            int      responseCode = (int)response.StatusCode;
            DateTime serverTime   = response.Headers.ServerTimeUTC();

            if (stream == null)
            {
                error = HttpWebClientServiceException.Exception(requestBaseUrl, new ArgumentNullException(nameof(stream)));
                return(new DownloadResult <Image>(null, error, responseCode, serverTime));
            }

            try
            {
                image = Image.FromStream(Util.ZlibUncompress(stream), true);
            }
            catch (ArgumentException ex)
            {
                error = HttpWebClientServiceException.ImageException(requestBaseUrl, ex);
            }

            return(new DownloadResult <Image>(image, error, responseCode, serverTime));
        }
コード例 #2
0
        /// <summary>
        /// Gets the result.
        /// </summary>
        /// <param name="requestBaseUrl">The request base URL.</param>
        /// <param name="stream">The stream.</param>
        /// <returns></returns>
        private static DownloadResult <Image> GetImage(Uri requestBaseUrl, Stream stream)
        {
            Image image = null;
            HttpWebClientServiceException error = null;

            if (stream == null)
            {
                error = HttpWebClientServiceException.Exception(requestBaseUrl, new ArgumentNullException(nameof(stream)));
                return(new DownloadResult <Image>(null, error));
            }

            try
            {
                image = Image.FromStream(Util.ZlibUncompress(stream), true);
            }
            catch (ArgumentException ex)
            {
                error = HttpWebClientServiceException.ImageException(requestBaseUrl, ex);
            }

            return(new DownloadResult <Image>(image, error));
        }