コード例 #1
0
ファイル: ShimController.cs プロジェクト: pratikkagda/nuget
        private ShimWebResponse CallDispatcher(InterceptDispatcher dispatcher, WebRequest request, MemoryStream requestStream)
        {
            ShimWebResponse response = null;

            _lastUsedDispatcher = dispatcher;

            Stopwatch timer = new Stopwatch();

            timer.Start();

            try
            {
                using (var context = new ShimCallContext(request, requestStream, _debugLogger))
                {
                    if (StringComparer.OrdinalIgnoreCase.Equals(request.Method, "POST") && requestStream != null)
                    {
                        // convert the batched call into a regular url
                        context.UnBatch();
                    }

                    Log(String.Format(CultureInfo.InvariantCulture, "[V3 RUN] {0}", request.RequestUri.AbsoluteUri), ConsoleColor.Yellow);

                    var t = Task.Run(async() => await dispatcher.Invoke(context));
                    t.Wait();

                    var stream = context.Data;

                    timer.Stop();

                    Log(String.Format(CultureInfo.InvariantCulture, "[V3 END] {0}ms", timer.ElapsedMilliseconds), ConsoleColor.Yellow);

                    response = new ShimWebResponse(stream, request.RequestUri, context.ResponseContentType, context.StatusCode);
                }
            }
            catch (AggregateException ex)
            {
                // unwrap the exception to get a useful error
                var innerException = ExceptionUtility.Unwrap(ex);

                // TODO: throw a DataServiceQueryException with the correct xml
                throw innerException;
            }

            return(response);
        }
コード例 #2
0
ファイル: ShimController.cs プロジェクト: pratikkagda/nuget
        private static void CallDispatcherForMetrics(InterceptDispatcher dispatcher, WebRequest request)
        {
            if (dispatcher != null)
            {
                try
                {
                    // do not wait for this
                    Task.Run(async() => await dispatcher.ReportMetrics(request));
                }
                catch (AggregateException ex)
                {
                    // unwrap the exception to get a useful error
                    var innerException = ExceptionUtility.Unwrap(ex);

                    // TODO: throw a DataServiceQueryException with the correct xml
                    throw innerException;
                }
            }
        }
コード例 #3
0
ファイル: ShimController.cs プロジェクト: pratikkagda/nuget
        public WebResponse ShimResponse(WebRequest request, MemoryStream requestStream)
        {
            Debug.Assert(request != null);
            WebResponse response = null;

            // pass the request to the interceptors
            if (!TryGetInterceptorResponse(request, requestStream, out response))
            {
                // Not handled by an interceptor, allow V2 to continue
                response = CallV2(request);

                // The metrics for downloads may come through on the CDN url, which is not handled
                // by the dispatcher. We need to give it a chance to log this info.
                CallDispatcherForMetrics(_lastUsedDispatcher, request);

                _lastUsedDispatcher = null;
            }

            return(response);
        }
コード例 #4
0
ファイル: ShimController.cs プロジェクト: directhex/nuget
        /// <summary>
        /// Entry point for requests from OData.
        /// </summary>
        public DataServiceClientRequestMessage ShimDataService(DataServiceClientRequestMessageArgs args)
        {
            DataServiceClientRequestMessage message = null;

            InterceptDispatcher dispatcher = GetDispatcher(args.RequestUri);

            if (dispatcher != null && dispatcher.Initialized == true)
            {
                // Let the interceptor handle this
                message = new ShimDataServiceClientRequestMessage(this, args);
            }

            // If no interceptors want the message create a normal HttpWebRequestMessage
            if (message == null)
            {
                Log(String.Format(CultureInfo.InvariantCulture, "[V2 REQ] {0}", args.RequestUri.AbsoluteUri), ConsoleColor.Gray);
                message = new HttpWebRequestMessage(args);
            }

            return(message);
        }
