Пример #1
0
        /// <summary>
        /// Gets a cacheable response.
        /// </summary>
        /// <exception cref="RallyUnavailableException">Rally returned an HTML page. This usually occurs when Rally is off-line. Please check the ErrorMessage property for more information.</exception>
        /// <exception cref="RallyFailedToDeserializeJson">The JSON returned by Rally was not able to be deserialized. Please check the JsonData property for what was returned by Rally.</exception>
        internal DynamicJsonObject GetCacheable(Uri target, out bool isCachedResult, IDictionary <string, string> headers = null)
        {
            DynamicJsonObject response        = null;
            DateTime          startTime       = DateTime.Now;
            String            requestHeaders  = "";
            String            responseHeaders = "";

            try
            {
                using (var webClient = GetWebClient(headers, true))
                {
                    requestHeaders = webClient.Headers.ToString();
                    CookieAwareCacheableWebClient cacheableWeb = webClient as CookieAwareCacheableWebClient;
                    if (cacheableWeb != null)
                    {
                        response = cacheableWeb.DownloadCacheableResult(target, out isCachedResult);
                    }
                    else
                    {
                        throw new InvalidOperationException("GetWebClient failed to create a CookieAwareCacheableWebClient");
                    }

                    responseHeaders = webClient.ResponseHeaders.ToString();
                    return(response);
                }
            }
            finally
            {
                TraceHelper.TraceHttpMessage("GET", startTime, target, requestHeaders, response, responseHeaders);
            }
        }
        /// <summary>
        /// Gets a cacheable response.
        /// </summary>
        /// <exception cref="RallyUnavailableException">Rally returned an HTML page. This usually occurs when Rally is off-line. Please check the ErrorMessage property for more information.</exception>
        /// <exception cref="RallyFailedToDeserializeJson">The JSON returned by Rally was not able to be deserialized. Please check the JsonData property for what was returned by Rally.</exception>
        internal DynamicJsonObject GetCacheable(Uri target, out bool isCachedResult, IDictionary <string, string> headers = null)
        {
            DynamicJsonObject response        = null;
            DateTime          startTime       = DateTime.Now;
            String            requestHeaders  = "";
            String            responseHeaders = "";

            try
            {
                using (var webClient = GetWebClient(headers, true))
                {
                    requestHeaders = webClient.Headers.ToString();
                    CookieAwareCacheableWebClient cacheableWeb = webClient as CookieAwareCacheableWebClient;
                    if (cacheableWeb != null)
                    {
                        response = cacheableWeb.DownloadCacheableResult(target, out isCachedResult);
                    }
                    else
                    {
                        throw new InvalidOperationException("GetWebClient failed to create a CookieAwareCacheableWebClient");
                    }

                    responseHeaders = webClient.ResponseHeaders.ToString();
                    return(response);
                }
            }
            finally
            {
                Trace.TraceInformation("Get ({0}):\r\n{1}\r\nRequest Headers:\r\n{2}Response Headers:\r\n{3}Response Data\r\n{4}",
                                       DateTime.Now.Subtract(startTime).ToString(),
                                       target.ToString(),
                                       requestHeaders,
                                       responseHeaders,
                                       response);
            }
        }