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)) { if (StringComparer.OrdinalIgnoreCase.Equals(request.Method, "POST") && requestStream != null) { // convert the batched call into a regular url context.UnBatch(); } V3InteropTraceSources.ShimController.Verbose("dispatching", "Dispatching {0} {1}", request.Method, request.RequestUri.AbsoluteUri); var t = Task.Run(async() => await dispatcher.Invoke(context)); t.Wait(); var stream = context.Data; timer.Stop(); V3InteropTraceSources.ShimController.Verbose("dispatched", "Dispatched {0} {1} in {2}ms", request.Method, request.RequestUri.AbsoluteUri, timer.ElapsedMilliseconds); 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); }
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; } } }
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); }
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) { V3InteropTraceSources.ShimController.Verbose("request", "{0} {1}", args.Method, args.RequestUri.AbsoluteUri); message = new HttpWebRequestMessage(args); } return(message); }
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; }
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)) { if (StringComparer.OrdinalIgnoreCase.Equals(request.Method, "POST") && requestStream != null) { // convert the batched call into a regular url context.UnBatch(); } V3InteropTraceSources.ShimController.Verbose("dispatching", "Dispatching {0} {1}", request.Method, request.RequestUri.AbsoluteUri); var t = Task.Run(async () => await dispatcher.Invoke(context)); t.Wait(); var stream = context.Data; timer.Stop(); V3InteropTraceSources.ShimController.Verbose("dispatched", "Dispatched {0} {1} in {2}ms", request.Method, request.RequestUri.AbsoluteUri, timer.ElapsedMilliseconds); 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; }
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; } } }