Esempio n. 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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;
        }