Exemple #1
0
        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);
        }
Exemple #2
0
        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;
                }
            }
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        /// <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);
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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;
        }
Exemple #7
0
        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;
        }
Exemple #8
0
        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;
                }
            }
        }