Ejemplo n.º 1
0
        public IWebResponse Invoke(Ds3Request request)
        {
            int redirectCount = 0;

            using (var content = request.GetContentStream())
            {
                do
                {
                    if (sdkNetworkSwitch.TraceInfo) { Trace.WriteLine(string.Format(Resources.RequestLogging, request.GetType().ToString())); }
                    if (sdkNetworkSwitch.TraceVerbose) { Trace.WriteLine(request.getDescription(BuildQueryParams(request.QueryParams))); }

                    HttpWebRequest httpRequest = CreateRequest(request, content);
                    try
                    {
                        long send = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                        var response = new WebResponse((HttpWebResponse)httpRequest.GetResponse());
                        long millis = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - send;
                        if (Is307(response))
                        {
                            redirectCount++;
                            if (sdkNetworkSwitch.TraceWarning) { Trace.Write(string.Format(Resources.Encountered307NTimes, redirectCount), "Ds3Network"); }
                        }
                        else
                        {
                            if (sdkNetworkSwitch.TraceInfo) { Trace.WriteLine(string.Format(Resources.ResponseLogging, response.StatusCode.ToString(), millis)); }
                            return response;
                        }
                    }
                    catch (WebException e)
                    {
                        if (e.Response == null)
                        {
                            throw e;
                        }
                        return new WebResponse((HttpWebResponse)e.Response);
                    }
                } while (redirectCount < _maxRedirects);
            }

            throw new Ds3RedirectLimitException(Resources.TooManyRedirectsException);
        }
Ejemplo n.º 2
0
        public IWebResponse Invoke(Ds3Request request)
        {
            var redirectCount = 0;

            using (var content = request.GetContentStream())
            {
                do
                {
                    if (SdkNetworkSwitch.TraceInfo) { Trace.WriteLine(string.Format(Resources.RequestLogging, request.GetType())); }
                    if (SdkNetworkSwitch.TraceVerbose) { Trace.WriteLine(request.getDescription(BuildQueryParams(request.QueryParams))); }

                    Ds3ServerCertificateValidation.OverrideValidation();

                    var ds3WebRequest = _createDs3WebRequestFunc(request, content);
                    try
                    {
                        var send = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                        var response = ds3WebRequest.GetResponse();
                        var millis = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - send;
                        if (Is307(response))
                        {
                            redirectCount++;
                            if (SdkNetworkSwitch.TraceWarning) { Trace.Write(string.Format(Resources.Encountered307NTimes, redirectCount), "Ds3Network"); }
                        }
                        else
                        {
                            if (SdkNetworkSwitch.TraceInfo) { Trace.WriteLine(string.Format(Resources.ResponseLogging, response.StatusCode, millis)); }
                            return response;
                        }
                    }
                    catch (WebException e)
                    {
                        if (e.Response == null)
                        {
                            throw;
                        }
                        return new Ds3WebResponse((HttpWebResponse)e.Response);
                    }
                } while (redirectCount < _redirectRetryCount);
            }

            throw new Ds3RedirectLimitException(Resources.TooManyRedirectsException, redirectCount);
        }