コード例 #5
0
ファイル: ShimController.cs プロジェクト: directhex/nuget
        private ShimWebResponse CallDispatcher(InterceptDispatcher dispatcher, WebRequest request)
        {
            ShimWebResponse response = null;

            Stopwatch timer = new Stopwatch();

            timer.Start();

            try
            {
                using (var context = new ShimCallContext(request, _debugLogger))
                {
                    Log(String.Format(CultureInfo.InvariantCulture, "[V3 RUN] {0}", request.RequestUri.AbsoluteUri), ConsoleColor.Yellow);

                    var t = Task.Run(async() => await dispatcher.Invoke(context));
                    t.Wait();

                    var stream = context.Data;

                    timer.Stop();

                    Log(String.Format(CultureInfo.InvariantCulture, "[V3 END] {0}ms", timer.ElapsedMilliseconds), ConsoleColor.Yellow);

                    response = new ShimWebResponse(stream, request.RequestUri, context.ResponseContentType);
                }
            }
            catch (AggregateException ex)
            {
                // unwrap the exception to get a useful error
                var innerException = ExceptionUtility.Unwrap(ex);

                // TODO: throw a DataServiceQueryException with the correct xml
                throw innerException;
            }

            return(response);
        }
コード例 #6
0
ファイル: ShimController.cs プロジェクト: rikoe/nuget
        public WebResponse ShimResponse(WebRequest request, MemoryStream requestStream)
        {
            Debug.Assert(request != null);
            WebResponse response = null;

            // pass the request to the interceptors
            if (!TryGetInterceptorResponse(request, requestStream, out response))
            {
                // Not handled by an interceptor, allow V2 to continue
                response = CallV2(request);

                // The metrics for downloads may come through on the CDN url, which is not handled
                // by the dispatcher. We need to give it a chance to log this info.
                CallDispatcherForMetrics(_lastUsedDispatcher, request);

                _lastUsedDispatcher = null;
            }

            return response;
        }
コード例 #7
0
ファイル: ShimController.cs プロジェクト: rikoe/nuget
        private ShimWebResponse CallDispatcher(InterceptDispatcher dispatcher, WebRequest request, MemoryStream requestStream)
        {
            ShimWebResponse response = null;
            _lastUsedDispatcher = dispatcher;

            Stopwatch timer = new Stopwatch();
            timer.Start();

            try
            {
                using (var context = new ShimCallContext(request, requestStream, _debugLogger))
                {
                    if (StringComparer.OrdinalIgnoreCase.Equals(request.Method, "POST") && requestStream != null)
                    {
                        // convert the batched call into a regular url
                        context.UnBatch();
                    }

                    Log(String.Format(CultureInfo.InvariantCulture, "[V3 RUN] {0}", request.RequestUri.AbsoluteUri), ConsoleColor.Yellow);

                    var t = Task.Run(async () => await dispatcher.Invoke(context));
                    t.Wait();

                    var stream = context.Data;

                    timer.Stop();

                    Log(String.Format(CultureInfo.InvariantCulture, "[V3 END] {0}ms", timer.ElapsedMilliseconds), ConsoleColor.Yellow);

                    response = new ShimWebResponse(stream, request.RequestUri, context.ResponseContentType, context.StatusCode);
                }
            }
            catch (AggregateException ex)
            {
                // unwrap the exception to get a useful error
                var innerException = ExceptionUtility.Unwrap(ex);

                // TODO: throw a DataServiceQueryException with the correct xml
                throw innerException;
            }

            return response;
        }
コード例 #8
0
ファイル: ShimController.cs プロジェクト: rikoe/nuget
        private static void CallDispatcherForMetrics(InterceptDispatcher dispatcher, WebRequest request)
        {
            if (dispatcher != null)
            {
                try
                {
                    // do not wait for this
                    Task.Run(async () => await dispatcher.ReportMetrics(request));
                }
                catch (AggregateException ex)
                {
                    // unwrap the exception to get a useful error
                    var innerException = ExceptionUtility.Unwrap(ex);

                    // TODO: throw a DataServiceQueryException with the correct xml
                    throw innerException;
                }
            }
        }